forked from Floliroy/SpeedRun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeedrun.lua
More file actions
229 lines (209 loc) · 5.65 KB
/
Speedrun.lua
File metadata and controls
229 lines (209 loc) · 5.65 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
local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
-----------------
---- Globals ----
-----------------
Speedrun = {}
Speedrun.name = "Speedrun"
Speedrun.version = "0.1"
Speedrun.raidList = {
[1] = {
name = "AA",
id = 638,
bestTimer,
timerSteps = {},
},
[2] = {
name = "HRC",
id = 636,
bestTimer,
timerSteps = {},
},
[3] = {
name = "SO",
id = 639,
bestTimer,
timerSteps = {},
},
[4] = {
name = "MoL",
id = 725,
bestTimer,
timerSteps = {},
},
[5] = {
name = "HoF",
id = 975,
bestTimer,
timerSteps = {},
},
[6] = {
name = "SO",
id = 1000,
bestTimer,
timerSteps = {},
},
[7] = {
name = "CR",
id = 1051,
bestTimer,
timerSteps = {},
},
[8] = {
name = "BRP",
id = 1082,
bestTimer,
timerSteps = {},
},
[9] = {
name = "MA",
id = 677,
bestTimer,
timerSteps = {},
},
[10] = {
name = "DSA",
id = 635,
bestTimer,
timerSteps = {},
},
}
---------------------------
---- Variables Default ----
---------------------------
Speedrun.Default = {
}
-------------------------
---- Settings Window ----
-------------------------
function Speedrun.CreateSettingsWindow()
--TODO switch in settings window in another file and complete it
local panelData = {
type = "panel",
name = "Speedrun",
displayName = "SpeedRun",
author = "Floliroy",
version = Speedrun.version,
slashCommand = "/speedrun",
registerForRefresh = true,
registerForDefaults = true,
}
local cntrlOptionsPanel = LAM2:RegisterAddonPanel("Speedrun_Settings", panelData)
local optionsData = {
[1] = {
type = "header",
name = "Header",
},
[2] = {
type = "description",
text = "Description",
},
}
LAM2:RegisterOptionControls("Speedrun_Settings", optionsData)
end
-------------------
---- Functions ----
-------------------
function Speedrun.Test()
--if IsRaidInProgress() then
-- d("|cffffffTest: |r" .. math.floor(GetRaidDuration() / 1000))
--end
if DoesUnitExist("reticleover") then
local currentTargetHP, maxTargetHP, effmaxTargetHP = GetUnitPower("reticleover", POWERTYPE_HEALTH)
if currentTargetHP <= 0 then
d("Test 0 HP")
else
d("Test en Vie")
end
end
end
function Speedrun.GetScore(timer, vitality, raidID)
if raidID == 638 then --AA
return (124300 + (1000 * vitality)) * (1 + (900 - timer) / 10000)
elseif raidID == 636 then --HRC
return (133100 + (1000 * vitality)) * (1 + (900 - timer) / 10000)
elseif raidID == 639 then --SO
return (142700 + (1000 * vitality)) * (1 + (1500 - timer) / 10000)
elseif raidID == 725 then --MoL
return (108150 + (1000 * vitality)) * (1 + (2700 - timer) / 10000)
elseif raidID == 975 then --HoF
return (160100 + (1000 * vitality)) * (1 + (2700 - timer) / 10000)
elseif raidID == 1000 then --AS
return (70000 + (1000 * vitality)) * (1 + (1200 - timer) / 10000)
elseif raidID == 1051 then --CR
if Speedrun.addsOnCR == 1 then
return (85750 + (1000 * vitality)) * (1 + (1200 - timer) / 10000)
else
return (88000 + (1000 * vitality)) * (1 + (1200 - timer) / 10000)
end
elseif raidID == 1082 then --BRP
return (75000 + (1000 * vitality)) * (1 + (2400 - timer) / 10000)
elseif raidID == 677 then --MA
return (426000 + (1000 * vitality)) * (1 + (5400 - timer) / 10000)
elseif raidID == 635 then --DSA
return (20000 + (1000 * vitality)) * (1 + (3600 - timer) / 10000)
end
end
function Speedrun.UpdateWaypoint(waypoint)
for i=1, Speedrun.raidList.getn() do
local raid = Speedrun.raidList[i]
if raid.id == GetZoneId(GetUnitZoneIndex("player")) then
--TODO Speedrun.UpdateWindowPanel
if raid.timerSteps.waypoint > math.floor(GetRaidDuration() / 1000) then
raid.timerSteps.waypoint = math.floor(GetRaidDuration() / 1000)
end
return
end
end
end
function Speedrun.Main()
for i = 1, MAX_BOSSES do
if DoesUnitExist("boss" .. i) then
if IsUnitInCombat("player") then
--Begin fight with a boss
else
local currentTargetHP, maxTargetHP, effmaxTargetHP = GetUnitPower("boss" .. i, POWERTYPE_HEALTH)
if currentTargetHP <= 0 then
--End fight with a boss
end
end
end
end
end
function Speedrun.Reset()
--TODO : test
--When EVENT_BOSSES_CHANGED and EVENT_PLAYER_COMBAT_STATE proc
--Maybe EVENT_PLAYER_ACTIVATED also
for i=1, Speedrun.raidList.getn() do
if Speedrun.raidList[i].id == GetZoneId(GetUnitZoneIndex("player")) then --if in trial zone
if IsRaidInProgress() then --if vet trial started
EVENT_MANAGER:RegisterForEvent(Speedrun.name,EVENT_BOSSES_CHANGED, Speedrun.Main)
EVENT_MANAGER:RegisterForEvent(Speedrun.name,EVENT_PLAYER_COMBAT_STATE, Speedrun.Main)
EVENT_MANAGER:RegisterForUpdate(Speedrun.name, 900, Speedrun.UpdateWindowPanel)
return
end
else
EVENT_MANAGER:UnregisterForEvent(Speedrun.name,EVENT_BOSSES_CHANGED, Speedrun.Main)
EVENT_MANAGER:UnregisterForEvent(Speedrun.name,EVENT_PLAYER_COMBAT_STATE, Speedrun.Main)
EVENT_MANAGER:UnregisterForUpdate(Speedrun.name)
end
end
end
function Speedrun:Initialize()
--Settings
Speedrun.CreateSettingsWindow()
--Saved Variables
Speedrun.savedVariables = ZO_SavedVars:New("SpeedrunVariables", 1, nil, Speedrun.Default)
--EVENT_MANAGER
EVENT_MANAGER:RegisterForUpdate(Speedrun.name, 500, Speedrun.Test)
--EVENT_MANAGER:RegisterForEvent(Speedrun.name, EVENT_ZONE_CHANGED, Speedrun.Reset)
EVENT_MANAGER:UnregisterForEvent(Speedrun.name, EVENT_ADD_ON_LOADED)
end
function Speedrun.SaveLoc()
Speedrun.savedVariables.OffsetX = SpeedrunAlert:GetLeft()
Speedrun.savedVariables.OffsetY = SpeedrunAlert:GetTop()
end
function Speedrun.OnAddOnLoaded(event, addonName)
if addonName ~= Speedrun.name then return end
Speedrun:Initialize()
end
EVENT_MANAGER:RegisterForEvent(Speedrun.name, EVENT_ADD_ON_LOADED, Speedrun.OnAddOnLoaded)