From 03c646d2c89caaf0d68ef4d8a9cfa020f4aaffcc Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 28 Feb 2022 14:13:02 -0500 Subject: [PATCH] Core/CombatAI: Use TimeSpan overloads of EventMap Port From (https://github.com/TrinityCore/TrinityCore/commit/d62b7c1e352e76f35490c22b2ab291ed299f4fa4) --- Source/Game/AI/CoreAI/CombatAI.cs | 11 ++++++----- Source/Game/AI/CoreAI/CreatureAI.cs | 7 ++++--- Source/Game/AI/CoreAI/UnitAI.cs | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Game/AI/CoreAI/CombatAI.cs b/Source/Game/AI/CoreAI/CombatAI.cs index 8a065c9a7..07b7a2fde 100644 --- a/Source/Game/AI/CoreAI/CombatAI.cs +++ b/Source/Game/AI/CoreAI/CombatAI.cs @@ -17,6 +17,7 @@ using Framework.Constants; using Game.Entities; +using System; using System.Collections.Generic; namespace Game.AI @@ -61,7 +62,7 @@ namespace Game.AI if (info.condition == AICondition.Aggro) me.CastSpell(victim, id, false); else if (info.condition == AICondition.Combat) - _events.ScheduleEvent(id, info.cooldown + RandomHelper.Rand32() % info.cooldown); + _events.ScheduleEvent(id, info.cooldown, info.cooldown * 2); } } } @@ -90,7 +91,7 @@ namespace Game.AI public override void SpellInterrupted(uint spellId, uint unTimeMs) { - _events.RescheduleEvent(spellId, unTimeMs); + _events.RescheduleEvent(spellId, TimeSpan.FromMilliseconds(unTimeMs)); } } @@ -153,11 +154,11 @@ namespace Game.AI me.CastSpell(victim, id, false); else if (info.condition == AICondition.Combat) { - uint cooldown = info.realCooldown; + TimeSpan cooldown = info.realCooldown; if (count == spell) { DoCast(Spells[spell]); - cooldown += (uint)me.GetCurrentSpellCastTime(id); + cooldown += TimeSpan.FromMilliseconds(me.GetCurrentSpellCastTime(id)); } _events.ScheduleEvent(id, cooldown); } @@ -188,7 +189,7 @@ namespace Game.AI uint casttime = (uint)me.GetCurrentSpellCastTime(spellId); AISpellInfoType info = GetAISpellInfo(spellId, me.GetMap().GetDifficultyID()); if (info != null) - _events.ScheduleEvent(spellId, (casttime != 0 ? casttime : 500) + info.realCooldown); + _events.ScheduleEvent(spellId, TimeSpan.FromMilliseconds(casttime != 0 ? casttime : 500) + info.realCooldown); } } } diff --git a/Source/Game/AI/CoreAI/CreatureAI.cs b/Source/Game/AI/CoreAI/CreatureAI.cs index 23d68c623..60d7d1d82 100644 --- a/Source/Game/AI/CoreAI/CreatureAI.cs +++ b/Source/Game/AI/CoreAI/CreatureAI.cs @@ -22,6 +22,7 @@ using Game.DataStorage; using Game.Entities; using Game.Maps; using Game.Spells; +using System; using System.Collections.Generic; using System.Linq; @@ -575,13 +576,13 @@ namespace Game.AI { target = AITarget.Self; condition = AICondition.Combat; - cooldown = SharedConst.AIDefaultCooldown; + cooldown = TimeSpan.FromMilliseconds(SharedConst.AIDefaultCooldown); } public AITarget target; public AICondition condition; - public uint cooldown; - public uint realCooldown; + public TimeSpan cooldown; + public TimeSpan realCooldown; public float maxRange; public byte Targets; // set of enum SelectTarget diff --git a/Source/Game/AI/CoreAI/UnitAI.cs b/Source/Game/AI/CoreAI/UnitAI.cs index 6f49ad19e..bab124e3d 100644 --- a/Source/Game/AI/CoreAI/UnitAI.cs +++ b/Source/Game/AI/CoreAI/UnitAI.cs @@ -331,8 +331,8 @@ namespace Game.AI else AIInfo.condition = AICondition.Combat; - if (AIInfo.cooldown < spellInfo.RecoveryTime) - AIInfo.cooldown = spellInfo.RecoveryTime; + if (AIInfo.cooldown.TotalMilliseconds < spellInfo.RecoveryTime) + AIInfo.cooldown = TimeSpan.FromMilliseconds(spellInfo.RecoveryTime); if (spellInfo.GetMaxRange(false) == 0) { @@ -370,7 +370,7 @@ namespace Game.AI } } } - AIInfo.realCooldown = spellInfo.RecoveryTime + spellInfo.StartRecoveryTime; + AIInfo.realCooldown = TimeSpan.FromMilliseconds(spellInfo.RecoveryTime + spellInfo.StartRecoveryTime); AIInfo.maxRange = spellInfo.GetMaxRange(false) * 3 / 4; AIInfo.Effects = 0;