From 5feb47d5edaf5ecf031675b9a013062edc36e28b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 8 Aug 2023 18:24:59 +0800 Subject: [PATCH] fix ammo cache, enchant coredump --- src/PlayerbotAI.cpp | 2 +- src/RandomItemMgr.cpp | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index cb8e42cc..943a746b 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4013,7 +4013,7 @@ void PlayerbotAI::ImbueItem(Item* item, uint32 targetFlag, ObjectGuid targetGUID void PlayerbotAI::EnchantItemT(uint32 spellid, uint8 slot) { Item* pItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); - if (!pItem || !pItem->IsInWorld()) + if (!pItem || !pItem->IsInWorld() || !pItem->GetOwner() || !pItem->GetOwner()->IsInWorld() || !pItem->GetOwner()->GetSession()) return; SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellid); diff --git a/src/RandomItemMgr.cpp b/src/RandomItemMgr.cpp index 8269b845..eddea0de 100644 --- a/src/RandomItemMgr.cpp +++ b/src/RandomItemMgr.cpp @@ -3,6 +3,7 @@ */ #include "RandomItemMgr.h" +#include "ItemTemplate.h" #include "LootValues.h" #include "Playerbots.h" @@ -951,6 +952,10 @@ void RandomItemMgr::BuildItemInfoCache() continue; } + if (proto->Flags & ITEM_FLAG_DEPRECATED) { + itemForTest.insert(proto->ItemId); + continue; + } // skip items with rank/rep requirements /*if (proto->RequiredHonorRank > 0 || proto->RequiredSkillRank > 0 || @@ -2179,17 +2184,23 @@ void RandomItemMgr::BuildAmmoCache() uint32 counter = 0; for (uint32 level = 1; level <= maxLevel; level += 1) { - for (uint32 subClass = ITEM_SUBCLASS_ARROW; subClass <= ITEM_SUBCLASS_THROWN; subClass++) + for (uint32 subClass = ITEM_SUBCLASS_ARROW; subClass <= ITEM_SUBCLASS_BULLET; subClass++) { - QueryResult results = WorldDatabase.Query("SELECT entry FROM item_template WHERE class = {} AND subclass = {} AND RequiredLevel <= {} " - "ORDER BY RequiredLevel DESC, Quality DESC, ItemLevel DESC", ITEM_CLASS_PROJECTILE, subClass, level); + QueryResult results = WorldDatabase.Query("SELECT entry, Flags FROM item_template WHERE class = {} AND subclass = {} AND RequiredLevel <= {} AND stackable = 1000 " + "ORDER BY RequiredLevel DESC", ITEM_CLASS_PROJECTILE, subClass, level); if (!results) - return; - - Field* fields = results->Fetch(); - uint32 entry = fields[0].Get(); - ammoCache[level][subClass] = entry; - ++counter; + continue; + do { + Field* fields = results->Fetch(); + uint32 entry = fields[0].Get(); + uint32 flags = fields[1].Get(); + if (flags & ITEM_FLAG_DEPRECATED) { + continue; + } + ammoCache[level][subClass] = entry; + ++counter; + break; + } while (results->NextRow()); } }