-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVortexMeter_Players.lua
332 lines (284 loc) · 7.37 KB
/
VortexMeter_Players.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
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
---------------------------------------------------------------------------------------
-- Vortex Meter
--- Maintained by Vim <Codex>
--- Original addon : Rift Meter by Vince (http://www.curse.com/addons/rift/rift-meter)
local VortexMeter = VortexMeter
local L = VortexMeter.L
local Abilities = VortexMeter.Abilities
local Ability = VortexMeter.Meta.Ability
local Player = VortexMeter.Meta.Player
Player.__index = Player
function Player:new(unit, reduced)
local self = {}
self.detail = unit
self.reduced = reduced
self.damage = 0
self.damageTaken = 0
self.friendlyFire = 0
self.overkill = 0
self.heal = 0
self.healTaken = 0
self.absorb = 0
self.absorbTaken = 0
self.overheal = 0
self.interrupts = 0
if reduced then
self.abilities = {}
self.linkedToOwner = false
self.pets = false
self.interactions = false
else
self.linkedToOwner = false
self.pets = {}
self.interactions = {
damage = {},
damageTaken = {},
friendlyFire = {},
overkill = {},
heal = {},
healTaken = {},
absorb = {},
absorbTaken = {},
overheal = {},
interrupts = {}
}
end
return setmetatable(self, Player)
end
function Player:addStat(interactedWith, statType, stat, amount, info)
local ability = self:addAbility(interactedWith, statType, stat, amount, info)
if not ability.filter then
self[statType] = self[statType] + amount
end
end
function Player:addAbility(interactedWith, statType, stat, amount, info)
local abilityDetail = Abilities[info.ability:GetId() .. (info.periodic and "1" or "0")]
if self.reduced then
local ability = self.abilities[abilityDetail]
if not ability then
ability = Ability:new(info)
self.abilities[abilityDetail] = ability
end
ability:add(stat, amount, info)
end
if not self.reduced and self.interactions then
local key = interactedWith and interactedWith or L["Unknown"]
local player = self.interactions[statType][key]
if not player then
player = self:new(interactedWith, true)
if not player.detail then
player.detail = { name = key }
end
self.interactions[statType][key] = player
end
player:addStat(interactedWith, statType, stat, amount, info)
end
return abilityDetail
end
function Player:getStat(sort)
local stat = self[sort]
for _, value in pairs(self.pets) do
stat = stat + value[sort]
end
return stat
end
function Player:getInteractions(sort)
local data = {
interactions = {},
count = 0,
max = 1,
total = 1
}
local interactions = {}
for _, interaction in pairs(self.interactions[sort]) do
table.insert(interactions, interaction)
end
table.sort(interactions, function (a, b)
return a[sort] > b[sort]
end)
for _, interaction in pairs(interactions) do
local value = interaction[sort]
local name = interaction.detail.name
table.insert(data.interactions, {
name = name,
value = value,
ref = interaction
})
data.total = data.total + value
data.count = data.count + 1
end
if data.count > 0 then
data.max = math.max(data.interactions[1].value, 1)
end
return data
end
function Player:getAbility(ability, sort)
local returnAbility
for _, interaction in pairs(self.interactions[sort]) do
for _, ability2 in pairs(interaction.abilities) do
if ability.name == ability2.name then
if not returnAbility then
returnAbility = ability2:clone()
else
returnAbility:merge(ability2)
end
end
end
end
return returnAbility
end
function Player:getAbilities(sort)
local abilities = {}
for _, interaction in pairs(self.interactions[sort]) do
for _, ability in pairs(interaction.abilities) do
local found = false
for _, insertedAbility in pairs(abilities) do
if insertedAbility.name == ability.name then
found = true
insertedAbility:merge(ability)
end
end
if not found then
table.insert(abilities, ability:clone())
end
end
end
for _, pet in pairs(self.pets) do
for _, interaction in pairs(pet.interactions[sort]) do
for _, ability in pairs(interaction.abilities) do
local found = false
for _, insertedAbility in pairs(abilities) do
if insertedAbility.name == ability.name then
found = true
insertedAbility:merge(ability)
end
end
if not found then
table.insert(abilities, ability:clone())
end
end
end
end
table.sort(abilities, function (a, b)
return a.total > b.total
end)
return abilities
end
function Player:getPreparedAbilityData(sort)
local data = {
abilities = {},
count = 0,
max = 1,
total = 0
}
local abilities = self:getAbilities(sort)
for _, ability in pairs(abilities) do
local value = ability.total
table.insert(data.abilities, {
value = value,
ref = ability
})
data.total = data.total + value
data.count = data.count + 1
end
data.total = math.max(data.total, 1)
if data.count > 0 then
data.max = math.max(data.abilities[1].value, 1)
end
return data
end
function Player:getInteractionAbilityData()
local data = {
abilities = {},
count = 0,
max = 1,
total = 0
}
local abilities = {}
for _, ability in pairs(self.abilities) do
table.insert(abilities, ability)
end
table.sort(abilities, function (a, b)
return a.total > b.total
end)
for _, ability in pairs(abilities) do
local value = ability.total
table.insert(data.abilities, {
value = value,
ref = ability
})
data.total = data.total + value
data.count = data.count + 1
end
data.total = math.max(data.total, 1)
if data.count > 0 then
data.max = math.max(data.abilities[1].value, 1)
end
return data
end
function Player:createFakeAbility()
local fakeAbility = Ability:new({ability = {GetId = function() return nil end}})
local backup = fakeAbility.getPreparedAbilityStatData
local player = self
fakeAbility.detail = {
name = L["Total"],
icon = "",
type = "none",
filter = false,
}
fakeAbility.name = L["Total"]
function fakeAbility:getPreparedAbilityStatData(combat, sort)
-- force update on retrieve
self.total = 0
self.totalHit = 0
self.totalCrit = 0
self.totalMultiHit = 0
self.max = 0
self.min = 0
self.hits = 0
self.crits = 0
self.multihits = 0
self.swings = 0
self.glances = 0
self.filtered = 0
self.interrupts = 0
self.deflects = 0
if player.interactions then -- real player
for _, interaction in pairs(player.interactions[sort]) do
for _, ability in pairs(interaction.abilities) do
self:merge(ability)
end
end
else -- interacted player
for _, ability in pairs(player.abilities) do
self:merge(ability)
end
end
return backup(self, combat)
end
return fakeAbility
end
function Player:getTooltip(sort)
local result = {"<P TextColor=\"FFFFD100\">" .. L["Top 3 Abilities:"] .. "</P>"}
local players = {}
for _, player in pairs(self.interactions[sort]) do
table.insert(players, player)
end
table.sort(players, function(a, b)
return a[sort] > b[sort]
end)
local abilities = self:getAbilities(sort)
for i = 1, 3 do
if abilities[i] then
table.insert(result, (" (%d%%) %s"):format(abilities[i].total / self:getStat(sort) * 100, abilities[i].name:sub(0, 16)))
end
end
table.insert(result, "<P TextColor=\"FFFFD100\">" .. L["Top 3 Interactions:"] .. "</P>")
for i = 1, 3 do
if players[i] then
table.insert(result, (" (%d%%) %s"):format(players[i][sort] / self:getStat(sort) * 100, players[i].detail.name:sub(0, 16)))
end
end
table.insert(result, "<P TextColor=\"FF33FF33\"><" .. L["Middle-Click for interactions"] .. "></P>")
return table.concat(result, "\n")
end