forked from ZMOT7S/Spy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.lua
More file actions
886 lines (826 loc) · 30.1 KB
/
List.lua
File metadata and controls
886 lines (826 loc) · 30.1 KB
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
local Astrolabe = DongleStub("Astrolabe-0.4")
local AceLocale = LibStub("AceLocale-3.0")
local L = AceLocale:GetLocale("Spy")
function Spy:RefreshCurrentList(player, source)
local MainWindow = Spy.MainWindow
if not MainWindow:IsShown() then
return
end
local mode = Spy.db.profile.CurrentList
local manageFunction = Spy.ListTypes[mode][2]
if manageFunction then manageFunction() end
local button = 1
for index, data in pairs(Spy.CurrentList) do
if button <= Spy.ButtonLimit then
local level = "??"
local class = "UNKNOWN"
local opacity = 1
local playerData = SpyPerCharDB.PlayerData[data.player]
if playerData then
if playerData.level then
level = playerData.level
if playerData.isGuess == true and tonumber(playerData.level) < Spy.MaximumPlayerLevel then level = level.."+" end
end
if playerData.class then class = playerData.class end
end
local description = level.." "
if L[class] and type(L[class]) == "string" then description = description..L[class] end
if mode == 1 and Spy.InactiveList[data.player] then
opacity = 0.5
end
if player == data.player then
if not source or source ~= Spy.CharacterName then
Spy:AlertPlayer(player, source)
if not source then Spy:AnnouncePlayer(player) end
end
end
Spy:SetBar(button, data.player, description, 100, "Class", class, nil, opacity)
Spy.ButtonName[button] = data.player
button = button + 1
end
end
Spy.ListAmountDisplayed = button - 1
if Spy.db.profile.ResizeSpy then
Spy:AutomaticallyResize()
end
Spy:ManageBarsDisplayed()
end
function Spy:ManageNearbyList()
local prioritiseKoS = Spy.db.profile.PrioritiseKoS
local activeKoS = {}
local active = {}
for player in pairs(Spy.ActiveList) do
local position = Spy.NearbyList[player]
if position ~= nil then
if prioritiseKoS and SpyPerCharDB.KOSData[player] then
table.insert(activeKoS, { player = player, time = position })
else
table.insert(active, { player = player, time = position })
end
end
end
local inactiveKoS = {}
local inactive = {}
for player in pairs(Spy.InactiveList) do
local position = Spy.NearbyList[player]
if position ~= nil then
if prioritiseKoS and SpyPerCharDB.KOSData[player] then
table.insert(inactiveKoS, { player = player, time = position })
else
table.insert(inactive, { player = player, time = position })
end
end
end
table.sort(activeKoS, function(a, b) return a.time < b.time end)
table.sort(inactiveKoS, function(a, b) return a.time < b.time end)
table.sort(active, function(a, b) return a.time < b.time end)
table.sort(inactive, function(a, b) return a.time < b.time end)
local list = {}
for player in pairs(activeKoS) do table.insert(list, activeKoS[player]) end
for player in pairs(inactiveKoS) do table.insert(list, inactiveKoS[player]) end
for player in pairs(active) do table.insert(list, active[player]) end
for player in pairs(inactive) do table.insert(list, inactive[player]) end
Spy.CurrentList = list
end
function Spy:ManageLastHourList()
local list = {}
for player in pairs(Spy.LastHourList) do
table.insert(list, { player = player, time = Spy.LastHourList[player] })
end
table.sort(list, function(a, b) return a.time > b.time end)
Spy.CurrentList = list
end
function Spy:ManageIgnoreList()
local list = {}
for player in pairs(SpyPerCharDB.IgnoreData) do
local playerData = SpyPerCharDB.PlayerData[player]
local position = time()
if playerData then position = playerData.time end
table.insert(list, { player = player, time = position })
end
table.sort(list, function(a, b) return a.time > b.time end)
Spy.CurrentList = list
end
function Spy:ManageKillOnSightList()
local list = {}
for player in pairs(SpyPerCharDB.KOSData) do
local playerData = SpyPerCharDB.PlayerData[player]
local position = time()
if playerData then position = playerData.time end
table.insert(list, { player = player, time = position })
end
table.sort(list, function(a, b) return a.time > b.time end)
Spy.CurrentList = list
end
function Spy:GetNearbyListSize()
local entries = 0
for _ in pairs(Spy.NearbyList) do
entries = entries + 1
end
return entries
end
function Spy:ManageExpirations()
local mode = Spy.db.profile.CurrentList
local expirationFunction = Spy.ListTypes[mode][3]
if expirationFunction then expirationFunction() end
end
function Spy:ManageNearbyListExpirations()
local expired = false
local currentTime = time()
for player in pairs(Spy.ActiveList) do
if (currentTime - Spy.ActiveList[player]) > Spy.ActiveTimeout then
Spy.InactiveList[player] = Spy.ActiveList[player]
Spy.ActiveList[player] = nil
expired = true
end
end
if Spy.db.profile.RemoveUndetected ~= "Never" then
for player in pairs(Spy.InactiveList) do
if (currentTime - Spy.InactiveList[player]) > Spy.InactiveTimeout then
if Spy.PlayerCommList[player] ~= nil then
Spy.MapNoteList[Spy.PlayerCommList[player]].displayed = false
Spy.MapNoteList[Spy.PlayerCommList[player]].worldIcon:Hide()
Astrolabe:RemoveIconFromMinimap(Spy.MapNoteList[Spy.PlayerCommList[player]].miniIcon)
Spy.PlayerCommList[player] = nil
end
Spy.InactiveList[player] = nil
Spy.NearbyList[player] = nil
expired = true
end
end
end
if expired then
Spy:RefreshCurrentList()
if Spy.db.profile.HideSpy and Spy:GetNearbyListSize() == 0 then
Spy.MainWindow:Hide()
end
end
end
function Spy:ManageLastHourListExpirations()
local expired = false
local currentTime = time()
for player in pairs(Spy.LastHourList) do
if (currentTime - Spy.LastHourList[player]) > 3600 then
Spy.LastHourList[player] = nil
expired = true
end
end
if expired then
Spy:RefreshCurrentList()
end
end
function Spy:RemovePlayerFromList(player)
Spy.NearbyList[player] = nil
Spy.ActiveList[player] = nil
Spy.InactiveList[player] = nil
if Spy.PlayerCommList[player] ~= nil then
Spy.MapNoteList[Spy.PlayerCommList[player]].displayed = false
Spy.MapNoteList[Spy.PlayerCommList[player]].worldIcon:Hide()
Astrolabe:RemoveIconFromMinimap(Spy.MapNoteList[Spy.PlayerCommList[player]].miniIcon)
Spy.PlayerCommList[player] = nil
end
Spy:RefreshCurrentList()
end
function Spy:ClearList()
Spy.NearbyList = {}
Spy.ActiveList = {}
Spy.InactiveList = {}
Spy.PlayerCommList = {}
Spy.ListAmountDisplayed = 0
for i = 1, Spy.MapNoteLimit do
Spy.MapNoteList[i].displayed = false
Spy.MapNoteList[i].worldIcon:Hide()
Astrolabe:RemoveIconFromMinimap(Spy.MapNoteList[i].miniIcon)
end
Spy:SetCurrentList(1)
if IsControlKeyDown() then
Spy:EnableSpy(not Spy.db.profile.Enabled, false)
end
end
function Spy:AddPlayerData(name, class, level, race, guild, isEnemy, isGuess)
local info = {}
info.class = class
if type(level) == "number" then info.level = level end
info.race = race
info.guild = guild
info.isEnemy = isEnemy
info.isGuess = isGuess
SpyPerCharDB.PlayerData[name] = info
return SpyPerCharDB.PlayerData[name]
end
function Spy:UpdatePlayerData(name, class, level, race, guild, isEnemy, isGuess)
local detected = true
local playerData = SpyPerCharDB.PlayerData[name]
if not playerData then
playerData = Spy:AddPlayerData(name, class, level, race, guild, isEnemy, isGuess)
else
if class ~= nil then playerData.class = class end
if type(level) == "number" then playerData.level = level end
if race ~= nil then playerData.race = race end
if guild ~= nil then playerData.guild = guild end
if isEnemy ~= nil then playerData.isEnemy = isEnemy end
if isGuess ~= nil then playerData.isGuess = isGuess end
end
if playerData then
playerData.time = time()
if not Spy.ActiveList[name] then
if WorldMapFrame:IsVisible() then
SetMapToCurrentZone()
end
local mapX, mapY = GetPlayerMapPosition("player")
if mapX ~= 0 and mapY ~= 0 then
mapX = math.floor(tonumber(mapX) * 100) / 100
mapY = math.floor(tonumber(mapY) * 100) / 100
playerData.mapX = mapX
playerData.mapY = mapY
playerData.zone = GetZoneText()
playerData.subZone = GetSubZoneText()
else
detected = false
end
end
end
return detected
end
function Spy:RemovePlayerData(name)
SpyPerCharDB.PlayerData[name] = nil
end
function Spy:AddIgnoreData(name)
SpyPerCharDB.IgnoreData[name] = true
end
function Spy:RemoveIgnoreData(name)
if SpyPerCharDB.IgnoreData[name] then
SpyPerCharDB.IgnoreData[name] = nil
end
end
function Spy:AddKOSData(name)
SpyPerCharDB.KOSData[name] = time()
if Spy.db.profile.ShareKOSBetweenCharacters then SpyDB.removeKOSData[Spy.RealmName][Spy.FactionName][name] = nil end
end
function Spy:RemoveKOSData(name)
if SpyPerCharDB.KOSData[name] then
local playerData = SpyPerCharDB.PlayerData[name]
if playerData and playerData.reason then playerData.reason = nil end
SpyPerCharDB.KOSData[name] = nil
if Spy.db.profile.ShareKOSBetweenCharacters then SpyDB.removeKOSData[Spy.RealmName][Spy.FactionName][name] = time() end
end
end
function Spy:SetKOSReason(name, reason, other)
local playerData = SpyPerCharDB.PlayerData[name]
if playerData then
if not reason then
playerData.reason = nil
else
if not playerData.reason then playerData.reason = {} end
if reason == L["KOSReasonOther"] then
if not other then
local dialog = StaticPopup_Show("Spy_SetKOSReasonOther", name)
if dialog then dialog.playerName = name end
else
if other == "" then
playerData.reason[L["KOSReasonOther"]] = nil
else
playerData.reason[L["KOSReasonOther"]] = other
end
Spy:RegenerateKOSCentralList(name)
end
else
if playerData.reason[reason] then
playerData.reason[reason] = nil
else
playerData.reason[reason] = true
end
Spy:RegenerateKOSCentralList(name)
end
end
end
end
function Spy:AlertPlayer(player, source)
local playerData = SpyPerCharDB.PlayerData[player]
if SpyPerCharDB.KOSData[player] and Spy.db.profile.WarnOnKOS then
if Spy.db.profile.DisplayWarningsInErrorsFrame then
local text = Spy.db.profile.Colors.Warning["Warning Text"]
local msg = L["KOSWarning"]..player
UIErrorsFrame:AddMessage(msg, text.r, text.g, text.b, 1.0, UIERRORS_HOLD_TIME)
else
if source ~= nil and source ~= Spy.CharacterName then
Spy:ShowAlert("kosaway", player, source, Spy:GetPlayerLocation(playerData))
else
local reasonText = ""
if playerData.reason then
for reason in pairs(playerData.reason) do
if reasonText ~= "" then reasonText = reasonText..", " end
if reason == L["KOSReasonOther"] then
reasonText = reasonText..playerData.reason[reason]
else
reasonText = reasonText..reason
end
end
end
Spy:ShowAlert("kos", player, nil, reasonText)
end
end
if Spy.db.profile.EnableSound then
if source ~= nil and source ~= Spy.CharacterName then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-kosaway.wav")
else
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-kos.wav")
end
end
if Spy.db.profile.ShareKOSBetweenCharacters then Spy:RegenerateKOSCentralList(player) end
elseif Spy.db.profile.WarnOnKOSGuild then
if playerData and playerData.guild and Spy.KOSGuild[playerData.guild] then
if Spy.db.profile.DisplayWarningsInErrorsFrame then
local text = Spy.db.profile.Colors.Warning["Warning Text"]
local msg = L["KOSGuildWarning"].."<"..playerData.guild..">"
UIErrorsFrame:AddMessage(msg, text.r, text.g, text.b, 1.0, UIERRORS_HOLD_TIME)
else
if source ~= nil and source ~= Spy.CharacterName then
Spy:ShowAlert("kosguildaway", "<"..playerData.guild..">", source, Spy:GetPlayerLocation(playerData))
else
Spy:ShowAlert("kosguild", "<"..playerData.guild..">")
end
end
if Spy.db.profile.EnableSound then
if source ~= nil and source ~= Spy.CharacterName then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-kosaway.wav")
else
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-kosguild.wav")
end
end
else
if Spy.db.profile.EnableSound then
if source == nil or source == Spy.CharacterName then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-nearby.wav")
end
end
end
elseif Spy.db.profile.EnableSound then
if source == nil or source == Spy.CharacterName then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-nearby.wav")
end
end
end
function Spy:AlertStealthPlayer(player)
if Spy.db.profile.WarnOnStealth then
if Spy.db.profile.DisplayWarningsInErrorsFrame then
local text = Spy.db.profile.Colors.Warning["Warning Text"]
local msg = L["StealthWarning"]..player
UIErrorsFrame:AddMessage(msg, text.r, text.g, text.b, 1.0, UIERRORS_HOLD_TIME)
else
Spy:ShowAlert("stealth", player)
end
if Spy.db.profile.EnableSound then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\detected-stealth.wav")
end
end
end
function Spy:AnnouncePlayer(player, channel)
local msg = ""
local isKOS = SpyPerCharDB.KOSData[player]
local playerData = SpyPerCharDB.PlayerData[player]
local announce = Spy.db.profile.Announce
if channel or announce == "Self" or announce == "LocalDefense" or (announce == "Guild" and GetGuildInfo("player") ~= nil and not Spy.InInstance) or (announce == "Party" and GetNumPartyMembers() > 0) or (announce == "Raid" and UnitInRaid("player")) then
if announce == "Self" and not channel then
if isKOS then
msg = msg..L["SpySignatureColored"]..L["KillOnSightDetectedColored"]..player.." "
else
msg = msg..L["SpySignatureColored"]..L["PlayerDetectedColored"]..player.." "
end
else
if isKOS then
msg = msg..L["KillOnSightDetected"]..player.." "
else
msg = msg..L["PlayerDetected"]..player.." "
end
end
if playerData then
if playerData.guild and playerData.guild ~= "" then
msg = msg.."<"..playerData.guild.."> "
end
if playerData.level or playerData.race or (playerData.class and playerData.class ~= "") then
msg = msg.."- "
if playerData.level and playerData.isGuess == false then msg = msg..L["Level"].." "..playerData.level.." " end
if playerData.race and playerData.race ~= "" then msg = msg..playerData.race.." " end
if playerData.class and playerData.class ~= "" then
if announce == "Self" and not channel then
msg = msg .. L[playerData.class] .. " "
else
msg = msg .. strlower(playerData.class):gsub("^%l", strupper) .. " "
end
end
end
if playerData.zone then
if playerData.subZone and playerData.subZone ~= "" and playerData.subZone ~= playerData.zone then
msg = msg.."- "..playerData.subZone..", "..playerData.zone
else
msg = msg.."- "..playerData.zone
end
end
if playerData.mapX and playerData.mapY then msg = msg.." ("..math.floor(tonumber(playerData.mapX) * 100)..","..math.floor(tonumber(playerData.mapY) * 100)..")" end
end
if channel then
-- announce to selected channel
if (channel == "PARTY" and GetNumPartyMembers() > 0) or (channel == "RAID" and UnitInRaid("player")) or (channel == "GUILD" and GetGuildInfo("player") ~= nil) then
SendChatMessage(msg, channel)
elseif channel == "LOCAL" then
SendChatMessage(msg, "CHANNEL", nil, GetChannelName(L["LocalDefenseChannelName"].." - "..GetZoneText()))
end
else
-- announce to standard channel
if isKOS or not Spy.db.profile.OnlyAnnounceKoS then
if announce == "Self" then
DEFAULT_CHAT_FRAME:AddMessage(msg)
elseif announce == "LocalDefense" then
SendChatMessage(msg, "CHANNEL", nil, GetChannelName(L["LocalDefenseChannelName"].." - "..GetZoneText()))
else
SendChatMessage(msg, strupper(announce))
end
end
end
end
-- announce to other Spy users
if Spy.db.profile.ShareData then
local class, level, race, zone, subZone, mapX, mapY, guild = "", "", "", "", "", "", "", ""
if playerData then
if playerData.class then class = playerData.class end
if playerData.level and playerData.isGuess == false then level = playerData.level end
if playerData.race then race = playerData.race end
if playerData.zone then zone = playerData.zone end
if playerData.subZone then subZone = playerData.subZone end
if playerData.mapX then mapX = playerData.mapX end
if playerData.mapY then mapY = playerData.mapY end
if playerData.guild then guild = playerData.guild end
end
local details = Spy.Version.."|"..player.."|"..class.."|"..level.."|"..race.."|"..zone.."|"..subZone.."|"..mapX.."|"..mapY.."|"..guild
if strlen(details) < 240 then
if channel then
if (channel == "PARTY" and GetNumPartyMembers() > 0) or (channel == "RAID" and UnitInRaid("player")) or (channel == "GUILD" and GetGuildInfo("player") ~= nil) then
Spy:SendCommMessage(Spy.Signature, details, channel)
end
else
if GetNumPartyMembers() > 0 then Spy:SendCommMessage(Spy.Signature, details, "PARTY") end
if UnitInRaid("player") then Spy:SendCommMessage(Spy.Signature, details, "RAID") end
if Spy.InInstance == false and GetGuildInfo("player") ~= nil then Spy:SendCommMessage(Spy.Signature, details, "GUILD") end
end
end
end
end
function Spy:ToggleIgnorePlayer(ignore, player)
if ignore then
Spy:AddIgnoreData(player)
Spy:RemoveKOSData(player)
if Spy.db.profile.EnableSound then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\list-add.wav")
end
DEFAULT_CHAT_FRAME:AddMessage(L["SpySignatureColored"]..L["PlayerAddedToIgnoreColored"]..player)
else
Spy:RemoveIgnoreData(player)
if Spy.db.profile.EnableSound then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\list-remove.wav")
end
DEFAULT_CHAT_FRAME:AddMessage(L["SpySignatureColored"]..L["PlayerRemovedFromIgnoreColored"]..player)
end
Spy:RegenerateKOSGuildList()
if Spy.db.profile.ShareKOSBetweenCharacters then Spy:RegenerateKOSCentralList() end
Spy:RefreshCurrentList()
end
function Spy:ToggleKOSPlayer(kos, player)
if kos then
Spy:AddKOSData(player)
Spy:RemoveIgnoreData(player)
if Spy.db.profile.EnableSound then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\list-add.wav")
end
DEFAULT_CHAT_FRAME:AddMessage(L["SpySignatureColored"]..L["PlayerAddedToKOSColored"]..player)
else
Spy:RemoveKOSData(player)
if Spy.db.profile.EnableSound then
PlaySoundFile("Interface\\AddOns\\Spy\\Sounds\\list-remove.wav")
end
DEFAULT_CHAT_FRAME:AddMessage(L["SpySignatureColored"]..L["PlayerRemovedFromKOSColored"]..player)
end
Spy:RegenerateKOSGuildList()
if Spy.db.profile.ShareKOSBetweenCharacters then Spy:RegenerateKOSCentralList() end
Spy:RefreshCurrentList()
end
function Spy:PurgeUndetectedData()
local secondsPerDay = 60 * 60 * 24
local timeout = 90 * secondsPerDay
if Spy.db.profile.PurgeData == "OneDay" then
timeout = secondsPerDay
elseif Spy.db.profile.PurgeData == "FiveDays" then
timeout = 5 * secondsPerDay
elseif Spy.db.profile.PurgeData == "TenDays" then
timeout = 10 * secondsPerDay
elseif Spy.db.profile.PurgeData == "ThirtyDays" then
timeout = 30 * secondsPerDay
elseif Spy.db.profile.PurgeData == "SixtyDays" then
timeout = 60 * secondsPerDay
elseif Spy.db.profile.PurgeData == "NinetyDays" then
timeout = 90 * secondsPerDay
end
local currentTime = time()
for player in pairs(SpyPerCharDB.PlayerData) do
local playerData = SpyPerCharDB.PlayerData[player]
if not playerData.time or (currentTime - playerData.time) > timeout or not playerData.isEnemy then
Spy:RemoveIgnoreData(player)
Spy:RemoveKOSData(player)
SpyPerCharDB.PlayerData[player] = nil
end
end
for characterName in pairs(SpyDB.kosData[Spy.RealmName][Spy.FactionName]) do
for player in pairs(SpyDB.kosData[Spy.RealmName][Spy.FactionName][characterName]) do
local kosPlayerData = SpyDB.kosData[Spy.RealmName][Spy.FactionName][characterName][player]
if not kosPlayerData.time or (currentTime - kosPlayerData.time) > timeout or not kosPlayerData.isEnemy then
SpyDB.kosData[Spy.RealmName][Spy.FactionName][characterName][player] = nil
SpyDB.removeKOSData[Spy.RealmName][Spy.FactionName][player] = nil
end
end
end
end
function Spy:RegenerateKOSGuildList()
Spy.KOSGuild = {}
for player in pairs(SpyPerCharDB.KOSData) do
local playerData = SpyPerCharDB.PlayerData[player]
if playerData and playerData.guild then
Spy.KOSGuild[playerData.guild] = true
end
end
end
function Spy:RemoveLocalKOSPlayers()
for player in pairs(SpyPerCharDB.KOSData) do
if SpyDB.removeKOSData[Spy.RealmName][Spy.FactionName][player] then
Spy:RemoveKOSData(player)
end
end
end
function Spy:RegenerateKOSCentralList(player)
if player then
local playerData = SpyPerCharDB.PlayerData[player]
SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player] = {}
if playerData then SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player] = playerData end
SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player].added = SpyPerCharDB.KOSData[player]
else
for player in pairs(SpyPerCharDB.KOSData) do
local playerData = SpyPerCharDB.PlayerData[player]
SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player] = {}
if playerData then SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player] = playerData end
SpyDB.kosData[Spy.RealmName][Spy.FactionName][Spy.CharacterName][player].added = SpyPerCharDB.KOSData[player]
end
end
end
function Spy:RegenerateKOSListFromCentral()
for characterName in pairs(SpyDB.kosData[Spy.RealmName][Spy.FactionName]) do
if characterName ~= Spy.CharacterName then
for player in pairs(SpyDB.kosData[Spy.RealmName][Spy.FactionName][characterName]) do
if not SpyDB.removeKOSData[Spy.RealmName][Spy.FactionName][player] then
local playerData = SpyPerCharDB.PlayerData[player]
if not playerData then
playerData = Spy:AddPlayerData(player, class, level, race, guild, isEnemy, isGuess)
end
local kosPlayerData = SpyDB.kosData[Spy.RealmName][Spy.FactionName][characterName][player]
if kosPlayerData.time and (not playerData.time or (playerData.time and playerData.time < kosPlayerData.time)) then
playerData.time = kosPlayerData.time
if kosPlayerData.class then playerData.class = kosPlayerData.class end
if type(kosPlayerData.level) == "number" and (type(playerData.level) ~= "number" or playerData.level < kosPlayerData.level) then playerData.level = kosPlayerData.level end
if kosPlayerData.race then playerData.race = kosPlayerData.race end
if kosPlayerData.guild then playerData.guild = kosPlayerData.guild end
if kosPlayerData.isEnemy then playerData.isEnemy = kosPlayerData.isEnemy end
if kosPlayerData.isGuess then playerData.isGuess = kosPlayerData.isGuess end
if type(kosPlayerData.wins) == "number" and (type(playerData.wins) ~= "number" or playerData.wins < kosPlayerData.wins) then playerData.wins = kosPlayerData.wins end
if type(kosPlayerData.loses) == "number" and (type(playerData.loses) ~= "number" or playerData.loses < kosPlayerData.loses) then playerData.loses = kosPlayerData.loses end
if kosPlayerData.mapX then playerData.mapX = kosPlayerData.mapX end
if kosPlayerData.mapY then playerData.mapY = kosPlayerData.mapY end
if kosPlayerData.zone then playerData.zone = kosPlayerData.zone end
if kosPlayerData.subZone then playerData.subZone = kosPlayerData.subZone end
if kosPlayerData.reason then
playerData.reason = {}
for reason in pairs(kosPlayerData.reason) do
playerData.reason[reason] = kosPlayerData.reason[reason]
end
end
end
local characterKOSPlayerData = SpyPerCharDB.KOSData[player]
if kosPlayerData.added and (not characterKOSPlayerData or characterKOSPlayerData < kosPlayerData.added) then
SpyPerCharDB.KOSData[player] = kosPlayerData.added
end
end
end
end
end
end
function Spy:ButtonClicked()
local name = Spy.ButtonName[this.id]
if name and name ~= "" then
if arg1 == "LeftButton" then
if IsShiftKeyDown() then
if SpyPerCharDB.KOSData[name] then
Spy:ToggleKOSPlayer(false, name)
else
Spy:ToggleKOSPlayer(true, name)
end
elseif IsControlKeyDown() then
if SpyPerCharDB.IgnoreData[name] then
Spy:ToggleIgnorePlayer(false, name)
else
Spy:ToggleIgnorePlayer(true, name)
end
else
this:SetAttribute("macrotext", "/targetexact "..name)
end
elseif arg1 == "RightButton" then
Spy:BarDropDownOpen(this)
CloseDropDownMenus(1)
ToggleDropDownMenu(1, nil, Spy_BarDropDownMenu)
end
end
end
function Spy:ParseMinimapTooltip(tooltip)
local newTooltip = ""
local newLine = false
for text in string.gmatch(tooltip, "[^\n]*") do
local name = text
if string.len(text) > 0 then
if strsub(text, 1, 2) == "|c" then
name = strsub(text, 11, -3)
end
local playerData = SpyPerCharDB.PlayerData[name]
if not playerData then
for index, _ in pairs(Spy.LastHourList) do
local realmSeparator = strfind(index, "-")
if realmSeparator and realmSeparator > 1 and strsub(index, 1, realmSeparator - 1) == strsub(name, 1, realmSeparator - 1) then
playerData = SpyPerCharDB.PlayerData[index]
break
end
end
end
if playerData and playerData.isEnemy then
local desc = ""
if playerData.class and playerData.level then
desc = L["MinimapClassText"..playerData.class].."["..playerData.level.." "..L[playerData.class].."]|r"
elseif playerData.class then
desc = L["MinimapClassText"..playerData.class].."["..L[playerData.class].."]|r"
elseif playerData.level then
desc = "["..playerData.level.."]|r"
end
newTooltip = newTooltip..text.."|r "..desc
if not SpyPerCharDB.IgnoreData[name] and not Spy.InInstance then
local detected = Spy:UpdatePlayerData(name, nil, nil, nil, nil, true, nil)
if detected and Spy.db.profile.MinimapTracking then
Spy:AddDetected(name, time(), false)
end
end
else
newTooltip = newTooltip..text.."|r"
end
newLine = false
elseif not newLine then
newTooltip = newTooltip.."\n"
newLine = true
end
end
return newTooltip
end
function Spy:ParseUnitAbility(analyseSpell, event, player, flags, spellId, spellName)
local learnt = false
if player then
local class = nil
local level = nil
local race = nil
local isEnemy = true
local isGuess = true
local playerData = SpyPerCharDB.PlayerData[player]
if not playerData or playerData.isEnemy == nil then
learnt = true
end
if analyseSpell then
local abilityType = strsub(event, 1, 5)
if abilityType == "SWING" or abilityType == "SPELL" or abilityType == "RANGE" then
local ability = Spy_AbilityList[spellName]
if ability then
if ability.class and not (playerData and playerData.class) then
class = ability.class
learnt = true
end
if ability.level then
local playerLevelNumber = nil
if playerData and playerData.level then playerLevelNumber = tonumber(playerData.level) end
if type(playerLevelNumber) ~= "number" or playerLevelNumber < ability.level then
level = ability.level
learnt = true
end
end
if ability.race and not (playerData and playerData.race) then
race = ability.race
learnt = true
end
end
if class and race and level == Spy.MaximumPlayerLevel then
isGuess = false
learnt = true
end
end
end
Spy:UpdatePlayerData(player, class, level, race, nil, isEnemy, isGuess)
return learnt, playerData
end
return learnt, nil
end
function Spy:ParseUnitDetails(player, class, level, race, zone, subZone, mapX, mapY, guild)
if player then
local playerData = SpyPerCharDB.PlayerData[player]
if not playerData then
playerData = Spy:AddPlayerData(player, class, level, race, guild, true, true)
else
if not playerData.class then playerData.class = class end
if level then
local levelNumber = tonumber(level)
if type(levelNumber) == "number" then
if playerData.level then
local playerLevelNumber = tonumber(playerData.level)
if type(playerLevelNumber) == "number" and playerLevelNumber < levelNumber then playerData.level = levelNumber end
else
playerData.level = levelNumber
end
end
end
if not playerData.race then playerData.race = race end
if not playerData.guild then playerData.guild = guild end
end
playerData.isEnemy = true
playerData.time = time()
playerData.zone = zone
playerData.subZone = subZone
playerData.mapX = mapX
playerData.mapY = mapY
return true, playerData
end
return true, nil
end
function Spy:AddDetected(player, timestamp, learnt, source)
if not Spy.NearbyList[player] then
if Spy.db.profile.ShowOnDetection and not Spy.db.profile.MainWindowVis then
Spy:SetCurrentList(1)
Spy:EnableSpy(true, true, true)
end
if Spy.db.profile.CurrentList ~= 1 and Spy.db.profile.MainWindowVis and Spy.db.profile.ShowNearbyList then
Spy:SetCurrentList(1)
end
if source and source ~= Spy.CharacterName and not Spy.ActiveList[player] then
Spy.NearbyList[player] = timestamp
Spy.LastHourList[player] = timestamp
Spy.InactiveList[player] = timestamp
else
Spy.NearbyList[player] = timestamp
Spy.LastHourList[player] = timestamp
Spy.ActiveList[player] = timestamp
Spy.InactiveList[player] = nil
end
if Spy.db.profile.CurrentList == 1 then
Spy:RefreshCurrentList(player, source)
else
if not source or source ~= Spy.CharacterName then
Spy:AlertPlayer(player, source)
if not source then Spy:AnnouncePlayer(player) end
end
end
elseif not Spy.ActiveList[player] then
if Spy.db.profile.ShowOnDetection and not Spy.db.profile.MainWindowVis then
Spy:SetCurrentList(1)
Spy:EnableSpy(true, true, true)
end
if Spy.db.profile.CurrentList ~= 1 and Spy.db.profile.MainWindowVis and Spy.db.profile.ShowNearbyList then
Spy:SetCurrentList(1)
end
Spy.LastHourList[player] = timestamp
Spy.ActiveList[player] = timestamp
Spy.InactiveList[player] = nil
if Spy.PlayerCommList[player] ~= nil then
if Spy.db.profile.CurrentList == 1 then
Spy:RefreshCurrentList(player, source)
else
if not source or source ~= Spy.CharacterName then
Spy:AlertPlayer(player, source)
if not source then Spy:AnnouncePlayer(player) end
end
end
else
if Spy.db.profile.CurrentList == 1 then
Spy:RefreshCurrentList()
end
end
else
Spy.ActiveList[player] = timestamp
Spy.LastHourList[player] = timestamp
if learnt and Spy.db.profile.CurrentList == 1 then
Spy:RefreshCurrentList()
end
end
end
Spy.ListTypes = {
{L["Nearby"], Spy.ManageNearbyList, Spy.ManageNearbyListExpirations},
{L["LastHour"], Spy.ManageLastHourList, Spy.ManageLastHourListExpirations},
{L["Ignore"], Spy.ManageIgnoreList},
{L["KillOnSight"], Spy.ManageKillOnSightList},
}