diff --git a/src/modules/Bots/playerbot/strategy/actions/ActionContext.h b/src/modules/Bots/playerbot/strategy/actions/ActionContext.h index c24315d94..e77f3c591 100644 --- a/src/modules/Bots/playerbot/strategy/actions/ActionContext.h +++ b/src/modules/Bots/playerbot/strategy/actions/ActionContext.h @@ -71,6 +71,7 @@ namespace ai creators["move to loot"] = &ActionContext::move_to_loot; creators["open loot"] = &ActionContext::open_loot; creators["guard"] = &ActionContext::guard; + creators["goto"] = &ActionContext::goto_action; creators["move out of enemy contact"] = &ActionContext::move_out_of_enemy_contact; creators["set facing"] = &ActionContext::set_facing; creators["attack duel opponent"] = &ActionContext::attack_duel_opponent; @@ -88,6 +89,7 @@ namespace ai static Action* drop_target(PlayerbotAI* ai) { return new DropTargetAction(ai); } static Action* attack_duel_opponent(PlayerbotAI* ai) { return new AttackDuelOpponentAction(ai); } static Action* guard(PlayerbotAI* ai) { return new GuardAction(ai); } + static Action* goto_action(PlayerbotAI* ai) { return new GotoAction(ai); } static Action* open_loot(PlayerbotAI* ai) { return new OpenLootAction(ai); } static Action* move_to_loot(PlayerbotAI* ai) { return new MoveToLootAction(ai); } static Action* move_random(PlayerbotAI* ai) { return new MoveRandomAction(ai); } diff --git a/src/modules/Bots/playerbot/strategy/actions/PositionAction.cpp b/src/modules/Bots/playerbot/strategy/actions/PositionAction.cpp index ad7cedd00..0e42df440 100644 --- a/src/modules/Bots/playerbot/strategy/actions/PositionAction.cpp +++ b/src/modules/Bots/playerbot/strategy/actions/PositionAction.cpp @@ -43,3 +43,54 @@ bool MoveToPositionAction::Execute(Event event) return MoveTo(bot->GetMapId(), pos.x, pos.y, pos.z, true); } +bool GotoAction::Execute(Event event) +{ + if (!m_positionName.empty() && getMSTime() >= m_deadline) + { + m_positionName.clear(); + m_deadline = 0; + return false; + } + + string param = event.getParam(); + if (param.empty()) + { + return false; + } + + string posName = param; + uint32 seconds = 5; + size_t space = param.find(' '); + if (space != string::npos) + { + posName = param.substr(0, space); + string timeStr = param.substr(space + 1); + if (!timeStr.empty()) + { + seconds = max(1, atoi(timeStr.c_str())); + } + } + + if (posName == m_positionName) + { + return MoveTo(m_targetMapId, m_targetX, m_targetY, m_targetZ, true); + } + + ai::Position& pos = context->GetValue("position", posName)->Get(); + if (!pos.isSet()) + { + ostringstream out; out << "Position " << posName << " is not set"; + ai->TellMaster(out); + return false; + } + + m_positionName = posName; + m_targetMapId = bot->GetMapId(); + m_targetX = (float)pos.x; + m_targetY = (float)pos.y; + m_targetZ = (float)pos.z; + m_deadline = getMSTime() + seconds * 1000; + + return MoveTo(m_targetMapId, m_targetX, m_targetY, m_targetZ, true); +} + diff --git a/src/modules/Bots/playerbot/strategy/actions/PositionAction.h b/src/modules/Bots/playerbot/strategy/actions/PositionAction.h index f9b0cf678..0ba27ce57 100644 --- a/src/modules/Bots/playerbot/strategy/actions/PositionAction.h +++ b/src/modules/Bots/playerbot/strategy/actions/PositionAction.h @@ -33,4 +33,17 @@ namespace ai GuardAction(PlayerbotAI* ai) : MoveToPositionAction(ai, "guard") {} }; + + class GotoAction : public MovementAction + { + public: + GotoAction(PlayerbotAI* ai) : MovementAction(ai, "goto") {} + virtual bool Execute(Event event); + + private: + string m_positionName; + uint32 m_deadline = 0; + float m_targetX = 0, m_targetY = 0, m_targetZ = 0; + uint32 m_targetMapId = 0; + }; } diff --git a/src/modules/Bots/playerbot/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/modules/Bots/playerbot/strategy/generic/ChatCommandHandlerStrategy.cpp index d843598cd..477c2cde6 100644 --- a/src/modules/Bots/playerbot/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/modules/Bots/playerbot/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -10,6 +10,7 @@ class ChatCommandActionNodeFactoryInternal : public NamedObjectFactorypersist(3600000); + } }; void ChatCommandHandlerStrategy::InitTriggers(std::list &triggers) @@ -143,6 +151,10 @@ void ChatCommandHandlerStrategy::InitTriggers(std::list &triggers) triggers.push_back(new TriggerNode( "jump", NextAction::array(0, new NextAction("jump", relevance), NULL))); + + triggers.push_back(new TriggerNode( + "goto", + NextAction::array(0, new NextAction("goto", 1000.0f), NULL))); } ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* ai) : PassTroughStrategy(ai) @@ -180,6 +192,7 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* ai) : PassTr supported.push_back("spell"); supported.push_back("rti"); supported.push_back("position"); + supported.push_back("goto"); supported.push_back("summon"); supported.push_back("who"); supported.push_back("save mana"); diff --git a/src/modules/Bots/playerbot/strategy/triggers/ChatTriggerContext.h b/src/modules/Bots/playerbot/strategy/triggers/ChatTriggerContext.h index 4e8c81832..4772640f2 100644 --- a/src/modules/Bots/playerbot/strategy/triggers/ChatTriggerContext.h +++ b/src/modules/Bots/playerbot/strategy/triggers/ChatTriggerContext.h @@ -67,6 +67,7 @@ namespace ai creators["runaway"] = &ChatTriggerContext::runaway; creators["warning"] = &ChatTriggerContext::warning; creators["position"] = &ChatTriggerContext::position; + creators["goto"] = &ChatTriggerContext::goto_action; creators["summon"] = &ChatTriggerContext::summon; creators["who"] = &ChatTriggerContext::who; creators["save mana"] = &ChatTriggerContext::save_mana; @@ -83,6 +84,7 @@ namespace ai static Trigger* who(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "who"); } static Trigger* summon(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "summon"); } static Trigger* position(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "position"); } + static Trigger* goto_action(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "goto"); } static Trigger* runaway(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "runaway"); } static Trigger* warning(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "warning"); } static Trigger* revive(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "revive"); }