From 73f699fe8983a65e08d0cee165950003f8a340a4 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 5 Sep 2024 15:57:32 +0800 Subject: [PATCH] Fix initself crash --- src/PlayerbotAI.cpp | 1 + src/factory/PlayerbotFactory.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 5df7402b..0504b6b7 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -5257,6 +5257,7 @@ bool PlayerbotAI::EqualLowercaseName(std::string s1, std::string s2) return true; } +// A custom CanEquipItem (remove AutoUnequipOffhand in FindEquipSlot to prevent unequip on `item usage` calculation) InventoryResult PlayerbotAI::CanEquipItem(uint8 slot, uint16& dest, Item* pItem, bool swap, bool not_loading) const { dest = 0; diff --git a/src/factory/PlayerbotFactory.cpp b/src/factory/PlayerbotFactory.cpp index 47db56b6..a6dc88b7 100644 --- a/src/factory/PlayerbotFactory.cpp +++ b/src/factory/PlayerbotFactory.cpp @@ -2060,7 +2060,8 @@ bool PlayerbotFactory::CanEquipUnseenItem(uint8 slot, uint16& dest, uint32 item) if (Item* pItem = Item::CreateItem(item, 1, bot, false, 0, true)) { - InventoryResult result = botAI->CanEquipItem(slot, dest, pItem, true, true); + InventoryResult result = botAI ? botAI->CanEquipItem(slot, dest, pItem, true, true) + : bot->CanEquipItem(slot, dest, pItem, true, true); pItem->RemoveFromUpdateQueueOf(bot); delete pItem; return result == EQUIP_ERR_OK; @@ -2382,10 +2383,10 @@ void PlayerbotFactory::InitAvailableSpells() { bot->learnSpell(tSpell->learnedSpell[0], false); } - else - { - botAI->CastSpell(tSpell->spell, bot); - } + // else + // { + // botAI->CastSpell(tSpell->spell, bot); + // } } // LOG_INFO("playerbots", "C: {}, ok: {}", ++learnedCounter, oktest); // if (++learnedCounter > 20)