forked from kaminaris/MaxDps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
358 lines (288 loc) · 8.99 KB
/
Core.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
local addonName, MaxDps = ...;
LibStub('AceAddon-3.0'):NewAddon(MaxDps, 'MaxDps', 'AceConsole-3.0', 'AceEvent-3.0', 'AceTimer-3.0');
--- @class MaxDps
_G[addonName] = MaxDps;
local TableInsert = tinsert;
local TableRemove = tremove;
local TableContains = tContains;
local TableIndexOf = tIndexOf;
local UnitIsFriend = UnitIsFriend;
local IsPlayerSpell = IsPlayerSpell;
local UnitClass = UnitClass;
local GetSpecialization = GetSpecialization;
local CreateFrame = CreateFrame;
local GetAddOnInfo = GetAddOnInfo;
local IsAddOnLoaded = IsAddOnLoaded;
local LoadAddOn = LoadAddOn;
local spellHistoryBlacklist = {
[75] = true; -- Auto shot
};
function MaxDps:OnInitialize()
self.db = LibStub('AceDB-3.0'):New('MaxDpsOptions', self.defaultOptions);
self:RegisterChatCommand('maxdps', 'ShowMainWindow');
if not self.db.global.customRotations then
self.db.global.customRotations = {};
end
self:AddToBlizzardOptions();
end
function MaxDps:ShowMainWindow()
if not self.Window then
self.Window = self:GetModule('Window');
end
self.Window:ShowWindow();
end
function MaxDps:GetTexture()
if self.db.global.customTexture ~= '' and self.db.global.customTexture ~= nil then
self.FinalTexture = self.db.global.customTexture;
return self.FinalTexture;
end
self.FinalTexture = self.db.global.texture;
if self.FinalTexture == '' or self.FinalTexture == nil then
self.FinalTexture = 'Interface\\Cooldown\\ping4';
end
return self.FinalTexture;
end
MaxDps.DefaultPrint = MaxDps.Print;
function MaxDps:Print(...)
if self.db.global.disabledInfo then
return
end
MaxDps:DefaultPrint(...);
end
MaxDps.profilerStatus = 0;
function MaxDps:ProfilerStart()
local profiler = self:GetModule('Profiler');
profiler:StartProfiler();
self.profilerStatus = 1;
end
function MaxDps:ProfilerStop()
local profiler = self:GetModule('Profiler');
profiler:StopProfiler();
self.profilerStatus = 0;
end
function MaxDps:ProfilerToggle()
if self.profilerStatus == 0 then
self:ProfilerStart();
else
self:ProfilerStop();
end
end
function MaxDps:EnableRotation()
if self.NextSpell == nil or self.rotationEnabled then
self:Print(self.Colors.Error .. 'Failed to enable addon!');
return
end
self:Fetch();
self:UpdateButtonGlow();
self:CheckTalents();
self:GetAzeriteTraits();
self:GetAzeriteEssences();
self:GetCovenantInfo();
self:GetLegendaryEffects();
self:CheckIsPlayerMelee();
if self.ModuleOnEnable then
self.ModuleOnEnable();
end
self:EnableRotationTimer();
self.rotationEnabled = true;
end
function MaxDps:EnableRotationTimer()
self.RotationTimer = self:ScheduleRepeatingTimer('InvokeNextSpell', self.db.global.interval);
end
function MaxDps:DisableRotation()
if not self.rotationEnabled then
return
end
self:DisableRotationTimer();
self:DestroyAllOverlays();
self:Print(self.Colors.Info .. 'Disabling');
self.Spell = nil;
self.rotationEnabled = false;
end
function MaxDps:DisableRotationTimer()
if self.RotationTimer then
self:CancelTimer(self.RotationTimer);
end
end
local talentUpdateEvents = {
"TRAIT_CONFIG_CREATED",
"ACTIVE_COMBAT_CONFIG_CHANGED",
"STARTER_BUILD_ACTIVATION_FAILED",
"PLAYER_TALENT_UPDATE",
"AZERITE_ESSENCE_ACTIVATED",
"TRAIT_CONFIG_DELETED",
"TRAIT_CONFIG_UPDATED",
}
function MaxDps:OnEnable()
self:RegisterEvent('PLAYER_TARGET_CHANGED');
self:RegisterEvent('PLAYER_REGEN_DISABLED');
for _, event in pairs(talentUpdateEvents) do
self:RegisterEvent(event, 'TalentsUpdated')
end
self:RegisterEvent('ACTIONBAR_SLOT_CHANGED', 'ButtonFetch');
self:RegisterEvent('ACTIONBAR_HIDEGRID', 'ButtonFetch');
self:RegisterEvent('ACTIONBAR_PAGE_CHANGED', 'ButtonFetch');
self:RegisterEvent('LEARNED_SPELL_IN_TAB', 'ButtonFetch');
self:RegisterEvent('CHARACTER_POINTS_CHANGED', 'ButtonFetch');
self:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED', 'ButtonFetch');
self:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED', 'ButtonFetch');
self:RegisterEvent('UPDATE_MACROS', 'ButtonFetch');
self:RegisterEvent('VEHICLE_UPDATE', 'ButtonFetch');
self:RegisterEvent('UPDATE_STEALTH', 'ButtonFetch');
self:RegisterEvent('UNIT_ENTERED_VEHICLE');
self:RegisterEvent('UNIT_EXITED_VEHICLE');
self:RegisterEvent('NAME_PLATE_UNIT_ADDED');
self:RegisterEvent('NAME_PLATE_UNIT_REMOVED');
-- self:RegisterEvent('PLAYER_REGEN_ENABLED');
if not self.playerUnitFrame then
self.spellHistory = {};
self.playerUnitFrame = CreateFrame('Frame');
self.playerUnitFrame:RegisterUnitEvent('UNIT_SPELLCAST_SUCCEEDED', 'player');
self.playerUnitFrame:SetScript('OnEvent', function(_, _, _, _, spellId)
-- event, unit, lineId
if IsPlayerSpell(spellId) and not spellHistoryBlacklist[spellId] then
TableInsert(self.spellHistory, 1, spellId);
if #self.spellHistory > 5 then
TableRemove(self.spellHistory);
end
end
end);
end
self:Print(self.Colors.Info .. 'Initialized');
end
MaxDps.visibleNameplates = {};
function MaxDps:NAME_PLATE_UNIT_ADDED(_, nameplateUnit)
if not TableContains(self.visibleNameplates, nameplateUnit) then
TableInsert(self.visibleNameplates, nameplateUnit);
end
end
function MaxDps:NAME_PLATE_UNIT_REMOVED(_, nameplateUnit)
local index = TableIndexOf(self.visibleNameplates, nameplateUnit);
if index ~= nil then
TableRemove(self.visibleNameplates, index)
end
end
function MaxDps:TalentsUpdated()
self:DisableRotation();
end
function MaxDps:UNIT_ENTERED_VEHICLE(_, unit)
if unit == 'player' and self.rotationEnabled then
self:DisableRotation();
end
end
function MaxDps:UNIT_EXITED_VEHICLE(_, unit)
if unit == 'player' then
self:InitRotations();
self:EnableRotation();
end
end
function MaxDps:PLAYER_TARGET_CHANGED()
if self.rotationEnabled then
if UnitIsFriend('player', 'target') then
return
else
self:InvokeNextSpell();
end
end
end
function MaxDps:PLAYER_REGEN_DISABLED()
if self.db.global.onCombatEnter and not self.rotationEnabled then
self:Print(self.Colors.Success .. 'Auto enable on combat!');
self:InitRotations();
self:EnableRotation();
end
end
function MaxDps:ButtonFetch()
if self.rotationEnabled then
if self.fetchTimer then
self:CancelTimer(self.fetchTimer);
end
self.fetchTimer = self:ScheduleTimer('Fetch', 0.5);
end
end
function MaxDps:PrepareFrameData()
if not self.FrameData then
self.FrameData = {
cooldown = self.PlayerCooldowns,
activeDot = self.ActiveDots
};
end
self.FrameData.timeShift, self.FrameData.currentSpell, self.FrameData.gcdRemains = MaxDps:EndCast();
self.FrameData.gcd = self:GlobalCooldown();
self.FrameData.buff, self.FrameData.debuff = MaxDps:CollectAuras();
self.FrameData.talents = self.PlayerTalents;
self.FrameData.azerite = self.AzeriteTraits;
self.FrameData.essences = self.AzeriteEssences;
self.FrameData.covenant = self.CovenantInfo;
self.FrameData.runeforge = self.LegendaryBonusIds;
self.FrameData.spellHistory = self.spellHistory;
self.FrameData.timeToDie = self:GetTimeToDie();
end
function MaxDps:InvokeNextSpell()
-- invoke spell check
local oldSkill = self.Spell;
self:PrepareFrameData();
self:GlowConsumables();
-- Removed backward compatibility
self.Spell = self:NextSpell();
if (oldSkill ~= self.Spell or oldSkill == nil) and self.Spell ~= nil then
self:GlowNextSpell(self.Spell);
if WeakAuras then
WeakAuras.ScanEvents('MAXDPS_SPELL_UPDATE', self.Spell);
end
end
if self.Spell == nil and oldSkill ~= nil then
self:GlowClear();
if WeakAuras then
WeakAuras.ScanEvents('MAXDPS_SPELL_UPDATE', nil);
end
end
end
function MaxDps:InitRotations()
self:Print(self.Colors.Info .. 'Initializing rotations');
local _, _, classId = UnitClass('player');
local spec = GetSpecialization();
self.ClassId = classId;
self.Spec = spec;
if not self.Custom then
self.Custom = self:GetModule('Custom');
end
self.Custom:LoadCustomRotations();
local customRotation = self.Custom:GetCustomRotation(classId, spec);
if customRotation then
self.NextSpell = customRotation.fn;
self:Print(self.Colors.Success .. 'Loaded Custom Rotation: ' .. customRotation.name);
else
self:LoadModule();
end
end
function MaxDps:LoadModule()
if self.Classes[self.ClassId] == nil then
self:Print(self.Colors.Error .. 'Invalid player class, please contact author of addon.');
return
end
local className = self.Classes[self.ClassId];
local module = 'MaxDps_' .. className;
local _, _, _, _, reason = GetAddOnInfo(module);
if IsAddOnLoaded(module) then
self:EnableRotationModule(className);
return
end
if reason == 'MISSING' or reason == 'DISABLED' then
self:Print(self.Colors.Error .. 'Could not find class module ' .. module .. ', reason: ' .. reason);
self:Print(self.Colors.Error .. 'Make sure to install class module or create custom rotation');
self:Print(self.Colors.Error .. 'Missing addon: ' .. module);
return
end
LoadAddOn(module);
self:InitTTD();
self:EnableRotationModule(className);
end
function MaxDps:EnableRotationModule(className)
local loaded = self:EnableModule(className);
if not loaded then
self:Print(self.Colors.Error .. 'Could not find load module ' .. className .. ', reason: OUTDATED');
else
self:Print(self.Colors.Info .. 'Finished Loading class module');
end
end