Core/Auras: periodics refactor part 2: Move UpdatePeriodic to AuraScripts

Port From (https://github.com/TrinityCore/TrinityCore/commit/fd786c03a369b60bd29773e19f4213fd2e01624b)
This commit is contained in:
hondacrx
2021-03-17 16:22:22 -04:00
parent 1d8bab3b58
commit 8556495e5e
4 changed files with 145 additions and 130 deletions
+2 -2
View File
@@ -769,7 +769,7 @@ namespace Game.Scripting
public delegate void AuraEffectPeriodicDelegate(AuraEffect aura);
public delegate void AuraEffectUpdatePeriodicDelegate(AuraEffect aura);
public delegate void AuraEffectCalcAmountDelegate(AuraEffect aura, ref int amount, ref bool canBeRecalculated);
public delegate void AuraEffectCalcPeriodicDelegate(AuraEffect aura, bool isPeriodic, int amplitude);
public delegate void AuraEffectCalcPeriodicDelegate(AuraEffect aura, ref bool isPeriodic, ref int amplitude);
public delegate void AuraEffectCalcSpellModDelegate(AuraEffect aura, ref SpellModifier spellMod);
public delegate void AuraEffectAbsorbDelegate(AuraEffect aura, DamageInfo damageInfo, ref uint absorbAmount);
public delegate void AuraEffectSplitDelegate(AuraEffect aura, DamageInfo damageInfo, uint splitAmount);
@@ -869,7 +869,7 @@ namespace Game.Scripting
}
public void Call(AuraEffect aurEff, ref bool isPeriodic, ref int periodicTimer)
{
pEffectHandlerScript(aurEff, isPeriodic, periodicTimer);
pEffectHandlerScript(aurEff, ref isPeriodic, ref periodicTimer);
}
AuraEffectCalcPeriodicDelegate pEffectHandlerScript;
+2 -127
View File
@@ -413,7 +413,7 @@ namespace Game.Spells
++_ticksDone;
UpdatePeriodic(caster);
GetBase().CallScriptEffectUpdatePeriodicHandlers(this);
GetApplicationList(out List<AuraApplication> effectApplications);
// tick on targets of effects
@@ -423,131 +423,6 @@ namespace Game.Spells
}
}
}
void UpdatePeriodic(Unit caster)
{
switch (GetAuraType())
{
case AuraType.PeriodicDummy:
switch (GetSpellInfo().SpellFamilyName)
{
case SpellFamilyNames.Generic:
switch (GetId())
{
// Drink
case 430:
case 431:
case 432:
case 1133:
case 1135:
case 1137:
case 10250:
case 22734:
case 27089:
case 34291:
case 43182:
case 43183:
case 46755:
case 49472: // Drink Coffee
case 57073:
case 61830:
case 69176:
case 72623:
case 80166:
case 80167:
case 87958:
case 87959:
case 92736:
case 92797:
case 92800:
case 92803:
if (caster == null || !caster.IsTypeId(TypeId.Player))
return;
// Get SPELL_AURA_MOD_POWER_REGEN aura from spell
AuraEffect aurEff = GetBase().GetEffect(0);
if (aurEff != null)
{
if (aurEff.GetAuraType() != AuraType.ModPowerRegen)
{
m_isPeriodic = false;
Log.outError(LogFilter.Spells, "Aura {0} structure has been changed - first aura is no longer SPELL_AURA_MOD_POWER_REGEN", GetId());
}
else
{
// default case - not in arena
if (!caster.ToPlayer().InArena())
{
aurEff.ChangeAmount(GetAmount());
m_isPeriodic = false;
}
else
{
// **********************************************
// This feature uses only in arenas
// **********************************************
// Here need increase mana regen per tick (6 second rule)
// on 0 tick - 0 (handled in 2 second)
// on 1 tick - 166% (handled in 4 second)
// on 2 tick - 133% (handled in 6 second)
// Apply bonus for 1 - 4 tick
switch (_ticksDone)
{
case 1: // 0%
aurEff.ChangeAmount(0);
break;
case 2: // 166%
aurEff.ChangeAmount(GetAmount() * 5 / 3);
break;
case 3: // 133%
aurEff.ChangeAmount(GetAmount() * 4 / 3);
break;
default: // 100% - normal regen
aurEff.ChangeAmount(GetAmount());
// No need to update after 4th tick
m_isPeriodic = false;
break;
}
}
}
}
break;
case 58549: // Tenacity
case 59911: // Tenacity (vehicle)
GetBase().RefreshDuration();
break;
default:
break;
}
break;
case SpellFamilyNames.Mage:
if (GetId() == 55342)// Mirror Image
m_isPeriodic = false;
break;
case SpellFamilyNames.Deathknight:
// Chains of Ice
if (GetSpellInfo().SpellFamilyFlags[1].HasAnyFlag(0x00004000u))
{
// Get 0 effect aura
AuraEffect slow = GetBase().GetEffect(0);
if (slow != null)
{
int newAmount = slow.GetAmount() + GetAmount();
if (newAmount > 0)
newAmount = 0;
slow.ChangeAmount(newAmount);
}
return;
}
break;
default:
break;
}
break;
default:
break;
}
GetBase().CallScriptEffectUpdatePeriodicHandlers(this);
}
public bool IsAffectingSpell(SpellInfo spell)
{
@@ -924,7 +799,7 @@ namespace Game.Spells
public uint GetTotalTicks() { return (_period != 0 && !GetBase().IsPermanent()) ? (uint)(GetBase().GetMaxDuration() / _period) : 0u; }
public bool IsPeriodic() { return m_isPeriodic; }
void SetPeriodic(bool isPeriodic) { m_isPeriodic = isPeriodic; }
public void SetPeriodic(bool isPeriodic) { m_isPeriodic = isPeriodic; }
bool HasSpellClassMask() { return GetSpellEffectInfo().SpellClassMask; }
public SpellEffectInfo GetSpellEffectInfo() { return _effectInfo; }
+109 -1
View File
@@ -496,6 +496,94 @@ namespace Scripts.Spells.Generic
}
}
// 430 Drink
// 431 Drink
// 432 Drink
// 1133 Drink
// 1135 Drink
// 1137 Drink
// 10250 Drink
// 22734 Drink
// 27089 Drink
// 34291 Drink
// 43182 Drink
// 43183 Drink
// 46755 Drink
// 49472 Drink Coffee
// 57073 Drink
// 61830 Drink
[Script] // 72623 Drink
class spell_gen_arena_drink : AuraScript
{
public override bool Load()
{
return GetCaster() && GetCaster().IsTypeId(TypeId.Player);
}
void CalcPeriodic(AuraEffect aurEff, ref bool isPeriodic, ref int amplitude)
{
// Get SPELL_AURA_MOD_POWER_REGEN aura from spell
AuraEffect regen = GetAura().GetEffect(0);
if (regen == null)
return;
if (regen.GetAuraType() != AuraType.ModPowerRegen)
{
isPeriodic = false;
Log.outError(LogFilter.Spells, $"Aura {GetId()} structure has been changed - first aura is no longer SPELL_AURA_MOD_POWER_REGEN");
}
else
{
// default case - not in arena
if (!GetCaster().ToPlayer().InArena())
{
regen.ChangeAmount(aurEff.GetAmount());
isPeriodic = false;
}
}
}
void UpdatePeriodic(AuraEffect aurEff)
{
AuraEffect regen = GetAura().GetEffect(0);
if (regen == null)
return;
// **********************************************
// This feature used only in arenas
// **********************************************
// Here need increase mana regen per tick (6 second rule)
// on 0 tick - 0 (handled in 2 second)
// on 1 tick - 166% (handled in 4 second)
// on 2 tick - 133% (handled in 6 second)
// Apply bonus for 1 - 4 tick
switch (aurEff.GetTickNumber())
{
case 1: // 0%
regen.ChangeAmount(0);
break;
case 2: // 166%
regen.ChangeAmount(aurEff.GetAmount() * 5 / 3);
break;
case 3: // 133%
regen.ChangeAmount(aurEff.GetAmount() * 4 / 3);
break;
default: // 100% - normal regen
regen.ChangeAmount(aurEff.GetAmount());
// No need to update after 4th tick
aurEff.SetPeriodic(false);
break;
}
}
public override void Register()
{
DoEffectCalcPeriodic.Add(new EffectCalcPeriodicHandler(CalcPeriodic, 1, AuraType.PeriodicDummy));
OnEffectUpdatePeriodic.Add(new EffectUpdatePeriodicHandler(UpdatePeriodic, 1, AuraType.PeriodicDummy));
}
}
[Script] // 41337 Aura of Anger
class spell_gen_aura_of_anger : AuraScript
{
@@ -821,7 +909,27 @@ namespace Scripts.Spells.Generic
}
}
[Script]
[Script] // 66020 Chains of Ice
class spell_gen_chains_of_ice : AuraScript
{
void UpdatePeriodic(AuraEffect aurEff)
{
// Get 0 effect aura
AuraEffect slow = GetAura().GetEffect(0);
if (slow == null)
return;
int newAmount = Math.Min(slow.GetAmount() + aurEff.GetAmount(), 0);
slow.ChangeAmount(newAmount);
}
public override void Register()
{
OnEffectUpdatePeriodic.Add(new EffectUpdatePeriodicHandler(UpdatePeriodic, 1, AuraType.PeriodicDummy));
}
}
[Script]
class spell_gen_chaos_blast : SpellScript
{
public override bool Validate(SpellInfo spellInfo)
@@ -0,0 +1,32 @@
DELETE FROM `spell_script_names` WHERE `ScriptName` IN ('spell_gen_arena_drink','spell_wintergrasp_tenacity_refresh','spell_gen_chains_of_ice'/*,'spell_gen_one_tick_dummy'*/);
INSERT INTO `spell_script_names` (`spell_id`, `ScriptName`) VALUES
(430, 'spell_gen_arena_drink'),
(431, 'spell_gen_arena_drink'),
(432, 'spell_gen_arena_drink'),
(1133, 'spell_gen_arena_drink'),
(1135, 'spell_gen_arena_drink'),
(1137, 'spell_gen_arena_drink'),
(10250, 'spell_gen_arena_drink'),
(22734, 'spell_gen_arena_drink'),
(27089, 'spell_gen_arena_drink'),
(34291, 'spell_gen_arena_drink'),
(43182, 'spell_gen_arena_drink'),
(43183, 'spell_gen_arena_drink'),
(46755, 'spell_gen_arena_drink'),
(49472, 'spell_gen_arena_drink'),
(57073, 'spell_gen_arena_drink'),
(61830, 'spell_gen_arena_drink'),
(72623, 'spell_gen_arena_drink'),
(58549, 'spell_wintergrasp_tenacity_refresh'),
(59911, 'spell_wintergrasp_tenacity_refresh'),
-- (45524, 'spell_gen_chains_of_ice'),
(66020, 'spell_gen_chains_of_ice'),
-- (55342, 'spell_gen_one_tick_dummy'),
(80166, 'spell_gen_arena_drink'), -- master
(80167, 'spell_gen_arena_drink'), -- master
(87958, 'spell_gen_arena_drink'), -- master
(87959, 'spell_gen_arena_drink'), -- master
(92736, 'spell_gen_arena_drink'), -- master
(92797, 'spell_gen_arena_drink'), -- master
(92800, 'spell_gen_arena_drink'), -- master
(92803, 'spell_gen_arena_drink'); -- master