Entities/GO: GameObjects now support (delayed) despawning in a reasonable manner.
Port From (https://github.com/TrinityCore/TrinityCore/commit/bccd81e12ac418d2ba76c1cd6470c813a4d19229)
This commit is contained in:
@@ -982,7 +982,7 @@ namespace Game.AI
|
|||||||
((SmartAI)smartAI).StartDespawn();
|
((SmartAI)smartAI).StartDespawn();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
creature.DespawnOrUnsummon(respawnDelay);
|
creature.DespawnOrUnsummon(TimeSpan.FromMilliseconds(respawnDelay));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace Game.Entities
|
|||||||
m_updateFlag.Rotation = true;
|
m_updateFlag.Rotation = true;
|
||||||
|
|
||||||
m_respawnDelayTime = 300;
|
m_respawnDelayTime = 300;
|
||||||
|
m_despawnDelay = 0;
|
||||||
m_lootState = LootState.NotReady;
|
m_lootState = LootState.NotReady;
|
||||||
m_spawnedByDefault = true;
|
m_spawnedByDefault = true;
|
||||||
|
|
||||||
@@ -423,6 +424,14 @@ namespace Game.Entities
|
|||||||
else if (!AIM_Initialize())
|
else if (!AIM_Initialize())
|
||||||
Log.outError(LogFilter.Server, "Could not initialize GameObjectAI");
|
Log.outError(LogFilter.Server, "Could not initialize GameObjectAI");
|
||||||
|
|
||||||
|
if (m_despawnDelay != 0)
|
||||||
|
{
|
||||||
|
if (m_despawnDelay > diff)
|
||||||
|
m_despawnDelay -= diff;
|
||||||
|
else
|
||||||
|
DespawnOrUnsummon();
|
||||||
|
}
|
||||||
|
|
||||||
switch (m_lootState)
|
switch (m_lootState)
|
||||||
{
|
{
|
||||||
case LootState.NotReady:
|
case LootState.NotReady:
|
||||||
@@ -861,6 +870,21 @@ namespace Game.Entities
|
|||||||
m_unique_users.Add(player.GetGUID());
|
m_unique_users.Add(player.GetGUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DespawnOrUnsummon(TimeSpan delay = default)
|
||||||
|
{
|
||||||
|
if (delay > TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
if (m_despawnDelay == 0 || m_despawnDelay > delay.TotalMilliseconds)
|
||||||
|
m_despawnDelay = (uint)delay.TotalMilliseconds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_goData != null && m_respawnDelayTime != 0)
|
||||||
|
SaveRespawnTime(m_respawnDelayTime);
|
||||||
|
Delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Delete()
|
public void Delete()
|
||||||
{
|
{
|
||||||
SetLootState(LootState.NotReady);
|
SetLootState(LootState.NotReady);
|
||||||
@@ -1160,7 +1184,7 @@ namespace Game.Entities
|
|||||||
|
|
||||||
public override void SaveRespawnTime(uint forceDelay = 0, bool savetodb = true)
|
public override void SaveRespawnTime(uint forceDelay = 0, bool savetodb = true)
|
||||||
{
|
{
|
||||||
if (m_goData != null && m_respawnTime > GameTime.GetGameTime() && m_spawnedByDefault)
|
if (m_goData != null && (forceDelay != 0 || m_respawnTime > GameTime.GetGameTime()) && m_spawnedByDefault)
|
||||||
{
|
{
|
||||||
if (m_respawnCompatibilityMode)
|
if (m_respawnCompatibilityMode)
|
||||||
{
|
{
|
||||||
@@ -2858,6 +2882,7 @@ namespace Game.Entities
|
|||||||
uint m_spellId;
|
uint m_spellId;
|
||||||
long m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
|
long m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
|
||||||
uint m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
|
uint m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
|
||||||
|
uint m_despawnDelay;
|
||||||
LootState m_lootState;
|
LootState m_lootState;
|
||||||
ObjectGuid m_lootStateUnitGUID; // GUID of the unit passed with SetLootState(LootState, Unit*)
|
ObjectGuid m_lootStateUnitGUID; // GUID of the unit passed with SetLootState(LootState, Unit*)
|
||||||
bool m_spawnedByDefault;
|
bool m_spawnedByDefault;
|
||||||
|
|||||||
Reference in New Issue
Block a user