Core/Auras: Implemented helper function to estimate total damage/healing done by a periodic effect

Port From (https://github.com/TrinityCore/TrinityCore/commit/b3590184c0c31d080609af8e6edd3db33ac4cb8e)
This commit is contained in:
hondacrx
2023-06-13 04:58:09 -04:00
parent 4409189def
commit 645c06a460
+50 -9
View File
@@ -118,24 +118,65 @@ namespace Game.Spells
if (!GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack)) if (!GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack))
amount *= GetBase().GetStackAmount(); amount *= GetBase().GetStackAmount();
if (caster && GetBase().GetAuraType() == AuraObjectType.Unit) _estimatedAmount = CalculateEstimatedAmount(caster, amount);
{
uint stackAmountForBonuses = !GetSpellEffectInfo().EffectAttributes.HasFlag(SpellEffectAttributes.NoScaleWithStack) ? GetBase().GetStackAmount() : 1u;
switch (GetAuraType()) 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.PeriodicDamage:
case AuraType.PeriodicLeech: case AuraType.PeriodicLeech:
_estimatedAmount = caster.SpellDamageBonusDone(GetBase().GetUnitOwner(), GetSpellInfo(), (uint)amount, DamageEffectType.DOT, GetSpellEffectInfo(), stackAmountForBonuses); return caster.SpellDamageBonusDone(target, spellInfo, (uint)amount, DamageEffectType.DOT, spellEffectInfo, stackAmountForBonuses);
break;
case AuraType.PeriodicHeal: case AuraType.PeriodicHeal:
_estimatedAmount = caster.SpellHealingBonusDone(GetBase().GetUnitOwner(), GetSpellInfo(), (uint)amount, DamageEffectType.DOT, GetSpellEffectInfo(), stackAmountForBonuses); return caster.SpellHealingBonusDone(target, spellInfo, (uint)amount, DamageEffectType.DOT, spellEffectInfo, stackAmountForBonuses);
break;
default: default:
break; break;
} }
return null;
} }
return amount;
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() public uint GetTotalTicks()