From 908dff2d01a84bd3af3a519324c4046d10e78e31 Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 21 Sep 2025 00:15:00 -0400 Subject: [PATCH 1/6] Add new hook for aura application apply/removals. --- LuaEngine.h | 2 ++ hooks/Hooks.h | 4 +++- hooks/SpellHooks.cpp | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/LuaEngine.h b/LuaEngine.h index 408d340813..d760e71c44 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -611,6 +611,8 @@ class ELUNA_GAME_API Eluna /* Spell */ void OnSpellCast(Spell* pSpell, bool skipCheck); + void OnAuraApplication(Aura* aura, uint8 effId, uint8 mode, bool apply); + }; template<> Unit* Eluna::CHECKOBJ(int narg, bool error); template<> Object* Eluna::CHECKOBJ(int narg, bool error); diff --git a/hooks/Hooks.h b/hooks/Hooks.h index 0197f37810..44c16c50d4 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -276,6 +276,7 @@ namespace Hooks enum SpellEvents { SPELL_EVENT_ON_CAST = 1, // (event, spell, skipCheck) + SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, mode, apply) SPELL_EVENT_COUNT }; @@ -520,7 +521,8 @@ class HookToReadableString }; static constexpr EventEntry SpellEventsTable[] = { - {Hooks::SPELL_EVENT_ON_CAST, "on_cast"} + {Hooks::SPELL_EVENT_ON_CAST, "on_cast"}, + {Hooks::SPELL_EVENT_ON_AURA_APPLICATION, "on_aura_application" } }; static constexpr EventEntry ItemEventsTable[] = { diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index a5ef8a30a6..90e74396c7 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -15,7 +15,7 @@ using namespace Hooks; #define START_HOOK(EVENT, SPELL) \ auto binding = GetBinding>(REGTYPE_SPELL);\ - auto key = EntryKey(EVENT, SPELL->m_spellInfo->Id);\ + auto key = EntryKey(EVENT, SPELL->GetSpellInfo()->Id);\ if (!binding->HasBindingsFor(key))\ return; @@ -32,3 +32,13 @@ void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck) HookPush(skipCheck); CallAllFunctions(binding, key); } + +void Eluna::OnAuraApplication(Aura* aura, uint8 effId, uint8 mode, bool apply) +{ + START_HOOK(SPELL_EVENT_ON_AURA_APPLICATION, aura); + HookPush(aura); + HookPush(effId); + HookPush(mode); + HookPush(apply); + CallAllFunctions(binding, key); +} From a4a125f01e24d3d168a45836807f2a6c4033675d Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 21 Sep 2025 00:19:52 -0400 Subject: [PATCH 2/6] Fix missing effect Id arg in comment. --- hooks/Hooks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/Hooks.h b/hooks/Hooks.h index 44c16c50d4..31382e335c 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -276,7 +276,7 @@ namespace Hooks enum SpellEvents { SPELL_EVENT_ON_CAST = 1, // (event, spell, skipCheck) - SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, mode, apply) + SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, effectId, mode, apply) SPELL_EVENT_COUNT }; From b445c2e3f23c0c2381a146f8ed814cbdb0c76b99 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 23 Sep 2025 12:59:04 -0400 Subject: [PATCH 3/6] Expand into including most spell aura script hooks. Add auraeffect methods. --- ElunaIncludes.h | 1 + ElunaTemplate.cpp | 7 ++ ElunaTemplate.h | 1 + LuaEngine.h | 8 +- hooks/Hooks.h | 14 ++- hooks/SpellHooks.cpp | 106 +++++++++++++++- methods/Methods.cpp | 4 + methods/TrinityCore/AuraEffectMethods.h | 159 ++++++++++++++++++++++++ 8 files changed, 292 insertions(+), 8 deletions(-) create mode 100644 methods/TrinityCore/AuraEffectMethods.h diff --git a/ElunaIncludes.h b/ElunaIncludes.h index fec1f48d59..2e6cd85383 100644 --- a/ElunaIncludes.h +++ b/ElunaIncludes.h @@ -36,6 +36,7 @@ #include "ScriptMgr.h" #include "Spell.h" #include "SpellAuras.h" +#include "SpellAuraEffects.h" #include "SpellMgr.h" #include "TemporarySummon.h" #include "WorldPacket.h" diff --git a/ElunaTemplate.cpp b/ElunaTemplate.cpp index 462ea92d65..8baa2b1425 100644 --- a/ElunaTemplate.cpp +++ b/ElunaTemplate.cpp @@ -20,6 +20,13 @@ ElunaConstrainedObjectRef GetWeakPtrFor(Aura const* obj) #endif return { obj->GetWeakPtr(), map }; } + +ElunaConstrainedObjectRef GetWeakPtrFor(AuraEffect const* obj) +{ + Map* map = obj->GetBase()->GetOwner()->GetMap(); + return { obj->GetWeakPtr(), map }; +} + ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; } ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; } ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; } diff --git a/ElunaTemplate.h b/ElunaTemplate.h index 74d98f3bf2..7fcf780104 100644 --- a/ElunaTemplate.h +++ b/ElunaTemplate.h @@ -62,6 +62,7 @@ struct ElunaConstrainedObjectRef }; ElunaConstrainedObjectRef GetWeakPtrFor(Aura const* obj); +ElunaConstrainedObjectRef GetWeakPtrFor(AuraEffect const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj); diff --git a/LuaEngine.h b/LuaEngine.h index d760e71c44..7ab064941c 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -611,8 +611,12 @@ class ELUNA_GAME_API Eluna /* Spell */ void OnSpellCast(Spell* pSpell, bool skipCheck); - void OnAuraApplication(Aura* aura, uint8 effId, uint8 mode, bool apply); - + bool OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply); + void OnAuraDispel(Aura* aura, DispelInfo* dispelInfo); + bool OnPerodicTick(Aura* aura, AuraEffect const* auraEff); + void OnPerodicUpdate(Aura* aura, AuraEffect const* auraEff); + void OnAuraCalcAmount(Aura* aura, AuraEffect const* auraEff, int32& amount, bool& canBeRecalculated); + void OnCalcPerodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodic, int32& amplitude); }; template<> Unit* Eluna::CHECKOBJ(int narg, bool error); template<> Object* Eluna::CHECKOBJ(int narg, bool error); diff --git a/hooks/Hooks.h b/hooks/Hooks.h index 31382e335c..df3a0ff71f 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -276,7 +276,12 @@ namespace Hooks enum SpellEvents { SPELL_EVENT_ON_CAST = 1, // (event, spell, skipCheck) - SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, effectId, mode, apply) + SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, effectImdex, mode, apply) + SPELL_EVENT_ON_DISPEL = 3, // (event, aura, @todo: write args) + SPELL_EVENT_ON_PERODIC_TICK = 4, // (event, aura, effectIndex) + SPELL_EVENT_ON_PERODIC_UPDATE = 5, // (event, aura, effectIndex) + SPELL_EVENT_ON_AURA_CALC_AMOUNT = 6, // (event, aura, @todo: write args) + SPELL_EVENT_ON_CALC_PERODIC = 7, // (event, aura, @todo: write args) SPELL_EVENT_COUNT }; @@ -522,7 +527,12 @@ class HookToReadableString static constexpr EventEntry SpellEventsTable[] = { {Hooks::SPELL_EVENT_ON_CAST, "on_cast"}, - {Hooks::SPELL_EVENT_ON_AURA_APPLICATION, "on_aura_application" } + {Hooks::SPELL_EVENT_ON_AURA_APPLICATION, "on_aura_application" }, + {Hooks::SPELL_EVENT_ON_DISPEL, "on_aura_dispel" }, + {Hooks::SPELL_EVENT_ON_PERODIC_TICK, "on_perodic_tick" }, + {Hooks::SPELL_EVENT_ON_PERODIC_UPDATE, "on_perodic_update" }, + {Hooks::SPELL_EVENT_ON_AURA_CALC_AMOUNT, "on_aura_calc_amount" }, + {Hooks::SPELL_EVENT_ON_CALC_PERODIC, "on_calc_perodic" } }; static constexpr EventEntry ItemEventsTable[] = { diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index 90e74396c7..cb6d38d542 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -21,7 +21,7 @@ using namespace Hooks; #define START_HOOK_WITH_RETVAL(EVENT, SPELL, RETVAL) \ auto binding = GetBinding>(REGTYPE_SPELL);\ - auto key = EntryKey(EVENT, SPELL->m_spellInfo->Id);\ + auto key = EntryKey(EVENT, SPELL->GetSpellInfo()->Id);\ if (!binding->HasBindingsFor(key))\ return RETVAL; @@ -33,12 +33,110 @@ void Eluna::OnSpellCast(Spell* pSpell, bool skipCheck) CallAllFunctions(binding, key); } -void Eluna::OnAuraApplication(Aura* aura, uint8 effId, uint8 mode, bool apply) +bool Eluna::OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply) { - START_HOOK(SPELL_EVENT_ON_AURA_APPLICATION, aura); + START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_AURA_APPLICATION, aura, false); HookPush(aura); - HookPush(effId); + HookPush(auraEff); + HookPush(target); HookPush(mode); HookPush(apply); + return CallAllFunctionsBool(binding, key, false); +} + +void Eluna::OnAuraDispel(Aura* aura, DispelInfo* dispelInfo) +{ + START_HOOK(SPELL_EVENT_ON_DISPEL, aura); + HookPush(aura); + HookPush(dispelInfo->GetDispeller()); + HookPush(dispelInfo->GetDispellerSpellId()); + HookPush(dispelInfo->GetRemovedCharges()); CallAllFunctions(binding, key); } + +bool Eluna::OnPerodicTick(Aura* aura, AuraEffect const* auraEff) +{ + START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_PERODIC_TICK, aura, false); + HookPush(aura); + HookPush(auraEff); + return CallAllFunctionsBool(binding, key, false); +} + +void Eluna::OnPerodicUpdate(Aura* aura, AuraEffect const* auraEff) +{ + START_HOOK(SPELL_EVENT_ON_PERODIC_UPDATE, aura); + HookPush(aura); + HookPush(auraEff); + CallAllFunctions(binding, key); +} + +void Eluna::OnAuraCalcAmount(Aura* aura, AuraEffect const* auraEff, int32& amount, bool& canBeRecalculated) +{ + START_HOOK(SPELL_EVENT_ON_AURA_CALC_AMOUNT, aura); + HookPush(aura); + HookPush(auraEff); + HookPush(amount); + int amountIndex = lua_gettop(L); + HookPush(canBeRecalculated); + int canBeRecalculatedIndex = lua_gettop(L); + int n = SetupStack(binding, key, 4); + + while (n > 0) + { + int r = CallOneFunction(n--, 4, 2); + + if (lua_isnumber(L, r + 0)) + { + amount = CHECKVAL(r + 0); + // Update the stack for subsequent calls. + ReplaceArgument(amount, amountIndex); + } + + + if (lua_isboolean(L, r + 1)) + { + canBeRecalculated = lua_toboolean(L, r + 1); + // Update the stack for subsequent calls. + ReplaceArgument(amount, canBeRecalculatedIndex); + } + + lua_pop(L, 2); + } + + CleanUpStack(2); +} + +void Eluna::OnCalcPerodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodic, int32& amplitude) +{ + START_HOOK(SPELL_EVENT_ON_AURA_CALC_AMOUNT, aura); + HookPush(aura); + HookPush(auraEff); + HookPush(isPeriodic); + int isPeriodicIndex = lua_gettop(L); + HookPush(amplitude); + int amplitudeIndex = lua_gettop(L); + int n = SetupStack(binding, key, 4); + + while (n > 0) + { + int r = CallOneFunction(n--, 4, 2); + + if (lua_isboolean(L, r + 0)) + { + isPeriodic = lua_toboolean(L, r + 0); + // Update the stack for subsequent calls. + ReplaceArgument(isPeriodic, isPeriodicIndex); + } + + if (lua_isnumber(L, r + 1)) + { + amplitude = CHECKVAL(r + 1); + // Update the stack for subsequent calls. + ReplaceArgument(amplitude, amplitudeIndex); + } + + lua_pop(L, 2); + } + + CleanUpStack(2); +} diff --git a/methods/Methods.cpp b/methods/Methods.cpp index ae2bf4d229..0f53ef36c9 100644 --- a/methods/Methods.cpp +++ b/methods/Methods.cpp @@ -23,6 +23,7 @@ #include "GameObjectMethods.h" #include "ElunaQueryMethods.h" #include "AuraMethods.h" +#include "AuraEffectMethods.h" #include "ItemMethods.h" #include "WorldPacketMethods.h" #include "SpellMethods.h" @@ -90,6 +91,9 @@ void RegisterMethods(Eluna* E) ElunaTemplate::Register(E, "Aura"); ElunaTemplate::SetMethods(E, LuaAura::AuraMethods); + ElunaTemplate::Register(E, "AuraEffect"); + ElunaTemplate::SetMethods(E, LuaAuraEffects::AuraEffectMethods); + ElunaTemplate::Register(E, "Spell"); ElunaTemplate::SetMethods(E, LuaSpell::SpellMethods); diff --git a/methods/TrinityCore/AuraEffectMethods.h b/methods/TrinityCore/AuraEffectMethods.h new file mode 100644 index 0000000000..f2749c0296 --- /dev/null +++ b/methods/TrinityCore/AuraEffectMethods.h @@ -0,0 +1,159 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef AURAEFFECTMETHODS_H +#define AURAEFFECTMETHODS_H + + +namespace LuaAuraEffects +{ + int GetBase(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetBase()); + return 1; + } + + int GetBaseAmount(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetBaseAmount()); + return 1; + } + + int GetAmplitude(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetAmplitude()); + return 1; + } + + int GetAmount(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetAmount()); + return 1; + } + + int SetAmount(Eluna* E, AuraEffect* aurEff) + { + int32 amount = E->CHECKVAL(2); + aurEff->SetAmount(amount); + return 0; + } + + int GetPeriodicTimer(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetPeriodicTimer()); + return 1; + } + + int SetPeriodicTimer(Eluna* E, AuraEffect* aurEff) + { + int32 timer = E->CHECKVAL(2); + aurEff->SetPeriodicTimer(timer); + return 0; + } + + int CalculateAmount(Eluna* E, AuraEffect* aurEff) + { + Unit* caster = E->CHECKOBJ(2); + E->Push(aurEff->CalculateAmount(caster)); + return 1; + } + + int CalculatePeriodic(Eluna* E, AuraEffect* aurEff) + { + Unit* caster = E->CHECKOBJ(2); + bool resetPeriodicTimer = E->CHECKVAL(3, false); + bool load = E->CHECKVAL(4, false); + aurEff->CalculatePeriodic(caster, resetPeriodicTimer, load); + return 0; + } + + int ChangeAmount(Eluna* E, AuraEffect* aurEff) + { + int32 newAmount = E->CHECKVAL(2); + bool mark = E->CHECKVAL(3, true); + bool onStackOrReapply = E->CHECKVAL(4, false); + aurEff->ChangeAmount(newAmount, mark, onStackOrReapply); + return 0; + } + + int RecalculateAmount(Eluna* /*E*/, AuraEffect* aurEff) + { + aurEff->RecalculateAmount(); + return 0; + } + + int CanBeRecalculated(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->CanBeRecalculated()); + return 1; + } + + int SetCanBeRecalculated(Eluna* E, AuraEffect* aurEff) + { + bool val = E->CHECKVAL(2, true); + aurEff->SetCanBeRecalculated(val); + return 0; + } + + int GetTickNumber(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetTickNumber()); + return 1; + } + + int GetRemainingTicks(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetRemainingTicks()); + return 1; + } + + int GetTotalTicks(Eluna* E, AuraEffect* aurEff) + { + E->Push(aurEff->GetTotalTicks()); + return 1; + } + + int GetTargetList(Eluna* E, AuraEffect* aurEff) + { + std::list list; + aurEff->GetTargetList(list); + lua_createtable(E->L, list.size(), 0); + int tbl = lua_gettop(E->L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + E->Push(*it); + lua_rawseti(E->L, tbl, ++i); + } + + lua_settop(E->L, tbl); + return 1; + } + + ElunaRegister AuraEffectMethods[] = + { + {"GetBase", &LuaAuraEffects::GetBase}, + {"GetBaseAmount", &LuaAuraEffects::GetBaseAmount}, + {"GetAmplitude", &LuaAuraEffects::GetAmplitude}, + {"GetAmount", &LuaAuraEffects::GetAmount}, + {"SetAmount", &LuaAuraEffects::SetAmount}, + {"GetPeriodicTimer", &LuaAuraEffects::GetPeriodicTimer}, + {"SetPeriodicTimer", &LuaAuraEffects::SetPeriodicTimer}, + {"CalculateAmount", &LuaAuraEffects::CalculateAmount}, + {"CalculatePeriodic", &LuaAuraEffects::CalculatePeriodic}, + {"ChangeAmount", &LuaAuraEffects::ChangeAmount}, + {"RecalculateAmount", &LuaAuraEffects::RecalculateAmount}, + {"CanBeRecalculated", &LuaAuraEffects::CanBeRecalculated}, + {"SetCanBeRecalculated", &LuaAuraEffects::SetCanBeRecalculated}, + {"GetTickNumber", &LuaAuraEffects::GetTickNumber}, + {"GetRemainingTicks", &LuaAuraEffects::GetRemainingTicks}, + {"GetTotalTicks", &LuaAuraEffects::GetTotalTicks}, + {"GetTargetList", &LuaAuraEffects::GetTargetList} + }; +}; +#endif + From d37167f47d4b8995a0bf50d94dc758e470621323 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 23 Sep 2025 13:01:41 -0400 Subject: [PATCH 4/6] *Forgot to update staged files for previous commit. --- LuaEngine.h | 2 +- hooks/Hooks.h | 14 +++++++------- hooks/SpellHooks.cpp | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LuaEngine.h b/LuaEngine.h index 7ab064941c..82fcdbfc25 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -613,7 +613,7 @@ class ELUNA_GAME_API Eluna void OnSpellCast(Spell* pSpell, bool skipCheck); bool OnAuraApplication(Aura* aura, AuraEffect const* auraEff, Unit* target, uint8 mode, bool apply); void OnAuraDispel(Aura* aura, DispelInfo* dispelInfo); - bool OnPerodicTick(Aura* aura, AuraEffect const* auraEff); + bool OnPerodicTick(Aura* aura, AuraEffect const* auraEff, Unit* target); void OnPerodicUpdate(Aura* aura, AuraEffect const* auraEff); void OnAuraCalcAmount(Aura* aura, AuraEffect const* auraEff, int32& amount, bool& canBeRecalculated); void OnCalcPerodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodic, int32& amplitude); diff --git a/hooks/Hooks.h b/hooks/Hooks.h index df3a0ff71f..6f583c81c1 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -275,13 +275,13 @@ namespace Hooks enum SpellEvents { - SPELL_EVENT_ON_CAST = 1, // (event, spell, skipCheck) - SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, effectImdex, mode, apply) - SPELL_EVENT_ON_DISPEL = 3, // (event, aura, @todo: write args) - SPELL_EVENT_ON_PERODIC_TICK = 4, // (event, aura, effectIndex) - SPELL_EVENT_ON_PERODIC_UPDATE = 5, // (event, aura, effectIndex) - SPELL_EVENT_ON_AURA_CALC_AMOUNT = 6, // (event, aura, @todo: write args) - SPELL_EVENT_ON_CALC_PERODIC = 7, // (event, aura, @todo: write args) + SPELL_EVENT_ON_CAST = 1, // (event, spell, skipCheck) + SPELL_EVENT_ON_AURA_APPLICATION = 2, // (event, aura, auraEffect, target, mode, apply) - Can return true to stop normal action + SPELL_EVENT_ON_DISPEL = 3, // (event, aura, dispeler, dispelSpellId, removedCharges) + SPELL_EVENT_ON_PERODIC_TICK = 4, // (event, aura, auraEffect, target) Can return true to stop normal action + SPELL_EVENT_ON_PERODIC_UPDATE = 5, // (event, aura, auraEffect) + SPELL_EVENT_ON_AURA_CALC_AMOUNT = 6, // (event, aura, auraEffect, amount, canBeRecalculated) - can return new amount as first return value, can return new canBeRecalculated as second return value + SPELL_EVENT_ON_CALC_PERODIC = 7, // (event, aura, auraEffect, isPeriodic, amplitude) - can return new isPeriodic as first return value, can return new amplitude as second return value SPELL_EVENT_COUNT }; diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index cb6d38d542..e3e76ec986 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -54,11 +54,12 @@ void Eluna::OnAuraDispel(Aura* aura, DispelInfo* dispelInfo) CallAllFunctions(binding, key); } -bool Eluna::OnPerodicTick(Aura* aura, AuraEffect const* auraEff) +bool Eluna::OnPerodicTick(Aura* aura, AuraEffect const* auraEff, Unit* target) { START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_PERODIC_TICK, aura, false); HookPush(aura); HookPush(auraEff); + HookPush(target); return CallAllFunctionsBool(binding, key, false); } From 3e65a5cb5ca18cf5d8ba7569bbc4d50c1a1a1b06 Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 12 Feb 2026 22:52:13 -0500 Subject: [PATCH 5/6] Add checkproc/proc events. --- ElunaProcInfo.cpp | 113 +++++++++++ ElunaProcInfo.h | 102 ++++++++++ ElunaTemplate.cpp | 4 + ElunaTemplate.h | 2 + LuaEngine.h | 3 + hooks/Hooks.h | 94 ++++----- hooks/SpellHooks.cpp | 22 +++ methods/Methods.cpp | 4 + methods/TrinityCore/AuraEffectMethods.h | 6 - methods/TrinityCore/ElunaProcInfoMethods.h | 213 +++++++++++++++++++++ 10 files changed, 511 insertions(+), 52 deletions(-) create mode 100644 ElunaProcInfo.cpp create mode 100644 ElunaProcInfo.h create mode 100644 methods/TrinityCore/ElunaProcInfoMethods.h diff --git a/ElunaProcInfo.cpp b/ElunaProcInfo.cpp new file mode 100644 index 0000000000..0e46d82e92 --- /dev/null +++ b/ElunaProcInfo.cpp @@ -0,0 +1,113 @@ +#include "ElunaProcInfo.h" +#include "ElunaIncludes.h" +#include "ElunaTemplate.h" + +ElunaProcInfo::ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask, + uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, + Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map) + : _actor(actor), _actionTarget(actionTarget), _typeMask(typeMask), _spellTypeMask(spellTypeMask), _spellPhaseMask(spellPhaseMask) + , _hitMask(hitMask), _spell(spell), _spellInfo(spellInfo), _schoolMask(schoolMask), _damage(0) + , _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0) + , _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map), m_scriptRef(this, NoopAuraDeleter()) +{ +} + +ElunaProcInfo::ElunaProcInfo(ProcEventInfo& procInfo, Map* map) + : _actor(procInfo.GetActor()), _actionTarget(procInfo.GetActionTarget()), _typeMask(procInfo.GetTypeMask()), _spellTypeMask(procInfo.GetSpellTypeMask()), _spellPhaseMask(procInfo.GetSpellPhaseMask()) + , _hitMask(procInfo.GetHitMask()), _spell(const_cast(procInfo.GetProcSpell())), _spellInfo(procInfo.GetSpellInfo()), _schoolMask(procInfo.GetSchoolMask()), _damage(0) + , _damageType(DIRECT_DAMAGE), _attackType(BASE_ATTACK), _damageAbsorb(0), _resist(0), _block(0) + , _heal(0), _effectiveHeal(0), _healAbsorb(0), _map(map), m_scriptRef(this, NoopAuraDeleter()) +{ + if (DamageInfo* damageInfo = procInfo.GetDamageInfo()) + { + _damage = damageInfo->GetDamage(); + _damageType = damageInfo->GetDamageType(); + _attackType = damageInfo->GetAttackType(); + _damageAbsorb = damageInfo->GetAbsorb(); + _resist = damageInfo->GetResist(); + _block = damageInfo->GetBlock(); + + if (damageInfo->GetSpellInfo()) + { + _spellInfo = damageInfo->GetSpellInfo(); + _schoolMask = damageInfo->GetSchoolMask(); + } + } + + if (HealInfo* healInfo = procInfo.GetHealInfo()) + { + _heal = healInfo->GetHeal(); + _effectiveHeal = healInfo->GetEffectiveHeal(); + _healAbsorb = healInfo->GetAbsorb(); + + if (healInfo->GetSpellInfo() && !_spellInfo) + { + _spellInfo = healInfo->GetSpellInfo(); + _schoolMask = healInfo->GetSchoolMask(); + } + } +} + +SpellInfo const* ElunaProcInfo::GetSpellInfo() const +{ + if (_spellInfo) + return _spellInfo; + if (_spell) + return _spell->GetSpellInfo(); + return nullptr; +} + +void ElunaProcInfo::SetDamage(uint32 damage, DamageEffectType damageType, WeaponAttackType attackType) +{ + _damage = damage; + _damageType = damageType; + _attackType = attackType; +} + +void ElunaProcInfo::SetHeal(uint32 heal) +{ + _heal = heal; + _effectiveHeal = heal; +} + +void ElunaProcInfo::ApplyToProcEventInfo(ProcEventInfo& procInfo) const +{ + if (DamageInfo* damageInfo = procInfo.GetDamageInfo()) + { + if (HasDamage()) + { + int32 damageDiff = static_cast(_damage) - static_cast(damageInfo->GetDamage()); + if (damageDiff != 0) + damageInfo->ModifyDamage(damageDiff); + + uint32 currentAbsorb = damageInfo->GetAbsorb(); + uint32 currentResist = damageInfo->GetResist(); + uint32 currentBlock = damageInfo->GetBlock(); + + uint32 absorbToAdd = (_damageAbsorb > currentAbsorb) ? (_damageAbsorb - currentAbsorb) : 0; + uint32 resistToAdd = (_resist > currentResist) ? (_resist - currentResist) : 0; + uint32 blockToAdd = (_block > currentBlock) ? (_block - currentBlock) : 0; + + if (absorbToAdd > 0) + damageInfo->AbsorbDamage(absorbToAdd); + if (resistToAdd > 0) + damageInfo->ResistDamage(resistToAdd); + if (blockToAdd > 0) + damageInfo->BlockDamage(blockToAdd); + } + } + + if (HealInfo* healInfo = procInfo.GetHealInfo()) + { + if (HasHeal()) + { + uint32 currentAbsorb = healInfo->GetAbsorb(); + uint32 absorbToAdd = (_healAbsorb > currentAbsorb) ? (_healAbsorb - currentAbsorb) : 0; + + if (absorbToAdd > 0) + healInfo->AbsorbHeal(absorbToAdd); + + healInfo->SetEffectiveHeal(_effectiveHeal); + } + } +} diff --git a/ElunaProcInfo.h b/ElunaProcInfo.h new file mode 100644 index 0000000000..e5586c3113 --- /dev/null +++ b/ElunaProcInfo.h @@ -0,0 +1,102 @@ +#ifndef _ELUNA_PROCINFO_H +#define _ELUNA_PROCINFO_H + +class Unit; +class Spell; +class Map; +class SpellInfo; +class ProcEventInfo; +class DamageInfo; +class HealInfo; +enum SpellSchoolMask : uint32; +enum DamageEffectType : uint8; +enum WeaponAttackType : uint8; + +namespace Trinity +{ + template + class unique_trackable_ptr; + + template + class unique_weak_ptr; +} + +class TC_GAME_API ElunaProcInfo +{ +private: + Unit* _actor; + Unit* _actionTarget; + uint32 _typeMask; + uint32 _spellTypeMask; + uint32 _spellPhaseMask; + uint32 _hitMask; + Spell* _spell; + + SpellInfo const* _spellInfo; + SpellSchoolMask _schoolMask; + + uint32 _damage; + DamageEffectType _damageType; + WeaponAttackType _attackType; + uint32 _damageAbsorb; + uint32 _resist; + uint32 _block; + + uint32 _heal; + uint32 _effectiveHeal; + uint32 _healAbsorb; + Map* _map; + + struct NoopAuraDeleter { void operator()(ElunaProcInfo*) const { } }; + Trinity::unique_trackable_ptr m_scriptRef; + +public: + ElunaProcInfo(Unit* actor, Unit* actionTarget, uint32 typeMask, + uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, + Spell* spell, SpellInfo const* spellInfo, SpellSchoolMask schoolMask, Map* map); + + explicit ElunaProcInfo(ProcEventInfo& procInfo, Map* map); + + Unit* GetActor() const { return _actor; } + Unit* GetActionTarget() const { return _actionTarget; } + uint32 GetTypeMask() const { return _typeMask; } + uint32 GetSpellTypeMask() const { return _spellTypeMask; } + uint32 GetSpellPhaseMask() const { return _spellPhaseMask; } + uint32 GetHitMask() const { return _hitMask; } + Spell const* GetProcSpell() const { return _spell; } + + SpellInfo const* GetSpellInfo() const; + SpellSchoolMask GetSchoolMask() const { return _schoolMask; } + + uint32 GetDamage() const { return _damage; } + DamageEffectType GetDamageType() const { return _damageType; } + WeaponAttackType GetAttackType() const { return _attackType; } + uint32 GetDamageAbsorb() const { return _damageAbsorb; } + uint32 GetResist() const { return _resist; } + uint32 GetBlock() const { return _block; } + + uint32 GetHeal() const { return _heal; } + uint32 GetEffectiveHeal() const { return _effectiveHeal; } + uint32 GetHealAbsorb() const { return _healAbsorb; } + + bool HasDamage() const { return _damage > 0; } + bool HasHeal() const { return _heal > 0; } + + void SetDamage(int32 amount) { _damage = amount; } + void SetAbsorbDamage(uint32 amount) { _damageAbsorb = amount; } + void SetResistDamage(uint32 amount) { _resist = amount; } + void SetBlockDamage(uint32 amount) { _block = amount; } + + void SetAbsorbHeal(uint32 amount) { _healAbsorb = amount; } + void SetEffectiveHeal(uint32 amount) { _effectiveHeal = amount; } + void SetHeal(int32 amount) { _heal = amount; } + + void SetDamage(uint32 damage, DamageEffectType damageType, WeaponAttackType attackType); + void SetHeal(uint32 heal); + + const Map* GetMap() const { return _map; } + Trinity::unique_weak_ptr GetWeakPtr() const { return m_scriptRef; } + void ApplyToProcEventInfo(ProcEventInfo& procInfo) const; +}; + +#endif diff --git a/ElunaTemplate.cpp b/ElunaTemplate.cpp index 8baa2b1425..f896d16787 100644 --- a/ElunaTemplate.cpp +++ b/ElunaTemplate.cpp @@ -27,6 +27,10 @@ ElunaConstrainedObjectRef GetWeakPtrFor(AuraEffect const* obj) return { obj->GetWeakPtr(), map }; } +ElunaConstrainedObjectRef GetWeakPtrFor(ElunaProcInfo const* obj) +{ + return { obj->GetWeakPtr(), obj->GetMap()}; +} ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; } ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; } ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; } diff --git a/ElunaTemplate.h b/ElunaTemplate.h index 7fcf780104..3c2fbc6437 100644 --- a/ElunaTemplate.h +++ b/ElunaTemplate.h @@ -17,6 +17,7 @@ extern "C" #include "ElunaUtility.h" #include "ElunaCompat.h" #include "ElunaConfig.h" +#include "ElunaProcInfo.h" #if !defined ELUNA_CMANGOS #include "SharedDefines.h" #else @@ -63,6 +64,7 @@ struct ElunaConstrainedObjectRef ElunaConstrainedObjectRef GetWeakPtrFor(Aura const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(AuraEffect const* obj); +ElunaConstrainedObjectRef GetWeakPtrFor(ElunaProcInfo const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj); ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj); diff --git a/LuaEngine.h b/LuaEngine.h index 3f08eb0c05..8d4bca1976 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -35,6 +35,7 @@ #include #include +#include "ElunaProcInfo.h" extern "C" { @@ -629,6 +630,8 @@ class ELUNA_GAME_API Eluna void OnPerodicUpdate(Aura* aura, AuraEffect const* auraEff); void OnAuraCalcAmount(Aura* aura, AuraEffect const* auraEff, int32& amount, bool& canBeRecalculated); void OnCalcPerodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodic, int32& amplitude); + bool OnAuraCanProc(Aura* aura, ProcEventInfo& procInfo); + bool OnAuraProc(Aura* aura, ProcEventInfo& procInfo); }; template<> Unit* Eluna::CHECKOBJ(int narg, bool error); template<> Object* Eluna::CHECKOBJ(int narg, bool error); diff --git a/hooks/Hooks.h b/hooks/Hooks.h index 1663346ca5..bbb42361f6 100644 --- a/hooks/Hooks.h +++ b/hooks/Hooks.h @@ -54,16 +54,16 @@ namespace Hooks }; // PACKET EVENTS -#define PACKET_EVENTS_LIST(X) \ + #define PACKET_EVENTS_LIST(X) \ X(PACKET_EVENT_ON_PACKET_RECEIVE, 5, "on_receive") \ X(PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN, 6, "on_receive_unk") \ X(PACKET_EVENT_ON_PACKET_SEND, 7, "on_send") enum PacketEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, PACKET_EVENTS_LIST(X) -#undef X + #undef X PACKET_EVENT_COUNT }; @@ -74,7 +74,7 @@ namespace Hooks }; // SERVER EVENTS -#define SERVER_EVENTS_LIST(X) \ + #define SERVER_EVENTS_LIST(X) \ /* Server */ \ X(SERVER_EVENT_ON_NETWORK_START, 1, "on_network_start") \ X(SERVER_EVENT_ON_NETWORK_STOP, 2, "on_network_stop") \ @@ -123,9 +123,9 @@ namespace Hooks enum ServerEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, SERVER_EVENTS_LIST(X) -#undef X + #undef X SERVER_EVENT_COUNT }; @@ -136,7 +136,7 @@ namespace Hooks }; // PLAYER EVENTS -#define PLAYER_EVENTS_LIST(X) \ + #define PLAYER_EVENTS_LIST(X) \ X(PLAYER_EVENT_ON_CHARACTER_CREATE, 1, "on_character_create") \ X(PLAYER_EVENT_ON_CHARACTER_DELETE, 2, "on_character_delete") \ X(PLAYER_EVENT_ON_LOGIN, 3, "on_login") \ @@ -191,9 +191,9 @@ namespace Hooks enum PlayerEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, PLAYER_EVENTS_LIST(X) -#undef X + #undef X PLAYER_EVENT_COUNT }; @@ -204,7 +204,7 @@ namespace Hooks }; // GUILD EVENTS -#define GUILD_EVENTS_LIST(X) \ + #define GUILD_EVENTS_LIST(X) \ X(GUILD_EVENT_ON_ADD_MEMBER, 1, "on_add_member") \ X(GUILD_EVENT_ON_REMOVE_MEMBER, 2, "on_remove_member") \ X(GUILD_EVENT_ON_MOTD_CHANGE, 3, "on_motd_change") \ @@ -219,9 +219,9 @@ namespace Hooks enum GuildEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, GUILD_EVENTS_LIST(X) -#undef X + #undef X GUILD_EVENT_COUNT }; @@ -232,7 +232,7 @@ namespace Hooks }; // GROUP EVENTS -#define GROUP_EVENTS_LIST(X) \ + #define GROUP_EVENTS_LIST(X) \ X(GROUP_EVENT_ON_MEMBER_ADD, 1, "on_add_member") \ X(GROUP_EVENT_ON_MEMBER_INVITE, 2, "on_invite_member") \ X(GROUP_EVENT_ON_MEMBER_REMOVE, 3, "on_remove_member") \ @@ -243,9 +243,9 @@ namespace Hooks enum GroupEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, GROUP_EVENTS_LIST(X) -#undef X + #undef X GROUP_EVENT_COUNT }; @@ -256,7 +256,7 @@ namespace Hooks }; // VEHICLE EVENTS -#define VEHICLE_EVENTS_LIST(X) \ + #define VEHICLE_EVENTS_LIST(X) \ X(VEHICLE_EVENT_ON_INSTALL, 1, "on_install") \ X(VEHICLE_EVENT_ON_UNINSTALL, 2, "on_uninstall") \ /* 3 unused */ \ @@ -266,9 +266,9 @@ namespace Hooks enum VehicleEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, VEHICLE_EVENTS_LIST(X) -#undef X + #undef X VEHICLE_EVENT_COUNT }; @@ -279,7 +279,7 @@ namespace Hooks }; // CREATURE EVENTS -#define CREATURE_EVENTS_LIST(X) \ + #define CREATURE_EVENTS_LIST(X) \ X(CREATURE_EVENT_ON_ENTER_COMBAT, 1, "on_enter_combat") \ X(CREATURE_EVENT_ON_LEAVE_COMBAT, 2, "on_leave_combat") \ X(CREATURE_EVENT_ON_TARGET_DIED, 3, "on_target_died") \ @@ -316,9 +316,9 @@ namespace Hooks enum CreatureEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, CREATURE_EVENTS_LIST(X) -#undef X + #undef X CREATURE_EVENT_COUNT }; @@ -329,7 +329,7 @@ namespace Hooks }; // GAMEOBJECT EVENTS -#define GAMEOBJECT_EVENTS_LIST(X) \ + #define GAMEOBJECT_EVENTS_LIST(X) \ X(GAMEOBJECT_EVENT_ON_AIUPDATE, 1, "on_ai_update") \ X(GAMEOBJECT_EVENT_ON_SPAWN, 2, "on_spawn") \ X(GAMEOBJECT_EVENT_ON_DUMMY_EFFECT, 3, "on_dummy_effect") \ @@ -347,9 +347,9 @@ namespace Hooks enum GameObjectEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, GAMEOBJECT_EVENTS_LIST(X) -#undef X + #undef X GAMEOBJECT_EVENT_COUNT }; @@ -360,20 +360,22 @@ namespace Hooks }; // SPELL EVENTS -#define SPELL_EVENTS_LIST(X) \ - X(SPELL_EVENT_ON_CAST, 1, "on_cast") - X(SPELL_EVENT_ON_AURA_APPLICATION, 2, "on_aura_application") - X(SPELL_EVENT_ON_DISPEL, 3, "on_dispel") - X(SPELL_EVENT_ON_PERODIC_TICK, 4, "on_periodic_tick") - X(SPELL_EVENT_ON_PERODIC_UPDATE, 5, "on_periodic_update") - X(SPELL_EVENT_ON_AURA_CALC_AMOUNT, 6, "on_aura_calc_amount") - X(SPELL_EVENT_ON_CALC_PERODIC, 7, "on_calc_periodic") + #define SPELL_EVENTS_LIST(X) \ + X(SPELL_EVENT_ON_CAST, 1, "on_cast") \ + X(SPELL_EVENT_ON_AURA_APPLICATION, 2, "on_aura_application") \ + X(SPELL_EVENT_ON_DISPEL, 3, "on_dispel") \ + X(SPELL_EVENT_ON_PERODIC_TICK, 4, "on_periodic_tick") \ + X(SPELL_EVENT_ON_PERODIC_UPDATE, 5, "on_periodic_update") \ + X(SPELL_EVENT_ON_AURA_CALC_AMOUNT, 6, "on_aura_calc_amount") \ + X(SPELL_EVENT_ON_CALC_PERODIC, 7, "on_calc_periodic") \ + X(SPELL_EVENT_ON_CHECK_PROC, 7, "on_check_proc") \ + X(SPELL_EVENT_ON_PROC, 8, "on_proc") \ enum SpellEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, SPELL_EVENTS_LIST(X) -#undef X + #undef X SPELL_EVENT_COUNT }; @@ -384,7 +386,7 @@ namespace Hooks }; // ITEM EVENTS -#define ITEM_EVENTS_LIST(X) \ + #define ITEM_EVENTS_LIST(X) \ X(ITEM_EVENT_ON_DUMMY_EFFECT, 1, "on_dummy_effect") \ X(ITEM_EVENT_ON_USE, 2, "on_use") \ X(ITEM_EVENT_ON_QUEST_ACCEPT, 3, "on_quest_accept") \ @@ -397,9 +399,9 @@ namespace Hooks enum ItemEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, ITEM_EVENTS_LIST(X) -#undef X + #undef X ITEM_EVENT_COUNT }; @@ -410,15 +412,15 @@ namespace Hooks }; // GOSSIP EVENTS -#define GOSSIP_EVENTS_LIST(X) \ + #define GOSSIP_EVENTS_LIST(X) \ X(GOSSIP_EVENT_ON_HELLO, 1, "on_hello") \ X(GOSSIP_EVENT_ON_SELECT, 2, "on_select") enum GossipEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, GOSSIP_EVENTS_LIST(X) -#undef X + #undef X GOSSIP_EVENT_COUNT }; @@ -429,7 +431,7 @@ namespace Hooks }; // BG EVENTS -#define BG_EVENTS_LIST(X) \ + #define BG_EVENTS_LIST(X) \ X(BG_EVENT_ON_START, 1, "on_start") \ X(BG_EVENT_ON_END, 2, "on_end") \ X(BG_EVENT_ON_CREATE, 3, "on_create") \ @@ -437,9 +439,9 @@ namespace Hooks enum BGEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, BG_EVENTS_LIST(X) -#undef X + #undef X BG_EVENT_COUNT }; @@ -450,7 +452,7 @@ namespace Hooks }; // INSTANCE EVENTS -#define INSTANCE_EVENTS_LIST(X) \ + #define INSTANCE_EVENTS_LIST(X) \ X(INSTANCE_EVENT_ON_INITIALIZE, 1, "on_initialize") \ X(INSTANCE_EVENT_ON_LOAD, 2, "on_load") \ X(INSTANCE_EVENT_ON_UPDATE, 3, "on_update") \ @@ -461,9 +463,9 @@ namespace Hooks enum InstanceEvents { -#define X(ID, VALUE, NAME) ID = VALUE, + #define X(ID, VALUE, NAME) ID = VALUE, INSTANCE_EVENTS_LIST(X) -#undef X + #undef X INSTANCE_EVENT_COUNT }; diff --git a/hooks/SpellHooks.cpp b/hooks/SpellHooks.cpp index e3e76ec986..6506ae21b9 100644 --- a/hooks/SpellHooks.cpp +++ b/hooks/SpellHooks.cpp @@ -141,3 +141,25 @@ void Eluna::OnCalcPerodic(Aura* aura, AuraEffect const* auraEff, bool& isPeriodi CleanUpStack(2); } + +bool Eluna::OnAuraCanProc(Aura* aura, ProcEventInfo& procInfo) +{ + START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_CHECK_PROC, aura, true); + ElunaProcInfo luaProcInfo(procInfo, aura->GetCaster()->GetMap()); + HookPush(aura); + HookPush(&luaProcInfo); + bool retVal = CallAllFunctionsBool(binding, key, true); + luaProcInfo.ApplyToProcEventInfo(procInfo); + return retVal; +} + +bool Eluna::OnAuraProc(Aura* aura, ProcEventInfo& procInfo) +{ + START_HOOK_WITH_RETVAL(SPELL_EVENT_ON_CHECK_PROC, aura, false); + ElunaProcInfo luaProcInfo(procInfo, aura->GetCaster()->GetMap()); + HookPush(aura); + HookPush(&luaProcInfo); + bool defaultPrevented = CallAllFunctionsBool(binding, key, false); + luaProcInfo.ApplyToProcEventInfo(procInfo); + return defaultPrevented; +} diff --git a/methods/Methods.cpp b/methods/Methods.cpp index 0f53ef36c9..40ca7801fa 100644 --- a/methods/Methods.cpp +++ b/methods/Methods.cpp @@ -24,6 +24,7 @@ #include "ElunaQueryMethods.h" #include "AuraMethods.h" #include "AuraEffectMethods.h" +#include "ElunaProcInfoMethods.h" #include "ItemMethods.h" #include "WorldPacketMethods.h" #include "SpellMethods.h" @@ -94,6 +95,9 @@ void RegisterMethods(Eluna* E) ElunaTemplate::Register(E, "AuraEffect"); ElunaTemplate::SetMethods(E, LuaAuraEffects::AuraEffectMethods); + ElunaTemplate::Register(E, "ElunaProcInfo"); + ElunaTemplate::SetMethods(E, LuaElunaProcInfo::ElunaProcInfoMethods); + ElunaTemplate::Register(E, "Spell"); ElunaTemplate::SetMethods(E, LuaSpell::SpellMethods); diff --git a/methods/TrinityCore/AuraEffectMethods.h b/methods/TrinityCore/AuraEffectMethods.h index 1fd750258a..6e5ba509d2 100644 --- a/methods/TrinityCore/AuraEffectMethods.h +++ b/methods/TrinityCore/AuraEffectMethods.h @@ -146,12 +146,6 @@ namespace LuaAuraEffects return 1; } - int GetEffIndex(Eluna* E, AuraEffect* aurEff) - { - E->Push(uint8(aurEff->GetEffIndex())); - return 1; - } - int GetAuraType(Eluna* E, AuraEffect* aurEff) { E->Push(uint16(aurEff->GetAuraType())); diff --git a/methods/TrinityCore/ElunaProcInfoMethods.h b/methods/TrinityCore/ElunaProcInfoMethods.h new file mode 100644 index 0000000000..8cd3fd3056 --- /dev/null +++ b/methods/TrinityCore/ElunaProcInfoMethods.h @@ -0,0 +1,213 @@ +#ifndef ELUNAPROCINFOMETHODS_H +#define ELUNAPROCINFOMETHODS_H + +namespace LuaElunaProcInfo +{ + int GetActor(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetActor()); + return 1; + } + + int GetActionTarget(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetActionTarget()); + return 1; + } + + int GetTypeMask(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetTypeMask()); + return 1; + } + + int GetSpellTypeMask(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetSpellTypeMask()); + return 1; + } + + int GetSpellPhaseMask(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetSpellPhaseMask()); + return 1; + } + + int GetHitMask(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetHitMask()); + return 1; + } + + int GetProcSpell(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetProcSpell()); + return 1; + } + + /*int GetSpellInfo(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetSpellInfo()); + return 1; + }*/ + + int GetSchoolMask(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetSchoolMask()); + return 1; + } + + int GetDamage(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetDamage()); + return 1; + } + + int GetDamageType(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetDamageType()); + return 1; + } + + int GetAttackType(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetAttackType()); + return 1; + } + + int GetDamageAbsorb(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetDamageAbsorb()); + return 1; + } + + int GetResist(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetResist()); + return 1; + } + + int GetBlock(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetBlock()); + return 1; + } + + int GetHeal(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetHeal()); + return 1; + } + + int GetEffectiveHeal(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetEffectiveHeal()); + return 1; + } + + int GetHealAbsorb(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetHealAbsorb()); + return 1; + } + + int HasDamage(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->HasDamage()); + return 1; + } + + int HasHeal(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->HasHeal()); + return 1; + } + + int SetDamage(Eluna* E, ElunaProcInfo* procInfo) + { + int32 damage = E->CHECKVAL(2); + procInfo->SetDamage(damage); + return 0; + } + + int SetAbsorbDamage(Eluna* E, ElunaProcInfo* procInfo) + { + uint32 absorb = E->CHECKVAL(2); + procInfo->SetAbsorbDamage(absorb); + return 0; + } + + int SetResistDamage(Eluna* E, ElunaProcInfo* procInfo) + { + uint32 resist = E->CHECKVAL(2); + procInfo->SetResistDamage(resist); + return 0; + } + + int SetBlockDamage(Eluna* E, ElunaProcInfo* procInfo) + { + uint32 block = E->CHECKVAL(2); + procInfo->SetBlockDamage(block); + return 0; + } + + int SetHeal(Eluna* E, ElunaProcInfo* procInfo) + { + int32 heal = E->CHECKVAL(2); + procInfo->SetHeal(heal); + return 0; + } + + int SetAbsorbHeal(Eluna* E, ElunaProcInfo* procInfo) + { + uint32 absorb = E->CHECKVAL(2); + procInfo->SetAbsorbHeal(absorb); + return 0; + } + + int SetEffectiveHeal(Eluna* E, ElunaProcInfo* procInfo) + { + uint32 effectiveHeal = E->CHECKVAL(2); + procInfo->SetEffectiveHeal(effectiveHeal); + return 0; + } + + int GetMap(Eluna* E, ElunaProcInfo* procInfo) + { + E->Push(procInfo->GetMap()); + return 1; + } + + ElunaRegister ElunaProcInfoMethods[] = + { + { "GetActor", &LuaElunaProcInfo::GetActor }, + { "GetActionTarget", &LuaElunaProcInfo::GetActionTarget }, + { "GetTypeMask", &LuaElunaProcInfo::GetTypeMask }, + { "GetSpellTypeMask", &LuaElunaProcInfo::GetSpellTypeMask }, + { "GetSpellPhaseMask", &LuaElunaProcInfo::GetSpellPhaseMask }, + { "GetHitMask", &LuaElunaProcInfo::GetHitMask }, + { "GetProcSpell", &LuaElunaProcInfo::GetProcSpell }, + //{ "GetSpellInfo", &LuaElunaProcInfo::GetSpellInfo }, + { "GetSchoolMask", &LuaElunaProcInfo::GetSchoolMask }, + { "GetDamage", &LuaElunaProcInfo::GetDamage }, + { "GetDamageType", &LuaElunaProcInfo::GetDamageType }, + { "GetAttackType", &LuaElunaProcInfo::GetAttackType }, + { "GetDamageAbsorb", &LuaElunaProcInfo::GetDamageAbsorb }, + { "GetResist", &LuaElunaProcInfo::GetResist }, + { "GetBlock", &LuaElunaProcInfo::GetBlock }, + { "SetDamage", &LuaElunaProcInfo::SetDamage }, + { "SetAbsorbDamage", &LuaElunaProcInfo::SetAbsorbDamage }, + { "SetResistDamage", &LuaElunaProcInfo::SetResistDamage }, + { "SetBlockDamage", &LuaElunaProcInfo::SetBlockDamage }, + { "GetHeal", &LuaElunaProcInfo::GetHeal }, + { "GetEffectiveHeal", &LuaElunaProcInfo::GetEffectiveHeal }, + { "GetHealAbsorb", &LuaElunaProcInfo::GetHealAbsorb }, + { "SetHeal", &LuaElunaProcInfo::SetHeal }, + { "SetAbsorbHeal", &LuaElunaProcInfo::SetAbsorbHeal }, + { "SetEffectiveHeal", &LuaElunaProcInfo::SetEffectiveHeal }, + { "HasDamage", &LuaElunaProcInfo::HasDamage }, + { "HasHeal", &LuaElunaProcInfo::HasHeal }, + }; +} + +#endif From 0482b3d2d67094b8151a6eb19cd4625ab03afddd Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 12 Feb 2026 22:55:50 -0500 Subject: [PATCH 6/6] Remove copy paste error of TC_GAME_API in eluna proc info. --- ElunaProcInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElunaProcInfo.h b/ElunaProcInfo.h index e5586c3113..2504db56fb 100644 --- a/ElunaProcInfo.h +++ b/ElunaProcInfo.h @@ -21,7 +21,7 @@ namespace Trinity class unique_weak_ptr; } -class TC_GAME_API ElunaProcInfo +class ElunaProcInfo { private: Unit* _actor;