Core/Creatures: add TimeSpan to TempSummon

Port From (https://github.com/TrinityCore/TrinityCore/commit/1dd4b38170339e2d1d959c45ecad1b3b8dceb216)
This commit is contained in:
hondacrx
2023-09-13 20:59:45 -04:00
parent 7b2d198832
commit 0e2dd0cda3
11 changed files with 51 additions and 48 deletions
+3 -3
View File
@@ -1544,7 +1544,7 @@ namespace Game.Entities
Map map = GetMap();
if (map != null)
{
TempSummon summon = map.SummonCreature(entry, pos, null, (uint)despawnTime.TotalMilliseconds, this, spellId, vehId, privateObjectOwner);
TempSummon summon = map.SummonCreature(entry, pos, null, despawnTime, this, spellId, vehId, privateObjectOwner);
if (summon != null)
{
summon.SetTempSummonType(despawnType);
@@ -1560,7 +1560,7 @@ namespace Game.Entities
Map map = GetMap();
if (map != null)
{
TempSummon summon = map.SummonCreature(GetEntry(), pos, null, (uint)despawnTime.TotalMilliseconds, privateObjectOwner, spellId, vehId, privateObjectOwner.GetGUID(), new SmoothPhasingInfo(GetGUID(), true, true));
TempSummon summon = map.SummonCreature(GetEntry(), pos, null, despawnTime, privateObjectOwner, spellId, vehId, privateObjectOwner.GetGUID(), new SmoothPhasingInfo(GetGUID(), true, true));
if (summon != null)
{
summon.SetTempSummonType(despawnType);
@@ -1648,7 +1648,7 @@ namespace Game.Entities
foreach (var tempSummonData in data)
{
TempSummon summon = SummonCreature(tempSummonData.entry, tempSummonData.pos, tempSummonData.type, TimeSpan.FromMilliseconds(tempSummonData.time));
TempSummon summon = SummonCreature(tempSummonData.entry, tempSummonData.pos, tempSummonData.type, tempSummonData.time);
if (summon)
list.Add(summon);
}
+1 -1
View File
@@ -1239,7 +1239,7 @@ namespace Game.Entities
petSpells.PetGUID = vehicle.GetGUID();
petSpells.CreatureFamily = 0; // Pet Family (0 for all vehicles)
petSpells.Specialization = 0;
petSpells.TimeLimit = vehicle.IsSummon() ? vehicle.ToTempSummon().GetTimer() : 0;
petSpells.TimeLimit = (uint)(vehicle.IsSummon() ? vehicle.ToTempSummon().GetTimer().TotalMilliseconds : 0);
petSpells.ReactState = vehicle.GetReactState();
petSpells.CommandState = CommandStates.Follow;
petSpells.Flag = 0x8;
+20 -19
View File
@@ -60,6 +60,7 @@ namespace Game.Entities
return;
}
TimeSpan msDiff = TimeSpan.FromMilliseconds(diff);
switch (m_type)
{
case TempSummonType.ManualDespawn:
@@ -67,26 +68,26 @@ namespace Game.Entities
break;
case TempSummonType.TimedDespawn:
{
if (m_timer <= diff)
if (m_timer <= msDiff)
{
UnSummon();
return;
}
m_timer -= diff;
m_timer -= msDiff;
break;
}
case TempSummonType.TimedDespawnOutOfCombat:
{
if (!IsInCombat())
{
if (m_timer <= diff)
if (m_timer <= msDiff)
{
UnSummon();
return;
}
m_timer -= diff;
m_timer -= msDiff;
}
else if (m_timer != m_lifetime)
m_timer = m_lifetime;
@@ -98,13 +99,13 @@ namespace Game.Entities
{
if (m_deathState == DeathState.Corpse)
{
if (m_timer <= diff)
if (m_timer <= msDiff)
{
UnSummon();
return;
}
m_timer -= diff;
m_timer -= msDiff;
}
break;
}
@@ -129,13 +130,13 @@ namespace Game.Entities
if (!IsInCombat())
{
if (m_timer <= diff)
if (m_timer <= msDiff)
{
UnSummon();
return;
}
else
m_timer -= diff;
m_timer -= msDiff;
}
else if (m_timer != m_lifetime)
m_timer = m_lifetime;
@@ -145,13 +146,13 @@ namespace Game.Entities
{
if (!IsInCombat() && IsAlive())
{
if (m_timer <= diff)
if (m_timer <= msDiff)
{
UnSummon();
return;
}
else
m_timer -= diff;
m_timer -= msDiff;
}
else if (m_timer != m_lifetime)
m_timer = m_lifetime;
@@ -164,7 +165,7 @@ namespace Game.Entities
}
}
public virtual void InitStats(WorldObject summoner, uint duration)
public virtual void InitStats(WorldObject summoner, TimeSpan duration)
{
Cypher.Assert(!IsPet());
@@ -172,7 +173,7 @@ namespace Game.Entities
m_lifetime = duration;
if (m_type == TempSummonType.ManualDespawn)
m_type = (duration == 0) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
m_type = (duration == TimeSpan.Zero) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
if (summoner != null && summoner.IsPlayer())
{
@@ -363,7 +364,7 @@ namespace Game.Entities
TempSummonType GetSummonType() { return m_type; }
public uint GetTimer() { return m_timer; }
public TimeSpan GetTimer() { return m_timer; }
public uint? GetCreatureIdVisibleToSummoner() { return m_creatureIdVisibleToSummoner; }
public uint? GetDisplayIdVisibleToSummoner() { return m_displayIdVisibleToSummoner; }
@@ -373,8 +374,8 @@ namespace Game.Entities
public SummonPropertiesRecord m_Properties;
TempSummonType m_type;
uint m_timer;
uint m_lifetime;
TimeSpan m_timer;
TimeSpan m_lifetime;
ObjectGuid m_summonerGUID;
uint? m_creatureIdVisibleToSummoner;
uint? m_displayIdVisibleToSummoner;
@@ -394,7 +395,7 @@ namespace Game.Entities
InitCharmInfo();
}
public override void InitStats(WorldObject summoner, uint duration)
public override void InitStats(WorldObject summoner, TimeSpan duration)
{
base.InitStats(summoner, duration);
@@ -488,7 +489,7 @@ namespace Game.Entities
}
}
public override void InitStats(WorldObject summoner, uint duration)
public override void InitStats(WorldObject summoner, TimeSpan duration)
{
base.InitStats(summoner, duration);
@@ -1085,7 +1086,7 @@ namespace Game.Entities
UnitTypeMask |= UnitTypeMask.Puppet;
}
public override void InitStats(WorldObject summoner, uint duration)
public override void InitStats(WorldObject summoner, TimeSpan duration)
{
base.InitStats(summoner, duration);
@@ -1135,7 +1136,7 @@ namespace Game.Entities
public uint entry; // Entry of summoned creature
public Position pos; // Position, where should be creature spawned
public TempSummonType type; // Summon type, see TempSummonType for available types
public uint time; // Despawn time, usable only with certain temp summon types
public TimeSpan time; // Despawn time, usable only with certain temp summon types
}
enum PetEntry
+8 -7
View File
@@ -26,18 +26,19 @@ namespace Game.Entities
return;
}
if (m_duration <= diff)
if (m_duration <= TimeSpan.FromMilliseconds(diff))
{
UnSummon(); // remove self
return;
}
else
m_duration -= diff;
m_duration -= TimeSpan.FromMilliseconds(diff);
base.Update(diff);
}
public override void InitStats(WorldObject summoner, uint duration)
public override void InitStats(WorldObject summoner, TimeSpan duration)
{
// client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
Player owner = GetOwner().ToPlayer();
@@ -156,9 +157,9 @@ namespace Game.Entities
public uint GetSpell(byte slot = 0) { return m_spells[slot]; }
public uint GetTotemDuration() { return m_duration; }
public TimeSpan GetTotemDuration() { return m_duration; }
public void SetTotemDuration(uint duration) { m_duration = duration; }
public void SetTotemDuration(TimeSpan duration) { m_duration = duration; }
public TotemType GetTotemType() { return m_type; }
@@ -174,7 +175,7 @@ namespace Game.Entities
public override void UpdateDamagePhysical(WeaponAttackType attType) { }
TotemType m_type;
uint m_duration;
TimeSpan m_duration;
}
public enum TotemType
+1 -1
View File
@@ -431,7 +431,7 @@ namespace Game.Entities
return go;
}
public TempSummon SummonPassenger(uint entry, Position pos, TempSummonType summonType, SummonPropertiesRecord properties = null, uint duration = 0, Unit summoner = null, uint spellId = 0, uint vehId = 0)
public TempSummon SummonPassenger(uint entry, Position pos, TempSummonType summonType, SummonPropertiesRecord properties = null, TimeSpan duration = default, Unit summoner = null, uint spellId = 0, uint vehId = 0)
{
Map map = GetMap();
if (map == null)
+1 -1
View File
@@ -9426,7 +9426,7 @@ namespace Game
continue;
}
data.time = result.Read<uint>(9);
data.time = TimeSpan.FromMilliseconds(result.Read<uint>(9));
Tuple<uint, SummonerType, byte> key = Tuple.Create(summonerId, summonerType, group);
_tempSummonDataStorage.Add(key, data);
+1 -1
View File
@@ -3572,7 +3572,7 @@ namespace Game.Maps
}
}
public TempSummon SummonCreature(uint entry, Position pos, SummonPropertiesRecord properties = null, uint duration = 0, WorldObject summoner = null, uint spellId = 0, uint vehId = 0, ObjectGuid privateObjectOwner = default, SmoothPhasingInfo smoothPhasingInfo = null)
public TempSummon SummonCreature(uint entry, Position pos, SummonPropertiesRecord properties = null, TimeSpan duration = default, WorldObject summoner = null, uint spellId = 0, uint vehId = 0, ObjectGuid privateObjectOwner = default, SmoothPhasingInfo smoothPhasingInfo = null)
{
var mask = UnitTypeMask.Summon;
if (properties != null)
@@ -3,6 +3,7 @@
using Framework.Constants;
using Game.Entities;
using System;
namespace Game.Networking.Packets
{
@@ -28,7 +29,7 @@ namespace Game.Networking.Packets
{
_worldPacket.WriteUInt8(Slot);
_worldPacket.WritePackedGuid(Totem);
_worldPacket.WriteUInt32(Duration);
_worldPacket.WriteUInt32((uint)Duration.TotalMilliseconds);
_worldPacket.WriteUInt32(SpellID);
_worldPacket.WriteFloat(TimeMod);
_worldPacket.WriteBit(CannotDismiss);
@@ -37,7 +38,7 @@ namespace Game.Networking.Packets
public ObjectGuid Totem;
public uint SpellID;
public uint Duration;
public TimeSpan Duration;
public byte Slot;
public float TimeMod = 1.0f;
public bool CannotDismiss;
+10 -10
View File
@@ -1470,7 +1470,7 @@ namespace Game.Spells
if (caster.IsPlayer() && m_originalCaster.ToPlayer().GetGroup())
privateObjectOwner = caster.ToPlayer().GetGroup().GetGUID();
int duration = m_spellInfo.CalcDuration(caster);
TimeSpan duration = TimeSpan.FromMilliseconds(m_spellInfo.CalcDuration(caster));
Unit unitCaster = GetUnitCasterForEffectHandlers();
@@ -1532,7 +1532,7 @@ namespace Game.Spells
if (unitCaster == null)
return;
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, (uint)duration, unitCaster, m_spellInfo.Id);
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, duration, unitCaster, m_spellInfo.Id);
break;
}
case SummonTitle.LightWell:
@@ -1541,7 +1541,7 @@ namespace Game.Spells
if (unitCaster == null)
return;
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
if (summon == null || !summon.IsTotem())
return;
@@ -1557,7 +1557,7 @@ namespace Game.Spells
if (unitCaster == null)
return;
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
if (summon == null || !summon.HasUnitTypeMask(UnitTypeMask.Minion))
return;
@@ -1569,7 +1569,7 @@ namespace Game.Spells
{
float radius = effectInfo.CalcRadius();
TempSummonType summonType = (duration == 0) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
TempSummonType summonType = (duration == TimeSpan.Zero) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
for (uint count = 0; count < numSummons; ++count)
{
@@ -1580,7 +1580,7 @@ namespace Game.Spells
// randomize position for multiple summons
pos = caster.GetRandomPoint(destTarget, radius);
summon = caster.GetMap().SummonCreature(entry, pos, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
summon = caster.GetMap().SummonCreature(entry, pos, properties, duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
if (summon == null)
continue;
@@ -1602,7 +1602,7 @@ namespace Game.Spells
if (unitCaster == null)
return;
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
break;
}
case SummonCategory.Vehicle:
@@ -1612,7 +1612,7 @@ namespace Game.Spells
// Summoning spells (usually triggered by npc_spellclick) that spawn a vehicle and that cause the clicker
// to cast a ride vehicle spell on the summoned unit.
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, (uint)duration, unitCaster, m_spellInfo.Id);
summon = unitCaster.GetMap().SummonCreature(entry, destTarget, properties, duration, unitCaster, m_spellInfo.Id);
if (summon == null || !summon.IsVehicle())
return;
@@ -4590,7 +4590,7 @@ namespace Game.Spells
// in another case summon new
float radius = 5.0f;
int duration = m_spellInfo.CalcDuration(m_originalCaster);
TimeSpan duration = TimeSpan.FromMilliseconds(m_spellInfo.CalcDuration(m_originalCaster));
//TempSummonType summonType = (duration == 0) ? TempSummonType.DeadDespawn : TempSummonType.TimedDespawn;
Map map = unitCaster.GetMap();
@@ -4604,7 +4604,7 @@ namespace Game.Spells
// randomize position for multiple summons
pos = unitCaster.GetRandomPoint(destTarget, radius);
TempSummon summon = map.SummonCreature(entry, pos, properties, (uint)duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
TempSummon summon = map.SummonCreature(entry, pos, properties, duration, unitCaster, m_spellInfo.Id, 0, privateObjectOwner);
if (summon == null)
return;
+1 -1
View File
@@ -4735,7 +4735,7 @@ namespace Scripts.Spells.Generic
Unit caster = GetCaster();
var properties = CliDB.SummonPropertiesStorage.LookupByKey((uint)GetEffectInfo().MiscValueB);
uint duration = (uint)GetSpellInfo().CalcDuration(caster);
TimeSpan duration = TimeSpan.FromMilliseconds(GetSpellInfo().CalcDuration(caster));
Position pos = GetHitDest().GetPosition();
Creature summon = caster.GetMap().SummonCreature(creatureId, pos, properties, duration, caster, GetSpellInfo().Id);
+2 -2
View File
@@ -588,8 +588,8 @@ namespace Scripts.Spells.Shaman
WorldLocation dest = GetExplTargetDest();
if (dest != null)
{
int duration = GetSpellInfo().CalcDuration(GetOriginalCaster());
TempSummon summon = GetCaster().GetMap().SummonCreature(CreatureIds.HealingRainInvisibleStalker, dest, null, (uint)duration, GetOriginalCaster());
TimeSpan duration = TimeSpan.FromMilliseconds(GetSpellInfo().CalcDuration(GetOriginalCaster()));
TempSummon summon = GetCaster().GetMap().SummonCreature(CreatureIds.HealingRainInvisibleStalker, dest, null, duration, GetOriginalCaster());
if (summon == null)
return;