From 9edddc5b26e4c960d0fa4638e5a7aab90d4120af Mon Sep 17 00:00:00 2001 From: avirar Date: Tue, 4 Mar 2025 01:09:47 +1100 Subject: [PATCH] Hunter equip bug (#1050) --- src/strategy/actions/EquipAction.cpp | 19 +++++++----- src/strategy/actions/QueryItemUsageAction.cpp | 30 ++++++++++++++++++- .../generic/ChatCommandHandlerStrategy.cpp | 3 ++ src/strategy/triggers/ChatTriggerContext.h | 2 ++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/strategy/actions/EquipAction.cpp b/src/strategy/actions/EquipAction.cpp index 1f147364..3b4c3880 100644 --- a/src/strategy/actions/EquipAction.cpp +++ b/src/strategy/actions/EquipAction.cpp @@ -132,7 +132,8 @@ void EquipAction::EquipItem(Item* item) Item* currentMHItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); bool have2HWeaponEquipped = (currentMHItem && currentMHItem->GetTemplate()->InventoryType == INVTYPE_2HWEAPON); - bool canDualWieldOrTG = (canDualWield || (canTitanGrip && isTwoHander)); + // bool canDualWieldOrTG = (canDualWield || (canTitanGrip && isTwoHander)); + bool canDualWieldOrTG = (canDualWield || isTwoHander); // If this is a weapon and we can dual wield or Titan Grip, check if we can improve main/off-hand setup if (isWeapon && canDualWieldOrTG) @@ -154,7 +155,7 @@ void EquipAction::EquipItem(Item* item) // Determine where this weapon can go bool canGoMain = (invType == INVTYPE_WEAPON || invType == INVTYPE_WEAPONMAINHAND || - (canTitanGrip && isTwoHander)); + isTwoHander); bool canTGOff = false; if (canTitanGrip && isTwoHander && isValidTGWeapon) @@ -186,7 +187,8 @@ void EquipAction::EquipItem(Item* item) // and if conditions allow (e.g. no conflicting 2H logic) bool betterThanMH = (newItemScore > mainHandScore); bool mhConditionOK = ((invType != INVTYPE_2HWEAPON && !have2HWeaponEquipped) || - (canTitanGrip && isValidTGWeapon)); + (isTwoHander && !canTitanGrip) || + (canTitanGrip && isValidTGWeapon)); if (canGoMain && betterThanMH && mhConditionOK) { @@ -288,7 +290,7 @@ void EquipAction::EquipItem(Item* item) } std::ostringstream out; - out << "equipping " << chat->FormatItem(itemProto); + out << "Equipping " << chat->FormatItem(itemProto); botAI->TellMaster(out); } @@ -318,9 +320,9 @@ bool EquipUpgradesAction::Execute(Event event) ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", i->first); if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP) { - // LOG_INFO("playerbots", "Bot {} <{}> auto equips item {} ({})", bot->GetGUID().ToString().c_str(), - // bot->GetName().c_str(), i->first, usage == 1 ? "no item in slot" : usage == 2 ? "replace" : usage == 3 ? - // "wrong item but empty slot" : ""); + // LOG_INFO("playerbots", "Bot {} <{}> EquipUpgradesAction {} ({})", bot->GetGUID().ToString().c_str(), + // bot->GetName().c_str(), i->first, usage == 1 ? "no item in slot" : usage == 2 ? "replace" : usage == 3 ? + // "wrong item but empty slot" : ""); items.insert(i->first); } } @@ -340,6 +342,9 @@ bool EquipUpgradeAction::Execute(Event event) ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", i->first); if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP) { + // LOG_INFO("playerbots", "Bot {} <{}> EquipUpgradeAction item {} ({})", bot->GetGUID().ToString().c_str(), + // bot->GetName().c_str(), i->first, usage == 1 ? "no item in slot" : usage == 2 ? "replace" : usage == 3 ? + // "wrong item but empty slot" : ""); items.insert(i->first); } } diff --git a/src/strategy/actions/QueryItemUsageAction.cpp b/src/strategy/actions/QueryItemUsageAction.cpp index d293d00d..71d46245 100644 --- a/src/strategy/actions/QueryItemUsageAction.cpp +++ b/src/strategy/actions/QueryItemUsageAction.cpp @@ -12,7 +12,35 @@ bool QueryItemUsageAction::Execute(Event event) { - return true; + std::string param = event.getParam(); + if (param.empty()) + { + return false; + } + + // Use parseItems() to extract item IDs from the input + ItemIds itemIds = chat->parseItems(param); + if (itemIds.empty()) + { + return false; + } + + // Process each extracted item ID (assuming single-item queries for now) + for (uint32 itemId : itemIds) + { + ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId); + if (!itemTemplate) + continue; + + uint32 count = GetCount(itemTemplate); + uint32 total = bot->GetItemCount(itemTemplate->ItemId, true); + std::string itemInfo = QueryItem(itemTemplate, count, total); + + botAI->TellMaster(itemInfo); + return true; // Only process the first valid item + } + + return false; } uint32 QueryItemUsageAction::GetCount(ItemTemplate const* item) diff --git a/src/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/strategy/generic/ChatCommandHandlerStrategy.cpp index 132f2423..072814a2 100644 --- a/src/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -94,6 +94,8 @@ void ChatCommandHandlerStrategy::InitTriggers(std::vector& trigger new TriggerNode("disperse", NextAction::array(0, new NextAction("disperse set", relevance), NULL))); triggers.push_back( new TriggerNode("open items", NextAction::array(0, new NextAction("open items", relevance), nullptr))); + triggers.push_back( + new TriggerNode("qi", NextAction::array(0, new NextAction("query item usage", relevance), nullptr))); } ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : PassTroughStrategy(botAI) @@ -168,4 +170,5 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : Pas supported.push_back("drink"); supported.push_back("calc"); supported.push_back("open items"); + supported.push_back("qi"); } diff --git a/src/strategy/triggers/ChatTriggerContext.h b/src/strategy/triggers/ChatTriggerContext.h index 2aef64b5..5f7ab843 100644 --- a/src/strategy/triggers/ChatTriggerContext.h +++ b/src/strategy/triggers/ChatTriggerContext.h @@ -127,6 +127,7 @@ public: creators["dps"] = &ChatTriggerContext::dps; creators["disperse"] = &ChatTriggerContext::disperse; creators["calc"] = &ChatTriggerContext::calc; + creators["qi"] = &ChatTriggerContext::qi; } private: @@ -233,6 +234,7 @@ private: static Trigger* dps(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "dps"); } static Trigger* disperse(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "disperse"); } static Trigger* calc(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "calc"); } + static Trigger* qi(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "qi"); } }; #endif