diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index c8749472f..f9620301f 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2028,8 +2028,15 @@ namespace Game.Entities SetNoSearchAssistance(false); //Dismiss group if is leader - if (m_formation != null && m_formation.GetLeader() == this) - m_formation.FormationReset(true); + if (m_formation != null) + { + if (m_formation.GetLeader() == this) + m_formation.FormationReset(true); + + ZoneScript script = GetZoneScript(); + if (script != null && !m_formation.HasAliveMembers()) + script.OnCreatureGroupDepleted(m_formation); + } bool needsFalling = (IsFlying() || IsHovering()) && !IsUnderWater() && !HasUnitState(UnitState.Root); SetHover(false, false); diff --git a/Source/Game/Entities/Creature/CreatureGroups.cs b/Source/Game/Entities/Creature/CreatureGroups.cs index b18bbd4cc..704700012 100644 --- a/Source/Game/Entities/Creature/CreatureGroups.cs +++ b/Source/Game/Entities/Creature/CreatureGroups.cs @@ -55,6 +55,12 @@ namespace Game.Entities Log.outDebug(LogFilter.Unit, $"Deleting member GUID: {leaderSpawnId} from group {member.GetSpawnId()}"); group.RemoveMember(member); + // If removed member was alive we need to check if we have any other alive members + // if not - fire OnCreatureGroupDepleted + ZoneScript script = member.GetZoneScript(); + if (script != null && member.IsAlive() && !group.HasAliveMembers()) + script.OnCreatureGroupDepleted(group); + if (group.IsEmpty()) { if (leaderSpawnId != 0) @@ -299,6 +305,29 @@ namespace Game.Entities return true; } + public bool HasAliveMembers() + { + return _members.Any(pair => pair.Key.IsAlive()); + } + + public bool LeaderHasStringId(string id) + { + if (_leader != null) + return _leader.HasStringId(id); + + CreatureData leaderCreatureData = Global.ObjectMgr.GetCreatureData(_leaderSpawnId); + if (leaderCreatureData != null) + { + if (leaderCreatureData.StringId == id) + return true; + + if (Global.ObjectMgr.GetCreatureTemplate(leaderCreatureData.Id).StringId == id) + return true; + } + + return false; + } + public Creature GetLeader() { return _leader; } public ulong GetLeaderSpawnId() { return _leaderSpawnId; } public bool IsEmpty() { return _members.Empty(); } diff --git a/Source/Game/Maps/ZoneScript.cs b/Source/Game/Maps/ZoneScript.cs index 1db873412..8e02c6f3d 100644 --- a/Source/Game/Maps/ZoneScript.cs +++ b/Source/Game/Maps/ZoneScript.cs @@ -34,6 +34,9 @@ namespace Game.Maps public virtual void OnUnitDeath(Unit unit) { } + // Triggers when the CreatureGroup no longer has any alive members (either last alive member dies or is removed from the group) + public virtual void OnCreatureGroupDepleted(CreatureGroup creatureGroup) { } + //All-purpose data storage 64 bit public virtual ObjectGuid GetGuidData(uint DataId) { return ObjectGuid.Empty; } public virtual void SetGuidData(uint DataId, ObjectGuid Value) { }