Core/Instances: New ZoneScript hook - OnCreatureGroupDepleted
Port From (https://github.com/TrinityCore/TrinityCore/commit/ec2631eca3a397dffd2e525b34c131c283beb167)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user