fix ammo cache, enchant coredump

This commit is contained in:
Yunfan Li
2023-08-08 18:24:59 +08:00
parent 863248b3f3
commit 5feb47d5ed
2 changed files with 21 additions and 10 deletions

View File

@@ -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);

View File

@@ -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<uint32>();
ammoCache[level][subClass] = entry;
++counter;
continue;
do {
Field* fields = results->Fetch();
uint32 entry = fields[0].Get<uint32>();
uint32 flags = fields[1].Get<uint32>();
if (flags & ITEM_FLAG_DEPRECATED) {
continue;
}
ammoCache[level][subClass] = entry;
++counter;
break;
} while (results->NextRow());
}
}