Core/Conditions: Implemented conditions for spawn groups

Port From (https://github.com/TrinityCore/TrinityCore/commit/5d27939667cf3ca985a33b93646fa4e34445c8d3)
This commit is contained in:
hondacrx
2022-06-24 22:08:58 -04:00
parent a0d4a4f522
commit e56f3792de
6 changed files with 166 additions and 64 deletions
+21 -1
View File
@@ -740,6 +740,7 @@ namespace Game.Maps
if (_respawnCheckTimer <= diff)
{
ProcessRespawns();
UpdateSpawnGroupConditions();
_respawnCheckTimer = WorldConfig.GetUIntValue(WorldCfg.RespawnMinCheckIntervalMs);
}
else
@@ -2849,7 +2850,7 @@ namespace Game.Maps
return true;
}
public bool SpawnGroupDespawn(uint groupId, bool deleteRespawnTimes)
public bool SpawnGroupDespawn(uint groupId, bool deleteRespawnTimes = false)
{
return SpawnGroupDespawn(groupId, deleteRespawnTimes, out _);
}
@@ -2910,6 +2911,25 @@ namespace Game.Maps
return _toggledSpawnGroupIds.Contains(groupId) != !data.flags.HasAnyFlag(SpawnGroupFlags.ManualSpawn);
}
void UpdateSpawnGroupConditions()
{
var spawnGroups = Global.ObjectMgr.GetSpawnGroupsForMap(GetId());
foreach (uint spawnGroupId in spawnGroups)
{
bool isActive = IsSpawnGroupActive(spawnGroupId);
bool shouldBeActive = Global.ConditionMgr.IsMapMeetingNotGroupedConditions(ConditionSourceType.SpawnGroup, spawnGroupId, this);
if (isActive == shouldBeActive)
continue;
if (shouldBeActive)
SpawnGroupSpawn(spawnGroupId);
else if (GetSpawnGroupData(spawnGroupId).flags.HasFlag(SpawnGroupFlags.DespawnOnConditionFailure))
SpawnGroupDespawn(spawnGroupId);
else
SetSpawnGroupInactive(spawnGroupId);
}
}
public void AddFarSpellCallback(FarSpellCallback callback)
{
_farSpellCallbacks.Enqueue(new FarSpellCallback(callback));