aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/CreatureAI.cpp
diff options
context:
space:
mode:
authormik1893 <michele.roscelli@gmail.com>2015-07-15 18:43:19 +0200
committerDDuarte <dnpd.dd@gmail.com>2015-07-19 01:43:05 +0100
commitfa0e5289a87fea15fac2ab0c2ace26ee06288174 (patch)
tree911637b91b6eb8560c9df986c5480fcfb6039598 /src/server/game/AI/CreatureAI.cpp
parent0ea0e9ee01383d8a74357000e854dc0777669d6d (diff)
Merge pull request #14974 from pete318/stealth_work
Stealth changes (Player stealthed vs NPCs) - 3.3.5 (cherry picked from commit 90fcfb3f2d71e15d162cb52b915b53a11bc42212) Conflicts: src/server/game/Entities/Object/Object.h src/server/game/Entities/Unit/Unit.cpp
Diffstat (limited to 'src/server/game/AI/CreatureAI.cpp')
-rw-r--r--src/server/game/AI/CreatureAI.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp
index 96a25588120..d76d106e81a 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -140,6 +140,30 @@ void CreatureAI::MoveInLineOfSight(Unit* who)
// me->GetMotionMaster()->MoveChase(who->GetVictim());
}
+// Distract creature, if player gets too close while stealthed/prowling
+void CreatureAI::TriggerAlert(Unit const* who) const
+{
+ // If there's no target, or target isn't a player do nothing
+ if (!who || who->GetTypeId() != TYPEID_PLAYER)
+ return;
+
+ // If this unit isn't an NPC, is already distracted, is in combat, is confused, stunned or fleeing, do nothing
+ if (me->GetTypeId() != TYPEID_UNIT || me->IsInCombat() || me->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_STUNNED | UNIT_STATE_FLEEING | UNIT_STATE_DISTRACTED))
+ return;
+
+ // Only alert for hostiles!
+ if (me->IsCivilian() || me->HasReactState(REACT_PASSIVE) || !me->IsHostileTo(who) || !me->_IsTargetAcceptable(who))
+ return;
+
+ // Send alert sound (if any) for this creature
+ 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()));
+ me->StopMoving();
+ me->GetMotionMaster()->MoveDistract(5 * IN_MILLISECONDS);
+}
+
void CreatureAI::EnterEvadeMode()
{
if (!_EnterEvadeMode())