Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/ActionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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); }
Expand Down
51 changes: 51 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/PositionAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ai::Position&>("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);
}

13 changes: 13 additions & 0 deletions src/modules/Bots/playerbot/strategy/actions/PositionAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ChatCommandActionNodeFactoryInternal : public NamedObjectFactory<ActionNod
ChatCommandActionNodeFactoryInternal()
{
creators["tank attack chat shortcut"] = &tank_attack_chat_shortcut;
creators["goto"] = &goto_action;
}

private:
Expand All @@ -20,6 +21,13 @@ class ChatCommandActionNodeFactoryInternal : public NamedObjectFactory<ActionNod
/*A*/ NULL,
/*C*/ NextAction::array(0, new NextAction("attack my target", 100.0f), NULL));
}
static ActionNode* goto_action(PlayerbotAI* ai)
{
return (new ActionNode ("goto",
/*P*/ NULL,
/*A*/ NULL,
/*C*/ NULL))->persist(3600000);
}
};

void ChatCommandHandlerStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
Expand Down Expand Up @@ -143,6 +151,10 @@ void ChatCommandHandlerStrategy::InitTriggers(std::list<TriggerNode*> &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)
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"); }
Expand Down
Loading