mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
added 'move from group' action/strat/shortcut-action
This commit is contained in:
@@ -24,6 +24,7 @@ PassiveMultiplier::PassiveMultiplier(PlayerbotAI* botAI) : Multiplier(botAI, "pa
|
||||
if (allowedParts.empty())
|
||||
{
|
||||
allowedParts.push_back("follow");
|
||||
allowedParts.push_back("move from group");
|
||||
allowedParts.push_back("stay");
|
||||
allowedParts.push_back("chat shortcut");
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "MaintenanceStrategy.h"
|
||||
#include "MarkRtiStrategy.h"
|
||||
#include "MeleeCombatStrategy.h"
|
||||
#include "MoveFromGroupStrategy.h"
|
||||
#include "NamedObjectContext.h"
|
||||
#include "NonCombatStrategy.h"
|
||||
#include "PassiveStrategy.h"
|
||||
@@ -115,6 +116,7 @@ public:
|
||||
creators["aaoe"] = &StrategyContext::avoid_aoe;
|
||||
creators["move random"] = &StrategyContext::move_random;
|
||||
creators["formation"] = &StrategyContext::combat_formation;
|
||||
creators["move from group"] = &StrategyContext::move_from_group;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -179,6 +181,7 @@ private:
|
||||
static Strategy* avoid_aoe(PlayerbotAI* botAI) { return new AvoidAoeStrategy(botAI); }
|
||||
static Strategy* move_random(PlayerbotAI* ai) { return new MoveRandomStrategy(ai); }
|
||||
static Strategy* combat_formation(PlayerbotAI* ai) { return new CombatFormationStrategy(ai); }
|
||||
static Strategy* move_from_group(PlayerbotAI* botAI) { return new MoveFromGroupStrategy(botAI); }
|
||||
};
|
||||
|
||||
class MovementStrategyContext : public NamedObjectContext<Strategy>
|
||||
|
||||
@@ -115,6 +115,7 @@ public:
|
||||
creators["release loot"] = &ActionContext::release_loot;
|
||||
creators["shoot"] = &ActionContext::shoot;
|
||||
creators["follow"] = &ActionContext::follow;
|
||||
creators["move from group"] = &ActionContext::move_from_group;
|
||||
creators["flee to master"] = &ActionContext::flee_to_master;
|
||||
creators["runaway"] = &ActionContext::runaway;
|
||||
creators["stay"] = &ActionContext::stay;
|
||||
@@ -294,6 +295,7 @@ private:
|
||||
static Action* sit(PlayerbotAI* botAI) { return new SitAction(botAI); }
|
||||
static Action* runaway(PlayerbotAI* botAI) { return new RunAwayAction(botAI); }
|
||||
static Action* follow(PlayerbotAI* botAI) { return new FollowAction(botAI); }
|
||||
static Action* move_from_group(PlayerbotAI* botAI) { return new MoveFromGroupAction(botAI); }
|
||||
static Action* flee_to_master(PlayerbotAI* botAI) { return new FleeToMasterAction(botAI); }
|
||||
static Action* add_gathering_loot(PlayerbotAI* botAI) { return new AddGatheringLootAction(botAI); }
|
||||
static Action* add_loot(PlayerbotAI* botAI) { return new AddLootAction(botAI); }
|
||||
|
||||
@@ -132,6 +132,7 @@ public:
|
||||
creators["stay chat shortcut"] = &ChatActionContext::stay_chat_shortcut;
|
||||
creators["flee chat shortcut"] = &ChatActionContext::flee_chat_shortcut;
|
||||
creators["runaway chat shortcut"] = &ChatActionContext::runaway_chat_shortcut;
|
||||
creators["move from group chat shortcut"] = &ChatActionContext::move_from_group_chat_shortcut;
|
||||
creators["grind chat shortcut"] = &ChatActionContext::grind_chat_shortcut;
|
||||
creators["tank attack chat shortcut"] = &ChatActionContext::tank_attack_chat_shortcut;
|
||||
creators["gossip hello"] = &ChatActionContext::gossip_hello;
|
||||
@@ -208,6 +209,7 @@ private:
|
||||
static Action* runaway_chat_shortcut(PlayerbotAI* botAI) { return new GoawayChatShortcutAction(botAI); }
|
||||
static Action* stay_chat_shortcut(PlayerbotAI* botAI) { return new StayChatShortcutAction(botAI); }
|
||||
static Action* follow_chat_shortcut(PlayerbotAI* botAI) { return new FollowChatShortcutAction(botAI); }
|
||||
static Action* move_from_group_chat_shortcut(PlayerbotAI* botAI) { return new MoveFromGroupChatShortcutAction(botAI); }
|
||||
static Action* gb(PlayerbotAI* botAI) { return new GuildBankAction(botAI); }
|
||||
static Action* bank(PlayerbotAI* botAI) { return new BankAction(botAI); }
|
||||
static Action* help(PlayerbotAI* botAI) { return new HelpAction(botAI); }
|
||||
|
||||
@@ -33,8 +33,8 @@ bool FollowChatShortcutAction::Execute(Event event)
|
||||
return false;
|
||||
|
||||
// botAI->Reset();
|
||||
botAI->ChangeStrategy("+follow,-passive,-grind", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("-follow,-passive,-grind", BOT_STATE_COMBAT);
|
||||
botAI->ChangeStrategy("+follow,-passive,-grind,-move from group", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("-follow,-passive,-grind,-move from group", BOT_STATE_COMBAT);
|
||||
botAI->GetAiObjectContext()->GetValue<GuidVector>("prioritized targets")->Set({});
|
||||
|
||||
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
|
||||
@@ -102,8 +102,8 @@ bool StayChatShortcutAction::Execute(Event event)
|
||||
return false;
|
||||
|
||||
botAI->Reset();
|
||||
botAI->ChangeStrategy("+stay,-passive", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("-follow,-passive", BOT_STATE_COMBAT);
|
||||
botAI->ChangeStrategy("+stay,-passive,-move from group", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("-follow,-passive,-move from group", BOT_STATE_COMBAT);
|
||||
|
||||
SetReturnPosition(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ());
|
||||
|
||||
@@ -111,6 +111,21 @@ bool StayChatShortcutAction::Execute(Event event)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MoveFromGroupChatShortcutAction::Execute(Event event)
|
||||
{
|
||||
Player* master = GetMaster();
|
||||
if (!master)
|
||||
return false;
|
||||
|
||||
// dont need to remove stay or follow, move from group takes priority over both
|
||||
// (see their isUseful() methods)
|
||||
botAI->ChangeStrategy("+move from group", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("+move from group", BOT_STATE_COMBAT);
|
||||
|
||||
botAI->TellMaster("Moving away from group");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FleeChatShortcutAction::Execute(Event event)
|
||||
{
|
||||
Player* master = GetMaster();
|
||||
|
||||
@@ -35,6 +35,14 @@ public:
|
||||
bool Execute(Event event) override;
|
||||
};
|
||||
|
||||
class MoveFromGroupChatShortcutAction : public Action
|
||||
{
|
||||
public:
|
||||
MoveFromGroupChatShortcutAction(PlayerbotAI* botAI) : Action(botAI, "move from group chat shortcut") {}
|
||||
|
||||
bool Execute(Event event) override;
|
||||
};
|
||||
|
||||
class FleeChatShortcutAction : public ReturnPositionResetAction
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -48,15 +48,19 @@ bool FollowAction::Execute(Event event)
|
||||
|
||||
bool FollowAction::isUseful()
|
||||
{
|
||||
if (bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != nullptr)
|
||||
{
|
||||
// move from group takes priority over follow as it's added and removed automatically
|
||||
// (without removing/adding follow)
|
||||
if (botAI->HasStrategy("move from group", BOT_STATE_COMBAT) ||
|
||||
botAI->HasStrategy("move from group", BOT_STATE_NON_COMBAT))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != nullptr)
|
||||
return false;
|
||||
|
||||
Formation* formation = AI_VALUE(Formation*, "formation");
|
||||
if (!formation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string const target = formation->GetTargetName();
|
||||
|
||||
Unit* fTarget = nullptr;
|
||||
|
||||
@@ -1501,7 +1501,7 @@ void MovementAction::ClearIdleState()
|
||||
context->GetValue<PositionMap&>("position")->Get()["random"].Reset();
|
||||
}
|
||||
|
||||
bool MovementAction::MoveAway(Unit* target)
|
||||
bool MovementAction::MoveAway(Unit* target, float distance)
|
||||
{
|
||||
if (!target)
|
||||
{
|
||||
@@ -1511,16 +1511,16 @@ bool MovementAction::MoveAway(Unit* target)
|
||||
for (float delta = 0; delta <= M_PI / 2; delta += M_PI / 8)
|
||||
{
|
||||
float angle = init_angle + delta;
|
||||
float dx = bot->GetPositionX() + cos(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
float dy = bot->GetPositionY() + sin(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
float dx = bot->GetPositionX() + cos(angle) * distance;
|
||||
float dy = bot->GetPositionY() + sin(angle) * distance;
|
||||
float dz = bot->GetPositionZ();
|
||||
bool exact = true;
|
||||
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
|
||||
bot->GetPositionZ(), dx, dy, dz))
|
||||
{
|
||||
// disable prediction if position is invalid
|
||||
dx = bot->GetPositionX() + cos(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dy = bot->GetPositionY() + sin(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dx = bot->GetPositionX() + cos(angle) * distance;
|
||||
dy = bot->GetPositionY() + sin(angle) * distance;
|
||||
dz = bot->GetPositionZ();
|
||||
exact = false;
|
||||
}
|
||||
@@ -1534,15 +1534,15 @@ bool MovementAction::MoveAway(Unit* target)
|
||||
}
|
||||
exact = true;
|
||||
angle = init_angle - delta;
|
||||
dx = bot->GetPositionX() + cos(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dy = bot->GetPositionY() + sin(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dx = bot->GetPositionX() + cos(angle) * distance;
|
||||
dy = bot->GetPositionY() + sin(angle) * distance;
|
||||
dz = bot->GetPositionZ();
|
||||
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
|
||||
bot->GetPositionZ(), dx, dy, dz))
|
||||
{
|
||||
// disable prediction if position is invalid
|
||||
dx = bot->GetPositionX() + cos(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dy = bot->GetPositionY() + sin(angle) * sPlayerbotAIConfig->fleeDistance;
|
||||
dx = bot->GetPositionX() + cos(angle) * distance;
|
||||
dy = bot->GetPositionY() + sin(angle) * distance;
|
||||
dz = bot->GetPositionZ();
|
||||
exact = false;
|
||||
}
|
||||
@@ -1554,6 +1554,63 @@ bool MovementAction::MoveAway(Unit* target)
|
||||
return false;
|
||||
}
|
||||
|
||||
// just calculates average position of group and runs away from that position
|
||||
bool MovementAction::MoveFromGroup(float distance)
|
||||
{
|
||||
LOG_ERROR("playerbots", "MovementAction::MoveFromGroup");
|
||||
//if (Player* master = botAI->GetMaster())
|
||||
//{
|
||||
// return MoveAway(master);
|
||||
//}
|
||||
if (Group* group = bot->GetGroup())
|
||||
{
|
||||
uint32 mapId = bot->GetMapId();
|
||||
float closestDist = FLT_MAX;
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
uint32 count = 0;
|
||||
|
||||
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
|
||||
{
|
||||
Player* player = gref->GetSource();
|
||||
if (!player || player == bot || !player->IsAlive() || player->GetMapId() != mapId)
|
||||
continue;
|
||||
float dist = bot->GetDistance2d(player);
|
||||
if (closestDist > dist)
|
||||
closestDist = dist;
|
||||
x += player->GetPositionX();
|
||||
y += player->GetPositionY();
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count && closestDist < distance)
|
||||
{
|
||||
x /= count;
|
||||
y /= count;
|
||||
// x and y are now average position of the group members
|
||||
float angle = bot->GetAngle(x, y) + M_PI;
|
||||
return Move(angle, distance - closestDist);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MovementAction::Move(float angle, float distance)
|
||||
{
|
||||
float x = bot->GetPositionX() + cos(angle) * distance;
|
||||
float y = bot->GetPositionY() + sin(angle) * distance;
|
||||
|
||||
//TODO do we need GetMapWaterOrGroundLevel() if we're using CheckCollisionAndGetValidCoords() ?
|
||||
float z = bot->GetMapWaterOrGroundLevel(x, y, bot->GetPositionZ());
|
||||
if (z == -100000.0f || z == -200000.0f)
|
||||
z = bot->GetPositionZ();
|
||||
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
|
||||
bot->GetPositionZ(), x, y, z, false))
|
||||
return false;
|
||||
|
||||
return MoveTo(bot->GetMapId(), x, y, z);
|
||||
}
|
||||
|
||||
bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float distance, MovementPriority priority)
|
||||
{
|
||||
if (bot->GetDistance2d(x, y) <= distance)
|
||||
@@ -2411,3 +2468,11 @@ bool RotateAroundTheCenterPointAction::Execute(Event event)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MoveFromGroupAction::Execute(Event event)
|
||||
{
|
||||
float distance = atoi(event.getParam().c_str());
|
||||
if (!distance)
|
||||
distance = 20.0f; // flee distance from config is too small for this
|
||||
return MoveFromGroup(distance);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,9 @@ protected:
|
||||
bool Flee(Unit* target);
|
||||
void ClearIdleState();
|
||||
void UpdateMovementState();
|
||||
bool MoveAway(Unit* target);
|
||||
bool MoveAway(Unit* target, float distance = sPlayerbotAIConfig -> fleeDistance);
|
||||
bool MoveFromGroup(float distance);
|
||||
bool Move(float angle, float distance);
|
||||
bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
|
||||
void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false);
|
||||
Position BestPositionForMeleeToFlee(Position pos, float radius);
|
||||
@@ -248,4 +250,12 @@ protected:
|
||||
bool clockwise;
|
||||
std::vector<std::pair<float, float>> waypoints;
|
||||
};
|
||||
|
||||
class MoveFromGroupAction : public MovementAction
|
||||
{
|
||||
public:
|
||||
MoveFromGroupAction(PlayerbotAI* botAI, std::string const name = "move from group") : MovementAction(botAI, name) {}
|
||||
|
||||
bool Execute(Event event) override;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -42,6 +42,12 @@ bool StayAction::Execute(Event event) { return Stay(); }
|
||||
|
||||
bool StayAction::isUseful()
|
||||
{
|
||||
// move from group takes priority over stay as it's added and removed automatically
|
||||
// (without removing/adding stay)
|
||||
if (botAI->HasStrategy("move from group", BOT_STATE_COMBAT) ||
|
||||
botAI->HasStrategy("move from group", BOT_STATE_NON_COMBAT))
|
||||
return false;
|
||||
|
||||
// Only useful if the bot is currently moving
|
||||
return AI_VALUE2(bool, "moving", "self target");
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ void ChatCommandHandlerStrategy::InitTriggers(std::vector<TriggerNode*>& trigger
|
||||
new TriggerNode("follow", NextAction::array(0, new NextAction("follow chat shortcut", relevance), nullptr)));
|
||||
triggers.push_back(
|
||||
new TriggerNode("stay", NextAction::array(0, new NextAction("stay chat shortcut", relevance), nullptr)));
|
||||
triggers.push_back(
|
||||
new TriggerNode("move from group", NextAction::array(0, new NextAction("move from group chat shortcut", relevance), nullptr)));
|
||||
triggers.push_back(
|
||||
new TriggerNode("flee", NextAction::array(0, new NextAction("flee chat shortcut", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode(
|
||||
|
||||
18
src/strategy/generic/MoveFromGroupStrategy.cpp
Normal file
18
src/strategy/generic/MoveFromGroupStrategy.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "MoveFromGroupStrategy.h"
|
||||
#include "PassiveMultiplier.h"
|
||||
#include "Playerbots.h"
|
||||
|
||||
NextAction** MoveFromGroupStrategy::getDefaultActions()
|
||||
{
|
||||
return NextAction::array(0, new NextAction("move from group", 1.0f), nullptr);
|
||||
}
|
||||
|
||||
void MoveFromGroupStrategy::InitMultipliers(std::vector<Multiplier*>& multipliers)
|
||||
{
|
||||
multipliers.push_back(new PassiveMultiplier(botAI));
|
||||
}
|
||||
23
src/strategy/generic/MoveFromGroupStrategy.h
Normal file
23
src/strategy/generic/MoveFromGroupStrategy.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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_MOVEFROMGROUPSTRATEGY_H
|
||||
#define _PLAYERBOT_MOVEFROMGROUPSTRATEGY_H
|
||||
|
||||
#include "Strategy.h"
|
||||
|
||||
class PlayerbotAI;
|
||||
|
||||
class MoveFromGroupStrategy : public Strategy
|
||||
{
|
||||
public:
|
||||
MoveFromGroupStrategy(PlayerbotAI* botAI) : Strategy(botAI) {}
|
||||
|
||||
std::string const getName() override { return "move from group"; }
|
||||
NextAction** getDefaultActions() override;
|
||||
void InitMultipliers(std::vector<Multiplier*>& multipliers) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
creators["gbank"] = &ChatTriggerContext::gb;
|
||||
creators["bank"] = &ChatTriggerContext::bank;
|
||||
creators["follow"] = &ChatTriggerContext::follow;
|
||||
creators["move from group"] = &ChatTriggerContext::move_from_group;
|
||||
creators["stay"] = &ChatTriggerContext::stay;
|
||||
creators["flee"] = &ChatTriggerContext::flee;
|
||||
creators["grind"] = &ChatTriggerContext::grind;
|
||||
@@ -164,6 +165,7 @@ private:
|
||||
static Trigger* tank_attack(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "tank attack"); }
|
||||
static Trigger* stay(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "stay"); }
|
||||
static Trigger* follow(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "follow"); }
|
||||
static Trigger* move_from_group(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "move from group"); }
|
||||
static Trigger* gb(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "gb"); }
|
||||
static Trigger* bank(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "bank"); }
|
||||
static Trigger* help(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "help"); }
|
||||
|
||||
Reference in New Issue
Block a user