mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 00:58:33 +00:00
Rerwite is moving allowed logic + fix root flag heartbeat spam (#1908)
Okay, what have been done: 1. Fix heartbeat spam for root flag: check against `MOVEMENTFLAG_ROOT` flag (`IsRooted`) instead of `HasRootAura`. 2. Rewrite `IsMovingAllowed` - place checks from most common to the rarest. 3. Remove unnecessary checks: `HasRootAura`, `HasConfuseAura`, `HasStunAura` - handled by AuraEffects and set unit state flags `UNIT_STATE_ROOT`, `UNIT_STATE_CONFUSED`, `UNIT_STATE_STUNNED` - `UNIT_STATE_LOST_CONTROL` already handles confused and stunned (rooted checked with `IsRooted` method). 4. Combine traveling state checks for taxi flights: `UNIT_STATE_IN_FLIGHT` + MM flag `FLIGHT_MOTION_TYPE`. 5. Simplify check against being in vehicle: use `MOVEMENTFLAG_ONTRANSPORT` as an indicator that the unit is in the vehicle. Also, update `UpdateMovementState` method with simplified checks and the updated logic (common > rare). This should fix issues: https://github.com/mod-playerbots/mod-playerbots/issues/1903 and https://github.com/mod-playerbots/mod-playerbots/issues/1902 NOTE: The `PlayerbotAI` class has a method `CanMove` with the same checks, but this method is only used once in the code. We should decide how to properly check if the bot can move or not: 1. Place all logic into `IsMovingAllowed` and drop `CanMove`. 2. Place all logic into `CanMove` and use it inside `IsMovingAllowed`. 3. Use them for different approaches: - `CanMove`: simple checks (unit flags, CC state, death state, travel state, vehicle state); - `IsMovingAllowed`: everything from `CanMove` + MM flags checks (not sure about rooted since it still checks for movement flags...).
This commit is contained in:
@@ -946,25 +946,37 @@ bool MovementAction::IsWaitingForLastMove(MovementPriority priority)
|
|||||||
|
|
||||||
bool MovementAction::IsMovingAllowed()
|
bool MovementAction::IsMovingAllowed()
|
||||||
{
|
{
|
||||||
// do not allow if not vehicle driver
|
// Most common checks: confused, stunned, fleeing, jumping, charging. All these
|
||||||
if (botAI->IsInVehicle() && !botAI->IsInVehicle(true))
|
// states are set when handling certain aura effects. We don't check against
|
||||||
|
// UNIT_STATE_ROOT here, because this state is used by vehicles.
|
||||||
|
if (bot->HasUnitState(UNIT_STATE_LOST_CONTROL))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (bot->isFrozen() || bot->IsPolymorphed() || (bot->isDead() && !bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) ||
|
// Death state (w/o spirit release) and Spirit of Redemption aura (priest)
|
||||||
bot->IsBeingTeleported() || bot->HasRootAura() || bot->HasSpiritOfRedemptionAura() || bot->HasConfuseAura() ||
|
if ((bot->isDead() && !bot->HasPlayerFlag(PLAYER_FLAGS_GHOST)) || bot->HasSpiritOfRedemptionAura())
|
||||||
bot->IsCharmed() || bot->HasStunAura() || bot->IsInFlight() || bot->HasUnitState(UNIT_STATE_LOST_CONTROL))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Common CC effects, ordered by frequency: rooted > frozen > polymorphed
|
||||||
|
if (bot->IsRooted() || bot->isFrozen() || bot->IsPolymorphed())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check for the MM controlled slot types: feared, confused, fleeing, etc.
|
||||||
if (bot->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_CONTROLLED) != NULL_MOTION_TYPE)
|
if (bot->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_CONTROLLED) != NULL_MOTION_TYPE)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FALLING))
|
// Traveling state: taxi flight and being teleported (relatively rare)
|
||||||
// {
|
if (bot->IsInFlight() || bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE ||
|
||||||
// return false;
|
bot->IsBeingTeleported())
|
||||||
// }
|
return false;
|
||||||
return bot->GetMotionMaster()->GetCurrentMovementGeneratorType() != FLIGHT_MOTION_TYPE;
|
|
||||||
|
// Vehicle state: is in the vehicle and can control it (rare, content-specific).
|
||||||
|
// We need to check charmed state AFTER vehicle one, cuz that's how it works:
|
||||||
|
// passengers are set to charmed by vehicle with CHARM_TYPE_VEHICLE.
|
||||||
|
if ((bot->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && !botAI->IsInVehicle(true)) ||
|
||||||
|
bot->IsCharmed())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MovementAction::Follow(Unit* target, float distance) { return Follow(target, distance, GetFollowAngle()); }
|
bool MovementAction::Follow(Unit* target, float distance) { return Follow(target, distance, GetFollowAngle()); }
|
||||||
@@ -972,12 +984,10 @@ bool MovementAction::Follow(Unit* target, float distance) { return Follow(target
|
|||||||
void MovementAction::UpdateMovementState()
|
void MovementAction::UpdateMovementState()
|
||||||
{
|
{
|
||||||
const bool isCurrentlyRestricted = // see if the bot is currently slowed, rooted, or otherwise unable to move
|
const bool isCurrentlyRestricted = // see if the bot is currently slowed, rooted, or otherwise unable to move
|
||||||
|
bot->HasUnitState(UNIT_STATE_LOST_CONTROL) ||
|
||||||
|
bot->IsRooted() ||
|
||||||
bot->isFrozen() ||
|
bot->isFrozen() ||
|
||||||
bot->IsPolymorphed() ||
|
bot->IsPolymorphed();
|
||||||
bot->HasRootAura() ||
|
|
||||||
bot->HasStunAura() ||
|
|
||||||
bot->HasConfuseAura() ||
|
|
||||||
bot->HasUnitState(UNIT_STATE_LOST_CONTROL);
|
|
||||||
|
|
||||||
// no update movement flags while movement is current restricted.
|
// no update movement flags while movement is current restricted.
|
||||||
if (!isCurrentlyRestricted && bot->IsAlive())
|
if (!isCurrentlyRestricted && bot->IsAlive())
|
||||||
|
|||||||
Reference in New Issue
Block a user