mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-15 09:50:27 +00:00
Merge pull request #569 from avirar/master
Modified TeleportAction and created OpenItemAction
This commit is contained in:
@@ -73,12 +73,14 @@
|
||||
#include "UseMeetingStoneAction.h"
|
||||
#include "WhoAction.h"
|
||||
#include "WtsAction.h"
|
||||
#include "OpenItemAction.h"
|
||||
|
||||
class ChatActionContext : public NamedObjectContext<Action>
|
||||
{
|
||||
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 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); }
|
||||
|
||||
74
src/strategy/actions/OpenItemAction.cpp
Normal file
74
src/strategy/actions/OpenItemAction.cpp
Normal file
@@ -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());
|
||||
}
|
||||
31
src/strategy/actions/OpenItemAction.h
Normal file
31
src/strategy/actions/OpenItemAction.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, 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"
|
||||
|
||||
class Player;
|
||||
class Item;
|
||||
class Event;
|
||||
|
||||
class OpenItemAction : public Action
|
||||
{
|
||||
public:
|
||||
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
|
||||
@@ -11,6 +11,54 @@
|
||||
|
||||
bool TeleportAction::Execute(Event event)
|
||||
{
|
||||
// List of allowed portal entries (you can populate this dynamically)
|
||||
std::vector<uint32> 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<GuidVector>("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<GuidVector>("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<LastMovement&>("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;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ void ChatCommandHandlerStrategy::InitTriggers(std::vector<TriggerNode*>& 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");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class ChatTriggerContext : public NamedObjectContext<Trigger>
|
||||
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"); }
|
||||
|
||||
Reference in New Issue
Block a user