Make backwards movement for flee

This commit is contained in:
Yunfan Li
2024-12-29 23:21:03 +08:00
parent adc0d6e72c
commit 79a5fdd7c1
5 changed files with 52 additions and 19 deletions

View File

@@ -4115,11 +4115,16 @@ inline bool ZoneHasRealPlayers(Player* bot)
return false; return false;
} }
for (auto& player : sRandomPlayerbotMgr->GetPlayers()) for (Player* player : sRandomPlayerbotMgr->GetPlayers())
{ {
if (player->GetMapId() != bot->GetMapId()) if (player->GetMapId() != bot->GetMapId())
continue; continue;
if (player->IsGameMaster() && !player->IsVisible())
{
continue;
}
if (player->GetZoneId() == bot->GetZoneId()) if (player->GetZoneId() == bot->GetZoneId())
{ {
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player); PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);

View File

@@ -33,7 +33,7 @@ bool FollowAction::Execute(Event event)
MovementPriority priority = botAI->GetState() == BOT_STATE_COMBAT ? MovementPriority::MOVEMENT_COMBAT : MovementPriority::MOVEMENT_NORMAL; MovementPriority priority = botAI->GetState() == BOT_STATE_COMBAT ? MovementPriority::MOVEMENT_COMBAT : MovementPriority::MOVEMENT_NORMAL;
moved = MoveTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), false, false, false, moved = MoveTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), false, false, false,
true, priority); true, priority, true);
} }
if (Pet* pet = bot->GetPet()) if (Pet* pet = bot->GetPet())

View File

@@ -177,7 +177,7 @@ bool MovementAction::MoveToLOS(WorldObject* target, bool ranged)
} }
bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, bool react, bool normal_only, bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, bool react, bool normal_only,
bool exact_waypoint, MovementPriority priority, bool lessDelay) bool exact_waypoint, MovementPriority priority, bool lessDelay, bool backwards)
{ {
UpdateMovementState(); UpdateMovementState();
if (!IsMovingAllowed(mapId, x, y, z)) if (!IsMovingAllowed(mapId, x, y, z))
@@ -208,8 +208,16 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
{ {
MotionMaster& mm = *vehicleBase->GetMotionMaster(); // need to move vehicle, not bot MotionMaster& mm = *vehicleBase->GetMotionMaster(); // need to move vehicle, not bot
mm.Clear(); mm.Clear();
mm.MovePoint(0, x, y, z, generatePath); if (!backwards)
float delay = 1000.0f * (distance / vehicleBase->GetSpeed(MOVE_RUN)); {
mm.MovePoint(0, x, y, z, generatePath);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
}
float speed = backwards ? vehicleBase->GetSpeed(MOVE_RUN_BACK) : vehicleBase->GetSpeed(MOVE_RUN);
float delay = 1000.0f * (distance / speed);
if (lessDelay) if (lessDelay)
{ {
delay -= botAI->GetReactDelay(); delay -= botAI->GetReactDelay();
@@ -235,8 +243,15 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
} }
MotionMaster& mm = *bot->GetMotionMaster(); MotionMaster& mm = *bot->GetMotionMaster();
mm.Clear(); mm.Clear();
mm.MovePoint(0, x, y, z, generatePath); if (!backwards)
float delay = 1000.0f * MoveDelay(distance); {
mm.MovePoint(0, x, y, z, generatePath);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
}
float delay = 1000.0f * MoveDelay(distance, backwards);
if (lessDelay) if (lessDelay)
{ {
delay -= botAI->GetReactDelay(); delay -= botAI->GetReactDelay();
@@ -270,8 +285,15 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
MotionMaster& mm = *bot->GetMotionMaster(); MotionMaster& mm = *bot->GetMotionMaster();
G3D::Vector3 endP = path.back(); G3D::Vector3 endP = path.back();
mm.Clear(); mm.Clear();
mm.MovePoint(0, endP.x, endP.y, endP.z, generatePath); if (!backwards)
float delay = 1000.0f * MoveDelay(distance); {
mm.MovePoint(0, x, y, z, generatePath);
}
else
{
mm.MovePointBackwards(0, x, y, z, generatePath);
}
float delay = 1000.0f * MoveDelay(distance, backwards);
if (lessDelay) if (lessDelay)
{ {
delay -= botAI->GetReactDelay(); delay -= botAI->GetReactDelay();
@@ -1265,20 +1287,20 @@ bool MovementAction::ChaseTo(WorldObject* obj, float distance, float angle)
return true; return true;
} }
float MovementAction::MoveDelay(float distance) float MovementAction::MoveDelay(float distance, bool backwards)
{ {
float speed; float speed;
if (bot->isSwimming()) if (bot->isSwimming())
{ {
speed = bot->GetSpeed(MOVE_SWIM); speed = backwards ? bot->GetSpeed(MOVE_SWIM_BACK) : bot->GetSpeed(MOVE_SWIM);
} }
else if (bot->IsFlying()) else if (bot->IsFlying())
{ {
speed = bot->GetSpeed(MOVE_FLIGHT); speed = backwards ? bot->GetSpeed(MOVE_FLIGHT_BACK) : bot->GetSpeed(MOVE_FLIGHT);
} }
else else
{ {
speed = bot->GetSpeed(MOVE_RUN); speed = backwards ? bot->GetSpeed(MOVE_RUN_BACK) :bot->GetSpeed(MOVE_RUN);
} }
float delay = distance / speed; float delay = distance / speed;
return delay; return delay;
@@ -1502,6 +1524,12 @@ void MovementAction::ClearIdleState()
bool MovementAction::MoveAway(Unit* target, float distance) bool MovementAction::MoveAway(Unit* target, float distance)
{ {
// MotionMaster& mm = *bot->GetMotionMaster();
// mm.Clear();
// mm.MoveBackwards(target, distance);
// botAI->SetNextCheckDelay(3000);
// // bot->GetSpeed()
// return true;
if (!target) if (!target)
{ {
return false; return false;
@@ -1523,7 +1551,7 @@ bool MovementAction::MoveAway(Unit* target, float distance)
dz = bot->GetPositionZ(); dz = bot->GetPositionZ();
exact = false; exact = false;
} }
if (MoveTo(target->GetMapId(), dx, dy, dz, false, false, true, exact, MovementPriority::MOVEMENT_COMBAT)) if (MoveTo(target->GetMapId(), dx, dy, dz, false, false, true, exact, MovementPriority::MOVEMENT_COMBAT, false, true))
{ {
return true; return true;
} }
@@ -1545,7 +1573,7 @@ bool MovementAction::MoveAway(Unit* target, float distance)
dz = bot->GetPositionZ(); dz = bot->GetPositionZ();
exact = false; exact = false;
} }
if (MoveTo(target->GetMapId(), dx, dy, dz, false, false, true, exact, MovementPriority::MOVEMENT_COMBAT)) if (MoveTo(target->GetMapId(), dx, dy, dz, false, false, true, exact, MovementPriority::MOVEMENT_COMBAT, false, true))
{ {
return true; return true;
} }

View File

@@ -32,7 +32,7 @@ protected:
bool MoveNear(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->contactDistance, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL); bool MoveNear(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->contactDistance, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
bool MoveToLOS(WorldObject* target, bool ranged = false); bool MoveToLOS(WorldObject* target, bool ranged = false);
bool MoveTo(uint32 mapId, float x, float y, float z, bool idle = false, bool react = false, bool MoveTo(uint32 mapId, float x, float y, float z, bool idle = false, bool react = false,
bool normal_only = false, bool exact_waypoint = false, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL, bool lessDelay = false); bool normal_only = false, bool exact_waypoint = false, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL, bool lessDelay = false, bool backwards = false);
bool MoveTo(WorldObject* target, float distance = 0.0f, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL); bool MoveTo(WorldObject* target, float distance = 0.0f, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
bool MoveNear(WorldObject* target, float distance = sPlayerbotAIConfig->contactDistance, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL); bool MoveNear(WorldObject* target, float distance = sPlayerbotAIConfig->contactDistance, MovementPriority priority = MovementPriority::MOVEMENT_NORMAL);
float GetFollowAngle(); float GetFollowAngle();
@@ -40,7 +40,7 @@ protected:
bool Follow(Unit* target, float distance, float angle); bool Follow(Unit* target, float distance, float angle);
bool ChaseTo(WorldObject* obj, float distance = 0.0f, float angle = 0.0f); bool ChaseTo(WorldObject* obj, float distance = 0.0f, float angle = 0.0f);
bool ReachCombatTo(Unit* target, float distance = 0.0f); bool ReachCombatTo(Unit* target, float distance = 0.0f);
float MoveDelay(float distance); float MoveDelay(float distance, bool backwards = false);
void WaitForReach(float distance); void WaitForReach(float distance);
void SetNextMovementDelay(float delayMillis); void SetNextMovementDelay(float delayMillis);
bool IsMovingAllowed(WorldObject* target); bool IsMovingAllowed(WorldObject* target);

View File

@@ -44,7 +44,7 @@ bool NewRpgStatusUpdateAction::Execute(Event event)
} }
} }
// IDLE -> GO_INNKEEPER // IDLE -> GO_INNKEEPER
else if (bot->GetLevel() >= 6 && roll <= 40) else if (bot->GetLevel() >= 6 && roll <= 45)
{ {
WorldPosition pos = SelectRandomInnKeeperPos(); WorldPosition pos = SelectRandomInnKeeperPos();
if (pos != WorldPosition() && bot->GetExactDist(pos) > 50.0f) if (pos != WorldPosition() && bot->GetExactDist(pos) > 50.0f)