-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsodrunes.lua
76 lines (68 loc) · 2.31 KB
/
sodrunes.lua
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
---@class AddonEnv
local _addon = select(2, ...);
local pd = _addon.util.PrintDebug;
-- spellId -> effects
---@type table<integer, UnitAuraEffect[]>
local runeSpellEffects = {};
-- spellId -> isActive
---@type table<integer, boolean|nil>
local activeRuneSpells = {};
---Clear effects from rune spell.
---@param spellId integer
local function RemoveRuneSpell(spellId)
if activeRuneSpells[spellId] then
pd("Clear rune spell " .. spellId);
local effects = runeSpellEffects[spellId];
local spellName = GetSpellInfo(spellId);
for k, auraEffect in ipairs(effects) do
pd("Remove effect " .. spellName .. " " .. k);
_addon:RemoveAuraEffect(spellName .. "1", auraEffect, auraEffect.value, spellId, true);
end
activeRuneSpells[spellId] = nil;
end
end
---Apply a rune spell.
---@param spellId integer
---@param effects UnitAuraEffect[]
local function ApplyRuneSpell(spellId, effects)
pd("Apply rune spell: " .. spellId);
local spellName = GetSpellInfo(spellId);
activeRuneSpells[spellId] = true;
for k, auraEffect in ipairs(effects) do
pd("Apply effect " .. spellName .. " " .. k);
_addon:ApplyAuraEffect(spellName .. "1", auraEffect, auraEffect.value, spellId, true);
end
end
---Check if a rune spell is known.
---@param spellId integer
---@return boolean
local function RuneSpellIsKnown(spellId)
local baseSpellId = FindBaseSpellByID(spellId);
if baseSpellId and FindSpellOverrideByID(baseSpellId) == spellId then
spellId = baseSpellId;
end
return IsPlayerSpell(spellId);
end
---Update all rune slots.
local function UpdateRunes()
pd("Updating all runes");
for spellId, effects in pairs(runeSpellEffects) do
if RuneSpellIsKnown(spellId) then
if not activeRuneSpells[spellId] then
ApplyRuneSpell(spellId, effects);
end
else
if activeRuneSpells[spellId] then
RemoveRuneSpell(spellId);
end
end
end
end
---Register a rune spell.
---@param spellId integer
---@param effects UnitAuraEffect[]
function _addon:DefineRuneSpell(spellId, effects)
assert(not runeSpellEffects[spellId], "Rune spell was already defined!");
runeSpellEffects[spellId] = effects;
end
_addon.events.Register("SPELLS_CHANGED", UpdateRunes);