From 1e0213bc57922719d4f7e8897cb7e8871c138fdc Mon Sep 17 00:00:00 2001 From: pete318 Date: Sun, 28 Jun 2015 23:42:47 +0000 Subject: The following stealth changes are implemented. - Combat no longer removes stealth, only damage does - Creatures will pursue a stealthed unit they cannot see if they're already in combat with them - When a player is ~~3 yards~~ 8% + 1.5 yards away from the usual stealth detection distance, the creature will perform the "alerted" effect. - When sitting/sleeping creatures are distracted or alerted, they will stand up - Idle movement creatures will return to their original (spawn) orientation after distract/alert - When entering combat with a distracted/alerted creature, distract state is removed - NPC no longer have a limit to stealth visibility (granted by stealth modifier spells/buffs) - If alert visibility is greater than aggro range, no alert sent --- src/server/game/AI/CreatureAI.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/server/game/AI/CreatureAI.cpp') 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()) -- cgit v1.2.3