-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathevents.lua
164 lines (136 loc) · 3.67 KB
/
events.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
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
---@type string
local _addonName = select(1, ...);
---@type AddonEnv
local _addon = select(2, ...);
-- dirty fix to "disable" the addon preventing errors on unsupported classes
-- TODO: Remove when classes are supported
local _, class = UnitClass("player");
if class == "WARRIOR" or class == "ROGUE" or class == "HUNTER" then
_addon:PrintError("Class not (yet) supported, addon won't work!");
return;
end
local frame = CreateFrame("Frame");
local handlers = {};
function handlers.ADDON_LOADED(addonName)
if addonName ~= _addonName then
return;
end
frame:UnregisterEvent("ADDON_LOADED");
_addon:SetupSettings();
_addon.events:TogglePowerUpdate(SpellCalc_settings.useCurrentPowerLevel);
if _addon.spellRankInfo == nil or _addon.talentData == nil then
_addon:PrintError(_addonName .. ": No data for this class (yet)! Addon won't work!");
end
end
function handlers.PLAYER_LOGIN()
_addon.ActionBarValues:Setup();
-- Beast Slaying (Troll Racial)
local _, raceEn = UnitRace("player");
if raceEn == "Troll" then
_addon:ApplyAuraEffect(GetSpellInfo(20557), { type = _addon.EFFECT_TYPE.VERSUSMOD_PCT_DAMAGE, affectMask = _addon.CREATURE_TYPE_MASK.BEAST }, 5);
end
end
function handlers.PLAYER_ENTERING_WORLD()
_addon:FullUpdate();
end
function handlers.UNIT_AURA(unit)
if unit ~= "player" then
return;
end
_addon:UpdatePlayerAuras();
_addon:UpdateWeaponEnchants();
_addon:UpdateManaRegen();
end
function handlers.UNIT_STATS(unit)
if unit ~= "player" then
return;
end
_addon:UpdateStats();
_addon:UpdateManaRegen();
end
function handlers.CHARACTER_POINTS_CHANGED(gain)
if gain > -1 then
return;
end
_addon:UpdateTalents();
end
function handlers.SPELL_POWER_CHANGED()
_addon:UpdateSpellPower();
end
function handlers.PLAYER_DAMAGE_DONE_MODS(unit)
if unit ~= "player" then
return;
end
_addon:UpdateDmgDoneMods();
end
function handlers.COMBAT_RATING_UPDATE()
_addon:CombatRatingUpdate();
end
function handlers.UPDATE_INVENTORY_DURABILITY()
_addon:UpdateItems();
end
function handlers.UNIT_INVENTORY_CHANGED(unit)
if unit ~= "player" then
return;
end
_addon:UpdateItems();
_addon:UpdateWeaponRestrictedAuras();
end
function handlers.PLAYER_TARGET_CHANGED()
_addon.Target:Update();
end
function handlers.ACTIONBAR_SLOT_CHANGED(slot)
if slot >= 1 and slot <= 120 then
_addon.ActionBarValues:SlotUpdate(slot)
end
end
function handlers.UNIT_ATTACK_SPEED(unit)
if unit ~= "player" then
return;
end
_addon:UpdateAttackSpeeds();
end
function handlers.UNIT_ATTACK(unit)
if unit ~= "player" then
return;
end
_addon:UpdateWeaponAttack();
end
function handlers.UNIT_DAMAGE(unit)
if unit ~= "player" then
return;
end
_addon:UpdateAttackDmg();
end
function handlers.UNIT_RANGEDDAMAGE(unit)
if unit ~= "player" then
return;
end
_addon:UpdateRangedAttackDmg();
end
function handlers.UNIT_POWER_UPDATE(unit, powerType)
if unit ~= "player" then
return;
end
_addon:UpdatePower(powerType);
end
function handlers.GET_ITEM_INFO_RECEIVED(itemId)
_addon:UpdateRecievedItemData(itemId);
end
frame:SetScript( "OnEvent",function(self, event, ...)
handlers[event](...);
end)
for k,_ in pairs(handlers) do
frame:RegisterEvent(k);
end
_addon.events = {};
--- Toggle power updates via UNIT_POWER_UPDATE
---@param active boolean
function _addon.events:TogglePowerUpdate(active)
if active then
frame:RegisterEvent("UNIT_POWER_UPDATE");
else
frame:UnregisterEvent("UNIT_POWER_UPDATE");
end
_addon:UpdatePower();
end