-
Notifications
You must be signed in to change notification settings - Fork 10
/
FiveSecondRule.lua
executable file
·226 lines (179 loc) · 6.18 KB
/
FiveSecondRule.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
-- NAMESPACE / CLASS: FiveSecondRule
-- OPTIONS: FiveSecondRule_Options
FiveSecondRule = CreateFrame("Frame")
do -- Private Scope
local ADDON_NAME = "FiveSecondRule"
local defaults = {
["enabled"] = true,
["unlocked"] = false,
["integrateIntoPlayerFrame"] = false,
["showTicks"] = true,
["barWidth"] = 117,
["barHeight"] = 11,
["barLeft"] = 90,
["barTop"] = -68,
["flat"] = false,
["showText"] = true,
["showSpark"] = true,
["alwaysShowTicks"] = false,
["enableCountdown"] = true,
["forceTrackDruidEnergy"] = false,
["statusBarColor"] = {0,0,1,0.95},
["statusBarBackgroundColor"] = {0,0,0,0.55},
["manaTicksColor"] = {0.95, 0.95, 0.95, 1},
["manaTicksBackgroundColor"] = {0.35, 0.35, 0.35, 0.8},
}
-- STATE VARIABLES
FiveSecondRule.gainingMana = false
FiveSecondRule.mp5StartTime = 0
FiveSecondRule.rapidRegenStartTime = nil
FiveSecondRule.previousPower = 0
-- REGISTER EVENTS
FiveSecondRule:RegisterEvent("ADDON_LOADED")
FiveSecondRule:RegisterEvent("PLAYER_ENTERING_WORLD")
FiveSecondRule:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
FiveSecondRule:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
FiveSecondRule:RegisterEvent("PLAYER_UNGHOST")
FiveSecondRule:SetScript("OnEvent", function(self, event, arg1, ...) onEvent(self, event, arg1, ...) end);
-- INITIALIZATION
function Init()
LoadOptions()
if (select(2, UnitClass("player")) == "WARRIOR") then
-- Disable the addon for warriors, since there is no reliable power or life to track in order to show power ticks.
DisableAddon()
return
else
EnableAddon()
end
TickBar:LoadSpells() -- LOCALIZATION
FiveSecondRule:Refresh()
end
function IsWOTLK()
local _, _, _, tocversion = GetBuildInfo()
return tocversion >= 30400
end
function DisableAddon()
StatusBar.statusbar:Hide()
TickBar.tickbar:Hide()
FiveSecondRule:SetScript("OnUpdate", nil)
end
function EnableAddon()
FiveSecondRule:SetScript("OnUpdate", function(self, sinceLastUpdate) onUpdate(sinceLastUpdate); end);
end
function LoadOptions()
FiveSecondRule_Options = FiveSecondRule_Options or AddonUtils:deepcopy(defaults)
for key,value in pairs(defaults) do
if (FiveSecondRule_Options[key] == nil) then
FiveSecondRule_Options[key] = value
end
end
if (IsWOTLK()) then
FiveSecondRule_Options["alwaysShowTicks"] = false
FiveSecondRule_Options["showTicks"] = false
end
FiveSecondRule_Options.unlocked = false
end
function onEvent(self, event, arg1, ...)
if event == "ADDON_LOADED" then
if arg1 == ADDON_NAME then
Init()
end
end
if not FiveSecondRule_Options.enabled then
return
end
if event == "PLAYER_ENTERING_WORLD" then
savePlayerPower()
end
if event == "PLAYER_EQUIPMENT_CHANGED" then
savePlayerPower()
end
if event == "UNIT_SPELLCAST_SUCCEEDED" then
-- Make sure we spent mana, as free casts do not trigger FSR.
if arg1 == "player" and GetPower() < FiveSecondRule.previousPower then
-- Only show the FSR for classes using mana
-- Subsequently, this also means that the tick bar won't be hidden for classes not using mana (rogue)
if (FiveSecondRule.GetPowerType() == 0) then
FiveSecondRule.gainingMana = false
savePlayerPower()
FiveSecondRule.mp5StartTime = GetTime() + 5
TickBar.tickbar:Hide()
StatusBar.statusbar:Show()
end
end
end
end
function onUpdate(sinceLastUpdate)
if (not FiveSecondRule_Options.enabled) or UnitIsDead("player") then
StatusBar.statusbar:Hide()
TickBar.tickbar:Hide()
return
end
-- time needs to be defined for this to work
if (GetTime() == nil) then
savePlayerPower()
return
end
StatusBar:OnUpdate()
TickBar:OnUpdate()
savePlayerPower()
end
function GetPower()
return UnitPower("player", GetPowerType())
end
function GetPowerMax()
return UnitPowerMax("player", GetPowerType())
end
function GetPowerType()
local class = select(2, UnitClass("player"))
if class == "DRUID" and FiveSecondRule_Options.forceTrackDruidEnergy then
return 3
end
if class == "ROGUE" then
return 3
else
return 0
end
end
function savePlayerPower()
FiveSecondRule.previousPower = GetPower()
end
function SpellIdToName(id)
local name, _, _, _, _, _ = GetSpellInfo(id)
return name
end
function Refresh()
StatusBar:Refresh()
TickBar:Refresh()
end
function Unlock()
FiveSecondRule_Options.unlocked = true
StatusBar:Unlock()
TickBar:Unlock()
end
function Lock()
FiveSecondRule_Options.unlocked = false
StatusBar:Lock()
TickBar:Lock()
end
function Reset()
StatusBar:Reset()
TickBar:Reset()
FiveSecondRule_Options = AddonUtils:deepcopy(defaults)
Init()
end
function PrintNotSupported()
local colorHex = "ed2d2d"
print("|cff"..colorHex.."FiveSecondRule is not supported in this game version.")
print("|cff"..colorHex.."The addon has been automatically disable with effect from your next UI reload.")
end
-- Expose Field Variables and Functions
FiveSecondRule.Unlock = Unlock
FiveSecondRule.Lock = Lock
FiveSecondRule.Reset = Reset
FiveSecondRule.Refresh = Refresh
FiveSecondRule.GetPower = GetPower
FiveSecondRule.GetPowerMax = GetPowerMax
FiveSecondRule.GetPowerType = GetPowerType
FiveSecondRule.IsWOTLK = IsWOTLK
end