-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoaura.lua
341 lines (303 loc) · 11 KB
/
autoaura.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
--[==[
Copyright ©2020 Porthios of Myzrael
The contents of this addon, excluding third-party resources, are
copyrighted to Porthios with all rights reserved.
This addon is free to use and the authors hereby grants you the following rights:
1. You may make modifications to this addon for private use only, you
may not publicize any portion of this addon.
2. Do not modify the name of this addon, including the addon folders.
3. This copyright notice shall be included in all copies or substantial
portions of the Software.
All rights not explicitly addressed in this license are reserved by
the copyright holders.
fontstring = Frame:CreateFontString(["name" [, "layer" [, "inherits"]]])
https://wowwiki.fandom.com/wiki/UI_Object_UIDropDownMenu
https://www.wowinterface.com/forums/showthread.php?t=40444
-- notes: if unitid ~= "player" then return end
]==]--
local app_name = "AutoAura"
local app_global = "|cffDA70D6" .. app_name .. ": |r"
local app_font = "Fonts/ARIALN.ttf"
local app_version= 1.24
local title_color= "|cffFF7D0A"
local only_tank_key = "OnlyTankRole"
print(app_global .. "Initializing v" .. app_version .. "...")
local function getPlayerInformation()
player_name = UnitName("player")
return player_name
end
local playerName = getPlayerInformation() .. "-" .. GetRealmName()
AANotification = {}
local function clearNotifications()
AANotification:Hide()
end
local _GTime = 1
local function fadeNotification()
_GTime = _GTime -0.020
--print(_GTime)
AANotification.text:SetTextColor(1,1,1,_GTime)
if (_GTime <= 0.01) then
_GTime = 1
--print("clear")
clearNotifications()
else
C_Timer.After(0.20, fadeNotification)
end
end
local function Notification(msg, color)
AANotification:Show()
AANotification.text:SetText(app_global .. "|cff" .. color .. msg)
_GTime = 1
AANotification.text:SetTextColor(1,1,1,_GTime)
timerReset = C_Timer.NewTimer(1, fadeNotification())
timerReset:Cancel()
--[==[
C_Timer.After(6, function()
fadeNotification()
end)
]==]--
end
local function CancelPlayerBuff(buffName, buffIndex)
local i = 0
if (UnitAffectingCombat('player')) then
Notification("Unable to remove [" .. buffName .. "] during combat!", "ff0000")
else
Notification(buffName .. " removed!", "ffffff")
CancelUnitBuff("player", buffIndex)
end
end
local checkbox = {}
local buffList = {
{"ARSalv", "Blessing of Salvation", "Interface/Icons/Spell_Holy_GreaterBlessingofSalvation"},
{"ARMight", "Blessing of Might", "Interface/Icons/Spell_Holy_GreaterBlessingofKings"},
{"ARSanc", "Blessing of Sanctuary", "Interface/Icons/Spell_Holy_GreaterBlessingofSanctuary"},
{"ARInt", "Arcane Brilliance", "Interface/Icons/Spell_Holy_ArcaneIntellect"},
{"ARPoS", "Prayer of Spirit", "Interface/Icons/Spell_Holy_PrayerofSpirit"},
{"ARThorns","Thorns", "Interface/Icons/Spell_Nature_Thorns"},
}
--[==[
for k,v in pairs(buffList) do
print(k .. " " .. v[1])
end
]==]--
local function handleAuras()
local total = 1
if (checkbox[only_tank_key]:GetChecked()) then
local playerClass, englishClass = UnitClass("player")
local form = GetShapeshiftForm()
-- print(app_global .. playerClass .. " " .. englishClass .. " " .. form )
if (englishClass == "DRUID") then
if (form ~= 1) then return end -- druid bear form
end
if (englishClass == "WARRIOR") then
if (form ~= 2) then return end -- warrior defensive stance
end
end
while UnitBuff("player", total) do
local buff = UnitBuff("player", total)
for k,v in pairs(buffList) do
local localBuff = v[2]
if (checkbox[v[1]]:GetChecked()) then
if string.find(buff, localBuff) then
CancelPlayerBuff(localBuff, total)
end
end
end
total = total + 1
end
end
local AAFrame = CreateFrame("Frame")
AAFrame:RegisterEvent("ADDON_LOADED")
AAFrame:RegisterEvent("PLAYER_LOGOUT")
AAFrame:RegisterEvent("UNIT_AURA")
AAFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
AAFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
AAFrame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "AutoAura" then
if AutoAura == nil then
AutoAura = {}
end
if AutoAura[playerName] == nil then
AutoAura[playerName] = {}
print(app_global .. "Creating New Profile: " .. playerName)
else
print(app_global .. "Loading Profile: " .. playerName)
setAutoAuraVars()
end
end
if event == "UNIT_AURA" then
handleAuras()
end
if event == "UPDATE_SHAPESHIFT_FORM" then
handleAuras()
end
if event == "PLAYER_REGEN_ENABLED" then -- leaves combat for all
handleAuras()
end
end)
SLASH_AutoAura1 = "/AutoAura"
SLASH_AutoAura2 = "/aa"
function SlashCmdList.AutoAura(msg)
-- print("debug " .. AutoAura)
end
local buttonMinimap ={}
local function split(s, delimiter)
result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
function setAutoAuraVars()
for k,v in pairs(buffList) do
if (AutoAura[playerName][v[1]]) then
checkbox[v[1]]:SetChecked(true)
end
end
if (AutoAura[playerName]["HideMMI"]) then
checkbox["HideMMI"]:SetChecked(true)
buttonMinimap:Hide()
end
if (AutoAura[playerName][only_tank_key]) then
checkbox[only_tank_key]:SetChecked(true)
end
if (AutoAura[playerName]["ICONPOS"]) then
minimapIconPos = split(AutoAura[playerName]["ICONPOS"], ",")
if ((minimapIconPos[1]) and (minimapIconPos[2])) then
buttonMinimap:SetPoint("TOPLEFT", Minimap, "TOPLEFT", minimapIconPos[1]+130, minimapIconPos[2]+22)
end
end
end
function saveAutoAuraVars()
for k,v in pairs(buffList) do
AutoAura[playerName][v[1]] = checkbox[v[1]]:GetChecked()
end
AutoAura[playerName]["HideMMI"] = checkbox["HideMMI"]:GetChecked()
if (checkbox["HideMMI"]:GetChecked()) then
buttonMinimap:Hide()
else
buttonMinimap:Show()
end
AutoAura[playerName][only_tank_key] = checkbox[only_tank_key]:GetChecked()
end
local AAFrameMain = CreateFrame("Frame", nil, UIParent, "BasicFrameTemplateWithInset")
AAFrameMain:SetWidth(260)
AAFrameMain:SetHeight(360)
AAFrameMain:SetPoint("CENTER", 0, 0)
AAFrameMain:SetMovable(true)
AAFrameMain.text = AAFrameMain:CreateFontString(nil,"ARTWORK")
AAFrameMain.text:SetFont(app_font, 13, "OUTLINE")
AAFrameMain.text:SetPoint("TOPLEFT", AAFrameMain, "TOPLEFT", 10, -5)
AAFrameMain.text:SetText("|cffFF7D0AAUTO AURA v" .. app_version)
AAFrameMain:Hide()
local AAProfileText = CreateFrame("Frame",nil, AAFrameMain)
AAProfileText:SetSize(100, 30)
AAProfileText:SetPoint("TOPLEFT", 10, -40)
AAProfileText.text=AAProfileText:CreateFontString(nil, "ARTWORK")
AAProfileText.text:SetFont(app_font, 15, "OUTLINE")
AAProfileText.text:SetPoint("TOPLEFT", 0, 0)
AAProfileText.text:SetText(title_color .. "Profile")
local AAProfileChar = CreateFrame("Frame",nil, AAFrameMain)
AAProfileChar:SetWidth(100)
AAProfileChar:SetHeight(30)
AAProfileChar:SetPoint("TOPLEFT", 20, -30)
AAProfileChar.text=AAProfileChar:CreateFontString(nil, "ARTWORK")
AAProfileChar.text:SetFont(app_font, 14, "OUTLINE")
AAProfileChar.text:SetPoint("TOPLEFT", 20, -30)
AAProfileChar.text:SetText(UnitName("player") .. " [" .. GetRealmName() .. "]")
AANotification = CreateFrame("Frame", nil, UIParent)
AANotification:SetWidth(300)
AANotification:SetHeight(30)
AANotification:SetPoint("BOTTOMLEFT", 30, 350)
AANotification:SetFrameLevel(500)
AANotification.text = AANotification:CreateFontString(nil, "ARTWORK")
AANotification.text:SetFont(app_font, 16)
AANotification.text:SetPoint("TOPLEFT", 0, 0)
AANotification.text:SetText("")
AANotification.text:SetTextColor(1, 1, 1, 1)
AANotification:Hide()
function checkItem(checkID, checkName, icon, posY)
local check_static = CreateFrame("CheckButton", nil, AAFrameMain, "ChatConfigCheckButtonTemplate")
check_static:SetPoint("TOPLEFT", 30, posY)
check_static.text = check_static:CreateFontString(nil,"ARTWORK")
check_static.text:SetFont(app_font, 14, "OUTLINE")
check_static.text:SetPoint("TOPLEFT", check_static, "TOPLEFT", 50, -5)
check_static.text:SetText(checkName)
-- check_static.tooltip = checkID
local licon = check_static:CreateTexture(nil, "BACKGROUND", nil, -6)
licon:SetTexture(icon)
licon:SetSize(16, 16)
licon:SetPoint("TOPLEFT", 30, -3)
check_static:SetScript("OnClick",
function()
saveAutoAuraVars()
end
)
checkbox[checkID] = check_static
end
local frameTextBuffs = CreateFrame("Frame",nil, AAFrameMain)
frameTextBuffs:SetSize(100, 30)
frameTextBuffs:SetPoint("TOPLEFT", 10, -100)
frameTextBuffs.text=frameTextBuffs:CreateFontString(nil, "ARTWORK")
frameTextBuffs.text:SetFont(app_font, 15, "OUTLINE")
frameTextBuffs.text:SetPoint("TOPLEFT", 0, 0)
frameTextBuffs.text:SetText(title_color .. "Auto Remove")
local frameTextConfig = CreateFrame("Frame",nil, AAFrameMain)
frameTextConfig:SetSize(100, 30)
frameTextConfig:SetPoint("TOPLEFT", 10, -270)
frameTextConfig.text=frameTextConfig:CreateFontString(nil, "ARTWORK")
frameTextConfig.text:SetFont(app_font, 15, "OUTLINE")
frameTextConfig.text:SetPoint("TOPLEFT", 0, 0)
frameTextConfig.text:SetText(title_color .. "Config")
local checkPos_y = 100
for k,v in pairs(buffList) do
checkPos_y = checkPos_y +20
checkItem(v[1], v[2], v[3], -checkPos_y)
end
checkItem("HideMMI", "Hide Minimap Icon", "", -290)
checkItem(only_tank_key, "Only for tank roles", "", -310)
local function openWindow()
AAFrameMain:Show()
end
local function closeWindow()
AAFrameMain:Hide()
end
SlashCmdList["AutoAura"] = function(msg)
openWindow()
end
buttonMinimap = CreateFrame("Button", nil, Minimap)
buttonMinimap:SetFrameLevel(499)
buttonMinimap:SetFrameStrata("TOOLTIP")
buttonMinimap:SetSize(26, 26)
buttonMinimap:SetMovable(true)
local MMIcon = "Interface/Addons/" .. app_name .. "/images/icon_aa"
buttonMinimap:SetNormalTexture(MMIcon)
buttonMinimap:SetPushedTexture(MMIcon)
buttonMinimap:SetHighlightTexture(MMIcon)
local myIconPos = 0
local function UpdateMapButton()
local Xpoa, Ypoa = GetCursorPosition()
local Xmin, Ymin = Minimap:GetLeft(), Minimap:GetBottom()
Xpoa = Xmin - Xpoa / Minimap:GetEffectiveScale() + 70
Ypoa = Ypoa / Minimap:GetEffectiveScale() - Ymin - 70
myIconPos = math.deg(math.atan2(Ypoa, Xpoa))
buttonMinimap:ClearAllPoints()
buttonMinimap:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 60 - (80 * cos(myIconPos)), (80 * sin(myIconPos)) - 56)
end
buttonMinimap:RegisterForDrag("LeftButton")
buttonMinimap:SetScript("OnDragStart", function()
buttonMinimap:StartMoving()
buttonMinimap:SetScript("OnUpdate", UpdateMapButton)
end)
buttonMinimap:SetScript("OnDragStop", function()
buttonMinimap:StopMovingOrSizing()
buttonMinimap:SetScript("OnUpdate", nil)
local point, relativeTo, relativePoint, xOfs, yOfs = buttonMinimap:GetPoint()
AutoAura[playerName]["ICONPOS"] = math.ceil(xOfs) .. "," .. math.ceil(yOfs)
UpdateMapButton()
end)
buttonMinimap:ClearAllPoints()
buttonMinimap:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 60 - (80 * cos(myIconPos)),(80 * sin(myIconPos)) - 56)
buttonMinimap:SetScript("OnClick", function()
openWindow()
end)