From b91f6a8e15ee4c2f60aa49578b88ff5a59726fa1 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:28:44 +1000 Subject: [PATCH 1/8] Add files via upload --- src/strategy/actions/OpenItemAction.h | 20 ++++++ src/strategy/actions/OpenItemAction_v2.cpp | 74 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/strategy/actions/OpenItemAction.h create mode 100644 src/strategy/actions/OpenItemAction_v2.cpp diff --git a/src/strategy/actions/OpenItemAction.h b/src/strategy/actions/OpenItemAction.h new file mode 100644 index 00000000..2b3383de --- /dev/null +++ b/src/strategy/actions/OpenItemAction.h @@ -0,0 +1,20 @@ +#ifndef _PLAYERBOT_OPENITEMACTION_H +#define _PLAYERBOT_OPENITEMACTION_H + +#include "Action.h" +#include "Item.h" + +class PlayerbotAI; + +class OpenItemAction : public Action +{ +public: + OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") {} + + bool Execute(Event event) override; + +private: + bool CanOpenItem(Item* item); +}; + +#endif diff --git a/src/strategy/actions/OpenItemAction_v2.cpp b/src/strategy/actions/OpenItemAction_v2.cpp new file mode 100644 index 00000000..2ffa265a --- /dev/null +++ b/src/strategy/actions/OpenItemAction_v2.cpp @@ -0,0 +1,74 @@ +#include "OpenItemAction.h" +#include "PlayerbotAI.h" +#include "ItemTemplate.h" +#include "WorldPacket.h" +#include "Player.h" +#include "ObjectMgr.h" + +bool OpenItemAction::Execute(Event event) +{ + bool foundOpenable = false; + + // Check main inventory slots + for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot) + { + Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); + + if (item && CanOpenItem(item)) + { + OpenItem(item, INVENTORY_SLOT_BAG_0, slot); + foundOpenable = true; + } + } + + // Check items in the bags + for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag) + { + Bag* bagItem = bot->GetBagByPos(bag); + if (!bagItem) + continue; + + for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot) + { + Item* item = bot->GetItemByPos(bag, slot); + + if (item && CanOpenItem(item)) + { + OpenItem(item, bag, slot); + foundOpenable = true; + } + } + } + + // If no openable items found + if (!foundOpenable) + { + botAI->TellError("No openable items in inventory."); + } + + return foundOpenable; +} + +bool OpenItemAction::CanOpenItem(Item* item) +{ + if (!item) + return false; + + ItemTemplate const* itemTemplate = item->GetTemplate(); + if (!itemTemplate) + return false; + + // Check if the item has the openable flag + return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT; +} + +void OpenItemAction::OpenItem(Item* item, uint8 bag, uint8 slot) +{ + WorldPacket packet(CMSG_OPEN_ITEM); + packet << bag << slot; + bot->GetSession()->HandleOpenItemOpcode(packet); + + std::ostringstream out; + out << "Opened item: " << item->GetTemplate()->Name1; + botAI->TellMaster(out.str()); +} From 1f1dc1cdc8afce9a789aa9b2dcead107b86f6470 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:30:20 +1000 Subject: [PATCH 2/8] Update and rename OpenItemAction_v2.cpp to OpenItemAction.cpp --- .../actions/{OpenItemAction_v2.cpp => OpenItemAction.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/strategy/actions/{OpenItemAction_v2.cpp => OpenItemAction.cpp} (100%) diff --git a/src/strategy/actions/OpenItemAction_v2.cpp b/src/strategy/actions/OpenItemAction.cpp similarity index 100% rename from src/strategy/actions/OpenItemAction_v2.cpp rename to src/strategy/actions/OpenItemAction.cpp From 900b4c48b07a3da6524bac527332ef382895398f Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:37:12 +1000 Subject: [PATCH 3/8] Update TeleportAction.cpp Add alternative method for finding and using portals. Works with first boss of Sunwell Plateau, Kalecgos, using the Spectral Rifts. --- src/strategy/actions/TeleportAction.cpp | 52 ++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/TeleportAction.cpp b/src/strategy/actions/TeleportAction.cpp index 9f6ad068..acb4829a 100644 --- a/src/strategy/actions/TeleportAction.cpp +++ b/src/strategy/actions/TeleportAction.cpp @@ -11,6 +11,54 @@ bool TeleportAction::Execute(Event event) { + // List of allowed portal entries (you can populate this dynamically) + std::vector allowedPortals = { + 187055, 195142, 195141, 201797, 202079, 194481, 195682, 191164, 176498, 182351, + 178404, 176497, 181146, 184605, 176499, 195140, 193948, 193427, 193052, 193206, + 192786, 184594, 183384, 182352, 184604, 189994, 193053, 193207, 193956, 195139, + 176296, 194011, 194012, 189993, 176500, 176501, 193955, 193425, 193772, 193604, + 191006, 191007, 191008, 191009, 191013, 191014, 191010, 190960, 191011, 191012, + 183317, 183321, 183322, 187056, 183323, 183324, 183325, 183326, 183327, 190203, + 190204, 190205, 190206 + }; + + // Try teleporting using allowed portals + GuidVector closeObjects = *context->GetValue("nearest game objects no los"); + GameObject* closestPortal = nullptr; + float closestDistance = 100.0f; + + for (ObjectGuid const& guid : closeObjects) + { + GameObject* go = botAI->GetGameObject(guid); + if (!go) + continue; + + // Check if the game object entry is in the allowed portals list + if (std::find(allowedPortals.begin(), allowedPortals.end(), go->GetEntry()) != allowedPortals.end()) + { + float tempDist = bot->GetDistance(go); + + if (tempDist < closestDistance) + { + closestDistance = tempDist; + closestPortal = go; + } + } + } + + // If a nearby portal is found, use it + if (closestPortal && bot->IsWithinDistInMap(closestPortal, INTERACTION_DISTANCE)) + { + std::ostringstream out; + out << "Using portal: " << closestPortal->GetName(); + botAI->TellMasterNoFacing(out.str()); + + WorldPacket data(CMSG_GAMEOBJ_USE); + data << closestPortal->GetGUID(); + bot->GetSession()->HandleGameObjectUseOpcode(data); + return true; + } + // If no portal was found, fallback to spellcaster-type game objects GuidVector gos = *context->GetValue("nearest game objects"); for (ObjectGuid const guid : gos) { @@ -40,7 +88,8 @@ bool TeleportAction::Execute(Event event) spell->cast(true); return true; } - + + // If no game objects were found, try using the last area trigger LastMovement& movement = context->GetValue("last area trigger")->Get(); if (movement.lastAreaTrigger) { @@ -53,6 +102,7 @@ bool TeleportAction::Execute(Event event) return true; } + // If no teleport option is found botAI->TellError("Cannot find any portal to teleport"); return false; } From 53fca2b78b0b798d8b94c66caf199d27bcf71a83 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:38:58 +1000 Subject: [PATCH 4/8] Update ChatActionContext.h Added OpenItem chat handler --- src/strategy/actions/ChatActionContext.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index d56c5e6f..2f700a52 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -73,12 +73,14 @@ #include "UseMeetingStoneAction.h" #include "WhoAction.h" #include "WtsAction.h" +#include "OpenItemAction.h" class ChatActionContext : public NamedObjectContext { public: ChatActionContext() { + creators["open items"] = &ChatActionContext::open_items; creators["range"] = &ChatActionContext::range; creators["stats"] = &ChatActionContext::stats; creators["quests"] = &ChatActionContext::quests; @@ -178,6 +180,7 @@ public: } private: + static Action* open_items(PlayerbotAI* botAI) { return new OpenItemsAction(botAI); } static Action* range(PlayerbotAI* botAI) { return new RangeAction(botAI); } static Action* flag(PlayerbotAI* botAI) { return new FlagAction(botAI); } static Action* craft(PlayerbotAI* botAI) { return new SetCraftAction(botAI); } From c4d0f830a445668743c6a62cee385c8459e79350 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:40:15 +1000 Subject: [PATCH 5/8] Update ChatTriggerContext.h Added OpenItem chat command handling --- src/strategy/triggers/ChatTriggerContext.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/strategy/triggers/ChatTriggerContext.h b/src/strategy/triggers/ChatTriggerContext.h index bb05b588..af20f3a9 100644 --- a/src/strategy/triggers/ChatTriggerContext.h +++ b/src/strategy/triggers/ChatTriggerContext.h @@ -16,6 +16,7 @@ class ChatTriggerContext : public NamedObjectContext public: ChatTriggerContext() { + creators["open items"] = &ChatTriggerContext::open_items; creators["quests"] = &ChatTriggerContext::quests; creators["stats"] = &ChatTriggerContext::stats; creators["leave"] = &ChatTriggerContext::leave; @@ -128,6 +129,7 @@ public: } private: + static Trigger* open_items(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "open items"); } static Trigger* ra(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "ra"); } static Trigger* range(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "range"); } static Trigger* flag(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "flag"); } From 055f549dbd64ffc53b98c2a11038d635b480204c Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 12:41:44 +1000 Subject: [PATCH 6/8] Update ChatCommandHandlerStrategy.cpp Added OpenItem chat command handling --- src/strategy/generic/ChatCommandHandlerStrategy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/strategy/generic/ChatCommandHandlerStrategy.cpp index 58db48f5..e88ac5bb 100644 --- a/src/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -92,6 +92,8 @@ void ChatCommandHandlerStrategy::InitTriggers(std::vector& trigger new TriggerNode("dps", NextAction::array(0, new NextAction("tell estimated dps", relevance), NULL))); triggers.push_back( 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))); } ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : PassTroughStrategy(botAI) @@ -164,4 +166,5 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : Pas supported.push_back("rtsc"); supported.push_back("drink"); supported.push_back("calc"); + supported.push_back("open items"); } From ec7132bc3e4e6371d30f89097e8f05c5b5a424e0 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 13:14:13 +1000 Subject: [PATCH 7/8] Update ChatActionContext.h Removed the s --- src/strategy/actions/ChatActionContext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index 2f700a52..254dc919 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -180,7 +180,7 @@ public: } private: - static Action* open_items(PlayerbotAI* botAI) { return new OpenItemsAction(botAI); } + static Action* open_items(PlayerbotAI* botAI) { return new OpenItemAction(botAI); } static Action* range(PlayerbotAI* botAI) { return new RangeAction(botAI); } static Action* flag(PlayerbotAI* botAI) { return new FlagAction(botAI); } static Action* craft(PlayerbotAI* botAI) { return new SetCraftAction(botAI); } From ddbe4362d96632deec1131111be11a8734152430 Mon Sep 17 00:00:00 2001 From: avirar Date: Thu, 3 Oct 2024 13:39:28 +1000 Subject: [PATCH 8/8] Update OpenItemAction.h --- src/strategy/actions/OpenItemAction.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/strategy/actions/OpenItemAction.h b/src/strategy/actions/OpenItemAction.h index 2b3383de..a9ec20bd 100644 --- a/src/strategy/actions/OpenItemAction.h +++ b/src/strategy/actions/OpenItemAction.h @@ -1,20 +1,31 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, + * you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. + */ + #ifndef _PLAYERBOT_OPENITEMACTION_H #define _PLAYERBOT_OPENITEMACTION_H #include "Action.h" -#include "Item.h" -class PlayerbotAI; +class Player; +class Item; +class Event; class OpenItemAction : public Action { public: - OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") {} + OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") { } + // The main function that is executed when the action is triggered bool Execute(Event event) override; private: + // Checks if the given item can be opened (i.e., has the openable flag) bool CanOpenItem(Item* item); + + // Performs the action of opening the item + void OpenItem(Item* item, uint8 bag, uint8 slot); }; #endif