Skip to content

Commit

Permalink
Core/Movement: fix timed flee movement (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongdove authored Oct 23, 2024
1 parent bbe1a31 commit c9025c2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/server/game/AI/SmartScripts/SmartAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void SmartAI::StopPath(uint32 DespawnTime, uint32 quest, bool fail)

me->GetPosition(&mLastOOCPos);
me->StopMoving();//force stop
me->GetMotionMaster()->MovementExpired(false);
me->GetMotionMaster()->MoveIdle();
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_STOPPED, nullptr, mLastWP->id, GetScript()->GetPathId());
EndPath(fail);
Expand Down Expand Up @@ -718,14 +719,24 @@ void SmartAI::JustSummoned(Creature* creature)

void SmartAI::AttackStart(Unit* who)
{
if (who && me->Attack(who, true))
// dont allow charmed npcs to act on their own
if (me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED))
{
me->GetMotionMaster()->Clear(MOTION_SLOT_ACTIVE);
me->PauseMovement(0, 0, false);
if (who)
me->Attack(who, true);
return;
}

if (who && me->Attack(who, true))
{
if (mCanCombatMove)
{
SetRun(mRun);

MovementGeneratorType type = me->GetMotionMaster()->GetMotionSlotType(MOTION_SLOT_ACTIVE);
if (type == WAYPOINT_MOTION_TYPE || type == POINT_MOTION_TYPE)
me->StopMoving();

me->GetMotionMaster()->MoveChase(who);
}

Expand Down Expand Up @@ -907,6 +918,7 @@ void SmartAI::SetCombatMove(bool on)
{
if (mCanCombatMove == on)
return;

mCanCombatMove = on;
if (!HasEscortState(SMART_ESCORT_ESCORTING))
{
Expand All @@ -922,6 +934,8 @@ void SmartAI::SetCombatMove(bool on)
else
{
me->StopMoving();
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
me->GetMotionMaster()->Clear(false);
me->GetMotionMaster()->MoveIdle();
}
}
Expand Down

0 comments on commit c9025c2

Please sign in to comment.