This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
309 lines (268 loc) · 6.99 KB
/
core.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
--[[================
=== Core ===
================]]--
-- Core functions
local addon, ns = ...
ns.wham = CreateFrame("Frame", "Wham", UIParent)
ns.wham:SetPoint("LEFT", UIParent, 95, 0)
ns.wham:SetSize(ns.width, ns.height)
ns.wham:RegisterEvent("GROUP_ROSTER_UPDATE")
ns.wham:RegisterEvent("PLAYER_ENTERING_WORLD")
ns.wham:RegisterEvent("UNIT_PET")
ns.wham:RegisterEvent("CHAT_MSG_ADDON")
-- In the guidDB is stored all player and pet information
ns.guidDB = {
players = {},
pets = {},
rank = {},
whamUsers = {},
}
function ns.wham:addUnitToDB(unit, owner)
local guid = UnitGUID(unit)
if not guid or guid == "" then return end
local unitType = bit.band(tonumber("0x"..strsub(guid, 3,5)), 0x00f)
local name, realm = UnitName(unit)
if not name or name == "Unknown" then return end
-- Players
if unitType == 8 then
local realm = realm and realm ~= "" and "-"..realm or ""
local _, class, race, _, _ = GetPlayerInfoByGUID(guid)
if not ns.guidDB.players[guid] then
ns.guidDB.players[guid] = {
["name"] = name..realm,
["class"] = class,
["classcolor"] = RAID_CLASS_COLORS[class],
}
end
-- Pets or Vehicles
elseif unitType == 4 or unitType == 3 then
if not ns.guidDB.pets[guid] then
ns.guidDB.pets[guid] = {
["name"] = name,
["owner"] = owner,
}
end
end
end
function ns.wham:UpdateWatchedPlayers()
-- Delete old table
if ns.cleanOnGrpChange == true then
for k in pairs(ns.guidDB) do
ns.guidDB[k] = nil
end
end
-- Insert player name
ns.wham:addUnitToDB("player")
-- Insert playerpet name
if UnitExists("playerpet") then
ns.wham:addUnitToDB("playerpet", UnitName("player"))
end
-- Insert party members & pets
local isInGroup = IsInGroup("player")
if isInGroup then
for i=1, GetNumSubgroupMembers() do
ns.wham:addUnitToDB("party"..i)
if UnitExists("partypet"..i) then
ns.wham:addUnitToDB(("partypet"..i), UnitName("party"..i))
end
end
end
-- Insert raid members & pets
local isInRaid = IsInRaid("player")
if isInRaid then
for i=1, GetNumGroupMembers() do
ns.wham:addUnitToDB("raid"..i)
if UnitExists("raidpet"..i) then
ns.wham:addUnitToDB(("raidpet"..i), UnitName("raid"..i))
end
end
end
-- Delete Data of "old" players
ns.resetData()
-- Insert player names into rank-table
for _, guid in pairs(ns.guidDB.players) do
ns.guidDB.rank[#ns.guidDB.rank+1] = guid.name
end
end
-- Upate on certain events
ns.wham.GROUP_ROSTER_UPDATE = ns.wham.UpdateWatchedPlayers
ns.wham.UNIT_PET = ns.wham.UpdateWatchedPlayers
function ns.wham.PLAYER_ENTERING_WORLD()
RegisterAddonMessagePrefix("Wham_TOKEN")
ns.wham:UpdateWatchedPlayers()
ns.wham:sendToken()
if ns.wham.UpdateLayout then
ns.wham:UpdateLayout()
end
end
-- Sending the token, so other's can identify us, like we can idetify them as Wham-Users
function ns.wham:sendToken()
if IsInGroup("player") then
local channel = IsInRaid("player") and "RAID" or "PARTY"
SendAddonMessage("Wham_TOKEN", nil, channel)
end
end
function ns.wham:CHAT_MSG_ADDON(self, arg1, arg2, arg3, arg4)
local prefix, msg, channel, sender = arg1, arg2, arg3, arg4
if prefix == "Wham_TOKEN" then
tinsert(ns.guidDB.whamUsers, sender)
end
end
-- Select recieved mode as activeMode
function ns.switchMode(selectedMode)
ns.activeMode = selectedMode
-- Use the selected data
if selectedMode == "Damage" and ns.activatedModules["Current Fight Data"] == true then
ns.modeTotal = ns.curTotaldmg
ns.modeData = ns.curData
elseif selectedMode == "Damage" then
ns.modeTotal = ns.totaldmg
ns.modeData = ns.dmgData
elseif selectedMode == "Damage Taken" then
ns.modeTotal = ns.totaldmgtaken
ns.modeData = ns.dmgtakenData
elseif selectedMode == "Heal" then
ns.modeTotal = ns.totalheal
ns.modeData = ns.healData
elseif selectedMode == "OverHeal" then
ns.modeTotal = ns.totaloverheal
ns.modeData = ns.overhealData
elseif selectedMode == "Absorb" then
ns.modeTotal = ns.totalabsorb
ns.modeData = ns.absorbData
elseif selectedMode == "Deaths" then
ns.modeTotal = ns.totaldeaths
ns.modeData = ns.deathData
elseif selectedMode == "Dispels" then
ns.modeTotal = ns.totaldispels
ns.modeData = ns.dispelData
elseif selectedMode == "Interrupts" then
ns.modeTotal = ns.totalinterrupts
ns.modeData = ns.interruptData
end
if ns.switchModeEvent then
ns.switchModeEvent()
end
end
-- Sortingfunction (Damage)
function ns.sortByDamage(a, b)
if ns.activatedModules["Current Fight Data"] == true and ns.curData then
return (ns.curData[a] or 0) > (ns.curData[b] or 0)
else
if ns.dmgData then
return (ns.dmgData[a] or 0) > (ns.dmgData[b] or 0)
end
end
end
-- Sortingfunction (Damage Taken)
function ns.sortByDamageTaken(a, b)
if ns.dmgtakenData then
return (ns.dmgtakenData[a] or 0) > (ns.dmgtakenData[b] or 0)
end
end
-- Sortingfunction (Heal)
function ns.sortByHeal(a, b)
if ns.healData then
return (ns.healData[a] or 0) > (ns.healData[b] or 0)
end
end
-- Sortingfunction (OverHeal)
function ns.sortByOverHeal(a, b)
if ns.overhealData then
return (ns.overhealData[a] or 0) > (ns.overhealData[b] or 0)
end
end
-- Sortingfunction (Absorb)
function ns.sortByAbsorb(a, b)
if ns.absorbData then
return (ns.absorbData[a] or 0) > (ns.absorbData[b] or 0)
end
end
-- Sortingfunction (Deaths)
function ns.sortByDeaths(a, b)
if ns.deathData then
return (ns.deathData[a] or 0) > (ns.deathData[b] or 0)
end
end
-- Sortingfunction (Dispels)
function ns.sortByDispels(a, b)
if ns.dispelData then
return (ns.dispelData[a] or 0) > (ns.dispelData[b] or 0)
end
end
-- Sortingfunction (Interrupts)
function ns.sortByInterrupts(a, b)
if ns.interruptData then
return (ns.interruptData[a] or 0) > (ns.interruptData[b] or 0)
end
end
-- Resettingfunction (reset all collected data)
function ns.resetData()
if ns.curData then
for k in pairs(ns.curData) do
ns.curData[k] = nil
end
end
if ns.dmgData then
for k in pairs(ns.dmgData) do
ns.dmgData[k] = nil
end
end
if ns.overdmgData then
for k in pairs(ns.overdmgData) do
ns.overdmgData[k] = nil
end
end
if ns.dmgtakenData then
for k in pairs(ns.dmgtakenData) do
ns.dmgtakenData[k] = nil
end
end
if ns.healData then
for k in pairs(ns.healData) do
ns.healData[k] = nil
end
end
if ns.overhealData then
for k in pairs(ns.overhealData) do
ns.overhealData[k] = nil
end
end
if ns.absorbData then
for k in pairs(ns.absorbData) do
ns.absorbData[k] = nil
end
end
if ns.deathData then
for k in pairs(ns.deathData) do
ns.deathData[k] = nil
end
end
if ns.dispelData then
for k in pairs(ns.dispelData) do
ns.dispelData[k] = nil
end
end
if ns.interruptData then
for k in pairs(ns.interruptData) do
ns.interruptData[k] = nil
end
end
if ns.combatTotalTime then
ns.combatTotalTime = 0
end
if ns.layoutSpecificReset then
ns.layoutSpecificReset()
end
-- Clear rank-table
for k in ipairs(ns.guidDB.rank) do
ns.guidDB.rank[k] = nil
end
end
ns.wham:SetScript("OnEvent", function(self, event, ...)
if(self[event]) then
self[event](self, event, ...)
else
print("Wham debug: "..event)
end
end)