aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/CreatureAI.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-05-01 15:41:32 +0200
committerGitHub <noreply@github.com>2020-05-01 15:41:32 +0200
commit57a5969c2672b36160fea1b7c38c424de562a57b (patch)
treeee52f8ddaa8d37297142e59029df461d3000ce31 /src/server/game/AI/CreatureAI.cpp
parentfbd74eb5d8b5aa3a6874ee99044054e097b5ef21 (diff)
parent05ba662d5daaa3428cc01cdaa3794bf5a073ef17 (diff)
Merge pull request #24500 from funjoker/cherry-picks
Diffstat (limited to 'src/server/game/AI/CreatureAI.cpp')
-rw-r--r--src/server/game/AI/CreatureAI.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp
index b9d052cb528..3c65160aaf6 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -44,7 +44,7 @@ void CreatureAI::OnCharmed(bool apply)
AISpellInfoType* UnitAI::AISpellInfo;
AISpellInfoType* GetAISpellInfo(uint32 i) { return &UnitAI::AISpellInfo[i]; }
-CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), m_MoveInLineOfSight_locked(false)
+CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), m_MoveInLineOfSight_locked(false)
{
}
@@ -173,9 +173,9 @@ void CreatureAI::TriggerAlert(Unit const* who) const
me->SendAIReaction(AI_REACTION_ALERT);
// Face the unit (stealthed player) and set distracted state for 5 seconds
- me->SetFacingTo(me->GetAngle(who->GetPositionX(), who->GetPositionY()), true);
- me->StopMoving();
me->GetMotionMaster()->MoveDistract(5 * IN_MILLISECONDS);
+ me->StopMoving();
+ me->SetFacingTo(me->GetAngle(who));
}
void CreatureAI::EnterEvadeMode(EvadeReason why)
@@ -217,7 +217,7 @@ void CreatureAI::SetGazeOn(Unit* target)
{
if (me->IsValidAttackTarget(target))
{
- if (!me->IsFocusing(nullptr, true))
+ if (!me->IsFocusing(nullptr, true) && target != me->GetVictim())
AttackStart(target);
me->SetReactState(REACT_PASSIVE);
}
@@ -237,7 +237,7 @@ bool CreatureAI::UpdateVictimWithGaze()
}
if (Unit* victim = me->SelectVictim())
- if (!me->IsFocusing(nullptr, true))
+ if (!me->IsFocusing(nullptr, true) && victim != me->GetVictim())
AttackStart(victim);
return me->GetVictim() != nullptr;
@@ -251,7 +251,7 @@ bool CreatureAI::UpdateVictim()
if (!me->HasReactState(REACT_PASSIVE))
{
if (Unit* victim = me->SelectVictim())
- if (!me->IsFocusing(nullptr, true))
+ if (!me->IsFocusing(nullptr, true) && victim != me->GetVictim())
AttackStart(victim);
return me->GetVictim() != nullptr;
@@ -364,32 +364,28 @@ int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) con
bool CreatureAI::CheckBoundary(Position const* who) const
{
+ if (!_boundary)
+ return true;
+
if (!who)
who = me;
- if (_boundary)
- for (AreaBoundary const* areaBoundary : *_boundary)
- if (!areaBoundary->IsWithinBoundary(who))
- return false;
-
- return true;
+ return (CreatureAI::IsInBounds(*_boundary, who) != _negateBoundary);
}
-bool CreatureAI::IsInBounds(CreatureBoundary const* boundary, Position const* pos)
+bool CreatureAI::IsInBounds(CreatureBoundary const& boundary, Position const* pos)
{
- if (!boundary)
- return true;
-
- for (AreaBoundary const* areaBoundary : *boundary)
+ for (AreaBoundary const* areaBoundary : boundary)
if (!areaBoundary->IsWithinBoundary(pos))
return false;
return true;
}
-void CreatureAI::SetBoundary(CreatureBoundary const* boundary)
+void CreatureAI::SetBoundary(CreatureBoundary const* boundary, bool negateBoundaries /*= false*/)
{
_boundary = boundary;
+ _negateBoundary = negateBoundaries;
me->DoImmediateBoundaryCheck();
}