Skip to content

Commit

Permalink
Feature/move styles (#314)
Browse files Browse the repository at this point in the history
* move style +wait - do not rush to mob if it is moving towards the bot

* noedge move style

* Fix bad merge

* Prevent copying

---------

Co-authored-by: ike3 <[email protected]>
  • Loading branch information
ike3 and ike3 authored Dec 1, 2023
1 parent 48aacf8 commit b0097ae
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 0 deletions.
24 changes: 24 additions & 0 deletions playerbot/FleeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "FleeManager.h"
#include "PlayerbotAIConfig.h"
#include "Group.h"
#include "strategy/values/MoveStyleValue.h"
#include "ServerFacade.h"

using namespace ai;
Expand Down Expand Up @@ -74,6 +75,7 @@ void FleeManager::calculatePossibleDestinations(list<FleePoint*> &points)
if (intersectsOri(angle, enemyOri, angleIncrement)) continue;

float x = botPosX + cos(angle) * maxAllowedDistance, y = botPosY + sin(angle) * maxAllowedDistance, z = botPosZ + CONTACT_DISTANCE;
if (MoveStyleValue::CheckForEdges(bot->GetPlayerbotAI()) && isTooCloseToEdge(x, y, z, angle)) continue;

if (forceMaxDistance && sServerFacade.IsDistanceLessThan(sServerFacade.GetDistance2d(bot, x, y), maxAllowedDistance - sPlayerbotAIConfig.tooCloseDistance))
continue;
Expand All @@ -100,6 +102,28 @@ void FleeManager::calculatePossibleDestinations(list<FleePoint*> &points)
}
}

bool FleeManager::isTooCloseToEdge(float x, float y, float z, float angle)
{
Map* map = bot->GetMap();
const TerrainInfo* terrain = map->GetTerrain();
for (float a = angle; a <= angle + 2*M_PI; a += M_PI / 4)
{
float dist = sPlayerbotAIConfig.followDistance;
float tx = x + cos(a) * dist;
float ty = y + sin(a) * dist;
float tz = z;
bot->UpdateAllowedPositionZ(tx, ty, tz);

if (terrain && terrain->IsInWater(tx, ty, tz))
return true;

if (!bot->IsWithinLOS(tx, ty, tz))
return true;
}

return false;
}

void FleeManager::cleanup(list<FleePoint*> &points)
{
for (list<FleePoint*>::iterator i = points.begin(); i != points.end(); i++)
Expand Down
1 change: 1 addition & 0 deletions playerbot/FleeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace ai
void cleanup(list<FleePoint*> &points);
FleePoint* selectOptimalDestination(list<FleePoint*> &points);
bool isBetterThan(FleePoint* point, FleePoint* other);
bool isTooCloseToEdge(float x, float y, float z, float angle);

private:
Player* bot;
Expand Down
3 changes: 3 additions & 0 deletions playerbot/strategy/actions/ChatActionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "GuildManagementActions.h"
#include "RtscAction.h"
#include "BattleGroundJoinAction.h"
#include "MoveStyleAction.h"
#include "ValueActions.h"

namespace ai
Expand Down Expand Up @@ -190,6 +191,7 @@ namespace ai
creators["guild leader"] = &ChatActionContext::guild_leader;

creators["bg free"] = &ChatActionContext::bg_free;
creators["move style"] = &ChatActionContext::move_style;
}

private:
Expand Down Expand Up @@ -302,5 +304,6 @@ namespace ai
static Action* guild_leave(PlayerbotAI* ai) { return new GuildLeaveAction(ai); }
static Action* guild_leader(PlayerbotAI* ai) { return new GuildLeaderAction(ai); }
static Action* bg_free(PlayerbotAI* ai) { return new BGLeaveAction(ai); }
static Action* move_style(PlayerbotAI* ai) { return new MoveStyleAction(ai); }
};
};
38 changes: 38 additions & 0 deletions playerbot/strategy/actions/MoveStyleAction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "botpch.h"
#include "../../playerbot.h"
#include "MoveStyleAction.h"
#include "../values/SubStrategyValue.h"
#include "../values/MoveStyleValue.h"
#include "PlayerbotAIAware.h"

using namespace ai;

bool MoveStyleAction::Execute(Event& event)
{
string strategy = event.getParam();
Player* requester = event.getOwner() ? event.getOwner() : GetMaster();

MoveStyleValue* value = (MoveStyleValue*)context->GetValue<string>("move style");

if (strategy == "?")
{
{
ostringstream out;
out << "Move style: " << value->Get();
ai->TellPlayer(requester, out);
}
}
else
{
value->Set(strategy);

{
ostringstream out;
out << "Move style set to: " << value->Get();
ai->TellPlayer(requester, out);
}
}

return true;
}

13 changes: 13 additions & 0 deletions playerbot/strategy/actions/MoveStyleAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "../../LootObjectStack.h"
#include "GenericActions.h"

namespace ai
{
class MoveStyleAction : public ChatCommandAction
{
public:
MoveStyleAction(PlayerbotAI* ai) : ChatCommandAction(ai, "move style") {}
virtual bool Execute(Event& event) override;
};
}
8 changes: 8 additions & 0 deletions playerbot/strategy/actions/ReachTargetActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../ServerFacade.h"
#include "../generic/PullStrategy.h"
#include "../NamedObjectContext.h"
#include "../values/MoveStyleValue.h"
#include "GenericSpellActions.h"

namespace ai
Expand Down Expand Up @@ -51,6 +52,13 @@ namespace ai
chaseDist = (chaseDist - sPlayerbotAIConfig.contactDistance);
}

if (MoveStyleValue::WaitForEnemy(ai) && target->m_movementInfo.HasMovementFlag(movementFlagsMask) &&
sServerFacade.IsInFront(target, bot, sPlayerbotAIConfig.sightDistance, CAST_ANGLE_IN_FRONT) &&
sServerFacade.IsDistanceGreaterThan(distanceToTarget, sPlayerbotAIConfig.tooCloseDistance))
{
return true;
}

if (inLos && isFriend && (range <= ai->GetRange("follow")))
{
return MoveNear(target, chaseDist);
Expand Down
1 change: 1 addition & 0 deletions playerbot/strategy/generic/ChatCommandHandlerStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* ai) : PassTr
supported.push_back("keep");
supported.push_back("bg free");
supported.push_back("cast");
supported.push_back("move style");
}

void ChatCommandHandlerStrategy::InitReactionTriggers(std::list<TriggerNode*> &triggers)
Expand Down
2 changes: 2 additions & 0 deletions playerbot/strategy/triggers/ChatTriggerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace ai
creators["guild leave"] = &ChatTriggerContext::guild_leave;
creators["guild leader"] = &ChatTriggerContext::guild_leader;
creators["bg free"] = &ChatTriggerContext::bg_free;
creators["move style"] = &ChatTriggerContext::move_style;
}

private:
Expand Down Expand Up @@ -241,5 +242,6 @@ namespace ai
static Trigger* guild_leave(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "guild leave"); }
static Trigger* guild_leader(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "guild leader"); }
static Trigger* bg_free(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "bg free"); }
static Trigger* move_style(PlayerbotAI* ai) { return new ChatCommandTrigger(ai, "move style"); }
};
};
13 changes: 13 additions & 0 deletions playerbot/strategy/values/MoveStyleValue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "botpch.h"
#include "../../playerbot.h"
#include "MoveStyleValue.h"
#include "../values/ItemUsageValue.h"

using namespace ai;
using namespace std;

bool MoveStyleValue::HasValue(PlayerbotAI* ai, const string& value)
{
string styles = ai->GetAiObjectContext()->GetValue<string>("move style")->Get();
return styles.find(value) != string::npos;
}
19 changes: 19 additions & 0 deletions playerbot/strategy/values/MoveStyleValue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "../../LootObjectStack.h"
#include "../Value.h"
#include "SubStrategyValue.h"

namespace ai
{
class MoveStyleValue : public SubStrategyValue
{
public:
MoveStyleValue(PlayerbotAI* ai, const string& defaultValue = "", const string& name = "move style", const string& allowedValues = "wait,noedge") : SubStrategyValue(ai, defaultValue, name, allowedValues) {}

static bool WaitForEnemy(PlayerbotAI* ai) { return HasValue(ai, "wait"); }
static bool CheckForEdges(PlayerbotAI* ai) { return HasValue(ai, "noedge"); }

private:
static bool HasValue(PlayerbotAI* ai, const string& value);
};
}
2 changes: 2 additions & 0 deletions playerbot/strategy/values/ValueContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ namespace ai
creators["trigger active"] = &ValueContext::trigger_active;

creators["party tank without lifebloom"] = &ValueContext::party_tank_without_lifebloom;
creators["move style"] = &ValueContext::move_style;
}

private:
Expand Down Expand Up @@ -658,5 +659,6 @@ namespace ai
static UntypedValue* trigger_active(PlayerbotAI* ai) { return new TriggerActiveValue(ai); }

static UntypedValue* party_tank_without_lifebloom(PlayerbotAI* ai) { return new PartyTankWithoutLifebloomValue(ai); }
static UntypedValue* move_style(PlayerbotAI* ai) { return new MoveStyleValue(ai); }
};
};

0 comments on commit b0097ae

Please sign in to comment.