Repository navigation
Expand file tree
/
Copy pathBrezKey.lua
More file actions
198 lines (172 loc) · 7.27 KB
/
Copy pathBrezKey.lua
File metadata and controls
198 lines (172 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- Herramienta: resurrección en combate (brez) sobre una tecla ya usada.
--
-- Elegida una tecla, esta pasa a lanzar el brez de tu clase mientras el mouse esté sobre un
-- aliado muerto (por ejemplo su unitframe). En cualquier otro momento la tecla funciona como siempre.
--
-- En combate los addons no pueden cambiar teclas, así que se usa un manejador seguro de Blizzard
-- (SecureHandlerStateTemplate): un "state driver" evalúa la condición [@mouseover,help,dead] y
-- activa/desactiva el enlace de la tecla desde el propio entorno seguro, también en combate.
-- Los ajustes (tecla, hechizo) solo se pueden aplicar fuera de combate.
local _, ns = ...
local PREFIX = ns.PREFIX
local L = ns.L
local defaults = {
enabled = true,
key = "", -- por ejemplo "H" o "SHIFT-H"
onlyCombat = true, -- no gastar el brez fuera de combate
customSpell = "", -- ID de hechizo (número) a usar en lugar del detectado
}
local Brez = { noPosition = true }
ns.RegisterModule("brez", defaults, Brez)
local function cfg() return ns.db.brez end
-- Resurrecciones en combate por clase (spellIDs).
local BREZ = {
DRUID = { 20484 }, -- Renacer
DEATHKNIGHT = { 61999 }, -- Resucitar aliado
WARLOCK = { 20707 }, -- Piedra de alma
PALADIN = { 391054 }, -- Intercesión
}
---------------------------------------------------------------------------
-- Hechizo de la clase
---------------------------------------------------------------------------
local function SpellName(id)
if C_Spell and C_Spell.GetSpellName then return C_Spell.GetSpellName(id) end
return (GetSpellInfo(id))
end
local function IsKnown(id)
if IsPlayerSpell and IsPlayerSpell(id) then return true end
return IsSpellKnown and IsSpellKnown(id) or false
end
-- Devuelve nombre, conocido (bool), origen ("custom" | "clase" | nil), id
local function ResolveSpell()
local c = cfg()
local customID = tonumber(c.customSpell)
if customID then
local name = SpellName(customID)
return name, name ~= nil, "custom", customID
end
local _, class = UnitClass("player")
local list = BREZ[class]
if not list then return nil, false, nil end
for _, id in ipairs(list) do
local name = SpellName(id)
if name and IsKnown(id) then return name, true, "clase", id end
end
return SpellName(list[1]), false, "clase", list[1]
end
---------------------------------------------------------------------------
-- Marcos seguros
---------------------------------------------------------------------------
-- Botón que lanza el hechizo sobre el mouseover cuando se le hace "click" desde la tecla.
local button = CreateFrame("Button", "ModiToolsBrezButton", UIParent, "SecureActionButtonTemplate")
button:RegisterForClicks("AnyDown", "AnyUp")
button:SetAttribute("type", "macro")
-- Manejador seguro: activa la tecla solo mientras la condición se cumple.
local handler = CreateFrame("Frame", "ModiToolsBrezHandler", UIParent, "SecureHandlerStateTemplate")
handler:SetAttribute("_onstate-modibrez", [[
if newstate == "on" then
local key = self:GetAttribute("modikey")
if key and key ~= "" then
self:SetBindingClick(true, key, "ModiToolsBrezButton")
end
else
self:ClearBindings()
end
]])
local pending = false
local applied = { active = false }
function Brez.Apply()
if InCombatLockdown() then
pending = true -- se aplica al salir de combate
return
end
pending = false
local c = cfg()
local name, known = ResolveSpell()
local active = c.enabled and c.key ~= "" and name and known and true or false
UnregisterStateDriver(handler, "modibrez")
SecureHandlerExecute(handler, "self:ClearBindings()")
if active then
button:SetAttribute("macrotext", "/cast [@mouseover,help,dead,exists] " .. name)
handler:SetAttribute("modikey", c.key)
local cond = c.onlyCombat and "[combat,@mouseover,help,dead,exists] on; off"
or "[@mouseover,help,dead,exists] on; off"
RegisterStateDriver(handler, "modibrez", cond)
end
applied.active, applied.key, applied.spell = active, c.key, name
end
---------------------------------------------------------------------------
-- Estado (para la ventana de opciones)
---------------------------------------------------------------------------
-- Ícono del hechizo detectado (o del ID elegido). Devuelve textura, spellID, conocido.
function Brez.SpellIcon()
local name, known, _, id = ResolveSpell()
if not id then return nil end
local tex
if C_Spell and C_Spell.GetSpellTexture then
tex = C_Spell.GetSpellTexture(id)
elseif GetSpellTexture then
tex = GetSpellTexture(id)
end
return tex, id, known
end
function Brez.StatusText()
local c = cfg()
local green, red, grey = "|cff7fe07f", "|cffff6060", "|cffa0aa95"
local className = UnitClass("player") or "?"
local name, known, source, id = ResolveSpell()
local lines = {}
lines[#lines + 1] = string.format(L["Class: %s"], className)
if source == "custom" and not name then
lines[#lines + 1] = red .. string.format(L["ID %s is not a valid spell."], tostring(c.customSpell)) .. "|r"
elseif not name then
lines[#lines + 1] = red .. L["Your class has no combat res."] .. "|r"
elseif known then
lines[#lines + 1] = green .. string.format(L["Spell: %s (ID %d)"], name, id) .. "|r"
.. (source == "custom" and grey .. L[" custom"] .. "|r" or "")
else
lines[#lines + 1] = red .. string.format(L["Spell: %s (ID %d, not learned yet)"], name, id) .. "|r"
end
if not c.enabled then
lines[#lines + 1] = grey .. L["Status: disabled"] .. "|r"
elseif c.key == "" then
lines[#lines + 1] = grey .. L["Status: choose a key"] .. "|r"
elseif pending then
lines[#lines + 1] = "|cffffd060" .. L["Status: will apply after combat"] .. "|r"
elseif applied.active then
lines[#lines + 1] = green .. string.format(L["Status: active on %s"], c.key) .. "|r"
else
lines[#lines + 1] = red .. L["Status: inactive"] .. "|r"
end
return table.concat(lines, "\n")
end
---------------------------------------------------------------------------
-- Eventos
---------------------------------------------------------------------------
local events = CreateFrame("Frame")
for _, e in ipairs({
"PLAYER_LOGIN", "PLAYER_REGEN_ENABLED", "SPELLS_CHANGED",
"PLAYER_TALENT_UPDATE", "ACTIVE_PLAYER_SPECIALIZATION_CHANGED",
}) do
pcall(events.RegisterEvent, events, e)
end
events:SetScript("OnEvent", function(_, event)
if not ns.db then return end
if event == "PLAYER_REGEN_ENABLED" and not pending then return end
Brez.Apply()
if ns.RefreshOptions then ns.RefreshOptions() end
end)
function Brez.Slash(arg)
local cmd, rest = arg:match("^(%S+)%s*(.*)$")
cmd = cmd and cmd:lower()
if cmd == "key" and rest ~= "" then
cfg().key = rest:upper()
Brez.Apply()
if ns.RefreshOptions then ns.RefreshOptions() end
print(PREFIX .. string.format(L["Brez key: %s"], cfg().key) .. (pending and L[" (will apply after combat)"] or ""))
elseif cmd == "status" then
print(PREFIX .. (Brez.StatusText():gsub("\n", " | ")))
else
print(PREFIX .. L["Usage: /modi brez key <key> | status"])
end
end