forked from Road-block/RogueFocus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRogueFocus.lua
More file actions
315 lines (279 loc) · 9.95 KB
/
RogueFocus.lua
File metadata and controls
315 lines (279 loc) · 9.95 KB
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
----------------------------------------------------------------------------------------------------
-- Rogue Focus: Core
----------------------------------------------------------------------------------------------------
local _G = getfenv(0)
RogueFocus = {
Version = "1.0.4",
Lock = 1,
Class = "",
InCombat = false,
InStealth = false,
InOther = false,
Registered = false
}
local RogueFocusFrames = {}
local RogueFocusStealth = {
["Interface\\Icons\\Ability_Stealth"] = true,
["Interface\\Icons\\Ability_Ambush"] = true,
["Interface\\Icons\\ability_druid_prowl"] = true
}
local RogueFocus_Energy = {
Length = 2,
Alpha = 0.2,
Start = 0,
End = 0,
Mana = nil,
}
local RogueFocus_Default = {
Scale = 1.0,
InCombat = true,
InStealth = true,
InOther = true,
Audible = false,
Locked = false,
}
----------------------------------------------------------------------------------------------------
-- Blade Rush Talent Handler
----------------------------------------------------------------------------------------------------
local function GetEnergyTickRate()
local baseTickRate = 2.0 -- Base 2 seconds
-- Check for Blade Rush talent (tab 2, talent 16)
local _, _, _, _, currRank = GetTalentInfo(2, 16)
local bladeRushRank = currRank or 0
if bladeRushRank > 0 then
local agility = UnitStat("player", 2) -- 2 is agility stat index
local reductionPerAgi = 0.0006 * bladeRushRank -- 0.0006 for rank 1, 0.0012 for rank 2
local totalReduction = agility * reductionPerAgi
baseTickRate = baseTickRate - totalReduction
-- Ensure we don't go below a reasonable minimum (e.g., 0.5 seconds)
if baseTickRate < 0.5 then
baseTickRate = 0.5
end
end
return baseTickRate
end
function RogueFocus:UpdateEnergyTickRate()
RogueFocus_Energy.Length = GetEnergyTickRate()
end
----------------------------------------------------------------------------------------------------
-- Widgets Handlers
----------------------------------------------------------------------------------------------------
function RogueFocus:OnLoad()
localizedClass, RogueFocus.Class = UnitClass("player")
RogueFocus.Registered = RogueFocus:RegisterEvents()
if((not RogueFocusConfig) or (not RogueFocusConfig.Version) or (RogueFocusConfig.Version ~= RogueFocus.Version)) then
RogueFocusConfig = RogueFocus_Default
end
RogueFocus.InCombat = false
if (RogueFocus:inStealth()) then RogueFocus.InStealth = true else RogueFocus.InStealth = false end
function GetChildrenTree(Frame) --- Walk the frame hierarchy recursively adding children.
if Frame:GetChildren() then
for _,child in pairs({Frame:GetChildren()}) do
if child:IsMouseEnabled() then
tinsert(RogueFocusFrames,child)
end
GetChildrenTree(child)
end
end
end
GetChildrenTree(RogueFocusFrame)
-- Calculate initial energy tick rate
RogueFocus:UpdateEnergyTickRate()
RogueFocus:Toggle()
-- It seems that all has gone well till now. Hi there!
DEFAULT_CHAT_FRAME:AddMessage(ROGUEFOCUS_WELCOME)
end
function RogueFocus:OnEvent(eventArg)
if(not RogueFocus.Registered) then return end
if(eventArg == "VARIABLES_LOADED") then
if(RogueFocus.Registered) then
-- Scaling
RogueFocusFrame:SetScale(RogueFocusConfig.Scale)
-- Combo, Energy
local Frame
for i = 1, 5, 1 do
Frame = _G["RogueFocusCombo"..i]
Frame:SetStatusBarColor(1, 0, 0)
Frame:SetMinMaxValues(0, 1)
Frame:SetValue(0)
end
-- Energy ticks
RogueFocus_Energy.Mana = UnitMana("player")
-- Update energy tick rate
RogueFocus:UpdateEnergyTickRate()
-- Energy ticks text
RogueFocusEnergyTickText:SetText(ROGUEFOCUS_ENERGY)
-- Create slash events
SLASH_ROGUEFOCUS1 = "/rfc"
SLASH_ROGUEFOCUS2 = "/roguefocus"
SlashCmdList["ROGUEFOCUS"] = function() RogueFocusOptions:Handler() end
end
elseif (UnitIsDeadOrGhost("player")) then
RogueFocus.InCombat = false
RogueFocus:UpdateEnergyBar()
RogueFocusFrame:Hide()
elseif ((eventArg == "PLAYER_AURAS_CHANGED")
or ((eventArg == "UNIT_AURA") and (arg1 == "player"))
or (eventArg == "UPDATE_SHAPESHIFT_FORMS")
or (eventArg == "UPDATE_BONUS_ACTIONBAR")) then
if (RogueFocus:inStealth()) then RogueFocus.InStealth = true else RogueFocus.InStealth = false end
RogueFocus:Toggle()
elseif (eventArg == "PLAYER_COMBO_POINTS") then
RogueFocus:UpdateComboBar()
elseif(((eventArg == "UNIT_ENERGY") or (eventArg == "UNIT_MAXENERGY")) and (arg1 == "player")) then
RogueFocus:UpdateEnergyBar()
elseif(eventArg == "PLAYER_REGEN_DISABLED") then
RogueFocus.InCombat = true
RogueFocus:Toggle()
elseif(eventArg == "PLAYER_REGEN_ENABLED") then
RogueFocus.InCombat = false
RogueFocus:Toggle()
elseif(eventArg == "PLAYER_ENTERING_WORLD") then
RogueFocus:Toggle()
elseif(eventArg == "PLAYER_DEAD") then
RogueFocus.InCombat = false
RogueFocus:Toggle()
-- Update energy tick rate when talents or stats change
elseif(eventArg == "CHARACTER_POINTS_CHANGED" or eventArg == "UNIT_STATS" and arg1 == "player") then
RogueFocus:UpdateEnergyTickRate()
end
end
function RogueFocus:OnUpdate()
if(RogueFocus.Registered) then
local energy = UnitMana("player")
local currentTime = GetTime()
local sparkPosition = 1
if(energy > RogueFocus_Energy.Mana or currentTime >= RogueFocus_Energy.End) then
RogueFocus_Energy.Mana = energy
RogueFocus_Energy.Start = currentTime
RogueFocus_Energy.End = currentTime + RogueFocus_Energy.Length
if (RogueFocusConfig.Audible) then PlaySound("UChatScrollButton") end
else
if(RogueFocus_Energy.Mana ~= energy) then
RogueFocus_Energy.Mana = energy
end
sparkPosition = ((currentTime - RogueFocus_Energy.Start) / (RogueFocus_Energy.End - RogueFocus_Energy.Start)) * 99
end
RogueFocusEnergyTickBar:SetMinMaxValues(RogueFocus_Energy.Start, RogueFocus_Energy.End)
RogueFocusEnergyTickBar:SetValue(currentTime)
if(sparkPosition < 1) then
sparkPosition = 1
end
RogueFocusEnergyTickSpark:SetPoint("CENTER", "RogueFocusEnergyTickBar", "LEFT", sparkPosition, 0)
end
end
----------------------------------------------------------------------------------------------------
-- Events Handlers
----------------------------------------------------------------------------------------------------
function RogueFocus:UpdateComboBar()
local c = GetComboPoints()
local comboBar = {0, 0, 0, 0, 0}
local barColor = {[0] = {1, 0, 0}, {1, 0, 0}, {1, 0, 0}, {1, 1, 0}, {1, 1, 0}, {0, 1, 0}}
local Frame
for i = 1, c, 1 do
comboBar[i] = 1
end
for i = 1, 5, 1 do
Frame = _G["RogueFocusCombo"..i]
Frame:SetStatusBarColor(barColor[c][1], barColor[c][2], barColor[c][3])
Frame:SetValue(comboBar[i])
end
end
-- Author: Masso
function RogueFocus:UpdateEnergyBar()
local value, max = UnitMana("player"), UnitManaMax("player")
local text = value.." / "..max
local Frame = _G["RogueFocusEnergyBar"]
Frame:SetMinMaxValues(0, max)
Frame:SetValue(value)
RogueFocusEnergyText:SetText(text)
end
function RogueFocus:Toggle()
-- first of all: is he a rogue or a druid cat? No? HIDE!
if (not(RogueFocus:IsSupported())) then
RogueFocusFrame:Hide()
-- second: check the show cases. Is he in combat and the combat option is checked? SHOW!
elseif (RogueFocus.InCombat and RogueFocusConfig.InCombat) then
RogueFocusFrame:Show()
-- third: check the show cases. Is he in stealth and the stealth option is checked? SHOW!
elseif (RogueFocus.InStealth and RogueFocusConfig.InStealth) then
RogueFocusFrame:Show()
-- fourth: check the show cases. Now he's not in combat nor in stealth so he's in the other cases. Is the other cases option checked? SHOW!
elseif (RogueFocusConfig.InOther and not(RogueFocus.InCombat) and not(RogueFocus.InStealth)) then
RogueFocusFrame:Show()
-- fifth: there are no more cases! So now? HIDE!
else
RogueFocusFrame:Hide()
end
-- check lock status and enable/disable mouse.
if RogueFocusFrame:IsVisible() then
if RogueFocusConfig.Locked then
RogueFocusFrame:EnableMouse(false)
for _,childframe in pairs (RogueFocusFrames) do
childframe:EnableMouse(false)
end
else
RogueFocusFrame:EnableMouse(true)
for _,childframe in pairs (RogueFocusFrames) do
childframe:EnableMouse(true)
end
end
end
end
----------------------------------------------------------------------------------------------------
-- Main
----------------------------------------------------------------------------------------------------
function RogueFocus:RegisterEvents()
if(RogueFocus.Class ~= "ROGUE" and RogueFocus.Class ~= "DRUID") then
this:UnregisterEvent("PLAYER_COMBO_POINTS")
this:UnregisterEvent("PLAYER_AURAS_CHANGED")
this:UnregisterEvent("PLAYER_REGEN_DISABLED")
this:UnregisterEvent("PLAYER_REGEN_ENABLED")
this:UnregisterEvent("PLAYER_ENTERING_WORLD")
this:UnregisterEvent("PLAYER_DEAD")
this:UnregisterEvent("UNIT_ENERGY")
this:UnregisterEvent("UNIT_MAXENERGY")
this:UnregisterEvent("UNIT_AURA")
this:UnregisterEvent("UPDATE_SHAPESHIFT_FORMS")
this:UnregisterEvent("UPDATE_BONUS_ACTIONBAR")
this:UnregisterEvent("VARIABLES_LOADED")
this:UnregisterEvent("CHARACTER_POINTS_CHANGED")
this:UnregisterEvent("UNIT_STATS")
return false
else
this:RegisterForDrag("LeftButton")
this:RegisterEvent("PLAYER_COMBO_POINTS")
this:RegisterEvent("PLAYER_AURAS_CHANGED")
this:RegisterEvent("PLAYER_REGEN_DISABLED")
this:RegisterEvent("PLAYER_REGEN_ENABLED")
this:RegisterEvent("PLAYER_ENTERING_WORLD")
this:RegisterEvent("PLAYER_DEAD")
this:RegisterEvent("UNIT_ENERGY")
this:RegisterEvent("UNIT_MAXENERGY")
this:RegisterEvent("UNIT_AURA")
this:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
this:RegisterEvent("UPDATE_BONUS_ACTIONBAR")
this:RegisterEvent("VARIABLES_LOADED")
this:RegisterEvent("CHARACTER_POINTS_CHANGED")
this:RegisterEvent("UNIT_STATS")
return true
end
end
function RogueFocus:IsSupported()
if ( UnitPowerType("player") == 3 ) then
return true
else
return false
end
end
function RogueFocus:inStealth()
local i = 0
while GetPlayerBuffTexture(i) ~= nil do
if RogueFocusStealth[(GetPlayerBuffTexture(i))] == true then
return true
else
i = i + 1
end
end
return false
end