-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTankMD.lua
133 lines (111 loc) · 3.61 KB
/
TankMD.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
---@type string
local addonName = ...
---@class AddonNamespace
local addon = select(2, ...)
local AceAddon = LibStub("AceAddon-3.0")
local AceDB = LibStub("AceDB-3.0")
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceDBOptions = LibStub("AceDBOptions-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("TankMD")
---@class TankMD: AceAddon, AceEvent-3.0, AceConsole-3.0
local TankMD = AceAddon:NewAddon("TankMD", "AceEvent-3.0", "AceConsole-3.0")
---@type MisdirectButton[]
TankMD.buttons = {}
TankMD.isUpdateQueued = false
function TankMD:OnInitialize()
addon.db = AceDB:New("TankMDDB", addon.defaultProfile)
self:RegisterEvent("GROUP_ROSTER_UPDATE", "QueueButtonTargetUpdate")
self:RegisterEvent("PLAYER_FOCUS_CHANGED", "QueueButtonTargetUpdate")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "QueueButtonTargetUpdate")
self:RegisterEvent("PLAYER_REGEN_ENABLED", "ProcessQueuedButtonTargetUpdate")
end
function TankMD:OnEnable()
self:CreateMisdirectButtons()
self:RegisterChatCommand("tankmd", "SlashCommand")
AceConfig:RegisterOptionsTable(addonName, addon.optionsTable)
AceConfigDialog:AddToBlizOptions(addonName, L.title)
local profiles = AceDBOptions:GetOptionsTable(addon.db)
AceConfig:RegisterOptionsTable(addonName .. "_Profiles", profiles)
AceConfigDialog:AddToBlizOptions(addonName .. "_Profiles", L.profiles, L.title)
end
function TankMD:SlashCommand(args)
if args == "debug" then
for i, button in ipairs(self.buttons) do
self:Printf(
"Button %d: %s (%s)",
i,
button:GetTarget() or "no target",
button:IsEnabled() and "enabled" or "disabled"
)
end
else
for i, button in ipairs(self.buttons) do
if button:IsEnabled() and button:GetTarget() then
self:Printf(
L.button_target,
i,
button:GetTarget()
)
end
end
end
end
function TankMD:QueueButtonTargetUpdate()
self.isUpdateQueued = true
self:ProcessQueuedButtonTargetUpdate()
end
function TankMD:ProcessQueuedButtonTargetUpdate()
if not self.isUpdateQueued or InCombatLockdown() then return end
self.isUpdateQueued = false
local targets = self:GetTargets()
for i, button in ipairs(self.buttons) do
button:SetTarget(targets[i])
end
end
function TankMD:CreateMisdirectButtons()
if #self.buttons > 0 then return end -- only run once
local _, class = UnitClass("player")
local spell = self:GetMisdirectSpellID(class)
for i = 1, 5 do
local button = addon:CreateMisdirectButton(spell, i)
self.buttons[i] = button
end
self:QueueButtonTargetUpdate()
end
do
local misdirectSpells = {
["HUNTER"] = 34477,
["ROGUE"] = 57934,
["DRUID"] = 29166,
["EVOKER"] = 360827,
["PALADIN"] = 1044,
}
---@param class string
---@return integer spellID Spell id for the class's misdirect. Defaults to Misdirection if the class does not have a misdirect.
function TankMD:GetMisdirectSpellID(class)
return misdirectSpells[class] or misdirectSpells["HUNTER"]
end
end
do
-- What role to target with the ability
local targets = {
["HUNTER"] = "TANK",
["ROGUE"] = "TANK",
["DRUID"] = "HEALER",
["EVOKER"] = "TANK",
["PALADIN"] = "TANK",
}
---@param class string
---@return "TANK"|"HEALER" role Target role for the class's misdirect. Defaults to TANK if the class does not have a misdirect.
function TankMD:GetMisdirectTargetRole(class)
return targets[class] or "TANK"
end
end
---@return string[]
function TankMD:GetTargets()
local _, class = UnitClass("player")
local createSelector = addon.ClassTargetSelectors[class]
local selector = createSelector and createSelector() or addon.TargetSelector.Chain({})
return addon.TargetSelector.Evaluate(selector)
end