From 71b7844fef52475bd6959e7c3ab3adba6dfe62d4 Mon Sep 17 00:00:00 2001 From: Bobblybook Date: Fri, 8 Nov 2024 20:35:31 +1100 Subject: [PATCH] Offhand equip bugfix Prevent caster bots and others who cannot dual-wield from attempting to equip weapons in their offhand --- src/strategy/actions/EquipAction.cpp | 14 +++++++++++++- src/strategy/values/ItemUsageValue.cpp | 21 ++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/strategy/actions/EquipAction.cpp b/src/strategy/actions/EquipAction.cpp index f4437e2c..f9258d77 100644 --- a/src/strategy/actions/EquipAction.cpp +++ b/src/strategy/actions/EquipAction.cpp @@ -89,9 +89,21 @@ void EquipAction::EquipItem(Item* item) if (!equippedBag) { uint8 dstSlot = botAI->FindEquipSlot(itemProto, NULL_SLOT, true); + bool have2HWeapon = false; + bool isValidTGWeapon = false; + if (dstSlot == EQUIPMENT_SLOT_MAINHAND) + { + Item* currentWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + have2HWeapon = currentWeapon && currentWeapon->GetTemplate()->InventoryType == INVTYPE_2HWEAPON; + isValidTGWeapon = itemProto->SubClass == ITEM_SUBCLASS_WEAPON_AXE2 || + itemProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE2 || + itemProto->SubClass == ITEM_SUBCLASS_WEAPON_SWORD2; + } + if (dstSlot == EQUIPMENT_SLOT_FINGER1 || dstSlot == EQUIPMENT_SLOT_TRINKET1 || - dstSlot == EQUIPMENT_SLOT_MAINHAND) + (dstSlot == EQUIPMENT_SLOT_MAINHAND && bot->CanDualWield() && + ((itemProto->InventoryType != INVTYPE_2HWEAPON && !have2HWeapon) || (bot->CanTitanGrip() && isValidTGWeapon)))) { Item* const equippedItems[2] = { bot->GetItemByPos(INVENTORY_SLOT_BAG_0, dstSlot), diff --git a/src/strategy/values/ItemUsageValue.cpp b/src/strategy/values/ItemUsageValue.cpp index 0855f707..459340c3 100644 --- a/src/strategy/values/ItemUsageValue.cpp +++ b/src/strategy/values/ItemUsageValue.cpp @@ -207,13 +207,28 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) uint8 possibleSlots = 1; uint8 dstSlot = botAI->FindEquipSlot(itemProto, NULL_SLOT, true); - if (dstSlot == EQUIPMENT_SLOT_FINGER1 || - dstSlot == EQUIPMENT_SLOT_TRINKET1 || - dstSlot == EQUIPMENT_SLOT_MAINHAND) + if (dstSlot == EQUIPMENT_SLOT_FINGER1 || dstSlot == EQUIPMENT_SLOT_TRINKET1) { possibleSlots = 2; } + // Check weapon case separately to keep things a bit cleaner + bool have2HWeapon = false; + bool isValidTGWeapon = false; + if (dstSlot == EQUIPMENT_SLOT_MAINHAND) + { + Item* currentWeapon = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + have2HWeapon = currentWeapon && currentWeapon->GetTemplate()->InventoryType == INVTYPE_2HWEAPON; + isValidTGWeapon = itemProto->SubClass == ITEM_SUBCLASS_WEAPON_AXE2 || + itemProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE2 || + itemProto->SubClass == ITEM_SUBCLASS_WEAPON_SWORD2; + + if (bot->CanDualWield() && ((itemProto->InventoryType != INVTYPE_2HWEAPON && !have2HWeapon) || (bot->CanTitanGrip() && isValidTGWeapon))) + { + possibleSlots = 2; + } + } + for (uint8 i = 0; i < possibleSlots; i++) { bool shouldEquipInSlot = shouldEquip;