feat(Core/Movement): implement Pause and Resume to WaypointMovementGenerator (#19176)

* implement Pause and Resume for WaypointMovementGenerator

Co-authored-by: ccrs <ccrs@users.noreply.github.com>

* prevent restart from external sources if wp is paused

* don't update stopmove on every update

SetFacing breaks otherwise

* timer args not used

---------

Co-authored-by: ccrs <ccrs@users.noreply.github.com>
This commit is contained in:
Jelle Meeus
2024-06-26 22:24:59 +02:00
committed by GitHub
parent 77d3eb52df
commit 40b63666ad
2 changed files with 25 additions and 2 deletions

View File

@@ -61,6 +61,10 @@ void WaypointMovementGenerator<Creature>::DoFinalize(Creature* creature)
void WaypointMovementGenerator<Creature>::DoReset(Creature* creature)
{
if (stalled)
{
return;
}
creature->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
StartMoveNow(creature);
}
@@ -209,6 +213,11 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
{
// Waypoint movement can be switched on/off
// This is quite handy for escort quests and other stuff
if (stalled)
{
Stop(1000);
return true;
}
if (creature->HasUnitState(UNIT_STATE_NOT_MOVE) || creature->IsMovementPreventedByCasting())
{
creature->StopMoving();
@@ -278,6 +287,17 @@ void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature)
}
}
void WaypointMovementGenerator<Creature>::Pause(uint32 /*timer*/)
{
stalled = true;
i_nextMoveTime.Reset(1);
}
void WaypointMovementGenerator<Creature>::Resume(uint32 /*overrideTimer/*/)
{
stalled = false;
}
//----------------------------------------------------//
uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const

View File

@@ -54,13 +54,15 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea
public PathMovementBase<Creature, WaypointPath const*>
{
public:
WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true)
: PathMovementBase((WaypointPath const*)nullptr), i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {}
WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true, bool _stalled = false)
: PathMovementBase((WaypointPath const*)nullptr), i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating), stalled(_stalled) {}
~WaypointMovementGenerator() { i_path = nullptr; }
void DoInitialize(Creature*);
void DoFinalize(Creature*);
void DoReset(Creature*);
bool DoUpdate(Creature*, uint32 diff);
void Pause(uint32 timer/* = 0*/);
void Resume(uint32 overrideTimer/* = 0*/);
void MovementInform(Creature*);
@@ -93,6 +95,7 @@ private:
bool m_isArrivalDone;
uint32 path_id;
bool repeating;
bool stalled;
};
/** FlightPathMovementGenerator generates movement of the player for the paths