Core/Auras: fixed off by one error in counting SPELL_ATTR5_START_PERIODIC_AT_APPLY ticks

Port From (https://github.com/TrinityCore/TrinityCore/commit/794a3e43887d3fea4bb9b1ec77a98ab596eea0be)
This commit is contained in:
hondacrx
2021-03-17 16:56:24 -04:00
parent 4fa6122106
commit 1be0e4a685
2 changed files with 42 additions and 24 deletions
+23 -9
View File
@@ -125,15 +125,29 @@ namespace Game.Spells
amount *= GetBase().GetStackAmount(); amount *= GetBase().GetStackAmount();
return amount; return amount;
} }
public uint GetTotalTicks()
{
uint totalTicks = 0;
if (_period != 0 && !GetBase().IsPermanent())
{
totalTicks = (uint)(GetBase().GetMaxDuration() / _period);
if (m_spellInfo.HasAttribute(SpellAttr5.StartPeriodicAtApply))
++totalTicks;
}
return totalTicks;
}
void ResetPeriodic(bool resetPeriodicTimer = false) void ResetPeriodic(bool resetPeriodicTimer = false)
{ {
_ticksDone = 0; _ticksDone = 0;
if (resetPeriodicTimer) if (resetPeriodicTimer)
{ {
_periodicTimer = _period;
// Start periodic on next tick or at aura apply
if (!m_spellInfo.HasAttribute(SpellAttr5.StartPeriodicAtApply))
_periodicTimer = 0; _periodicTimer = 0;
// Start periodic on next tick or at aura apply
if (m_spellInfo.HasAttribute(SpellAttr5.StartPeriodicAtApply))
_periodicTimer = _period;
} }
} }
public void CalculatePeriodic(Unit caster, bool resetPeriodicTimer = true, bool load = false) public void CalculatePeriodic(Unit caster, bool resetPeriodicTimer = true, bool load = false)
@@ -401,14 +415,17 @@ namespace Game.Spells
public void Update(uint diff, Unit caster) public void Update(uint diff, Unit caster)
{ {
if (m_isPeriodic && (GetBase().GetDuration() >= 0 || GetBase().IsPassive() || GetBase().IsPermanent())) if (!m_isPeriodic || (GetBase().GetDuration() < 0 && !GetBase().IsPassive() && !GetBase().IsPermanent()))
{ return;
uint totalTicks = GetTotalTicks();
_periodicTimer += (int)diff; _periodicTimer += (int)diff;
while (_periodicTimer >= _period) while (_periodicTimer >= _period)
{ {
_periodicTimer -= _period; _periodicTimer -= _period;
if (!GetBase().IsPermanent() && (_ticksDone + 1) > GetTotalTicks()) if (!GetBase().IsPermanent() && (_ticksDone + 1) > totalTicks)
break; break;
++_ticksDone; ++_ticksDone;
@@ -418,11 +435,9 @@ namespace Game.Spells
GetApplicationList(out List<AuraApplication> effectApplications); GetApplicationList(out List<AuraApplication> effectApplications);
// tick on targets of effects // tick on targets of effects
foreach (var appt in effectApplications) foreach (var appt in effectApplications)
if (appt.HasEffect(GetEffIndex()))
PeriodicTick(appt, caster); PeriodicTick(appt, caster);
} }
} }
}
public bool IsAffectingSpell(SpellInfo spell) public bool IsAffectingSpell(SpellInfo spell)
{ {
@@ -796,7 +811,6 @@ namespace Game.Spells
public void ResetTicks() { _ticksDone = 0; } public void ResetTicks() { _ticksDone = 0; }
public uint GetTickNumber() { return _ticksDone; } public uint GetTickNumber() { return _ticksDone; }
public uint GetRemainingTicks() { return GetTotalTicks() - _ticksDone; } public uint GetRemainingTicks() { return GetTotalTicks() - _ticksDone; }
public uint GetTotalTicks() { return (_period != 0 && !GetBase().IsPermanent()) ? (uint)(GetBase().GetMaxDuration() / _period) : 0u; }
public bool IsPeriodic() { return m_isPeriodic; } public bool IsPeriodic() { return m_isPeriodic; }
public void SetPeriodic(bool isPeriodic) { m_isPeriodic = isPeriodic; } public void SetPeriodic(bool isPeriodic) { m_isPeriodic = isPeriodic; }
+9 -5
View File
@@ -2652,9 +2652,8 @@ namespace Game.Spells
public uint GetMaxTicks() public uint GetMaxTicks()
{ {
uint totalTicks = 0;
int DotDuration = GetDuration(); int DotDuration = GetDuration();
if (DotDuration == 0)
return 1;
foreach (SpellEffectInfo effect in _effects) foreach (SpellEffectInfo effect in _effects)
{ {
@@ -2676,14 +2675,19 @@ namespace Game.Spells
case AuraType.PeriodicTriggerSpell: case AuraType.PeriodicTriggerSpell:
case AuraType.PeriodicTriggerSpellWithValue: case AuraType.PeriodicTriggerSpellWithValue:
case AuraType.PeriodicHealthFunnel: case AuraType.PeriodicHealthFunnel:
if (effect.ApplyAuraPeriod != 0) // skip infinite periodics
return (uint)(DotDuration / effect.ApplyAuraPeriod); if (effect.ApplyAuraPeriod > 0 && DotDuration > 0)
{
totalTicks = (uint)DotDuration / effect.ApplyAuraPeriod;
if (HasAttribute(SpellAttr5.StartPeriodicAtApply))
++totalTicks;
}
break; break;
} }
} }
} }
return 6; return totalTicks;
} }
public uint GetRecoveryTime() public uint GetRecoveryTime()