Skip to content

Commit

Permalink
NPCBots: Fix being unable to equip a set with mh + oh if currently wi…
Browse files Browse the repository at this point in the history
…elding a two-handed weapon

(cherry picked from commit c7ebc08779617e4f16e99ded506d986c77179e51)
  • Loading branch information
trickerer committed Nov 18, 2024
1 parent 1d5d058 commit 603e2b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9944,7 +9944,7 @@ bool bot_ai::OnGossipSelect(Player* player, Creature* creature/* == me*/, uint32
ItemTemplate const* set_item_proto = sObjectMgr->GetItemTemplate(itemset_items[i]); // validated at load
if (!available_items.contains(itemset_items[i]) || available_items.at(itemset_items[i]).empty())
check_res = BotEquipResult::BOT_EQUIP_RESULT_FAIL_NO_ITEM;
else if (!_canEquip(set_item_proto, i, true, *available_items.at(itemset_items[i]).cbegin()))
else if (!_canEquip(set_item_proto, i, true, *available_items.at(itemset_items[i]).cbegin(), true))
check_res = BotEquipResult::BOT_EQUIP_RESULT_FAIL_CANT_EQUIP;
else
{
Expand Down Expand Up @@ -9997,6 +9997,7 @@ bool bot_ai::OnGossipSelect(Player* player, Creature* creature/* == me*/, uint32
{
std::string err_code = Bcore::ToString(uint32(AsUnderlyingType(res)));
BotWhisper(LocalizedNpcText(player, BOT_TEXT_FAILED) + " -" + Bcore::ToString(uint32(i)) + " (" + err_code + ")");
break;
}
}
}
Expand Down Expand Up @@ -12209,7 +12210,7 @@ void bot_ai::_autoLootCreature(Creature* creature)
//////////
//EQUIPS//
//////////
bool bot_ai::_canUseOffHand(ItemTemplate const* with/* = nullptr*/) const
bool bot_ai::_canUseOffHand(ItemTemplate const* with/* = nullptr*/, bool ignore_mh/* = false*/) const
{
//bm can on only equip in main hand
if (_botclass == BOT_CLASS_BM)
Expand All @@ -12228,6 +12229,9 @@ bool bot_ai::_canUseOffHand(ItemTemplate const* with/* = nullptr*/) const
if (_botclass == BOT_CLASS_WARRIOR && me->GetLevel() >= 60 && GetSpec() == BOT_SPEC_WARRIOR_FURY)
return true;

if (ignore_mh)
return true;

ItemTemplate const* protoMH = with ? with : _equips[BOT_SLOT_MAINHAND] ? _equips[BOT_SLOT_MAINHAND]->GetTemplate() : nullptr;

//no mainhand weapon OR
Expand Down Expand Up @@ -12262,10 +12266,10 @@ bool bot_ai::_canUseRelic() const

bool bot_ai::_canCombineWeapons(ItemTemplate const* mh, ItemTemplate const* oh) const
{
return _canEquip(mh, BOT_SLOT_MAINHAND, true) && _canEquip(oh, BOT_SLOT_OFFHAND, true) && _canUseOffHand(mh);
return _canEquip(mh, BOT_SLOT_MAINHAND, true, nullptr, true) && _canEquip(oh, BOT_SLOT_OFFHAND, true, nullptr, true) && _canUseOffHand(mh);
}

bool bot_ai::_canEquip(ItemTemplate const* newProto, uint8 slot, bool ignoreItemLevel, Item const* newItem) const
bool bot_ai::_canEquip(ItemTemplate const* newProto, uint8 slot, bool ignoreItemLevel, Item const* newItem/* = nullptr*/, bool ignore_combine/* = false*/) const
{
EquipmentInfo const* einfo = BotDataMgr::GetBotEquipmentInfo(me->GetEntry());

Expand All @@ -12283,7 +12287,7 @@ bool bot_ai::_canEquip(ItemTemplate const* newProto, uint8 slot, bool ignoreItem
return false;
}

if (slot == BOT_SLOT_OFFHAND && !_canUseOffHand())
if (slot == BOT_SLOT_OFFHAND && !_canUseOffHand(nullptr, ignore_combine))
return false;

//level requirements
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/NpcBots/bot_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@ class bot_ai : public CreatureAI
void _autoLootCreatureItems(Player* receiver, Creature* creature, uint32 lootQualityMask, uint32 lootThreshold) const;
void _autoLootCreature(Creature* creature);

bool _canUseOffHand(ItemTemplate const* with = nullptr) const;
bool _canUseOffHand(ItemTemplate const* with = nullptr, bool ignore_mh = false) const;
bool _canUseRanged() const;
bool _canUseRelic() const;
bool _canCombineWeapons(ItemTemplate const* mh, ItemTemplate const* oh) const;
bool _canEquip(ItemTemplate const* newProto, uint8 slot, bool ignoreItemLevel, Item const* newItem = nullptr) const;
bool _canEquip(ItemTemplate const* newProto, uint8 slot, bool ignoreItemLevel, Item const* newItem = nullptr, bool ignore_combine = false) const;
void _removeEquipment(uint8 slot);
[[nodiscard]] BotEquipResult _unequip(uint8 slot, ObjectGuid receiver, bool store_to_bank, bool on_equip_from_bank = false);
[[nodiscard]] BotEquipResult _equip(uint8 slot, Item* newItem, ObjectGuid receiver, bool store_to_bank, bool from_bank = false);
Expand Down

0 comments on commit 603e2b5

Please sign in to comment.