-
Notifications
You must be signed in to change notification settings - Fork 0
/
honorspy.lua
663 lines (594 loc) · 21.4 KB
/
honorspy.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
HonorSpy = LibStub("AceAddon-3.0"):NewAddon("HonorSpy", "AceConsole-3.0", "AceHook-3.0", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("HonorSpy", true)
local addonName = GetAddOnMetadata("HonorSpy", "Title");
local commPrefix = addonName .. "4";
local paused = false; -- pause all inspections when user opens inspect frame
local playerName = UnitName("player");
local callback = nil
local nameToTest = nil
local startRemovingFakes = false
function HonorSpy:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("HonorSpyDB", {
factionrealm = {
currentStandings = {},
last_reset = 0,
minimapButton = {hide = false},
actualCommPrefix = "",
fakePlayers = {},
goodPlayers = {}
},
char = {
today_kills = {},
estimated_honor = 0,
original_honor = 0
}
}, true)
self:SecureHook("InspectUnit");
self:SecureHook("UnitPopup_ShowMenu");
self:RegisterEvent("PLAYER_TARGET_CHANGED");
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
self:RegisterEvent("INSPECT_HONOR_UPDATE");
self:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN", CHAT_MSG_COMBAT_HONOR_GAIN_EVENT);
ChatFrame_AddMessageEventFilter("CHAT_MSG_COMBAT_HONOR_GAIN", CHAT_MSG_COMBAT_HONOR_GAIN_FILTER);
self:RegisterComm(commPrefix, "OnCommReceive")
self:RegisterEvent("PLAYER_DEAD");
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", FAKE_PLAYERS_FILTER);
DrawMinimapIcon();
HS_wait(5, function() HonorSpy:CheckNeedReset() end)
HonorSpyGUI:PrepareGUI()
PrintWelcomeMsg();
DBHealthCheck()
end
local inspectedPlayers = {}; -- stores last_checked time of all players met
local inspectedPlayerName = nil; -- name of currently inspected player
local function StartInspecting(unitID)
local name, realm = UnitName(unitID);
if (paused or (realm and realm ~= "")) then
return
end
if (name ~= inspectedPlayerName) then -- changed target, clear currently inspected player
ClearInspectPlayer();
inspectedPlayerName = nil;
end
if (name == nil
or name == inspectedPlayerName
or not UnitIsPlayer(unitID)
or not UnitIsFriend("player", unitID)
or not CheckInteractDistance(unitID, 1)
or not CanInspect(unitID)) then
return
end
local player = HonorSpy.db.factionrealm.currentStandings[name] or inspectedPlayers[name];
if (player == nil) then
inspectedPlayers[name] = {last_checked = 0};
player = inspectedPlayers[name];
end
if (GetServerTime() - player.last_checked < 30) then -- 30 seconds until new inspection request
return
end
-- we gonna inspect new player, clear old one
ClearInspectPlayer();
inspectedPlayerName = name;
player.unitID = unitID;
NotifyInspect(unitID);
RequestInspectHonorData();
_, player.rank = GetPVPRankInfo(UnitPVPRank(player.unitID)); -- rank must be get asap while mouse is still over a unit
_, player.class = UnitClass(player.unitID); -- same
end
function HonorSpy:INSPECT_HONOR_UPDATE()
if (inspectedPlayerName == nil or paused or not HasInspectHonorData()) then
return;
end
local player = self.db.factionrealm.currentStandings[inspectedPlayerName] or inspectedPlayers[inspectedPlayerName];
if (player.class == nil) then player.class = "nil" end
local _, _, _, _, thisweekHK, thisWeekHonor, _, lastWeekHonor, standing = GetInspectHonorData();
player.thisWeekHonor = thisWeekHonor;
player.lastWeekHonor = lastWeekHonor;
player.standing = standing;
player.rankProgress = GetInspectPVPRankProgress();
ClearInspectPlayer();
NotifyInspect("target"); -- change real target back to player's target, broken by prev NotifyInspect call
ClearInspectPlayer();
player.last_checked = GetServerTime();
player.RP = 0;
if (thisweekHK >= 15) then
if (player.rank >= 3) then
player.RP = math.ceil((player.rank-2) * 5000 + player.rankProgress * 5000)
elseif (player.rank == 2) then
player.RP = math.ceil(player.rankProgress * 3000 + 2000)
end
if (lastPlayer and lastPlayer.honor == thisWeekHonor and lastPlayer.name ~= inspectedPlayerName) then
return
end
lastPlayer = {name = inspectedPlayerName, honor = thisWeekHonor}
store_player(inspectedPlayerName, player)
broadcast(self:Serialize(inspectedPlayerName, player))
else
self.db.factionrealm.currentStandings[inspectedPlayerName] = nil
end
inspectedPlayers[inspectedPlayerName] = {last_checked = player.last_checked};
inspectedPlayerName = nil;
if callback then
callback()
callback = nil
end
end
-- parse message
-- COMBATLOG_HONORGAIN = "%s dies, honorable kill Rank: %s (Estimated Honor Points: %d)";
-- COMBATLOG_HONORAWARD = "You have been awarded %d honor points.";
local function parseHonorMessage(msg)
local honor_gain_pattern = string.gsub(COMBATLOG_HONORGAIN, "%(", "%%(")
honor_gain_pattern = string.gsub(honor_gain_pattern, "%)", "%%)")
honor_gain_pattern = string.gsub(honor_gain_pattern, "(%%s)", "(.+)")
honor_gain_pattern = string.gsub(honor_gain_pattern, "(%%d)", "(%%d+)")
local victim, rank, est_honor = msg:match(honor_gain_pattern)
if (victim) then
est_honor = math.max(0, math.floor(est_honor * (1-0.25*((HonorSpy.db.char.today_kills[victim] or 1)-1)) + 0.5))
end
local honor_award_pattern = string.gsub(COMBATLOG_HONORAWARD, "(%%d)", "(%%d+)")
local awarded_honor = msg:match(honor_award_pattern)
return victim, est_honor, awarded_honor
end
-- this is called before filter
function CHAT_MSG_COMBAT_HONOR_GAIN_EVENT(e, msg)
local victim, _, awarded_honor = parseHonorMessage(msg)
if victim then
HonorSpy.db.char.today_kills[victim] = (HonorSpy.db.char.today_kills[victim] or 0) + 1
local _, est_honor = parseHonorMessage(msg)
HonorSpy.db.char.estimated_honor = HonorSpy.db.char.estimated_honor + est_honor
elseif awarded_honor then
HonorSpy.db.char.estimated_honor = HonorSpy.db.char.estimated_honor + awarded_honor
end
end
-- this is called after eventg ww
function CHAT_MSG_COMBAT_HONOR_GAIN_FILTER(_s, e, msg, ...)
HonorSpy:CheckNeedReset()
local victim, est_honor, awarded_honor = parseHonorMessage(msg)
if (not victim) then
return
end
return false, format("%s kills: %d, honor: |cff00FF96%d", msg, HonorSpy.db.char.today_kills[victim] or 0, est_honor), ...
end
-- INSPECT HOOKS pausing to not mess with native inspect calls
-- pause when use opens target right click menu, as it breaks "inspect" button sometimes
function HonorSpy:UnitPopup_ShowMenu(s, menu, frame, name, id)
if (menu == "PLAYER" and not self:IsHooked(_G["DropDownList1"], "OnHide")) then
self:SecureHookScript(_G["DropDownList1"], "OnHide", "CloseDropDownMenu")
paused = true
return
end
end
function HonorSpy:CloseDropDownMenu()
self:Unhook(_G["DropDownList1"], "OnHide")
paused = false
end
-- pause when use opens inspect frame
function HonorSpy:InspectUnit(unitID)
paused = true;
if (not self:IsHooked(InspectFrame, "OnHide")) then
self:SecureHookScript(InspectFrame, "OnHide", "InspectFrameClose");
end
end
function HonorSpy:InspectFrameClose()
paused = false;
end
-- INSPECTION TRIGGERS
function HonorSpy:UPDATE_MOUSEOVER_UNIT()
StartInspecting("mouseover")
end
function HonorSpy:PLAYER_TARGET_CHANGED()
StartInspecting("target")
end
function HonorSpy:UpdatePlayerData(cb)
if (paused) then
return
end
callback = cb
StartInspecting("player")
end
-- CHAT COMMANDS
local options = {
name = 'HonorSpy',
type = 'group',
args = {
show = {
type = 'execute',
name = L['Show HonorSpy Standings'],
desc = L['Show HonorSpy Standings'],
func = function() HonorSpyGUI:Toggle() end
},
search = {
type = 'input',
name = L['Report specific player standings'],
desc = L['Report specific player standings'],
usage = L['player_name'],
get = false,
set = function(info, playerName) HonorSpy:Report(playerName) end
},
}
}
LibStub("AceConfig-3.0"):RegisterOptionsTable("HonorSpy", options, {"honorspy", "hs"})
function HonorSpy:BuildStandingsTable(sort_by)
local t = { }
for playerName, player in pairs(HonorSpy.db.factionrealm.currentStandings) do
table.insert(t, {playerName, player.class, player.thisWeekHonor or 0, player.lastWeekHonor or 0, player.standing or 0, player.RP or 0, player.rank or 0, player.last_checked or 0})
end
local sort_column = 3; -- ThisWeekHonor
if (sort_by == L["Standing"]) then sort_column = 4; end
if (sort_by == L["Rank"]) then sort_column = 6; end
local sort_func = function(a,b)
return a[sort_column] > b[sort_column]
end
table.sort(t, sort_func)
return t
end
-- REPORT
function HonorSpy:GetBrackets(pool_size)
-- 1 2 3 4 5 6 7 8 9 10 11 12 13 14
local brk = {1, 0.845, 0.697, 0.566, 0.436, 0.327, 0.228, 0.159, 0.100, 0.060, 0.035, 0.020, 0.008, 0.003} -- brackets percentage
if (not pool_size) then
return brk
end
for i = 1,14 do
brk[i] = math.floor(brk[i]*pool_size+.5)
end
return brk
end
function HonorSpy:Estimate(playerOfInterest)
if (not playerOfInterest) then
playerOfInterest = playerName
end
playerOfInterest = string.utf8upper(string.utf8sub(playerOfInterest, 1, 1))..string.utf8lower(string.utf8sub(playerOfInterest, 2))
local standing = -1;
local t = HonorSpy:BuildStandingsTable()
local avg_lastchecked = 0;
local pool_size = #t;
for i = 1, pool_size do
if (playerOfInterest == t[i][1]) then
standing = i
end
end
if (standing == -1) then
return
end;
local RP = {0, 400} -- RP for each bracket
local Ranks = {0, 2000} -- RP for each rank
local bracket = 1;
local inside_br_progress = 0;
local brk = self:GetBrackets(pool_size)
for i = 2,14 do
if (standing > brk[i]) then
inside_br_progress = (brk[i-1] - standing)/(brk[i-1] - brk[i])
break
end;
bracket = i;
end
if (bracket == 14 and standing == 1) then inside_br_progress = 1 end;
for i = 3,14 do
RP[i] = (i-2) * 1000;
Ranks[i] = (i-2) * 5000;
end
local award = RP[bracket] + 1000 * inside_br_progress;
local RP = HonorSpy.db.factionrealm.currentStandings[playerOfInterest].RP;
local EstRP = math.floor(RP*0.8+award+.5);
local Rank = HonorSpy.db.factionrealm.currentStandings[playerOfInterest].rank;
local EstRank = 14;
local Progress = math.floor(HonorSpy.db.factionrealm.currentStandings[playerOfInterest].rankProgress*100);
local EstProgress = math.floor((EstRP - math.floor(EstRP/5000)*5000) / 5000*100);
for i = 3,14 do
if (EstRP < Ranks[i]) then
EstRank = i-1;
break;
end
end
return pool_size, standing, bracket, RP, EstRP, Rank, Progress, EstRank, EstProgress
end
function HonorSpy:Report(playerOfInterest, skipUpdate)
if (not playerOfInterest) then
playerOfInterest = playerName
end
if (playerOfInterest == playerName) then
HonorSpy:UpdatePlayerData() -- will update for next time, this report gonna be for old data
end
playerOfInterest = string.utf8upper(string.utf8sub(playerOfInterest, 1, 1))..string.utf8lower(string.utf8sub(playerOfInterest, 2))
local pool_size, standing, bracket, RP, EstRP, Rank, Progress, EstRank, EstProgress = HonorSpy:Estimate(playerOfInterest)
if (not standing) then
self:Print(format(L["Player %s not found in table"], playerOfInterest));
return
end
local text = "- HonorSpy: "
if (playerOfInterest ~= playerName) then
text = text .. format("%s <%s>: ", L['Progress of'], playerOfInterest)
end
text = text .. format("%s = %d, %s = %d, %s = %d, %s = %d (%d%%), %s = %d (%d%%)", L["Standing"], standing, L["Bracket"], bracket, L["Next Week RP"], EstRP, L["Rank"], Rank, Progress, L["Next Week Rank"], EstRank, EstProgress)
SendChatMessage(text, "emote")
end
-- SYNCING --
function table.copy(t)
local u = { }
for k, v in pairs(t) do u[k] = v end
return setmetatable(u, getmetatable(t))
end
function class_exist(className)
if className == "WARRIOR" or
className == "PRIEST" or
className == "SHAMAN" or
className == "WARLOCK" or
className == "MAGE" or
className == "ROGUE" or
className == "HUNTER" or
className == "PALADIN" or
className == "DRUID" then
return true
end
return false
end
function playerIsValid(player)
if (not player.last_checked or type(player.last_checked) ~= "number" or player.last_checked < HonorSpy.db.factionrealm.last_reset + 24*60*60
or player.last_checked > GetServerTime()
or not player.thisWeekHonor or type(player.thisWeekHonor) ~= "number" or player.thisWeekHonor == 0
or not player.lastWeekHonor or type(player.lastWeekHonor) ~= "number"
or not player.standing or type(player.standing) ~= "number"
or not player.RP or type(player.RP) ~= "number"
or not player.rankProgress or type(player.rankProgress) ~= "number"
or not player.rank or type(player.rank) ~= "number"
or not player.class or not class_exist(player.class)
) then
return false
end
return true
end
function isFakePlayer(playerName)
if (HonorSpy.db.factionrealm.fakePlayers[playerName]) then
return true
end
return false
end
function store_player(playerName, player)
if (player == nil or playerName == nil or playerName:find("[%d%p%s%c%z]") or isFakePlayer(playerName) or not playerIsValid(player)) then return end
local player = table.copy(player);
local localPlayer = HonorSpy.db.factionrealm.currentStandings[playerName];
if (localPlayer == nil or localPlayer.last_checked < player.last_checked) then
HonorSpy.db.factionrealm.currentStandings[playerName] = player;
HonorSpy:TestNextFakePlayer();
end
end
function HonorSpy:OnCommReceive(prefix, message, distribution, sender)
if (distribution ~= "GUILD" and UnitRealmRelationship(sender) ~= 1) then
return -- discard any message from players from different servers (on x-realm BGs)
end
local ok, playerName, player = self:Deserialize(message);
if (not ok) then
return;
end
if (playerName == "filtered_players") then
for playerName, player in pairs(player) do
store_player(playerName, player);
end
return
end
store_player(playerName, player);
end
function broadcast(msg, skip_yell)
if (IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance()) then
HonorSpy:SendCommMessage(commPrefix, msg, "INSTANCE_CHAT");
elseif (IsInRaid()) then
HonorSpy:SendCommMessage(commPrefix, msg, "RAID");
end
if (GetGuildInfo("player") ~= nil) then
HonorSpy:SendCommMessage(commPrefix, msg, "GUILD");
end
if (not skip_yell) then
HonorSpy:SendCommMessage(commPrefix, msg, "YELL");
end
end
-- Broadcast on death
local last_send_time = 0;
function HonorSpy:PLAYER_DEAD()
local filtered_players, count = {}, 0;
if (time() - last_send_time < 10*60) then return end;
last_send_time = time();
for playerName, player in pairs(self.db.factionrealm.currentStandings) do
filtered_players[playerName] = player;
count = count + 1;
if (count == 10) then
broadcast(self:Serialize("filtered_players", filtered_players), true)
filtered_players, count = {}, 0;
end
end
if (count > 0) then
broadcast(self:Serialize("filtered_players", filtered_players), true)
end
end
function FAKE_PLAYERS_FILTER(_s, e, msg, ...)
-- not found, fake
if (msg == ERR_FRIEND_NOT_FOUND) then
if (not nameToTest) then
return true
end
HonorSpy.db.factionrealm.currentStandings[nameToTest] = nil
HonorSpy.db.factionrealm.fakePlayers[nameToTest] = true
HonorSpy.db.factionrealm.goodPlayers[nameToTest] = nil
-- HonorSpy:Print("removed non-existing player", nameToTest)
nameToTest = nil
return true
end
-- added or was in friends already, not fake
local friend = msg:match(string.gsub(ERR_FRIEND_ADDED_S, "(%%s)", "(.+)"))
if (not friend) then
friend = msg:match(string.gsub(ERR_FRIEND_ALREADY_S, "(%%s)", "(.+)"))
end
if (friend) then
HonorSpy.db.factionrealm.goodPlayers[friend] = true
HonorSpy.db.factionrealm.fakePlayers[friend] = nil
if (friend == nameToTest) then
HonorSpy:removeTestedFriends()
nameToTest = nil
end
return true
end
end
function HonorSpy:removeTestedFriends()
local limit = C_FriendList.GetNumFriends()
if (type(limit) ~= "number") then
return
end
for i = 1, limit do
local f = C_FriendList.GetFriendInfoByIndex(i)
if (f.notes == "HonorSpy testing") then
C_FriendList.RemoveFriend(f.name)
end
end
end
function HonorSpy:TestNextFakePlayer()
if (nameToTest or not startRemovingFakes) then return end
for playerName, player in pairs(HonorSpy.db.factionrealm.currentStandings) do
if (not HonorSpy.db.factionrealm.fakePlayers[playerName] and not HonorSpy.db.factionrealm.goodPlayers[playerName] and playerName ~= UnitName("player")) then
nameToTest = playerName
break
end
end
if (nameToTest) then
C_FriendList.AddFriend(nameToTest, "HonorSpy testing")
HS_wait(1, function() HonorSpy:TestNextFakePlayer() end)
end
end
-- RESET WEEK
function HonorSpy:Purge()
inspectedPlayers = {};
HonorSpy.db.factionrealm.currentStandings={};
HonorSpy.db.factionrealm.fakePlayers={};
HonorSpy.db.char.original_honor = 0;
HonorSpyGUI:Reset();
HonorSpy:Print(L["All data was purged"]);
end
function getResetTime()
local currentUnixTime = GetServerTime()
local regionId = GetCurrentRegion()
local resetDay = 3 -- wed
local resetHour = 7 -- 7 AM UTC
if (regionId == 1) then -- US + BR + Oceania: 3 PM UTC Tue (7 AM PST Tue)
resetDay = 2
resetHour = 15
elseif (regionId == 2 or regionId == 4 or regionId == 5) then -- Korea, Taiwan, China: 10 PM UTC Mon (7 AM KST Tue)
resetDay = 1
resetHour = 22
elseif (regionId == 3) then -- EU + RU: 7 AM UTC Wed (7 AM UTC Wed)
end
local day = date("!%w", currentUnixTime);
local h = date("!%H", currentUnixTime);
local m = date("!%M", currentUnixTime);
local s = date("!%S", currentUnixTime);
local reset_seconds = resetDay*24*60*60 + resetHour*60*60 -- reset time in seconds from week start
local now_seconds = s + m*60 + h*60*60 + day*24*60*60 -- seconds passed from week start
local week_start = currentUnixTime - now_seconds
local must_reset_on = 0
if (now_seconds - reset_seconds > 0) then -- we passed this week reset time
must_reset_on = week_start + reset_seconds
else -- we not yet passed the reset moment in this week, still on prev week reset time
must_reset_on = week_start - 7*24*60*60 + reset_seconds
end
return must_reset_on
end
function HonorSpy:ResetWeek()
HonorSpy.db.factionrealm.last_reset = getResetTime();
HonorSpy:Purge()
HonorSpy:Print(L["Weekly data was reset"]);
end
function HonorSpy:CheckNeedReset(skipUpdate)
if (not skipUpdate) then
HonorSpy:UpdatePlayerData(function() HonorSpy:CheckNeedReset(true) end)
end
-- reset weekly standings
local must_reset_on = getResetTime()
if (HonorSpy.db.factionrealm.last_reset ~= must_reset_on) then
HonorSpy:ResetWeek()
HonorSpy.db.char.original_honor = 0
HonorSpy.db.char.estimated_honor = 0
HonorSpy.db.char.today_kills = {}
end
-- reset daily honor
if (HonorSpy.db.factionrealm.currentStandings[playerName] and HonorSpy.db.char.original_honor ~= HonorSpy.db.factionrealm.currentStandings[playerName].thisWeekHonor) then
HonorSpy.db.char.original_honor = HonorSpy.db.factionrealm.currentStandings[playerName].thisWeekHonor
HonorSpy.db.char.estimated_honor = HonorSpy.db.char.original_honor
HonorSpy.db.char.today_kills = {}
end
end
-- Minimap icon
function DrawMinimapIcon()
LibStub("LibDBIcon-1.0"):Register("HonorSpy", LibStub("LibDataBroker-1.1"):NewDataObject("HonorSpy",
{
type = "data source",
text = addonName,
icon = "Interface\\Icons\\Inv_Misc_Bomb_04",
OnClick = function(self, button)
if (button == "RightButton") then
HonorSpy:Report()
elseif (button == "MiddleButton") then
HonorSpy:Report(UnitIsPlayer("target") and UnitName("target") or nil)
else
HonorSpy:CheckNeedReset()
HonorSpyGUI:Toggle()
end
end,
OnTooltipShow = function(tooltip)
tooltip:AddDoubleLine(format("%s", addonName), format("|cff777777v%s", GetAddOnMetadata(addonName, "Version")));
tooltip:AddLine("|cff777777by Kakysha|r");
tooltip:AddLine("|cFFCFCFCFLeft Click: |r" .. L['Show HonorSpy Standings']);
tooltip:AddLine("|cFFCFCFCFMiddle Click: |r" .. L['Report Target']);
tooltip:AddLine("|cFFCFCFCFRight Click: |r" .. L['Report Me']);
end
}), HonorSpy.db.factionrealm.minimapButton);
end
function PrintWelcomeMsg()
local realm = GetRealmName()
local faction = UnitFactionGroup("player")
local msg = format("|cffAAAAAAversion: %s, bugs & features: github.com/kakysha/honorspy|r\n|cff209f9b", GetAddOnMetadata(addonName, "Version"))
if (realm == "Earthshaker" and faction == "Horde") then
msg = msg .. format("You are lucky enough to play with HonorSpy author on one |cffFFFFFF%s |cff209f9brealm! Feel free to mail me (|cff8787edKakysha|cff209f9b) a supportive %s tip or kind word!", realm, GetCoinTextureString(50000))
end
HonorSpy:Print(msg .. "|r")
end
function DBHealthCheck()
for playerName, player in pairs(HonorSpy.db.factionrealm.currentStandings) do
if (not playerIsValid(player)) then
HonorSpy.db.factionrealm.currentStandings[playerName] = nil
HonorSpy:Print("removed bad table row", playerName)
end
end
if (HonorSpy.db.factionrealm.actualCommPrefix ~= commPrefix) then
HonorSpy:Purge()
HonorSpy.db.factionrealm.actualCommPrefix = commPrefix
end
HonorSpy:removeTestedFriends()
HS_wait(5, function() startRemovingFakes = true; HonorSpy:TestNextFakePlayer(); end)
end
local waitTable = {};
local waitFrame = nil;
function HS_wait(delay, func, ...)
if(type(delay)~="number" or type(func)~="function") then
return false;
end
if(waitFrame == nil) then
waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
waitFrame:SetScript("onUpdate",function (self,elapse)
local count = #waitTable;
local i = 1;
while(i<=count) do
local waitRecord = tremove(waitTable,i);
local d = tremove(waitRecord,1);
local f = tremove(waitRecord,1);
local p = tremove(waitRecord,1);
if(d>elapse) then
tinsert(waitTable,i,{d-elapse,f,p});
i = i + 1;
else
count = count - 1;
f(unpack(p));
end
end
end);
end
tinsert(waitTable,{delay,func,{...}});
return true;
end