Skip to content

Commit

Permalink
Creature/Movement: Include random movement in MotionMaster::PauseWayp…
Browse files Browse the repository at this point in the history
…oints
  • Loading branch information
killerwife committed Aug 13, 2023
1 parent 610da37 commit 0c08098
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/game/MotionGenerators/MotionMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,12 @@ void MotionMaster::PauseWaypoints(uint32 time)
gen->AddToPathPauseTime(time, true);
return;
}
else if (GetCurrentMovementGeneratorType() == RANDOM_MOTION_TYPE)
{
auto gen = (WanderMovementGenerator*)top();
gen->AddToRandomPauseTime(time, true);
return;
}
}

void MotionMaster::UnpauseWaypoints()
Expand Down
13 changes: 13 additions & 0 deletions src/game/MotionGenerators/RandomMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ void WanderMovementGenerator::Interrupt(Unit& owner)
static_cast<Creature&>(owner).SetWalk(!owner.hasUnitState(UNIT_STAT_RUNNING_STATE), false);
}

void WanderMovementGenerator::AddToRandomPauseTime(int32 waitTimeDiff, bool force)
{
if (force)
i_nextMoveTimer.Reset(waitTimeDiff);
else if (!i_nextMoveTimer.Passed())
{
// creature is stopped already
// Prevent <= 0, the code in Update requires to catch the change from moving to not moving
int32 newWaitTime = i_nextMoveTimer.GetExpiry() + waitTimeDiff;
i_nextMoveTimer.Reset(newWaitTime > 0 ? newWaitTime : 1);
}
}

TimedWanderMovementGenerator::TimedWanderMovementGenerator(Creature const& npc, uint32 timer, float radius, float verticalZ)
: TimedWanderMovementGenerator(timer, npc.GetPositionX(), npc.GetPositionY(), npc.GetPositionZ(), radius, verticalZ)
{
Expand Down
2 changes: 2 additions & 0 deletions src/game/MotionGenerators/RandomMovementGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class WanderMovementGenerator : public AbstractRandomMovementGenerator
void Finalize(Unit& owner) override;
void Interrupt(Unit& owner) override;

void AddToRandomPauseTime(int32 waitTimeDiff, bool force);

MovementGeneratorType GetMovementGeneratorType() const override { return RANDOM_MOTION_TYPE; }
};

Expand Down

0 comments on commit 0c08098

Please sign in to comment.