From 3cf7f6b831574809224c3fab0b07bcb50e0f71cc Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 24 Dec 2021 20:15:10 -0500 Subject: [PATCH] Combat/Threat: Split ThreatManager::NotifyDisengaged off from ThreatManager::ClearAllThreat. NotifyDisengaged signifies intent to clear the engagement flag, and should only be called from AI. Port From (https://github.com/TrinityCore/TrinityCore/commit/38d7c1530a65a7ff1bd10775c4a35269b2416538) --- Source/Game/AI/CoreAI/CreatureAI.cs | 7 ++----- Source/Game/AI/CoreAI/GuardAI.cs | 4 ++-- Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs | 2 +- Source/Game/AI/ScriptedAI/ScriptedFollowerAI.cs | 2 +- Source/Game/Combat/ThreatManager.cs | 8 ++++++++ Source/Game/Entities/Unit/Unit.cs | 1 - Source/Game/Maps/ObjectGridLoader.cs | 1 - Source/Scripts/Pets/Priest.cs | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Source/Game/AI/CoreAI/CreatureAI.cs b/Source/Game/AI/CoreAI/CreatureAI.cs index c8a5865a1..a8a93d5d8 100644 --- a/Source/Game/AI/CoreAI/CreatureAI.cs +++ b/Source/Game/AI/CoreAI/CreatureAI.cs @@ -224,18 +224,15 @@ namespace Game.AI me.RemoveAurasOnEvade(); // sometimes bosses stuck in combat? - me.GetThreatManager().ClearAllThreat(); me.CombatStop(true); + me.GetThreatManager().NotifyDisengaged(); me.SetLootRecipient(null); me.ResetPlayerDamageReq(); me.SetLastDamagedTime(0); me.SetCannotReachTarget(false); me.DoNotReacquireTarget(); - if (me.IsInEvadeMode()) - return false; - - return true; + return !me.IsInEvadeMode(); } public CypherStrings VisualizeBoundary(int duration, Unit owner = null, bool fill = false) diff --git a/Source/Game/AI/CoreAI/GuardAI.cs b/Source/Game/AI/CoreAI/GuardAI.cs index aeea572ab..463422e82 100644 --- a/Source/Game/AI/CoreAI/GuardAI.cs +++ b/Source/Game/AI/CoreAI/GuardAI.cs @@ -48,15 +48,15 @@ namespace Game.AI { me.GetMotionMaster().MoveIdle(); me.CombatStop(true); - me.GetThreatManager().ClearAllThreat(); + me.GetThreatManager().NotifyDisengaged(); return; } Log.outDebug(LogFilter.Unit, "Guard entry: {0} enters evade mode.", me.GetEntry()); me.RemoveAllAuras(); - me.GetThreatManager().ClearAllThreat(); me.CombatStop(true); + me.GetThreatManager().NotifyDisengaged(); me.GetMotionMaster().MoveTargetedHome(); } diff --git a/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs b/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs index bf8fe13ae..a2021763e 100644 --- a/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs +++ b/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs @@ -134,8 +134,8 @@ namespace Game.AI public override void EnterEvadeMode(EvadeReason why = EvadeReason.Other) { me.RemoveAllAuras(); - me.GetThreatManager().ClearAllThreat(); me.CombatStop(true); + me.GetThreatManager().NotifyDisengaged(); me.SetLootRecipient(null); if (HasEscortState(EscortState.Escorting)) diff --git a/Source/Game/AI/ScriptedAI/ScriptedFollowerAI.cs b/Source/Game/AI/ScriptedAI/ScriptedFollowerAI.cs index 79cc37939..bfd740231 100644 --- a/Source/Game/AI/ScriptedAI/ScriptedFollowerAI.cs +++ b/Source/Game/AI/ScriptedAI/ScriptedFollowerAI.cs @@ -126,8 +126,8 @@ namespace Game.AI return; me.RemoveAllAuras(); - me.GetThreatManager().ClearAllThreat(); me.CombatStop(true); + me.GetThreatManager().NotifyDisengaged(); me.SetLootRecipient(null); me.SetCannotReachTarget(false); me.DoNotReacquireTarget(); diff --git a/Source/Game/Combat/ThreatManager.cs b/Source/Game/Combat/ThreatManager.cs index 381876c50..9d09d8e03 100644 --- a/Source/Game/Combat/ThreatManager.cs +++ b/Source/Game/Combat/ThreatManager.cs @@ -396,6 +396,14 @@ namespace Game.Combat _myThreatListEntries.FirstOrDefault().Value.UnregisterAndFree(); while (!_myThreatListEntries.Empty()); } + } + + /// + /// THIS SHOULD ONLY BE CALLED FROM A CREATURE'S AI (typically in EnterEvadeMode) + /// notify the unit that the AI has disengaged + /// + public void NotifyDisengaged() + { // note: i don't really like having this here // (maybe engage flag should be in creature ai? it's inherently an AI property...) if (_owner.IsEngaged()) diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 05f6c14cf..10cd08480 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -1405,7 +1405,6 @@ namespace Game.Entities if (s != DeathState.Alive && s != DeathState.JustRespawned) { CombatStop(); - GetThreatManager().ClearAllThreat(); if (IsNonMeleeSpellCast(false)) InterruptNonMeleeSpells(false); diff --git a/Source/Game/Maps/ObjectGridLoader.cs b/Source/Game/Maps/ObjectGridLoader.cs index 9be8aa3bb..07bff3982 100644 --- a/Source/Game/Maps/ObjectGridLoader.cs +++ b/Source/Game/Maps/ObjectGridLoader.cs @@ -216,7 +216,6 @@ namespace Game.Maps if (creature.IsInCombat()) { creature.CombatStop(); - creature.GetThreatManager().ClearAllThreat(); if (creature.IsAIEnabled()) creature.GetAI().EnterEvadeMode(); } diff --git a/Source/Scripts/Pets/Priest.cs b/Source/Scripts/Pets/Priest.cs index 7cf313237..d657b8b32 100644 --- a/Source/Scripts/Pets/Priest.cs +++ b/Source/Scripts/Pets/Priest.cs @@ -44,8 +44,8 @@ namespace Scripts.Pets if (!me.IsAlive()) return; - me.GetThreatManager().ClearAllThreat(); me.CombatStop(true); + me.GetThreatManager().NotifyDisengaged(); me.ResetPlayerDamageReq(); } }