Scripts/Spells: Allow using templated spell script with multiple template arguments in RegisterSpellScriptWithArgs

* Also fixed some script conversion issues
This commit is contained in:
Shauren
2023-07-19 13:44:18 +02:00
parent 5be076b240
commit d949f86e28
5 changed files with 62 additions and 83 deletions

View File

@@ -104,7 +104,6 @@ Optional<std::size_t> SelectAddressForClient(boost::asio::ip::address const& cli
if (address.is_v4() && !externalIpv4Index)
externalIpv4Index = i;
}
}
if (IsInLocalNetwork(clientAddress) || clientAddress.is_loopback())

View File

@@ -22,6 +22,7 @@
#include "ObjectGuid.h"
#include "Tuples.h"
#include "Types.h"
#include <boost/preprocessor/punctuation/remove_parens.hpp>
#include <memory>
#include <vector>
@@ -1339,6 +1340,8 @@ class GenericSpellAndAuraScriptLoader : public SpellScriptLoader
using AuraScriptType = typename Trinity::find_type_if_t<Trinity::SpellScripts::is_AuraScript, Ts...>;
using ArgsType = typename Trinity::find_type_if_t<Trinity::is_tuple, Ts...>;
static_assert(!std::conjunction_v<std::is_same<SpellScriptType, Trinity::find_type_end>, std::is_same<AuraScriptType, Trinity::find_type_end>>, "At least one of SpellScript/AuraScript arguments must be provided for GenericSpellAndAuraScriptLoader");
public:
GenericSpellAndAuraScriptLoader(char const* name, ArgsType&& args) : SpellScriptLoader(name), _args(std::move(args)) { }
@@ -1362,9 +1365,9 @@ private:
ArgsType _args;
};
#define RegisterSpellScriptWithArgs(spell_script, script_name, ...) new GenericSpellAndAuraScriptLoader<spell_script, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
#define RegisterSpellScriptWithArgs(spell_script, script_name, ...) new GenericSpellAndAuraScriptLoader<BOOST_PP_REMOVE_PARENS(spell_script), decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
#define RegisterSpellScript(spell_script) RegisterSpellScriptWithArgs(spell_script, #spell_script)
#define RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, script_name, ...) new GenericSpellAndAuraScriptLoader<script_1, script_2, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
#define RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, script_name, ...) new GenericSpellAndAuraScriptLoader<BOOST_PP_REMOVE_PARENS(script_1), BOOST_PP_REMOVE_PARENS(script_2), decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
#define RegisterSpellAndAuraScriptPair(script_1, script_2) RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, #script_1)
template <class AI>

View File

@@ -344,5 +344,5 @@ void AddSC_boss_bronjahm()
RegisterSpellScriptWithArgs(spell_bronjahm_soulstorm_visual, "spell_bronjahm_soulstorm_channel");
RegisterSpellScriptWithArgs(spell_bronjahm_soulstorm_visual, "spell_bronjahm_soulstorm_visual");
RegisterSpellScript(spell_bronjahm_soulstorm_targeting);
RegisterSpellScript(achievement_bronjahm_soul_power);
new achievement_bronjahm_soul_power();
}

View File

@@ -2200,33 +2200,22 @@ class spell_gen_interrupt : public AuraScript
}
};
class spell_gen_increase_stats_buff : public SpellScriptLoader
class spell_gen_increase_stats_buff : public SpellScript
{
public:
spell_gen_increase_stats_buff(char const* scriptName) : SpellScriptLoader(scriptName) { }
PrepareSpellScript(spell_gen_increase_stats_buff);
class spell_gen_increase_stats_buff_SpellScript : public SpellScript
{
PrepareSpellScript(spell_gen_increase_stats_buff_SpellScript);
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (GetHitUnit()->IsInRaidWith(GetCaster()))
GetCaster()->CastSpell(GetCaster(), GetEffectValue() + 1, true); // raid buff
else
GetCaster()->CastSpell(GetHitUnit(), GetEffectValue(), true); // single-target buff
}
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (GetHitUnit()->IsInRaidWith(GetCaster()))
GetCaster()->CastSpell(GetCaster(), GetEffectValue() + 1, true); // raid buff
else
GetCaster()->CastSpell(GetHitUnit(), GetEffectValue(), true); // single-target buff
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_gen_increase_stats_buff_SpellScript::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
SpellScript* GetSpellScript() const override
{
return new spell_gen_increase_stats_buff_SpellScript();
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_gen_increase_stats_buff::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY);
}
};
enum GenericLifebloom

View File

@@ -1336,66 +1336,54 @@ enum Heartpierce
// Item - 50641: Heartpierce (Heroic)
// 71892 - Item - Icecrown 25 Heroic Dagger Proc
template <uint32 EnergySpellId, uint32 ManaSpellId, uint32 RageSpellId, uint32 RPSpellId>
class spell_item_heartpierce : public SpellScriptLoader
template <uint32 Energy, uint32 Mana, uint32 Rage, uint32 RunicPower>
class spell_item_heartpierce : public AuraScript
{
public:
spell_item_heartpierce(char const* ScriptName) : SpellScriptLoader(ScriptName) { }
PrepareAuraScript(spell_item_heartpierce);
template <uint32 Energy, uint32 Mana, uint32 Rage, uint32 RunicPower>
class spell_item_heartpierce_AuraScript : public AuraScript
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
PrepareAuraScript(spell_item_heartpierce_AuraScript);
Energy,
Mana,
Rage,
RunicPower
});
}
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
Energy,
Mana,
Rage,
RunicPower
});
}
void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
Unit* caster = eventInfo.GetActor();
void HandleProc(AuraEffect* aurEff, ProcEventInfo& eventInfo)
{
PreventDefaultAction();
Unit* caster = eventInfo.GetActor();
uint32 spellId;
switch (caster->GetPowerType())
{
case POWER_MANA:
spellId = Mana;
break;
case POWER_ENERGY:
spellId = Energy;
break;
case POWER_RAGE:
spellId = Rage;
break;
// Death Knights can't use daggers, but oh well
case POWER_RUNIC_POWER:
spellId = RunicPower;
break;
default:
return;
}
caster->CastSpell(nullptr, spellId, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_item_heartpierce_AuraScript::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
AuraScript* GetAuraScript() const override
uint32 spellId;
switch (caster->GetPowerType())
{
return new spell_item_heartpierce_AuraScript<EnergySpellId, ManaSpellId, RageSpellId, RPSpellId>();
case POWER_MANA:
spellId = Mana;
break;
case POWER_ENERGY:
spellId = Energy;
break;
case POWER_RAGE:
spellId = Rage;
break;
// Death Knights can't use daggers, but oh well
case POWER_RUNIC_POWER:
spellId = RunicPower;
break;
default:
return;
}
caster->CastSpell(nullptr, spellId, aurEff);
}
void Register() override
{
OnEffectProc += AuraEffectProcFn(spell_item_heartpierce::HandleProc, EFFECT_0, SPELL_AURA_DUMMY);
}
};
enum HourglassSand
@@ -5002,8 +4990,8 @@ void AddSC_item_spell_scripts()
RegisterSpellScript(spell_item_frozen_shadoweave);
RegisterSpellScript(spell_item_gnomish_death_ray);
RegisterSpellScript(spell_item_harm_prevention_belt);
new spell_item_heartpierce<SPELL_INVIGORATION_ENERGY, SPELL_INVIGORATION_MANA, SPELL_INVIGORATION_RAGE, SPELL_INVIGORATION_RP>("spell_item_heartpierce");
new spell_item_heartpierce<SPELL_INVIGORATION_ENERGY_HERO, SPELL_INVIGORATION_MANA_HERO, SPELL_INVIGORATION_RAGE_HERO, SPELL_INVIGORATION_RP_HERO>("spell_item_heartpierce_hero");
RegisterSpellScriptWithArgs((spell_item_heartpierce<SPELL_INVIGORATION_ENERGY, SPELL_INVIGORATION_MANA, SPELL_INVIGORATION_RAGE, SPELL_INVIGORATION_RP>), "spell_item_heartpierce");
RegisterSpellScriptWithArgs((spell_item_heartpierce<SPELL_INVIGORATION_ENERGY_HERO, SPELL_INVIGORATION_MANA_HERO, SPELL_INVIGORATION_RAGE_HERO, SPELL_INVIGORATION_RP_HERO>), "spell_item_heartpierce_hero");
RegisterSpellScript(spell_item_hourglass_sand);
RegisterSpellScript(spell_item_crystal_spire_of_karabor);
RegisterSpellScript(spell_item_make_a_wish);