

class spell_gen_enable_mastery_SpellScript : public SpellScript
{
PrepareSpellScript(spell_gen_enable_mastery_SpellScript);
void HandleDummy(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
Player* target = GetHitPlayer();
if (!target)
return;
// Add all mastery spells but only activates the ones we can have
uint32 const* talentTabs = GetTalentTabPages(target->getClass());
uint32 currentSpec = target->GetPrimaryTalentTree(target->GetActiveSpec());
for (uint32 i = 0; i < MAX_TALENT_TABS; ++i)
if (TalentTabEntry const* talentTab = sTalentTabStore.LookupEntry(talentTabs[i]))
for (uint32 i = 0; i < 2; ++i) // Max mastery spells per spec
if (uint32 mastery = talentTab->MasterySpells[i])
target->addSpell(mastery, currentSpec == talentTabs[i], false, false, currentSpec != talentTabs[i]);
// Activate mastery handling
target->SetMasteryState(true);
uint32 const MasterySpellBookSpells[11] = { 86479, 86474, 86472, 86476, 86475, 86471, 86477, 86473, 86478, 0, 86470 };
if (uint32 spellId = MasterySpellBookSpells[target->getClass() - 1])
if (!target->HasSpell(spellId))
target->learnSpell(MasterySpellBookSpells[target->getClass() - 1], false);
}
class MasteryAuraScript : public AuraScript
{
public:
MasteryAuraScript() : AuraScript(), _baseCoeff(12.5f), _scalingEffIndex(EFFECT_1) { }
MasteryAuraScript(float baseCoefficient) : _baseCoeff(baseCoefficient), _scalingEffIndex(EFFECT_1) { }
MasteryAuraScript(SpellEffIndex scalingEffIndex) : _scalingEffIndex(scalingEffIndex), _baseCoeff(0.0f) { }
MasteryAuraScript(float baseCoefficient, SpellEffIndex scalingEffIndex) : _baseCoeff(baseCoefficient), _scalingEffIndex(scalingEffIndex) { }
void CalcPeriodic(AuraEffect const* /*aurEff*/, bool& isPeriodic, int32& amplitude)
{
isPeriodic = true;
amplitude = 1000; // Should be enough
}
void UpdateAmount(AuraEffect* aurEff)
{
Unit* caster = aurEff->GetCaster();
int32 bonusValue = aurEff->GetSpellInfo()->Effects[_scalingEffIndex].CalcValue(caster);
float aurEffAmount = float(bonusValue) / _baseCoeff;
aurEffAmount += caster->GetFloatValue(PLAYER_MASTERY) * bonusValue;
aurEff->SetAmount(int32(aurEffAmount));
}
protected:
float _baseCoeff;
SpellEffIndex _scalingEffIndex;
};
class spell_gen_mastery_scaling_aura : public SpellScriptLoader
{
public:
spell_gen_mastery_scaling_aura(char const* scriptName, uint32 auraIdentifier) : SpellScriptLoader(scriptName),
_auraIdentifier(auraIdentifier), _scalingEffIndex(EFFECT_1) { }
spell_gen_mastery_scaling_aura(char const* scriptName, uint32 auraIdentifier, SpellEffIndex effIndex) : SpellScriptLoader(scriptName),
_auraIdentifier(auraIdentifier), _scalingEffIndex(effIndex) { }
class spell_generic_mastery_scaling_aura_AuraScript : public MasteryAuraScript
{
PrepareAuraScript(spell_generic_mastery_scaling_aura_AuraScript);
public:
spell_generic_mastery_scaling_aura_AuraScript(uint32 auraName, SpellEffIndex effIndex) : MasteryAuraScript(effIndex), _auraName(auraName) { }
void Register()
{
DoEffectCalcPeriodic += AuraEffectCalcPeriodicFn(spell_generic_mastery_scaling_aura_AuraScript::CalcPeriodic, EFFECT_0, _auraName);
OnEffectUpdatePeriodic += AuraEffectUpdatePeriodicFn(spell_generic_mastery_scaling_aura_AuraScript::UpdateAmount, EFFECT_0, _auraName);
}
private:
uint32 _auraName;
};
AuraScript* GetAuraScript() const
{
return new spell_generic_mastery_scaling_aura_AuraScript(_auraIdentifier, _scalingEffIndex);
}
private:
uint32 _auraIdentifier;
SpellEffIndex _scalingEffIndex;
};