From 155d94b264b610976721c05de5fde5eef54118a1 Mon Sep 17 00:00:00 2001 From: avitasia Date: Tue, 20 Jan 2026 17:56:36 -0800 Subject: [PATCH] add new event toggles --- Localization.lua | 24 ++++++++ helper.lua | 139 +++++++++++++++++++++++++++++++++++++++++++++++ settings.lua | 76 ++++++++++++++++++++++++++ 3 files changed, 239 insertions(+) diff --git a/Localization.lua b/Localization.lua index bd1072c..7cf73e2 100644 --- a/Localization.lua +++ b/Localization.lua @@ -127,6 +127,18 @@ L:RegisterTranslations("enUS", function() ["Enable Auto Attack Events"] = true, ["Whether to enable AUTO_ATTACK_SELF and AUTO_ATTACK_OTHER events."] = true, + + ["Enable Spell Start Events"] = true, + ["Whether to enable SPELL_START_SELF and SPELL_START_OTHER events."] = true, + + ["Enable Spell Go Events"] = true, + ["Whether to enable SPELL_GO_SELF and SPELL_GO_OTHER events."] = true, + + ["Enable Spell Heal Events"] = true, + ["Whether to enable SPELL_HEAL_BY_SELF, SPELL_HEAL_BY_OTHER, and SPELL_HEAL_ON_SELF events."] = true, + + ["Enable Spell Energize Events"] = true, + ["Whether to enable SPELL_ENERGIZE_BY_SELF, SPELL_ENERGIZE_BY_OTHER, and SPELL_ENERGIZE_ON_SELF events."] = true, } end) @@ -257,5 +269,17 @@ L:RegisterTranslations("zhCN", function() ["Enable Auto Attack Events"] = "启用自动攻击事件", ["Whether to enable AUTO_ATTACK_SELF and AUTO_ATTACK_OTHER events."] = "是否启用 AUTO_ATTACK_SELF 和 AUTO_ATTACK_OTHER 事件。", + + ["Enable Spell Start Events"] = "启用法术开始事件", + ["Whether to enable SPELL_START_SELF and SPELL_START_OTHER events."] = "是否启用 SPELL_START_SELF 和 SPELL_START_OTHER 事件。", + + ["Enable Spell Go Events"] = "启用法术释放事件", + ["Whether to enable SPELL_GO_SELF and SPELL_GO_OTHER events."] = "是否启用 SPELL_GO_SELF 和 SPELL_GO_OTHER 事件。", + + ["Enable Spell Heal Events"] = "启用法术治疗事件", + ["Whether to enable SPELL_HEAL_BY_SELF, SPELL_HEAL_BY_OTHER, and SPELL_HEAL_ON_SELF events."] = "是否启用 SPELL_HEAL_BY_SELF、SPELL_HEAL_BY_OTHER 和 SPELL_HEAL_ON_SELF 事件。", + + ["Enable Spell Energize Events"] = "启用法术回能事件", + ["Whether to enable SPELL_ENERGIZE_BY_SELF, SPELL_ENERGIZE_BY_OTHER, and SPELL_ENERGIZE_ON_SELF events."] = "是否启用 SPELL_ENERGIZE_BY_SELF、SPELL_ENERGIZE_BY_OTHER 和 SPELL_ENERGIZE_ON_SELF 事件。", } end) diff --git a/helper.lua b/helper.lua index 377a5e0..d1f6834 100644 --- a/helper.lua +++ b/helper.lua @@ -361,3 +361,142 @@ end --Nampower:RegisterEvent("AUTO_ATTACK_SELF", onAutoAttack) --Nampower:RegisterEvent("AUTO_ATTACK_OTHER", onAutoAttack) + +if not Nampower:HasMinimumVersion(2, 25, 0) then + return +end + +local function onSpellStart(itemId, spellId, casterGuid, targetGuid, castFlags, castTime) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "SPELL_START: %s (id:%d) | Caster: %s -> Target: %s | ItemId: %d | Flags: %d | CastTime: %d", + tostring(spellName), spellId, casterGuid, targetGuid, itemId, castFlags, castTime + )) +end + +local function onSpellGo(itemId, spellId, casterGuid, targetGuid, castFlags, numTargetsHit, numTargetsMissed) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "SPELL_GO: %s (id:%d) | Caster: %s -> Target: %s | ItemId: %d | Flags: %d | Hit: %d | Missed: %d", + tostring(spellName), spellId, casterGuid, targetGuid, itemId, castFlags, numTargetsHit, numTargetsMissed + )) +end + +local function onSpellFailedSelf(spellId, spellResult, failedByServer) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + local source = failedByServer == 1 and "Server" or "Client" + print(string.format( + "SPELL_FAILED_SELF: %s (id:%d) | Result: %d | Source: %s", + tostring(spellName), spellId, spellResult, source + )) +end + +local function onSpellFailedOther(casterGuid, spellId) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "SPELL_FAILED_OTHER: %s (id:%d) | Caster: %s", + tostring(spellName), spellId, casterGuid + )) +end + +local function onSpellDelayed(casterGuid, delayMs) + print(string.format( + "SPELL_DELAYED: Caster: %s | Delay: %dms", + casterGuid, delayMs + )) +end + +local function onSpellChannelStart(spellId, targetGuid, durationMs) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "SPELL_CHANNEL_START: %s (id:%d) | Target: %s | Duration: %dms", + tostring(spellName), spellId, targetGuid, durationMs + )) +end + +local function onSpellChannelUpdate(spellId, targetGuid, remainingMs) + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "SPELL_CHANNEL_UPDATE: %s (id:%d) | Target: %s | Remaining: %dms", + tostring(spellName), spellId, targetGuid, remainingMs + )) +end + +--Nampower:RegisterEvent("SPELL_START_SELF", onSpellStart) +--Nampower:RegisterEvent("SPELL_START_OTHER", onSpellStart) +--Nampower:RegisterEvent("SPELL_GO_SELF", onSpellGo) +--Nampower:RegisterEvent("SPELL_GO_OTHER", onSpellGo) +--Nampower:RegisterEvent("SPELL_FAILED_SELF", onSpellFailedSelf) +--Nampower:RegisterEvent("SPELL_FAILED_OTHER", onSpellFailedOther) +--Nampower:RegisterEvent("SPELL_DELAYED_SELF", onSpellDelayed) +--Nampower:RegisterEvent("SPELL_DELAYED_OTHER", onSpellDelayed) +--Nampower:RegisterEvent("SPELL_CHANNEL_START", onSpellChannelStart) +--Nampower:RegisterEvent("SPELL_CHANNEL_UPDATE", onSpellChannelUpdate) + +if not Nampower:HasMinimumVersion(2, 26, 0) then + return +end + +-- Spell Heal Events (gated behind NP_EnableSpellHealEvents CVar, default 0) +-- SPELL_HEAL_BY_SELF - Fires when the active player is the caster (you healed someone) +-- SPELL_HEAL_BY_OTHER - Fires when someone other than the active player is the caster (someone else healed someone) +-- SPELL_HEAL_ON_SELF - Fires when the active player is the target (you received a heal) +-- Note: SPELL_HEAL_BY_SELF and SPELL_HEAL_ON_SELF can both fire for the same heal if you heal yourself + +local function createSpellHealHandler(eventName) + return function(targetGuid, casterGuid, spellId, amount, critical, periodic) + local critText = critical == 1 and " (CRIT)" or "" + local periodicText = periodic == 1 and " (PERIODIC)" or "" + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "%s: %s healed %s for %d with %s%s%s", + eventName, UnitName(casterGuid), UnitName(targetGuid), amount, tostring(spellName), critText, periodicText + )) + end +end + +-- Spell Energize Events (gated behind NP_EnableSpellEnergizeEvents CVar, default 0) +-- SPELL_ENERGIZE_BY_SELF - Fires when the active player is the caster (you restored power to someone) +-- SPELL_ENERGIZE_BY_OTHER - Fires when someone other than the active player is the caster (someone else restored power) +-- SPELL_ENERGIZE_ON_SELF - Fires when the active player is the target (you received power) +-- Note: SPELL_ENERGIZE_BY_SELF and SPELL_ENERGIZE_ON_SELF can both fire for the same energize if you restore power to yourself + +-- Power Type Constants +local POWER_MANA = 0 +local POWER_RAGE = 1 +local POWER_FOCUS = 2 +local POWER_ENERGY = 3 +local POWER_HAPPINESS = 4 +local POWER_HEALTH = -2 -- 0xFFFFFFFE as unsigned + +local POWER_NAMES = { + [0] = "Mana", + [1] = "Rage", + [2] = "Focus", + [3] = "Energy", + [4] = "Happiness", + [-2] = "Health", +} + +function GetPowerTypeName(powerType) + return POWER_NAMES[powerType] or "Unknown" +end + +local function createSpellEnergizeHandler(eventName) + return function(targetGuid, casterGuid, spellId, powerType, amount, periodic) + local powerName = GetPowerTypeName(powerType) + local periodicText = periodic == 1 and " (PERIODIC)" or "" + local spellName = GetSpellRecField and GetSpellRecField(spellId, "name") or spellId + print(string.format( + "%s: %s restored %d %s to %s with %s%s", + eventName, UnitName(casterGuid), amount, powerName, UnitName(targetGuid), tostring(spellName), periodicText + )) + end +end + +--Nampower:RegisterEvent("SPELL_HEAL_BY_SELF", createSpellHealHandler("SPELL_HEAL_BY_SELF")) +--Nampower:RegisterEvent("SPELL_HEAL_BY_OTHER", createSpellHealHandler("SPELL_HEAL_BY_OTHER")) +--Nampower:RegisterEvent("SPELL_HEAL_ON_SELF", createSpellHealHandler("SPELL_HEAL_ON_SELF")) +--Nampower:RegisterEvent("SPELL_ENERGIZE_BY_SELF", createSpellEnergizeHandler("SPELL_ENERGIZE_BY_SELF")) +--Nampower:RegisterEvent("SPELL_ENERGIZE_BY_OTHER", createSpellEnergizeHandler("SPELL_ENERGIZE_BY_OTHER")) +--Nampower:RegisterEvent("SPELL_ENERGIZE_ON_SELF", createSpellEnergizeHandler("SPELL_ENERGIZE_ON_SELF")) diff --git a/settings.lua b/settings.lua index e4bcc98..24bb18e 100644 --- a/settings.lua +++ b/settings.lua @@ -852,6 +852,82 @@ if Nampower:HasMinimumVersion(2, 24, 0) then } end +if Nampower:HasMinimumVersion(2, 25, 0) then + Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellStartEvents = { + type = "toggle", + name = L["Enable Spell Start Events"], + desc = L["Whether to enable SPELL_START_SELF and SPELL_START_OTHER events."], + order = 165, + get = function() + return GetCVar("NP_EnableSpellStartEvents") == "1" + end, + set = function(v) + Nampower.db.profile.NP_EnableSpellStartEvents = v + if v == true then + SetCVar("NP_EnableSpellStartEvents", "1") + else + SetCVar("NP_EnableSpellStartEvents", "0") + end + end, + } + + Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellGoEvents = { + type = "toggle", + name = L["Enable Spell Go Events"], + desc = L["Whether to enable SPELL_GO_SELF and SPELL_GO_OTHER events."], + order = 170, + get = function() + return GetCVar("NP_EnableSpellGoEvents") == "1" + end, + set = function(v) + Nampower.db.profile.NP_EnableSpellGoEvents = v + if v == true then + SetCVar("NP_EnableSpellGoEvents", "1") + else + SetCVar("NP_EnableSpellGoEvents", "0") + end + end, + } +end + +if Nampower:HasMinimumVersion(2, 26, 0) then + Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellHealEvents = { + type = "toggle", + name = L["Enable Spell Heal Events"], + desc = L["Whether to enable SPELL_HEAL_BY_SELF, SPELL_HEAL_BY_OTHER, and SPELL_HEAL_ON_SELF events."], + order = 175, + get = function() + return GetCVar("NP_EnableSpellHealEvents") == "1" + end, + set = function(v) + Nampower.db.profile.NP_EnableSpellHealEvents = v + if v == true then + SetCVar("NP_EnableSpellHealEvents", "1") + else + SetCVar("NP_EnableSpellHealEvents", "0") + end + end, + } + + Nampower.cmdtable.args.advanced_options.args.NP_EnableSpellEnergizeEvents = { + type = "toggle", + name = L["Enable Spell Energize Events"], + desc = L["Whether to enable SPELL_ENERGIZE_BY_SELF, SPELL_ENERGIZE_BY_OTHER, and SPELL_ENERGIZE_ON_SELF events."], + order = 180, + get = function() + return GetCVar("NP_EnableSpellEnergizeEvents") == "1" + end, + set = function(v) + Nampower.db.profile.NP_EnableSpellEnergizeEvents = v + if v == true then + SetCVar("NP_EnableSpellEnergizeEvents", "1") + else + SetCVar("NP_EnableSpellEnergizeEvents", "0") + end + end, + } +end + local deuce = Nampower:NewModule("Nampower Options Menu") deuce.hasFuBar = IsAddOnLoaded("FuBar") and FuBar deuce.consoleCmd = not deuce.hasFuBar