-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSplits.lua
188 lines (153 loc) · 4.28 KB
/
Splits.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
function WarpDeplete:UpdateSplits()
self:PrintDebug("Updating splits")
local splits = self:GetSplitsForCurrentInstance()
if not splits then
self:PrintDebug("Could not get splits for current instance")
return
end
local best = splits.best
if not best then
best = {}
splits.best = best
end
local current = splits.current
if not current then
current = {}
splits.current = current
end
local currentDiff = splits.currentDiff
if not currentDiff then
currentDiff = {}
splits.currentDiff = currentDiff
end
for i, boss in ipairs(self.state.objectives) do
if boss.time and boss.time ~= current[i] then
self:PrintDebug("Setting current time for " .. tostring(i) .. ": " .. tostring(boss.time))
current[i] = boss.time
if best[i] then
currentDiff[i] = boss.time - best[i]
self:PrintDebug("Setting diff for " .. tostring(i) .. " to " .. tostring(currentDiff[i]))
end
elseif not boss.time then
current[i] = nil
currentDiff[i] = nil
end
end
if self.state.forcesCompleted and self.state.forcesCompletionTime ~= current.forces then
self:PrintDebug("Setting current time for forces")
current.forces = self.state.forcesCompletionTime
if best.forces then
currentDiff.forces = self.state.forcesCompletionTime - best.forces
self:PrintDebug("Setting diff for forces to " .. tostring(currentDiff.forces))
end
elseif not self.state.forcesCompleted then
current.forces = nil
currentDiff.forces = nil
end
if self.state.challengeCompleted and self.state.completionTimeMs ~= current.challenge then
self:PrintDebug("Setting current time for challenge")
current.challenge = self.state.completionTimeMs
if best.challenge then
currentDiff.challenge = self.state.completionTimeMs - best.challenge
self:PrintDebug("Setting diff for challenge to " .. tostring(currentDiff.challenge))
end
elseif not self.state.challengeCompleted then
current.challenge = nil
currentDiff.challenge = nil
end
self:PrintDebug("Splits updated")
end
---@param objective integer|"forces"|"challenge"
function WarpDeplete:GetCurrentDiff(objective)
if self.state.demoModeActive then
if type(objective) == "number" then
return -60 + (objective * 30)
end
if objective == "forces" then
return -40
end
if objective == "challenge" then
return 100 * 1000
end
return 0
end
local splits = self:GetSplitsForCurrentInstance()
if not splits then
return nil
end
local currentDiff = splits.currentDiff
if not currentDiff then
return nil
end
return currentDiff[objective]
end
---@param objective integer|"forces"|"challenge"
function WarpDeplete:GetBestSplit(objective)
if self.state.demoModeActive then
if type(objective) == "number" then
return 60 * 3 * objective
end
if objective == "forces" then
return 60 * 30
end
if objective == "challenge" then
return 60 * 36 * 1000
end
return 0
end
local splits = self:GetSplitsForCurrentInstance()
if not splits then
return nil
end
local best = splits.best
if not best then
return nil
end
return best[objective]
end
function WarpDeplete:GetSplitsForCurrentInstance()
if not self.state.mapId or not self.state.level then
return nil
end
return self:GetSplits(self.state.mapId, self.state.level)
end
function WarpDeplete:GetSplits(mapId, keystoneLevel)
local mapSplits = self.db.global.splits[mapId]
if not mapSplits then
mapSplits = {}
self.db.global.splits[mapId] = mapSplits
end
local keystoneSplits = mapSplits[keystoneLevel]
if not keystoneSplits then
keystoneSplits = {}
mapSplits[keystoneLevel] = keystoneSplits
end
return keystoneSplits
end
function WarpDeplete:ResetCurrentSplits()
local splits = self:GetSplitsForCurrentInstance()
if not splits then
return
end
splits.current = {}
splits.currentDiff = {}
end
function WarpDeplete:UpdateBestSplits()
local splits = self:GetSplitsForCurrentInstance()
if not splits or not splits.current then
return
end
if not splits.best then
splits.best = {}
end
for k, v in pairs(splits.current) do
self:PrintDebug("Updating best split for objective " .. tostring(k))
if not splits.best[k] then
self:PrintDebug("No best time found, setting " .. tostring(v))
splits.best[k] = v
elseif splits.best[k] > v then
self:PrintDebug("Better time found, setting " .. tostring(v))
splits.best[k] = v
end
end
end