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
342
343
344
345
346
347
348
349
350
351
352
353
354
|
--[[
The entire mergedplayer file exists to flatten individual stats in the db
into two numbers (per name). So normally the db is:
dps_db.dp[mob_name][player_name] = {stats}
Mergedplayer iterates over mob_name and returns a table that's just:
tab[player_name] = {CalculatedStatA,CalculatedStatB}
]]
local MergedPlayer = {}
function MergedPlayer:new (o)
o = o or {}
assert(o.players and #o.players > 0,
"MergedPlayer constructor requires at least one Player instance.")
setmetatable(o, self)
self.__index = self
return o
end
--[[
'wsmin', 'wsmax', 'wsavg'
]]
function MergedPlayer:mavg()
local hits, hit_dmg = 0, 0
for _, p in ipairs(self.players) do
hits = hits + p.m_hits
hit_dmg = hit_dmg + p.m_hits*p.m_avg
end
if hits > 0 then
return { hit_dmg / hits, hits}
else
return {0, 0}
end
end
function MergedPlayer:mrange()
local m_min, m_max = math.huge, 0
for _, p in ipairs(self.players) do
m_min = math.min(m_min, p.m_min)
m_max = math.max(m_max, p.m_max)
end
return {m_min~=math.huge and m_min or m_max, m_max}
end
function MergedPlayer:critavg()
local crits, crit_dmg = 0, 0
for _, p in ipairs(self.players) do
crits = crits + p.m_crits
crit_dmg = crit_dmg + p.m_crits*p.m_crit_avg
end
if crits > 0 then
return { crit_dmg / crits, crits}
else
return {0, 0}
end
end
function MergedPlayer:critrange()
local m_crit_min, m_crit_max = math.huge, 0
for _, p in ipairs(self.players) do
m_crit_min = math.min(m_crit_min, p.m_crit_min)
m_crit_max = math.max(m_crit_max, p.m_crit_max)
end
return {m_crit_min~=math.huge and m_crit_min or m_crit_max, m_crit_max}
end
function MergedPlayer:ravg()
local r_hits, r_hit_dmg = 0, 0
for _, p in ipairs(self.players) do
r_hits = r_hits + p.r_hits
r_hit_dmg = r_hit_dmg + p.r_hits*p.r_avg
end
if r_hits > 0 then
return { r_hit_dmg / r_hits, r_hits}
else
return {0, 0}
end
end
function MergedPlayer:rrange()
local r_min, r_max = math.huge, 0
for _, p in ipairs(self.players) do
r_min = math.min(r_min, p.r_min)
r_max = math.max(r_max, p.r_max)
end
return {r_min~=math.huge and r_min or r_max, r_max}
end
function MergedPlayer:rcritavg()
local r_crits, r_crit_dmg = 0, 0
for _, p in ipairs(self.players) do
r_crits = r_crits + p.r_crits
r_crit_dmg = r_crit_dmg + p.r_crits*p.r_crit_avg
end
if r_crits > 0 then
return { r_crit_dmg / r_crits, r_crits}
else
return {0, 0}
end
end
function MergedPlayer:rcritrange()
local r_crit_min, r_crit_max = math.huge, 0
for _, p in ipairs(self.players) do
r_crit_min = math.min(r_crit_min, p.r_crit_min)
r_crit_max = math.max(r_crit_max, p.r_crit_max)
end
return {r_crit_min~=math.huge and r_crit_min or r_crit_max, r_crit_max}
end
function MergedPlayer:acc()
local hits, crits, misses = 0, 0, 0
for _, p in ipairs(self.players) do
hits = hits + p.m_hits
crits = crits + p.m_crits
misses = misses + p.m_misses
end
local total = hits + crits + misses
if total > 0 then
return {(hits + crits) / total, total}
else
return {0, 0}
end
end
function MergedPlayer:racc()
local hits, crits, misses = 0, 0, 0
for _, p in ipairs(self.players) do
hits = hits + p.r_hits
crits = crits + p.r_crits
misses = misses + p.r_misses
end
local total = hits + crits + misses
if total > 0 then
return {(hits + crits) / total, total}
else
return {0, 0}
end
end
function MergedPlayer:crit()
local hits, crits = 0, 0
for _, p in ipairs(self.players) do
hits = hits + p.m_hits
crits = crits + p.m_crits
end
local total = hits + crits
if total > 0 then
return {crits / total, total}
else
return {0, 0}
end
end
function MergedPlayer:rcrit()
local hits, crits = 0, 0
for _, p in ipairs(self.players) do
hits = hits + p.r_hits
crits = crits + p.r_crits
end
local total = hits + crits
if total > 0 then
return {crits / total, total}
else
return {0, 0}
end
end
function MergedPlayer:wsavg()
local wsdmg = 0
local wscount = 0
--[[
for _, p in pairs(self.players) do
for _, dmgtable in pairs(p.ws) do
for _, dmg in pairs(dmgtable) do
wsdmg = wsdmg + dmg
wscount = wscount + 1
end
end
end
]]
for _, p in pairs(self.players) do
for _, dmg in pairs(p.ws) do
wsdmg = wsdmg + dmg
wscount = wscount + 1
end
end
if wscount > 0 then
return {wsdmg / wscount, wscount}
else
return {0, 0}
end
end
function MergedPlayer:wsacc()
local hits, misses = 0, 0
for _, p in ipairs(self.players) do
hits = hits + table.length(p.ws)
misses = misses + p.ws_misses
end
local total = hits + misses
if total > 0 then
return {hits / total, total}
else
return {0, 0}
end
end
-- Unused atm
function MergedPlayer:merge(other)
self.damage = self.damage + other.damage
for ws_id, values in pairs(other.ws) do
if self.ws[ws_id] then
for _, value in ipairs(values) do
self.ws[ws_id]:append(value)
end
else
self.ws[ws_id] = table.copy(values)
end
end
self.m_hits = self.m_hits + other.m_hits
self.m_misses = self.m_misses + other.m_misses
self.m_min = math.min(self.m_min, other.m_min)
self.m_max = math.max(self.m_max, other.m_max)
local total_m_hits = self.m_hits + other.m_hits
if total_m_hits > 0 then
self.m_avg = self.m_avg * self.m_hits/total_m_hits +
other.m_avg * other.m_hits/total_m_hits
else
self.m_avg = 0
end
self.m_crits = self.m_crits + other.m_crits
self.m_crit_min = math.min(self.m_crit_min, other.m_crit_min)
self.m_crit_max = math.max(self.m_crit_max, other.m_crit_max)
local total_m_crits = self.m_crits + other.m_crits
if total_m_crits > 0 then
self.m_crit_avg = self.m_crit_avg * self.m_crits / total_m_crits +
other.m_crit_avg * other.m_crits / total_m_crits
else
self.m_crit_avg = 0
end
self.r_hits = self.r_hits + other.r_hits
self.r_misses = self.r_misses + other.r_misses
self.r_min = math.min(self.r_min, other.r_min)
self.r_max = math.max(self.r_max, other.r_max)
local total_r_hits = self.r_hits + other.r_hits
if total_r_hits > 0 then
self.r_avg = self.r_avg * self.r_hits/total_r_hits +
other.r_avg * other.r_hits/total_r_hits
else
self.r_avg = 0
end
self.r_crits = self.r_crits + other.r_crits
self.r_crit_min = math.min(self.r_crit_min, other.r_crit_min)
self.r_crit_max = math.max(self.r_crit_max, other.r_crit_max)
local total_r_crits = self.r_crits + other.r_crits
if total_r_crits > 0 then
self.r_crit_avg = self.r_crit_avg * self.r_crits / total_r_crits +
other.r_crit_avg * other.r_crits / total_r_crits
else
self.r_crit_avg = 0
end
self.jobabils = self.jobabils + other.jobabils
self.spells = self.spells + other.spells
end
return MergedPlayer
--[[
Copyright (c) 2013, Jerry Hebert
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Scoreboard nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL JERRY HEBERT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
|