From a1dd6f6fc50426c4765b932b6686084cab36f26b Mon Sep 17 00:00:00 2001 From: Keleborn <22352763+Celandriel@users.noreply.github.com> Date: Fri, 1 Aug 2025 12:44:52 -0700 Subject: [PATCH] New roll for item action (#1482) * New roll for item action * Add general roll command as well. * Update ChatCommandHandlerStrategy.cpp Add accidental removal of glyph equip --------- Co-authored-by: bash <31279994+hermensbas@users.noreply.github.com> --- src/strategy/actions/ActionContext.h | 3 ++ src/strategy/actions/ChatActionContext.h | 3 ++ src/strategy/actions/LootRollAction.cpp | 34 +++++++++++++++++++ src/strategy/actions/LootRollAction.h | 8 +++++ .../generic/ChatCommandHandlerStrategy.cpp | 1 + src/strategy/triggers/ChatTriggerContext.h | 2 ++ 6 files changed, 51 insertions(+) diff --git a/src/strategy/actions/ActionContext.h b/src/strategy/actions/ActionContext.h index 06ee6461..832d799a 100644 --- a/src/strategy/actions/ActionContext.h +++ b/src/strategy/actions/ActionContext.h @@ -38,6 +38,7 @@ #include "InviteToGroupAction.h" #include "LeaveGroupAction.h" #include "LootAction.h" +#include "LootRollAction.h" #include "MoveToRpgTargetAction.h" #include "MoveToTravelTargetAction.h" #include "MovementActions.h" @@ -190,6 +191,7 @@ public: creators["buy tabard"] = &ActionContext::buy_tabard; creators["guild manage nearby"] = &ActionContext::guild_manage_nearby; creators["clean quest log"] = &ActionContext::clean_quest_log; + creators["roll"] = &ActionContext::roll_action; creators["cancel channel"] = &ActionContext::cancel_channel; // BG Tactics @@ -377,6 +379,7 @@ private: static Action* buy_tabard(PlayerbotAI* botAI) { return new BuyTabardAction(botAI); } static Action* guild_manage_nearby(PlayerbotAI* botAI) { return new GuildManageNearbyAction(botAI); } static Action* clean_quest_log(PlayerbotAI* botAI) { return new CleanQuestLogAction(botAI); } + static Action* roll_action(PlayerbotAI* botAI) { return new RollAction(botAI); } // BG Tactics static Action* bg_tactics(PlayerbotAI* botAI) { return new BGTactics(botAI); } diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index bc111ac6..520bc586 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -36,6 +36,7 @@ #include "ListSpellsAction.h" #include "LogLevelAction.h" #include "LootStrategyAction.h" +#include "LootRollAction.h" #include "MailAction.h" #include "NamedObjectContext.h" #include "NewRpgAction.h" @@ -193,6 +194,7 @@ public: creators["pet"] = &ChatActionContext::pet; creators["glyphs"] = &ChatActionContext::glyphs; // Added for custom Glyphs creators["glyph equip"] = &ChatActionContext::glyph_equip; // Added for custom Glyphs + creators["roll"] = &ChatActionContext::roll_action; } private: @@ -302,6 +304,7 @@ private: static Action* pet(PlayerbotAI* botAI) { return new PetAction(botAI); } static Action* glyphs(PlayerbotAI* botAI) { return new TellGlyphsAction(botAI); } // Added for custom Glyphs static Action* glyph_equip(PlayerbotAI* ai) { return new EquipGlyphsAction(ai); } // Added for custom Glyphs + static Action* roll_action(PlayerbotAI* botAI) { return new RollAction(botAI); } }; #endif diff --git a/src/strategy/actions/LootRollAction.cpp b/src/strategy/actions/LootRollAction.cpp index 53007b4e..a73e5c75 100644 --- a/src/strategy/actions/LootRollAction.cpp +++ b/src/strategy/actions/LootRollAction.cpp @@ -224,3 +224,37 @@ bool RollUniqueCheck(ItemTemplate const* proto, Player* bot) } return false; // Item is not equipped or in bags, roll for it } + +bool RollAction::Execute(Event event) +{ + std::string link = event.getParam(); + + if (link.empty()) + { + bot->DoRandomRoll(0,100); + return false; + } + ItemIds itemIds = chat->parseItems(link); + if (itemIds.empty()) + return false; + uint32 itemId = *itemIds.begin(); + ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId); + if (!proto) + { + return false; + } + std::string itemUsageParam; + itemUsageParam = std::to_string(itemId); + + ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", itemUsageParam); + switch (proto->Class) + { + case ITEM_CLASS_WEAPON: + case ITEM_CLASS_ARMOR: + if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP) + { + bot->DoRandomRoll(0,100); + } + } + return true; +} diff --git a/src/strategy/actions/LootRollAction.h b/src/strategy/actions/LootRollAction.h index bb0c3d89..2582274c 100644 --- a/src/strategy/actions/LootRollAction.h +++ b/src/strategy/actions/LootRollAction.h @@ -37,4 +37,12 @@ public: bool Execute(Event event) override; }; +class RollAction : public Action +{ +public: + RollAction(PlayerbotAI* botAI) : Action(botAI, "roll") {} + + bool Execute(Event event) override; +}; + #endif diff --git a/src/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/strategy/generic/ChatCommandHandlerStrategy.cpp index 89237eed..8c19d31a 100644 --- a/src/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -105,6 +105,7 @@ void ChatCommandHandlerStrategy::InitTriggers(std::vector& trigger triggers.push_back(new TriggerNode("pet", NextAction::array(0, new NextAction("pet", relevance), nullptr))); triggers.push_back(new TriggerNode("glyphs", NextAction::array(0, new NextAction("glyphs", relevance), nullptr))); // Added for custom Glyphs triggers.push_back(new TriggerNode("glyph equip", NextAction::array(0, new NextAction("glyph equip", relevance), nullptr))); // Added for custom Glyphs + triggers.push_back(new TriggerNode("roll", NextAction::array(0, new NextAction("roll", relevance), nullptr))); } ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : PassTroughStrategy(botAI) diff --git a/src/strategy/triggers/ChatTriggerContext.h b/src/strategy/triggers/ChatTriggerContext.h index aabbf529..7f294ce0 100644 --- a/src/strategy/triggers/ChatTriggerContext.h +++ b/src/strategy/triggers/ChatTriggerContext.h @@ -136,6 +136,7 @@ public: creators["pet"] = &ChatTriggerContext::pet; creators["glyphs"] = &ChatTriggerContext::glyphs; // Added for custom Glyphs creators["glyph equip"] = &ChatTriggerContext::glyph_equip; // Added for custom Glyphs + creators["roll"] = &ChatTriggerContext::roll_action; } private: @@ -251,6 +252,7 @@ private: static Trigger* pet(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "pet"); } static Trigger* glyphs(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "glyphs"); } // Added for custom Glyphs static Trigger* glyph_equip(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "glyph equip"); } // Added for custom Glyphs + static Trigger* roll_action(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "roll"); } }; #endif