diff options
author | treeston <treeston.mmoc@gmail.com> | 2015-09-13 03:29:28 +0200 |
---|---|---|
committer | MitchesD <majklprofik@seznam.cz> | 2015-10-16 12:37:42 +0200 |
commit | c64b71d01e16584c03d086d6eebc77a071c6173b (patch) | |
tree | fa1b439b314540b9b2a779bfa1b38849c16e73a9 | |
parent | 5c0a4ae3efaa5bdf723200abcf80a31b3304b3b7 (diff) |
Clean up SmartAI::MoveInLineOfSight. Remove tons of duplicate logic and forward to CreatureAI::MoveInLineOfSight instead of using its own (incorrect) implementation.
Move the removal of the 'distracted' state from SmartAI to UnitAI.cpp.
Fixes and closes #7197 and #15482.
(cherry picked from commit f446538cb16dad3dcd04e79aebc944feefc16275)
-rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.cpp | 8 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 36 |
2 files changed, 11 insertions, 33 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index d5dd4badd47..f53cbf18b2c 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -29,7 +29,15 @@ void UnitAI::AttackStart(Unit* victim) { if (victim && me->Attack(victim, true)) + { + // Clear distracted state on attacking + if (me->HasUnitState(UNIT_STATE_DISTRACTED)) + { + me->ClearUnitState(UNIT_STATE_DISTRACTED); + me->GetMotionMaster()->Clear(); + } me->GetMotionMaster()->MoveChase(victim); + } } void UnitAI::AttackStartCaster(Unit* victim, float dist) diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 70490c578ec..f66b1d3d75c 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -453,45 +453,15 @@ void SmartAI::MoveInLineOfSight(Unit* who) GetScript()->OnMoveInLineOfSight(who); - if (me->HasReactState(REACT_PASSIVE) || AssistPlayerInCombat(who)) + if (AssistPlayerInCombat(who)) return; - if (!CanAIAttack(who)) - return; - - if (!me->CanStartAttack(who, false)) - return; - - if (me->IsHostileTo(who)) - { - float fAttackRadius = me->GetAttackDistance(who); - if (me->IsWithinDistInMap(who, fAttackRadius) && me->IsWithinLOSInMap(who)) - { - if (!me->GetVictim()) - { - // Clear distracted state on combat - if (me->HasUnitState(UNIT_STATE_DISTRACTED)) - { - me->ClearUnitState(UNIT_STATE_DISTRACTED); - me->GetMotionMaster()->Clear(); - } - - AttackStart(who); - } - else/* if (me->GetMap()->IsDungeon())*/ - { - who->SetInCombatWith(me); - me->AddThreat(who, 0.0f); - } - } - } + CreatureAI::MoveInLineOfSight(who); } bool SmartAI::CanAIAttack(const Unit* /*who*/) const { - if (me->GetReactState() == REACT_PASSIVE) - return false; - return true; + return !(me->HasReactState(REACT_PASSIVE)); } bool SmartAI::AssistPlayerInCombat(Unit* who) |