-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.lua
1715 lines (1535 loc) · 60.1 KB
/
main.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addon_name, addon = ...
_G[addon_name] = LibStub("AceAddon-3.0"):NewAddon(addon, addon_name, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local AceConsole = LibStub("AceConsole-3.0")
local AceEvent = LibStub("AceEvent-3.0")
local SpellData = LibStub("AceGUI-3.0-SpellLoader")
local ItemData = LibStub("AceGUI-3.0-ItemLoader")
local L = LibStub("AceLocale-3.0"):GetLocale(addon_name)
local getCached, getRetryCached
local DBIcon = LibStub("LibDBIcon-1.0")
local Media = LibStub("LibSharedMedia-3.0")
local ThreatClassic = LibStub("ThreatClassic-1.0")
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
UnitThreatSituation = ThreatClassic.UnitThreatSituation
local LibClassicDurations = LibStub("LibClassicDurations")
LibClassicDurations:Register(addon_name)
else
ThreatClassic:Disable()
end
local pairs, color, string = pairs, color, string
local floor = math.floor
local isin, starts_with, isint = addon.isin, addon.starts_with, addon.isint
addon.pretty_name = GetAddOnMetadata(addon_name, "Title")
addon.delayed_condition = {}
local DataBroker = LibStub("LibDataBroker-1.1"):NewDataObject(addon_name,
{ type = "data source", label = addon.pretty_name, icon = "Interface\\AddOns\\" .. addon_name .. "\\textures\\RotationMaster-Minimap" })
--
-- Initialization
--
BINDING_HEADER_ROTATIONMASTER = addon.pretty_name
BINDING_NAME_ROTATIONMASTER_TOGGLE = string.format(L["Toggle %s " .. color.CYAN .. "/rm toggle" .. color.RESET], addon.pretty_name)
local playerGUID = UnitGUID("player")
local defaults = {
profile = {
enable = true,
poll = 0.15,
ignore_mana = false,
ignore_range = false,
effect = "61b36ed1-fa31-4656-ad71-f3d50f193a85",
color = { r = 1.0, g = 1.0, b = 1.0, a = 1.0 },
magnification = 1.4,
setpoint = 'CENTER',
xoffs = 0,
yoffs = 0,
loglevel = 2,
detailed_profiling = false,
disable_autoswitch = false,
live_config_update = 2,
spell_history = 60,
combat_history = 10,
damage_history = 30,
disable_buttons = false,
preview_spells = 0,
preview_window = {
point = "CENTER",
relpoint = "CENTER",
xoffs = 0,
yoffs = 0
},
rotations = {},
itemsets = {},
announces = {},
minimap = {
hide = false,
},
condition_groups = {},
switch_conditions = {},
other_conditions_order = {},
disabled_conditions = {},
},
char = {
bindings = {},
},
global = {
itemsets = {},
effects = {},
custom_conditions = {},
}
}
if WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE and
LE_EXPANSION_LEVEL_CURRENT >= 2 then
defaults.char.specs = {}
defaults.char.specs[1] = PRIMARY
defaults.char.specs[2] = SECONDARY
end
local events = {
-- Conditions that indicate a major combat event that should trigger an immediate
-- evaluation of the rotation conditions (or will disable your rotation entirely).
'PLAYER_TARGET_CHANGED',
'PLAYER_REGEN_DISABLED',
'PLAYER_REGEN_ENABLED',
'UNIT_PET',
'PLAYER_CONTROL_GAINED',
'PLAYER_CONTROL_LOST',
"UPDATE_STEALTH",
-- Conditions that affect whether the rotation should be switched.
'ZONE_CHANGED',
'ZONE_CHANGED_INDOORS',
'GROUP_ROSTER_UPDATE',
'CHARACTER_POINTS_CHANGED',
"PLAYER_FLAGS_CHANGED",
"UPDATE_SHAPESHIFT_FORM",
-- Conditions that affect affect the contents of highlighted buttons.
'ACTIONBAR_SLOT_CHANGED',
'PET_BAR_UPDATE',
'PLAYER_ENTERING_WORLD',
'ACTIONBAR_HIDEGRID',
'PET_BAR_HIDEGRID',
'ACTIONBAR_PAGE_CHANGED',
'LEARNED_SPELL_IN_TAB',
'UPDATE_MACROS',
'SPELLS_CHANGED',
-- Special Purpose
'NAME_PLATE_UNIT_ADDED',
'NAME_PLATE_UNIT_REMOVED',
'BAG_UPDATE',
'UNIT_COMBAT',
"UNIT_SPELLCAST_SENT",
"UNIT_SPELLCAST_START",
"UNIT_SPELLCAST_STOP",
"UNIT_SPELLCAST_SUCCEEDED",
"UNIT_SPELLCAST_INTERRUPTED",
"UNIT_SPELLCAST_FAILED",
"UNIT_SPELLCAST_DELAYED",
"UNIT_SPELLCAST_CHANNEL_START",
"UNIT_SPELLCAST_CHANNEL_STOP",
"COMBAT_LOG_EVENT_UNFILTERED",
"SPELL_DATA_LOAD_RESULT",
"ITEM_DATA_LOAD_RESULT"
}
local mainline_events = {
'PLAYER_FOCUS_CHANGED',
'VEHICLE_UPDATE',
'UNIT_ENTERED_VEHICLE',
'PLAYER_TALENT_UPDATE',
'ACTIVE_TALENT_GROUP_CHANGED',
'PLAYER_SPECIALIZATION_CHANGED',
}
local wrath_events = {
'PLAYER_TALENT_UPDATE',
-- 'ACTIVE_TALENT_GROUP_CHANGED', # Implied by the above
}
local tbc_events = {
'PLAYER_FOCUS_CHANGED',
}
local classic_events = {
}
function addon:HandleCommand(str)
local cmd, npos = AceConsole:GetArgs(str, 1, 1)
if not cmd or cmd == "help" then
addon:print(L["/rm help - This text."])
addon:print(L["/rm config - Open the config dialog."])
addon:print(L["/rm disable - Disable battle rotation."])
addon:print(L["/rm enable - Enable battle rotation."])
addon:print(L["/rm toggle - Toggle between enabled and disabled."])
addon:print(L["/rm current - Print out the name of the current rotation."])
addon:print(L["/rm set [auto|profile] - Switch to a specific rotation, or use automatic switching again."])
addon:print(L[" This is reset upon switching specializations."])
addon:print(L["/rm check - Check the database integrity."])
addon:print(L["/rm repair - Fix any DB errors found in the data with internal validation."])
elseif cmd == "config" then
InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Rotation.frame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrames.Rotation.frame)
elseif cmd == "disable" then
addon:disable()
elseif cmd == "enable" then
addon:enable()
elseif cmd == "toggle" then
if self.currentRotation == nil then
addon:enable()
else
addon:disable()
end
elseif cmd == "current" then
if self.currentRotation == nil then
addon:print(L["No rotation is currently active."])
else
addon:print(L["The current rotation is " .. color.WHITE .. "%s" .. color.INFO], addon:GetRotationName(self.currentRotation))
end
elseif cmd == "set" then
local name = string.sub(str, npos)
if name == "auto" then
self.manualRotation = false
self:SwitchRotation()
elseif name == self.currentRotation then
self.manualRotation = true
addon:info(L["Active rotation manually switched to " .. color.WHITE .. "%s" .. color.INFO], name)
elseif name == DEFAULT then
self:RemoveAllCurrentGlows()
self.manualRotation = true
self.currentRotation = DEFAULT
self.skipAnnounce = true
self.avail_announced = {}
self.announced = {}
self:EnableRotationTimer()
DataBroker.text = self:GetRotationName(DEFAULT)
AceEvent:SendMessage("ROTATIONMASTER_ROTATION", self.currentRotation, self:GetRotationName(self.currentRotation))
addon:info(L["Active rotation manually switched to " .. color.WHITE .. "%s" .. color.INFO], name)
else
if self.db.profile.rotations[self.currentSpec] ~= nil then
for id, rot in pairs(self.db.profile.rotations[self.currentSpec]) do
if rot.name == name then
self:RemoveAllCurrentGlows()
self.manualRotation = true
self.currentRotation = id
self.skipAnnounce = true
self.avail_announced = {}
self.announced = {}
self:EnableRotationTimer()
DataBroker.text = self:GetRotationName(id)
AceEvent:SendMessage("ROTATIONMASTER_ROTATION", self.currentRotation, self:GetRotationName(self.currentRotation))
addon:info(L["Active rotation manually switched to " .. color.WHITE .. "%s" .. color.INFO], name)
if (not self:rotationValidConditions(rot, self.currentSpec)) then
addon:warn(L["Active rotation is incomplete and may not work correctly!"])
end
return
end
end
end
addon:warn(L["Could not find rotation named " .. color.WHITE .. "%s" .. color.WARN .. " for your current specialization."], name)
end
elseif cmd == "check" then
addon:print(L["Validating database integrity"])
self:validate(defaults, false)
elseif cmd == "repair" then
addon:print(L["Validating database integrity"])
self:validate(defaults, true)
else
addon:warn(L["Invalid option " .. color.WHITE .. "%s" .. color.WARN], cmd)
end
end
function addon:OnInitialize()
self:augmentDefaults(defaults)
self.db = LibStub("AceDB-3.0"):New(addon_name .. "DB", defaults, true)
for ext_addon,conditions in pairs(self.delayed_condition) do
if IsAddOnLoaded(ext_addon) then
for name, condition in pairs(conditions) do
self:RegisterCondition(name, condition)
end
end
end
self:init()
self:validate(defaults)
AceConsole:RegisterChatCommand("rm", function(str)
addon:HandleCommand(str)
end)
AceConsole:RegisterChatCommand("rotationmaster", function(str)
addon:HandleCommand(str)
end)
if type(self.db.profile.minimap) == "boolean" then
self.db.profile.minimap = nil
end
DBIcon:Register(addon.name, DataBroker, self.db.profile.minimap)
DataBroker.text = color.RED .. OFF
self.funcDeserialize = {}
for key, condition in pairs(self.db.global.custom_conditions) do
addon:register_custom_condition(key, condition)
end
-- These values are cached for the entire time you are in combat. Their values
-- are unlikely to change during combat (and if they do, they will have minimal effect)
self.combatCache = {}
-- These values are cached until the cache is reset (spec change, etc). Their values
-- will not change without a respec (or sometimes never).
self.longtermCache = {}
self.currentSpec = nil
self.currentForm = nil
-- This is a list of rotations that are available (ie. they are complete). So we don't
-- have to call validate in a time of battle.
self.autoswitchRotation = {}
self.currentRotation = nil
self.manualRotation = false
self.inCombat = false
self.rotationTimer = nil
self.fetchTimer = nil
self.shapeshiftTimer = nil
-- This is a cache of spec based spell names -> IDs. Updated when we switch specs.
self.specSpells = {}
self.specSpellsReverse = {}
self.bagContents = {}
self.specTalents = {}
self.unitsInRange = {}
self.damageHistory = {}
self.lastMainSwing = nil
self.lastOffSwing = nil
self.spellHistory = {}
self.combatHistory = {}
self.avail_announced = {}
self.announced = {}
self.skipAnnounce = true
self.currentConditionEval = nil
self.conditionEvalTimer = nil
self.lastCacheReport = GetTime()
self.itemSetButtons = {}
self.itemSetCallback = nil
self.bindingItemSet = nil
self.evaluationProfile = addon:ProfiledCode()
self.currentSpell = nil
self.nextWindow = nil
-- This is here because of order of loading.
getCached = addon.getCached
getRetryCached = addon.getRetryCached
--self:SetupOptions()
end
function addon:GetRotationName(id)
if id == DEFAULT then
return DEFAULT
elseif self.db.profile.rotations[self.currentSpec] ~= nil and
self.db.profile.rotations[self.currentSpec][id] ~= nil then
return self.db.profile.rotations[self.currentSpec][id].name
else
return nil
end
end
local function minimapToggleRotation(_, _, _, checked)
if checked then
addon:enable()
else
addon:disable()
end
end
local function minimapChangeRotation(_, arg1, _, _)
if arg1 == nil then
addon.manualRotation = false
addon:SwitchRotation()
else
addon.manualRotation = true
if addon.currentSpec ~= arg1 then
addon:RemoveAllCurrentGlows()
addon.currentRotation = arg1
addon.skipAnnounce = true
addon.avail_announced = {}
addon.announced = {}
addon:EnableRotationTimer()
DataBroker.text = addon:GetRotationName(arg1)
AceEvent:SendMessage("ROTATIONMASTER_ROTATION", addon.currentRotation, addon:GetRotationName(addon.currentRotation))
end
addon:info(L["Active rotation manually switched to " .. color.WHITE .. "%s" .. color.INFO],
addon:GetRotationName(arg1))
end
end
function minimapInitialize()
local info = UIDropDownMenu_CreateInfo()
info.text = addon.pretty_name
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.isNotRadio = true
info.keepShownOnClick = true
info.text, info.checked = L["Battle rotation enabled"], addon.db.profile.enable
info.func = minimapToggleRotation
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.text = " "
info.notClickable = true
info.notCheckable = true
UIDropDownMenu_AddButton(info)
info.isTitle = true
info.text = L["Current Rotation"]
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.func = minimapChangeRotation
info.text, info.arg1, info.checked = L["Automatic Switching"], nil, (addon.manualRotation == false)
UIDropDownMenu_AddButton(info)
info.text, info.arg1, info.checked = DEFAULT, DEFAULT, (addon.manualRotation == true and addon.currentRotation == DEFAULT)
UIDropDownMenu_AddButton(info)
if addon.db.profile.rotations[addon.currentSpec] ~= nil then
for id, rot in pairs(addon.db.profile.rotations[addon.currentSpec]) do
if id ~= DEFAULT then
info.text, info.arg1, info.checked = rot.name, id, (addon.manualRotation == true and addon.currentRotation == id)
UIDropDownMenu_AddButton(info)
end
end
end
end
function DataBroker.OnClick(_, button)
local frame = CreateFrame("Frame", addon_name .. "LDBFrame")
local dropdownFrame = CreateFrame("Frame", addon_name .. "LDBDropdownFrame", frame, "UIDropDownMenuTemplate")
if button == "RightButton" then
UIDropDownMenu_Initialize(dropdownFrame, minimapInitialize)
ToggleDropDownMenu(1, nil, dropdownFrame, "cursor", 5, -10)
elseif button == "LeftButton" then
InterfaceOptionsFrame_OpenToCategory(addon.optionsFrames.Rotation.frame)
InterfaceOptionsFrame_OpenToCategory(addon.optionsFrames.Rotation.frame)
end
end
function DataBroker.OnTooltipShow(GameTooltip)
GameTooltip:SetText(addon.pretty_name .. " " .. GetAddOnMetadata(addon_name, "Version"), 0, 1, 1)
GameTooltip:AddLine(" ")
if addon.currentRotation ~= nil then
GameTooltip:AddLine(L["Current Rotation"], 0.55, 0.78, 0.33, 1)
GameTooltip:AddLine(addon:GetRotationName(addon.currentRotation), 1, 1, 1)
else
GameTooltip:AddLine(L["Battle rotation disabled"], 1, 0, 0, 1)
end
end
function addon:toggle()
if self.currentRotation == nil then
self:enable()
else
self:disable()
end
end
function addon:enable()
for _, v in pairs(events) do
self:RegisterEvent(v)
end
if (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE) then
self.currentSpec = GetSpecializationInfo(addon:GetSpecialization())
if self.specTab then
self.specTab:SelectTab(self.currentSpec)
end
for _, v in pairs(mainline_events) do
self:RegisterEvent(v)
end
elseif (LE_EXPANSION_LEVEL_CURRENT == 2) then
self.currentSpec = addon:GetSpecialization()
for _, v in pairs(wrath_events) do
self:RegisterEvent(v)
end
elseif (LE_EXPANSION_LEVEL_CURRENT == 1) then
self.currentSpec = 0
for _, v in pairs(tbc_events) do
self:RegisterEvent(v)
end
elseif (LE_EXPANSION_LEVEL_CURRENT == 0) then
self.currentSpec = 0
for _, v in pairs(classic_events) do
self:RegisterEvent(v)
end
end
if self.db.profile.preview_spells > 0 then
self:CreatePreviewWindow()
end
self:UpdateSkill()
self:EnableRotation()
end
function addon:disable()
self:DisableRotation()
if self.nextWindow then
local spells = self.db.profile.preview_spells
self.nextWindow:Release()
self.nextWindow = nil
self.db.profile.preview_spells = spells
end
self.spellHistory = {}
self.combatHistory = {}
self:UnregisterAllEvents()
end
function addon:OnEnable()
self:info(L["Starting up version %s"], GetAddOnMetadata(addon_name, "Version"))
if self.db.profile.live_config_update and not self.conditionEvalTimer then
self.conditionEvalTimer = self:ScheduleRepeatingTimer('UpdateCurrentCondition', self.db.profile.live_config_update)
end
if self.db.profile.enable then
self:enable()
end
end
function addon:rotationValidConditions(rot, spec)
local itemsets = self.db.profile.itemsets
local global_itemsets = self.db.global.itemsets
-- We found a cooldown OR a rotation step
local itemfound = false
if rot.cooldowns ~= nil then
-- All cooldowns are valid
for _, v in pairs(rot.cooldowns) do
if not v.disabled then
if (v.type == nil or v.action == nil or not self:validateCondition(v.conditions, spec)) then
return false
end
if v.type == "item" then
if type(v.action) == "string" then
local itemset
if itemsets[v.action] ~= nil then
itemset = itemsets[v.action]
elseif global_itemsets[v.action] ~= nil then
itemset = global_itemsets[v.action]
end
if not itemset or #itemset.items == 0 then
return false
end
else
if #v.action == 0 then
return false
end
end
end
itemfound = true
end
end
end
if rot.rotation ~= nil then
-- All rotation steps are valid
for _, v in pairs(rot.rotation) do
if not v.disabled then
if (v.type == nil or not self:validateCondition(v.conditions, spec)) then
return false
end
if (v.type ~= "none" and v.action == nil) then
return false
end
if v.type == "item" then
if type(v.action) == "string" then
local itemset
if itemsets[v.action] ~= nil then
itemset = itemsets[v.action]
elseif global_itemsets[v.action] ~= nil then
itemset = global_itemsets[v.action]
end
if not itemset or #itemset.items == 0 then
return false
end
else
if #v.action == 0 then
return false
end
end
end
itemfound = true
end
end
end
return itemfound
end
function addon:UpdateAutoSwitch()
self.autoswitchRotation = {}
if self.db.profile.rotations[self.currentSpec] ~= nil then
for id, rot in pairs(self.db.profile.rotations[self.currentSpec]) do
if id ~= DEFAULT then
-- The switch condition is nontrivial and valid.
if rot.switch and not rot.disabled and addon:usefulCondition(rot.switch) and
self:validateCondition(rot.switch, self.currentSpec) and
self:rotationValidConditions(rot, self.currentSpec) then
addon:debug(L["Rotaion " .. color.WHITE .. "%s" .. color.DEBUG .. " is now available for auto-switching."], rot.name)
table.insert(self.autoswitchRotation, id)
end
end
end
end
-- We autoswitch to the lowest (alphabetically) matching rotation.
table.sort(self.autoswitchRotation, function(lhs, rhs)
return self.db.profile.rotations[self.currentSpec][lhs].name <
self.db.profile.rotations[self.currentSpec][rhs].name
end)
addon:debug(L["Autoswitch rotation list has been updated."])
end
-- Figure out which of the autoswitch rotations best matches
function addon:SwitchRotation()
if self.db.profile.disable_autoswitch or self.manualRotation then
return
end
local newRotation
for _, v in pairs(self.autoswitchRotation) do
if addon:evaluateCondition(self.db.profile.rotations[self.currentSpec][v].switch) then
newRotation = v
break
end
end
if not newRotation and self.db.profile.rotations[self.currentSpec] ~= nil and
self.db.profile.rotations[self.currentSpec][DEFAULT] ~= nil and
self:rotationValidConditions(self.db.profile.rotations[self.currentSpec][DEFAULT], self.currentSpec) then
newRotation = DEFAULT
end
if newRotation then
if self.currentRotation ~= newRotation then
addon:info(L["Active rotation automatically switched to " .. color.WHITE .. "%s" .. color.INFO], self:GetRotationName(newRotation))
self:RemoveAllCurrentGlows()
self.currentRotation = newRotation
self.skipAnnounce = true
self.avail_announced = {}
self.announced = {}
self:EnableRotationTimer()
DataBroker.text = self:GetRotationName(newRotation)
AceEvent:SendMessage("ROTATIONMASTER_ROTATION", self.currentRotation, self:GetRotationName(self.currentRotation))
end
return
end
-- Could not find a rotation to switch to, even the default one.
if self.currentRotation ~= nil then
addon:warn(L["No rotation is active as there is none suitable to automatically switch to."])
self:DisableRotation()
end
end
function addon:EnableRotation()
if self.currentRotation then
return
end
self:Fetch()
self:UpdateAutoSwitch()
self:SwitchRotation()
if self.currentRotation ~= nil then
DataBroker.text = self:GetRotationName(self.currentRotation)
addon:info(L["Battle rotation enabled"])
end
end
function addon:DisableRotation()
if not self.currentRotation then
return
end
self:DisableRotationTimer()
self:RemoveAllCurrentGlows()
self:DestroyAllGlows()
self.currentRotation = nil
DataBroker.text = color.RED .. OFF
AceEvent:SendMessage("ROTATIONMASTER_ROTATION", nil)
addon:info(L["Battle rotation disabled"])
end
function addon:EnableRotationTimer()
if self.currentRotation and not self.rotationTimer then
self.rotationTimer = self:ScheduleRepeatingTimer('EvaluateNextAction', self.db.profile.poll)
end
end
function addon:DisableRotationTimer()
if self.rotationTimer then
self:CancelTimer(self.rotationTimer)
self.rotationTimer = nil
end
end
function addon:ButtonFetch()
if self.fetchTimer then
self:CancelTimer(self.fetchTimer)
end
self.fetchTimer = self:ScheduleTimer(function()
self.skipAnnounce = true
self:Fetch()
end, 0.25)
end
local function CreateUnitInfo(cache, unit)
local info = {
unit = unit,
name = getCached(cache, UnitName, unit),
attackable = getCached(cache, UnitCanAttack, "player", unit),
enemy = getCached(cache, UnitIsEnemy, "player", unit),
}
if info.enemy then
info.threat = getCached(cache, UnitThreatSituation, "player", unit)
end
return info
end
local function UpdateUnitInfo(cache, record)
if not getCached(cache, UnitExists, record.unit) then
return
end
record.attackable = getCached(cache, UnitCanAttack, "player", record.unit)
record.enemy = getCached(cache, UnitIsEnemy, "player", record.unit)
if record.enemy then
record.threat = getCached(cache, UnitThreatSituation, "player", record.unit)
else
record.threat = nil
end
end
local function announce(cache, cond, text)
local dest
if cond.announce == "local" then
addon:announce(text)
elseif cond.announce == "partyraid" then
if getCached(cache, IsInRaid) then
dest = "RAID"
elseif getCached(cache, IsInGroup) then
dest = "PARTY"
else
addon:announce(text)
end
elseif cond.announce == "party" then
if getCached(cache, IsInGroup) then
dest = "PARTY"
end
elseif cond.announce == "raidwarn" then
if getCached(cache, IsInRaid) then
if getCached(cache, IsRaidLeader) then
dest = "RAID_WARNING"
else
dest = "RAID"
end
elseif getCached(cache, IsInGroup) then
dest = "PARTY"
else
addon:announce(text)
end
elseif cond.announce == "say" then
dest = "SAY"
elseif cond.announce == "yell" then
dest = "YELL"
elseif cond.announce == "emote" then
dest = "EMOTE"
end
if dest ~= nil then
SendChatMessage(text, dest)
end
if cond.announce_sound then
PlaySoundFile(Media:Fetch("sound", cond.announce_sound), "Master")
end
end
function addon:EvaluateNextAction()
if self.currentRotation == nil then
addon:DisableRotationTimer()
elseif self.db.profile.rotations ~= nil and
self.db.profile.rotations[self.currentSpec] ~= nil and
self.db.profile.rotations[self.currentSpec][self.currentRotation] ~= nil then
self.evaluationProfile:start()
local now = GetTime()
local cache = {}
if not self.inCombat then
self.combatCache = cache
end
self.evaluationProfile:child("environment"):start()
local unitsHandled, unitsGUID = {}, {}
for unit, _ in pairs(addon.units) do
unitsGUID[unit] = getCached(cache, UnitGUID, unit)
end
for guid, entity in pairs(self.unitsInRange) do
if isin(addon.units, entity.unit) then
if unitsGUID[entity.unit] and unitsGUID[entity.unit] == guid then
unitsHandled[entity.unit] = true
else
self.unitsInRange[guid] = nil
end
end
addon:verbose("Updating Unit " .. guid .. " (" .. entity.name .. ")")
UpdateUnitInfo(cache, entity)
end
for unit, guid in pairs(unitsGUID) do
if not unitsHandled[unit] and not self.unitsInRange[guid] and
not starts_with(unit, "mouseover") then
self.unitsInRange[guid] = CreateUnitInfo(cache, unit)
end
end
local threshold_time = now - self.db.profile.spell_history
while #self.spellHistory ~= 0 do
if self.spellHistory[#self.spellHistory].time < threshold_time then
table.remove(self.spellHistory, #self.spellHistory)
else
break
end
end
threshold_time = now - self.db.profile.combat_history
for _,history in pairs(self.combatHistory) do
while #history ~= 0 do
if history[#history].time < threshold_time then
table.remove(history, #history)
else
break
end
end
end
self.evaluationProfile:child("environment"):stop()
threshold_time = now - self.db.profile.damage_history
for guid, entry in pairs(self.damageHistory) do
while #entry.heals ~= 0 do
if entry.heals[#entry.heals].time < threshold_time then
table.remove(entry.heals, #entry.heals)
else
break
end
end
while #entry.damage ~= 0 do
if entry.damage[#entry.damage].time < threshold_time then
table.remove(entry.damage, #entry.damage)
else
break
end
end
if #entry.heals == 0 and #entry.damage == 0 then
self.damageHistory[guid] = nil
end
end
-- The common way to evaluate any rotation or cooldown condition.
local function eval(cond)
local spellid, enabled = nil, false
if cond.action ~= nil and (cond.disabled == nil or cond.disabled == false) then
local spellids, itemids
if cond.type ~= "any" or getCached(addon.longtermCache, IsSpellKnown, cond.action, false) or
getCached(cache, IsSpellKnown, cond.action, true) then
spellids, itemids = addon:GetSpellIds(cond)
end
if spellids ~= nil then
local idx
spellid, idx = addon:FindSpell(spellids)
if (spellid and addon:evaluateCondition(cond.conditions)) then
local avail, nomana = getCached(cache, IsUsableSpell, spellid)
if avail and (self.db.profile.ignore_mana or not nomana) then
if self.db.profile.ignore_range then
enabled = true
else
local inrange
if cond.type == BOOKTYPE_SPELL or cond.type == BOOKTYPE_PET then
local sbid = getCached(cond.type == BOOKTYPE_SPELL and addon.longtermCache or cache,
FindSpellBookSlotBySpellID, spellid, cond.type == BOOKTYPE_PET)
inrange = getCached(cache, IsSpellInRange, sbid, cond.type, "target")
elseif cond.type == "any" then
local sbid = getCached(addon.longtermCache, FindSpellBookSlotBySpellID, spellid, false)
if sbid ~= nil then
inrange = getCached(cache, IsSpellInRange, sbid, BOOKTYPE_SPELL, "target")
else
sbid = getCached(cache, FindSpellBookSlotBySpellID, spellid, true)
if sbid ~= nil then
inrange = getCached(cache, IsSpellInRange, sbid, BOOKTYPE_PET, "target")
end
end
elseif cond.type == "item" then
inrange = getCached(cache, IsItemInRange, itemids[idx], "target")
end
enabled = (inrange ~= nil and inrange or true)
end
end
end
end
end
return spellid, enabled
end
self.evaluationProfile:child("rotation"):start()
local rot = self.db.profile.rotations[self.currentSpec][self.currentRotation]
if rot.rotation ~= nil then
local enabled
local preview = 0
if self.nextWindow then
self.nextWindow:ReleaseChildren()
self.nextWindow:PauseLayout()
end
for id, cond in pairs(rot.rotation) do
if cond.type == "none" and (cond.disabled == nil or cond.disabled == false) and
addon:evaluateCondition(cond.conditions) then
break
end
local spellid
spellid, enabled = eval(cond)
if spellid and enabled then
preview = preview + 1
if preview == 1 then
self.currentSpell = spellid
addon:verbose("Rotation step %d satisfied it's condition.", id)
if not addon:IsGlowing(spellid) then
if not self.db.profile.disable_buttons then
addon:GlowNextSpell(spellid)
end
if WeakAuras then
WeakAuras.ScanEvents("ROTATIONMASTER_SPELL_UPDATE", cond.type, spellid)
end
AceEvent:SendMessage("ROTATIONMASTER_SPELL_UPDATE", self.currentRotation, id, cond.id, cond.type, spellid)
end
end
if self.nextWindow then
local icon = AceGUI:Create("Icon")
local name, _, img = GetSpellInfo(spellid)
icon:SetImage(img)
if preview == 1 then
icon:SetImageSize(54, 54)
else
icon:SetImageSize(36, 36)
end
icon:SetLabel(name)
icon:SetCallback("OnEnter", function()
GameTooltip:SetOwner(icon.frame, "ANCHOR_BOTTOMRIGHT", 3)
GameTooltip:SetHyperlink("spell:" .. spellid)
end)
icon:SetCallback("OnLeave", function()
if GameTooltip:IsOwned(icon.frame) then
GameTooltip:Hide()
end
end)
addon.nextWindow:AddChild(icon)
if preview >= self.db.profile.preview_spells then
break
end
else
break
end
else
addon:verbose("Rotation step %d did not satisfy it's condition.", id)
end
end
if not enabled then
if not self.db.profile.disable_buttons then
addon:GlowClear()
end
if WeakAuras then
WeakAuras.ScanEvents("ROTATIONMASTER_SPELL_UPDATE", nil, nil)
end
AceEvent:SendMessage("ROTATIONMASTER_SPELL_UPDATE", self.currentRotation, nil)
end
if self.nextWindow then
self.nextWindow:ResumeLayout()
self.nextWindow:DoLayout()
end
end
self.evaluationProfile:child("rotation"):stop()
self.evaluationProfile:child("cooldowns"):start()
if rot.cooldowns ~= nil then
local enabled_cooldowns = {}
local disabled_cooldowns = {}
for id, cond in pairs(rot.cooldowns) do
local spellid, enabled = eval(cond)