Skip to content

Commit 15b8a43

Browse files
committed
Misc: improve UNIT_STATE_DISTRACTED handling
1 parent 502afe5 commit 15b8a43

5 files changed

Lines changed: 12 additions & 16 deletions

File tree

src/server/game/AI/CoreAI/UnitAI.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@
3030
void UnitAI::AttackStart(Unit* victim)
3131
{
3232
if (victim && me->Attack(victim, true))
33-
{
34-
// Clear distracted state on attacking
35-
if (me->HasUnitState(UNIT_STATE_DISTRACTED))
36-
{
37-
me->ClearUnitState(UNIT_STATE_DISTRACTED);
38-
me->GetMotionMaster()->Clear();
39-
}
4033
me->GetMotionMaster()->MoveChase(victim);
41-
}
4234
}
4335

4436
void UnitAI::InitializeAI()

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8773,6 +8773,12 @@ void Unit::AtExitCombat()
87738773
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LEAVE_COMBAT);
87748774
}
87758775

8776+
void Unit::AtEngage(Unit *)
8777+
{
8778+
if (HasUnitState(UNIT_STATE_DISTRACTED))
8779+
GetMotionMaster()->Remove(DISTRACT_MOTION_TYPE);
8780+
}
8781+
87768782
void Unit::AtTargetAttacked(Unit* target, bool canInitialAggro)
87778783
{
87788784
if (!target->IsEngaged() && !canInitialAggro)

src/server/game/Entities/Unit/Unit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ class TC_GAME_API Unit : public WorldObject
19141914
virtual void AtEnterCombat() { }
19151915
virtual void AtExitCombat();
19161916

1917-
virtual void AtEngage(Unit* /*target*/) {}
1917+
void AtEngage(Unit* /*target*/);
19181918
virtual void AtDisengage() {}
19191919

19201920
private:

src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ MovementGeneratorType RotateMovementGenerator::GetMovementGeneratorType() const
140140

141141
//----------------------------------------------------//
142142

143-
DistractMovementGenerator::DistractMovementGenerator(uint32 timer, float orientation) : _timer(timer), _orientation(orientation)
143+
DistractMovementGenerator::DistractMovementGenerator(uint32 timer, float orientation) : _timer(timer), _orientation(orientation), _originalOrientation(0.f)
144144
{
145145
Mode = MOTION_MODE_DEFAULT;
146146
Priority = MOTION_PRIORITY_HIGHEST;
@@ -157,6 +157,8 @@ void DistractMovementGenerator::Initialize(Unit* owner)
157157
if (!owner->IsStandState())
158158
owner->SetStandState(UNIT_STAND_STATE_STAND);
159159

160+
_originalOrientation = owner->GetOrientation();
161+
160162
Movement::MoveSplineInit init(owner);
161163
init.MoveTo(PositionToVector3(*owner), false);
162164
if (owner->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && !owner->GetTransGUID().IsEmpty())
@@ -196,13 +198,8 @@ void DistractMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool move
196198
{
197199
AddFlag(MOVEMENTGENERATOR_FLAG_FINALIZED);
198200

199-
// TODO: This code should be handled somewhere else
200-
// If this is a creature, then return orientation to original position (for idle movement creatures)
201201
if (movementInform && HasFlag(MOVEMENTGENERATOR_FLAG_INFORM_ENABLED) && owner->GetTypeId() == TYPEID_UNIT)
202-
{
203-
float angle = owner->ToCreature()->GetHomePosition().GetOrientation();
204-
owner->SetFacingTo(angle);
205-
}
202+
owner->SetFacingTo(_originalOrientation, true);
206203
}
207204

208205
MovementGeneratorType DistractMovementGenerator::GetMovementGeneratorType() const

src/server/game/Movement/MovementGenerators/IdleMovementGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class DistractMovementGenerator : public MovementGenerator
6868
private:
6969
uint32 _timer;
7070
float _orientation;
71+
float _originalOrientation;
7172
};
7273

7374
class AssistanceDistractMovementGenerator : public DistractMovementGenerator

0 commit comments

Comments
 (0)