From 0e2dd0cda3f57bbe66e41bf67394d8fa4dbfda66 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 13 Sep 2023 20:59:45 -0400 Subject: [PATCH] Core/Creatures: add TimeSpan to TempSummon Port From (https://github.com/TrinityCore/TrinityCore/commit/1dd4b38170339e2d1d959c45ecad1b3b8dceb216) --- Source/Game/Entities/Object/WorldObject.cs | 6 +-- Source/Game/Entities/Player/Player.cs | 2 +- Source/Game/Entities/TemporarySummon.cs | 39 ++++++++++--------- Source/Game/Entities/Totem.cs | 15 +++---- Source/Game/Entities/Transport.cs | 2 +- Source/Game/Globals/ObjectManager.cs | 2 +- Source/Game/Maps/Map.cs | 2 +- .../Game/Networking/Packets/TotemPackets.cs | 5 ++- Source/Game/Spells/SpellEffects.cs | 20 +++++----- Source/Scripts/Spells/Generic.cs | 2 +- Source/Scripts/Spells/Shaman.cs | 4 +- 11 files changed, 51 insertions(+), 48 deletions(-) diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 74fd14899..3d54bf191 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -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); } diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 115988e47..42ef94bd7 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -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; diff --git a/Source/Game/Entities/TemporarySummon.cs b/Source/Game/Entities/TemporarySummon.cs index d7e42e286..6e44ef6b4 100644 --- a/Source/Game/Entities/TemporarySummon.cs +++ b/Source/Game/Entities/TemporarySummon.cs @@ -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 diff --git a/Source/Game/Entities/Totem.cs b/Source/Game/Entities/Totem.cs index 3ff4680a0..26203645c 100644 --- a/Source/Game/Entities/Totem.cs +++ b/Source/Game/Entities/Totem.cs @@ -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 diff --git a/Source/Game/Entities/Transport.cs b/Source/Game/Entities/Transport.cs index cd7afc7d1..11f6fdbdc 100644 --- a/Source/Game/Entities/Transport.cs +++ b/Source/Game/Entities/Transport.cs @@ -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) diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 2d12f2660..23999cb71 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -9426,7 +9426,7 @@ namespace Game continue; } - data.time = result.Read(9); + data.time = TimeSpan.FromMilliseconds(result.Read(9)); Tuple key = Tuple.Create(summonerId, summonerType, group); _tempSummonDataStorage.Add(key, data); diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index f6d86d6e8..5cb6ede6a 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -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) diff --git a/Source/Game/Networking/Packets/TotemPackets.cs b/Source/Game/Networking/Packets/TotemPackets.cs index 8bec9b1ec..61f106fca 100644 --- a/Source/Game/Networking/Packets/TotemPackets.cs +++ b/Source/Game/Networking/Packets/TotemPackets.cs @@ -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; diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 8911f93a0..3ef231427 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -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; diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index e713c56dc..b0e5364f3 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -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); diff --git a/Source/Scripts/Spells/Shaman.cs b/Source/Scripts/Spells/Shaman.cs index cd9c9155c..6bca76806 100644 --- a/Source/Scripts/Spells/Shaman.cs +++ b/Source/Scripts/Spells/Shaman.cs @@ -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;