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

(cherry picked from commit 0510bf7afe)
This commit is contained in:
ariel-
2017-12-14 12:43:32 -03:00
committed by funjoker
parent 5f9e0d92d5
commit fd786c03a3
5 changed files with 166 additions and 125 deletions

View File

@@ -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

View File

@@ -960,7 +960,7 @@ void AuraEffect::Update(uint32 diff, Unit* caster)
++_ticksDone;
UpdatePeriodic(caster);
GetBase()->CallScriptEffectUpdatePeriodicHandlers(this);
std::vector<AuraApplication*> effectApplications;
GetApplicationList(effectApplications);
@@ -972,129 +972,6 @@ void AuraEffect::Update(uint32 diff, Unit* caster)
}
}
void AuraEffect::UpdatePeriodic(Unit* caster)
{
switch (GetAuraType())
{
case SPELL_AURA_PERIODIC_DUMMY:
switch (GetSpellInfo()->SpellFamilyName)
{
case SPELLFAMILY_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 || caster->GetTypeId() != TYPEID_PLAYER)
return;
// Get SPELL_AURA_MOD_POWER_REGEN aura from spell
if (AuraEffect* aurEff = GetBase()->GetEffect(0))
{
if (aurEff->GetAuraType() != SPELL_AURA_MOD_POWER_REGEN)
{
m_isPeriodic = false;
TC_LOG_ERROR("spells", "Aura %d 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 SPELLFAMILY_MAGE:
if (GetId() == 55342)// Mirror Image
m_isPeriodic = false;
break;
case SPELLFAMILY_DEATHKNIGHT:
// Chains of Ice
if (GetSpellInfo()->SpellFamilyFlags[1] & 0x00004000)
{
// Get 0 effect aura
if (AuraEffect* slow = GetBase()->GetEffect(EFFECT_0))
{
int32 newAmount = slow->GetAmount() + GetAmount();
if (newAmount > 0)
newAmount = 0;
slow->ChangeAmount(newAmount);
}
return;
}
break;
default:
break;
}
default:
break;
}
GetBase()->CallScriptEffectUpdatePeriodicHandlers(this);
}
bool AuraEffect::IsAffectingSpell(SpellInfo const* spell) const
{
if (!spell)

View File

@@ -80,7 +80,6 @@ class TC_GAME_API AuraEffect
float GetDonePct() const { return m_donePct; }
void Update(uint32 diff, Unit* caster);
void UpdatePeriodic(Unit* caster);
void ResetTicks() { _ticksDone = 0; }
uint32 GetTickNumber() const { return _ticksDone; }

View File

@@ -27,6 +27,7 @@
#include "ScriptedCreature.h"
#include "ScriptedGossip.h"
#include "ScriptSystem.h"
#include "SpellAuras.h"
#include "SpellScript.h"
#include "Vehicle.h"
#include "WorldSession.h"
@@ -579,6 +580,23 @@ public:
}
};
// 58549 Tenacity
// 59911 Tenacity
class spell_wintergrasp_tenacity_refresh : public AuraScript
{
PrepareAuraScript(spell_wintergrasp_tenacity_refresh);
void Refresh(AuraEffect* /*aurEff*/)
{
GetAura()->RefreshDuration();
}
void Register() override
{
OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_wintergrasp_tenacity_refresh::Refresh, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY);
}
};
class condition_is_wintergrasp_horde : public ConditionScript
{
public:
@@ -619,6 +637,7 @@ void AddSC_wintergrasp()
new achievement_wg_didnt_stand_a_chance();
new spell_wintergrasp_defender_teleport();
new spell_wintergrasp_defender_teleport_trigger();
RegisterAuraScript(spell_wintergrasp_tenacity_refresh);
new condition_is_wintergrasp_horde();
new condition_is_wintergrasp_alliance();
}

View File

@@ -201,6 +201,96 @@ class spell_gen_animal_blood : public AuraScript
}
};
// 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
// 72623 Drink
class spell_gen_arena_drink : public AuraScript
{
PrepareAuraScript(spell_gen_arena_drink);
bool Load() override
{
return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER;
}
void CalcPeriodic(AuraEffect const* aurEff, bool& isPeriodic, int32& amplitude)
{
// Get SPELL_AURA_MOD_POWER_REGEN aura from spell
AuraEffect* regen = GetAura()->GetEffect(EFFECT_0);
if (!regen)
return;
if (regen->GetAuraType() != SPELL_AURA_MOD_POWER_REGEN)
{
isPeriodic = false;
TC_LOG_ERROR("spells", "Aura %d structure has been changed - first aura is no longer SPELL_AURA_MOD_POWER_REGEN", GetId());
}
else
{
// default case - not in arena
if (!GetCaster()->ToPlayer()->InArena())
{
regen->ChangeAmount(aurEff->GetAmount());
isPeriodic = false;
}
}
}
void UpdatePeriodic(AuraEffect* aurEff)
{
AuraEffect* regen = GetAura()->GetEffect(EFFECT_0);
if (!regen)
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;
}
}
void Register() override
{
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_gen_arena_drink::CalcPeriodic, EFFECT_1, SPELL_AURA_PERIODIC_DUMMY);
OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_gen_arena_drink::UpdatePeriodic, EFFECT_1, SPELL_AURA_PERIODIC_DUMMY);
}
};
// 41337 Aura of Anger
class spell_gen_aura_of_anger : public AuraScript
{
@@ -610,6 +700,28 @@ class spell_gen_cannibalize : public SpellScript
}
};
// 66020 Chains of Ice
class spell_gen_chains_of_ice : public AuraScript
{
PrepareAuraScript(spell_gen_chains_of_ice);
void UpdatePeriodic(AuraEffect* aurEff)
{
// Get 0 effect aura
AuraEffect* slow = GetAura()->GetEffect(EFFECT_0);
if (!slow)
return;
int32 newAmount = std::min<int32>(slow->GetAmount() + aurEff->GetAmount(), 0);
slow->ChangeAmount(newAmount);
}
void Register() override
{
OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_gen_chains_of_ice::UpdatePeriodic, EFFECT_1, SPELL_AURA_PERIODIC_DUMMY);
}
};
enum ChaosBlast
{
SPELL_CHAOS_BLAST = 37675
@@ -3584,6 +3696,7 @@ void AddSC_generic_spell_scripts()
RegisterAuraScript(spell_gen_adaptive_warding);
RegisterSpellScript(spell_gen_allow_cast_from_item_only);
RegisterAuraScript(spell_gen_animal_blood);
RegisterAuraScript(spell_gen_arena_drink);
RegisterAuraScript(spell_gen_aura_of_anger);
RegisterAuraScript(spell_gen_aura_service_uniform);
RegisterAuraScript(spell_gen_av_drekthar_presence);
@@ -3595,6 +3708,7 @@ void AddSC_generic_spell_scripts()
RegisterAuraScript(spell_gen_burn_brutallus);
RegisterAuraScript(spell_gen_burning_depths_necrolyte_image);
RegisterSpellScript(spell_gen_cannibalize);
RegisterAuraScript(spell_gen_chains_of_ice);
RegisterSpellScript(spell_gen_chaos_blast);
RegisterSpellScript(spell_gen_clone);
RegisterSpellScript(spell_gen_clone_weapon);