From 645c06a460a2b9aca0b245b4bffa5aa512417d0a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 13 Jun 2023 04:58:09 -0400 Subject: [PATCH] Core/Auras: Implemented helper function to estimate total damage/healing done by a periodic effect Port From (https://github.com/TrinityCore/TrinityCore/commit/b3590184c0c31d080609af8e6edd3db33ac4cb8e) --- Source/Game/Spells/Auras/AuraEffect.cs | 73 ++++++++++++++++++++------ 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 35f32588c..86a3f1652 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -118,26 +118,67 @@ namespace Game.Spells if (!GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack)) amount *= GetBase().GetStackAmount(); - if (caster && GetBase().GetAuraType() == AuraObjectType.Unit) - { - uint stackAmountForBonuses = !GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack) ? GetBase().GetStackAmount() : 1u; + _estimatedAmount = CalculateEstimatedAmount(caster, amount); - switch (GetAuraType()) - { - case AuraType.PeriodicDamage: - case AuraType.PeriodicLeech: - _estimatedAmount = caster.SpellDamageBonusDone(GetBase().GetUnitOwner(), GetSpellInfo(), (uint)amount, DamageEffectType.DOT, GetSpellEffectInfo(), stackAmountForBonuses); - break; - case AuraType.PeriodicHeal: - _estimatedAmount = caster.SpellHealingBonusDone(GetBase().GetUnitOwner(), GetSpellInfo(), (uint)amount, DamageEffectType.DOT, GetSpellEffectInfo(), stackAmountForBonuses); - break; - default: - break; - } - } return amount; } + public static float? CalculateEstimatedAmount(Unit caster, Unit target, SpellInfo spellInfo, SpellEffectInfo spellEffectInfo, int amount, byte stack) + { + uint stackAmountForBonuses = !spellEffectInfo.EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack) ? stack : 1u; + + switch (spellEffectInfo.ApplyAuraName) + { + case AuraType.PeriodicDamage: + case AuraType.PeriodicLeech: + return caster.SpellDamageBonusDone(target, spellInfo, (uint)amount, DamageEffectType.DOT, spellEffectInfo, stackAmountForBonuses); + case AuraType.PeriodicHeal: + return caster.SpellHealingBonusDone(target, spellInfo, (uint)amount, DamageEffectType.DOT, spellEffectInfo, stackAmountForBonuses); + default: + break; + } + + return null; + } + + public float? CalculateEstimatedAmount(Unit caster, int amount) + { + if (!caster || GetBase().GetAuraType() != AuraObjectType.Unit) + return null; + + return CalculateEstimatedAmount(caster, GetBase().GetUnitOwner(), GetSpellInfo(), GetSpellEffectInfo(), amount, GetBase().GetStackAmount()); + } + + public static float CalculateEstimatedfTotalPeriodicAmount(Unit caster, Unit target, SpellInfo spellInfo, SpellEffectInfo spellEffectInfo, float amount, byte stack) + { + int maxDuration = Aura.CalcMaxDuration(spellInfo, caster); + if (maxDuration <= 0) + return 0.0f; + + int period = (int)spellEffectInfo.ApplyAuraPeriod; + if (period == 0) + return 0.0f; + + Player modOwner = caster.GetSpellModOwner(); + if (modOwner != null) + modOwner.ApplySpellMod(spellInfo, SpellModOp.Period, ref period); + + // Haste modifies periodic time of channeled spells + if (spellInfo.IsChanneled()) + caster.ModSpellDurationTime(spellInfo, ref period); + else if (spellInfo.HasAttribute(SpellAttr5.SpellHasteAffectsPeriodic)) + period = (int)(period * caster.m_unitData.ModCastingSpeed); + + if (period == 0) + return 0.0f; + + float totalTicks = (float)maxDuration / period; + if (spellInfo.HasAttribute(SpellAttr5.ExtraInitialPeriod)) + totalTicks += 1.0f; + + return totalTicks * CalculateEstimatedAmount(caster, target, spellInfo, spellEffectInfo, (int)amount, stack).GetValueOrDefault(amount); + } + public uint GetTotalTicks() { uint totalTicks = 0;