diff options
Diffstat (limited to 'src/server/game/AI')
| -rw-r--r-- | src/server/game/AI/CreatureAI.cpp | 24 | ||||
| -rw-r--r-- | src/server/game/AI/CreatureAI.h | 3 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 8 |
5 files changed, 48 insertions, 3 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()) diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 2e862c37c0e..33616d076e7 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -89,6 +89,9 @@ class CreatureAI : public UnitAI // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter void MoveInLineOfSight_Safe(Unit* who); + // Trigger Creature "Alert" state (creature can see stealthed unit) + void TriggerAlert(Unit const* who) const; + // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events. virtual bool CanRespawn() { return true; } diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 66164730219..7ea77341567 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -120,7 +120,13 @@ void npc_escortAI::MoveInLineOfSight(Unit* who) { if (!me->GetVictim()) { - who->RemoveAurasByType(SPELL_AURA_MOD_STEALTH); + // 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()) diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp index ab91b0b5b27..856ca1d9e16 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp @@ -117,7 +117,13 @@ void FollowerAI::MoveInLineOfSight(Unit* who) { if (!me->GetVictim()) { - who->RemoveAurasByType(SPELL_AURA_MOD_STEALTH); + // 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()) diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 4203e796aa5..3157ea4ecd4 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -473,7 +473,13 @@ void SmartAI::MoveInLineOfSight(Unit* who) { if (!me->GetVictim()) { - who->RemoveAurasByType(SPELL_AURA_MOD_STEALTH); + // 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())*/ |
