From 0cd489e402537965a9a75dae9566762ecd29c557 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Mon, 1 Sep 2025 16:52:40 -0400 Subject: [PATCH] Core/Spells: Support spells that have both charge recovery and separate cooldown Port From (https://github.com/TrinityCore/TrinityCore/commit/b248e059064031fdbb75a863913d7d5eb461db41) --- Source/Game/Spells/SpellHistory.cs | 40 +++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/Source/Game/Spells/SpellHistory.cs b/Source/Game/Spells/SpellHistory.cs index 0e1a2c2fe..2ddc2f595 100644 --- a/Source/Game/Spells/SpellHistory.cs +++ b/Source/Game/Spells/SpellHistory.cs @@ -185,8 +185,7 @@ namespace Game.Spells if (spell != null && spell.IsIgnoringCooldowns()) return; - if (ConsumeCharge(spellInfo.ChargeCategoryId)) - return; + ConsumeCharge(spellInfo.ChargeCategoryId); if (_owner.HasAuraTypeWithAffectMask(AuraType.IgnoreSpellCooldown, spellInfo)) return; @@ -537,7 +536,7 @@ namespace Game.Spells public void ModifySpellCooldown(uint spellId, TimeSpan cooldownMod, bool withoutCategoryCooldown) { var cooldownEntry = _spellCooldowns.LookupByKey(spellId); - if (cooldownMod.TotalMilliseconds == 0 || cooldownEntry == null) + if (cooldownEntry == null) return; ModifySpellCooldown(cooldownEntry, cooldownMod, withoutCategoryCooldown); @@ -623,10 +622,8 @@ namespace Game.Spells if (cooldownMod == TimeSpan.Zero) return; - if (GetChargeRecoveryTime(spellInfo.ChargeCategoryId) > 0 && GetMaxCharges(spellInfo.ChargeCategoryId) > 0) - ModifyChargeRecoveryTime(spellInfo.ChargeCategoryId, cooldownMod); - else - ModifySpellCooldown(spellInfo.Id, cooldownMod, withoutCategoryCooldown); + ModifyChargeRecoveryTime(spellInfo.ChargeCategoryId, cooldownMod); + ModifySpellCooldown(spellInfo.Id, cooldownMod, withoutCategoryCooldown); } public void ModifyCoooldowns(Func predicate, TimeSpan cooldownMod, bool withoutCategoryCooldown = false) @@ -838,29 +835,26 @@ namespace Game.Spells return false; } - public bool ConsumeCharge(uint chargeCategoryId) + public void ConsumeCharge(uint chargeCategoryId) { if (!CliDB.SpellCategoryStorage.ContainsKey(chargeCategoryId)) - return false; + return; int chargeRecovery = GetChargeRecoveryTime(chargeCategoryId); - if (chargeRecovery > 0 && GetMaxCharges(chargeCategoryId) > 0) - { - if (_owner.HasAuraTypeWithMiscvalue(AuraType.IgnoreSpellChargeCooldown, (int)chargeCategoryId)) - return true; + if (chargeRecovery <= 0 && GetMaxCharges(chargeCategoryId) <= 0) + return; - DateTime recoveryStart; - var charges = _categoryCharges.LookupByKey(chargeCategoryId); - if (charges.Empty()) - recoveryStart = GameTime.GetSystemTime(); - else - recoveryStart = charges.Last().RechargeEnd; + if (_owner.HasAuraTypeWithMiscvalue(AuraType.IgnoreSpellChargeCooldown, (int)chargeCategoryId)) + return; - _categoryCharges.Add(chargeCategoryId, new ChargeEntry(recoveryStart, TimeSpan.FromMilliseconds(chargeRecovery))); - return true; - } + DateTime recoveryStart; + var charges = _categoryCharges.LookupByKey(chargeCategoryId); + if (charges.Empty()) + recoveryStart = GameTime.GetSystemTime(); + else + recoveryStart = charges.Last().RechargeEnd; - return false; + _categoryCharges.Add(chargeCategoryId, new ChargeEntry(recoveryStart, TimeSpan.FromMilliseconds(chargeRecovery))); } void ModifyChargeRecoveryTime(uint chargeCategoryId, TimeSpan cooldownMod)