Entities/GO: Add forceRespawnTimer support to DespawnOrUnsummon. Use it in SAI.
Port From (https://github.com/TrinityCore/TrinityCore/commit/168be492f5924d306a90e7f8dfd86a6c547da3d7)
This commit is contained in:
@@ -63,7 +63,6 @@ namespace Game.AI
|
|||||||
uint _invincibilityHpLevel;
|
uint _invincibilityHpLevel;
|
||||||
|
|
||||||
uint _despawnTime;
|
uint _despawnTime;
|
||||||
uint _respawnTime;
|
|
||||||
uint _despawnState;
|
uint _despawnState;
|
||||||
|
|
||||||
// Vehicle conditions
|
// Vehicle conditions
|
||||||
@@ -570,7 +569,6 @@ namespace Game.AI
|
|||||||
GetScript().OnInitialize(me);
|
GetScript().OnInitialize(me);
|
||||||
|
|
||||||
_despawnTime = 0;
|
_despawnTime = 0;
|
||||||
_respawnTime = 0;
|
|
||||||
_despawnState = 0;
|
_despawnState = 0;
|
||||||
_escortState = SmartEscortState.None;
|
_escortState = SmartEscortState.None;
|
||||||
|
|
||||||
@@ -1021,7 +1019,7 @@ namespace Game.AI
|
|||||||
_despawnState++;
|
_despawnState++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
me.DespawnOrUnsummon(0, TimeSpan.FromSeconds(_respawnTime));
|
me.DespawnOrUnsummon();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_despawnTime -= diff;
|
_despawnTime -= diff;
|
||||||
@@ -1048,7 +1046,6 @@ namespace Game.AI
|
|||||||
public void SetDespawnTime(uint t, uint r = 0)
|
public void SetDespawnTime(uint t, uint r = 0)
|
||||||
{
|
{
|
||||||
_despawnTime = t;
|
_despawnTime = t;
|
||||||
_respawnTime = r;
|
|
||||||
_despawnState = t != 0 ? 1 : 0u;
|
_despawnState = t != 0 ? 1 : 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2696,7 +2696,7 @@ namespace Game.AI
|
|||||||
public struct ForceDespawn
|
public struct ForceDespawn
|
||||||
{
|
{
|
||||||
public uint delay;
|
public uint delay;
|
||||||
public uint respawn;
|
public uint forceRespawnTimer;
|
||||||
}
|
}
|
||||||
public struct InvincHP
|
public struct InvincHP
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -968,27 +968,22 @@ namespace Game.AI
|
|||||||
case SmartActions.ForceDespawn:
|
case SmartActions.ForceDespawn:
|
||||||
{
|
{
|
||||||
// there should be at least a world update tick before despawn, to avoid breaking linked actions
|
// there should be at least a world update tick before despawn, to avoid breaking linked actions
|
||||||
uint respawnDelay = Math.Max(e.Action.forceDespawn.delay, 1u);
|
TimeSpan despawnDelay = TimeSpan.FromMilliseconds(e.Action.forceDespawn.delay);
|
||||||
|
if (despawnDelay <= TimeSpan.Zero)
|
||||||
|
despawnDelay = TimeSpan.FromMilliseconds(1);
|
||||||
|
|
||||||
|
TimeSpan forceRespawnTimer = TimeSpan.FromSeconds(e.Action.forceDespawn.forceRespawnTimer);
|
||||||
|
|
||||||
foreach (var target in targets)
|
foreach (var target in targets)
|
||||||
{
|
{
|
||||||
Creature creature = target.ToCreature();
|
Creature creature = target.ToCreature();
|
||||||
if (creature != null)
|
if (creature != null)
|
||||||
{
|
creature.DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||||
CreatureAI smartAI = creature.GetAI();
|
|
||||||
if (smartAI != null && smartAI is SmartAI)
|
|
||||||
{
|
|
||||||
((SmartAI)smartAI).SetDespawnTime(respawnDelay);
|
|
||||||
((SmartAI)smartAI).StartDespawn();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
creature.DespawnOrUnsummon(TimeSpan.FromMilliseconds(respawnDelay));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GameObject go = target.ToGameObject();
|
GameObject go = target.ToGameObject();
|
||||||
if (go != null)
|
if (go != null)
|
||||||
go.SetRespawnTime((int)respawnDelay);
|
go.DespawnOrUnsummon(despawnDelay, forceRespawnTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ namespace Game.Entities
|
|||||||
if (m_despawnDelay > diff)
|
if (m_despawnDelay > diff)
|
||||||
m_despawnDelay -= diff;
|
m_despawnDelay -= diff;
|
||||||
else
|
else
|
||||||
DespawnOrUnsummon();
|
DespawnOrUnsummon(TimeSpan.FromMilliseconds(0), m_despawnRespawnTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_lootState)
|
switch (m_lootState)
|
||||||
@@ -870,17 +870,21 @@ namespace Game.Entities
|
|||||||
m_unique_users.Add(player.GetGUID());
|
m_unique_users.Add(player.GetGUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DespawnOrUnsummon(TimeSpan delay = default)
|
public void DespawnOrUnsummon(TimeSpan delay = default, TimeSpan forceRespawnTime = default)
|
||||||
{
|
{
|
||||||
if (delay > TimeSpan.Zero)
|
if (delay > TimeSpan.Zero)
|
||||||
{
|
{
|
||||||
if (m_despawnDelay == 0 || m_despawnDelay > delay.TotalMilliseconds)
|
if (m_despawnDelay == 0 || m_despawnDelay > delay.TotalMilliseconds)
|
||||||
|
{
|
||||||
m_despawnDelay = (uint)delay.TotalMilliseconds;
|
m_despawnDelay = (uint)delay.TotalMilliseconds;
|
||||||
|
m_despawnRespawnTime = forceRespawnTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_goData != null && m_respawnDelayTime != 0)
|
uint respawnDelay = (uint)((forceRespawnTime > TimeSpan.Zero) ? forceRespawnTime.TotalSeconds : m_respawnDelayTime);
|
||||||
SaveRespawnTime(m_respawnDelayTime);
|
if (m_goData != null && respawnDelay != 0)
|
||||||
|
SaveRespawnTime(respawnDelay);
|
||||||
Delete();
|
Delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2883,6 +2887,7 @@ namespace Game.Entities
|
|||||||
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;
|
uint m_despawnDelay;
|
||||||
|
TimeSpan m_despawnRespawnTime; // override respawn time after delayed despawn
|
||||||
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