From 2276940252e9b506aaa3ae857a4b485b0f620e1b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 30 May 2022 13:26:37 -0400 Subject: [PATCH] Core/Combat: Fixed combat after remove charm Port From (https://github.com/TrinityCore/TrinityCore/commit/4ed918fcb38d7fd3752899a0eafd7ad62b7217af) --- Source/Game/Combat/CombatManager.cs | 21 +++++++++++++++++++++ Source/Game/Entities/Unit/Unit.Pets.cs | 1 + 2 files changed, 22 insertions(+) diff --git a/Source/Game/Combat/CombatManager.cs b/Source/Game/Combat/CombatManager.cs index ea7135254..af0ba9707 100644 --- a/Source/Game/Combat/CombatManager.cs +++ b/Source/Game/Combat/CombatManager.cs @@ -235,6 +235,27 @@ namespace Game.Combat _pveRefs.First().Value.EndCombat(); } + public void RevalidateCombat() + { + foreach(var (guid, refe) in _pveRefs.ToList()) + { + if (!CanBeginCombat(_owner, refe.GetOther(_owner))) + { + _pveRefs.Remove(guid); // erase manually here to avoid iterator invalidation + refe.EndCombat(); + } + } + + foreach (var (guid, refe) in _pvpRefs.ToList()) + { + if (!CanBeginCombat(_owner, refe.GetOther(_owner))) + { + _pvpRefs.Remove(guid); // erase manually here to avoid iterator invalidation + refe.EndCombat(); + } + } + } + void EndAllPvPCombat() { while (!_pvpRefs.Empty()) diff --git a/Source/Game/Entities/Unit/Unit.Pets.cs b/Source/Game/Entities/Unit/Unit.Pets.cs index cc032db9b..a1cab890a 100644 --- a/Source/Game/Entities/Unit/Unit.Pets.cs +++ b/Source/Game/Entities/Unit/Unit.Pets.cs @@ -481,6 +481,7 @@ namespace Game.Entities Cypher.Assert(type != CharmType.Vehicle || (IsTypeId(TypeId.Unit) && IsVehicle())); charmer.SetCharm(this, false); + m_combatManager.RevalidateCombat(); Player playerCharmer = charmer.ToPlayer(); if (playerCharmer)