-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeamfightCounter.lua
1702 lines (1487 loc) · 57.1 KB
/
TeamfightCounter.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
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
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...
local L = addon.L
_G['TeamfightCounter'] = CreateFrame('Frame')
local addonFrame = _G['TeamfightCounter']
local TeamfightCounterWindow = _G['TeamfightCounterWindow']
local LRC = LibStub("LibRangeCheck-3.0")
local AceComm = LibStub("AceComm-3.0")
local AceEvent = LibStub("AceEvent-3.0")
addon.version = 0.1
addon.timer = 0
addon.timeSinceLastUpdate = 0
addon.texturePath = "Interface\\AddOns\\TeamfightCounter\\Textures\\"
local removedList = {}
local playerData = nil
local playerBGData = {}
local playerList = {}
local displayFrame
local counters = {}
local groups = {}
local POIList = nil
local selfPlayer = {}
local deadEnemies = {}
local missingEnemies = {}
local refreshFrames = false
local Map = nil
local flagCarriers = {}
local messageCounts = {}
--A group tracks everything about that group. The players, counter, frames, etc.
local group = {}
----------------------- SelfCounter tracks who you see
local selfCounter = {}
function selfCounter:addFrame(frame)
if frame.fullName == nil then addon:Debug("addFrame called with no fullName") end
if self.frames[frame.fullName] == nil then
self.frames[frame.fullName] = frame
self:addPlayer(frame)
end
end
function selfCounter:removeFrame(frame)
if frame.fullName == nil then addon:Debug("removeFrame called with no fullName") end
if self.frames[frame.fullName] ~= nil then
self.frames[frame.fullName] = nil
if self.nearby[frame.fullName] == nil then
self:removePlayer(frame)
end
end
end
function selfCounter:addNearbyRaidMember(player)
if player.fullName == nil then addon:Debug("addNearbyRaidMember called with no fullName") end
if self.nearby[player.fullName] == nil then
self.nearby[player.fullName] = player
self:addPlayer(player)
end
end
function selfCounter:removeNearbyRaidMember(player)
if player.fullName == nil then addon:Debug("removeNearbyRaidMember called with no fullName") end
if self.nearby[player.fullName] ~= nil then
self.nearby[player.fullName] = nil
if self.frames[player.fullName] == nil then
self:removePlayer(player)
end
end
end
function selfCounter:addPlayer(player)
if player.fullName == nil then
addon:Debug("addPlayer called with no fullName")
return
end
if self.players[player.fullName] == nil then
self.players[player.fullName] = player
if not player.class then addon:Debug("No class for", player.fullName) end
addon:SendMsg(player, 'add')
end
end
function selfCounter:removePlayer(player)
if player.fullName == nil then addon:Debug("removePlayer called with no fullName") end
if self.players[player.fullName] ~= nil then
self.players[player.fullName] = nil
if not player.class then addon:Debug("No class for", player.fullName) end
if player.isDead then
if deadEnemies[player.fullName] == nil then
deadEnemies[player.fullName] = GetTime()
end
addon:SendMsg(player, "dead")
else
addon:SendMsg(player, 'remove')
end
end
end
function selfCounter:reset()
if self.players then
for k, player in pairs(self.players) do
self:removePlayer(player)
end
end
addon:Debug("SelfCounter reset")
self.players = {}
self.frames = {}
self.nearby = {}
end
------------------Counter tracks who each ally sees. Updated by addonMsgs
local Counter = {}
function Counter:new(name)
addon:updateSelfPlayer()
local obj = {}
setmetatable(obj, self)
self.__index = self
obj.name = name
obj.zone = nil
obj.players = {}
obj.nearby = {}
obj.allyCount = 0
obj.enemyCount = 0
local counterOwner = {}
counterOwner.fullName = addon:getFullName(name)
local nameparts = addon.utils:splitString(name, '-')
counterOwner.name, counterOwner.realm = nameparts[0], nameparts[1] or ""
counterOwner.isAlly = true
counterOwner.class = nil
counterOwner.zone = nil
obj.isSelfOwned = selfPlayer.fullName == counterOwner.fullName
obj:addPlayer(counterOwner)
return obj
end
function Counter:addPlayer(player)
-- addon:Debug("Counter " .. self.name .. " addPlayer", player.fullName)
if self.players[player.fullName] then
addon:Debug("Counter " .. self.name .. " already has player", player.fullName)
return
end
self.players[player.fullName] = player
if player.isAlly then
self.allyCount = self.allyCount + 1
else
self.enemyCount = self.enemyCount + 1
end
self.zone = player.zone
if not playerList[player.fullName] then
-- addon:updateGroups() --Temporarily disabling for performance
end
end
function Counter:updatePlayer(player)
if self.players[player.fullName] == nil then
self:addPlayer(player)
return
end
-- addon:Debug("Counter" .. self.name .. " updatePlayer", player.fullName)
self.players[player.fullName] = player
self.zone = player.zone
end
function Counter:removePlayer(player)
if self.players[player.fullName] == nil then
return
end
if self.players[player.fullName].isAlly then
self.allyCount = self.allyCount - 1
else
self.enemyCount = self.enemyCount - 1
end
self.zone = player.zone
-- addon:Debug("Counter " .. self.name .. " removePlayer", player.fullName)
self.players[player.fullName] = nil
end
-------------------------Addon MSGs
--Send an addon message to group
-- function addon:SendMsg(frame, msgType)
-- local zone = addon:getZoneId()
-- --Fix for when player dies and returns to graveyard but their zone remains where their body is.
-- if selfPlayer['isDead'] then
-- zone = nil
-- end
-- -- addon:Debug("MSG", frame.name, frame.realm, frame.class)
-- local msg = addon.version .. ";" .. msgType .. ";" .. frame['fullName'] .. ";" .. (frame['isAlly'] and '1' or '0') .. ";" .. frame['class'] .. ";" .. (zone or "")
-- if (select(2, IsInInstance()) == "pvp") then
-- C_ChatInfo.SendAddonMessage("TFC", msg, "INSTANCE_CHAT")
-- else
-- C_ChatInfo.SendAddonMessage("TFC", msg, "WHISPER", UnitName('player'))
-- end
-- -- addon:Debug("SendAddonMSG:",msg)
-- end
-- function addon:SendMsg(frame, msgType)
-- local zone = addon:getZoneId()
-- if selfPlayer['isDead'] then
-- zone = nil
-- end
-- local msg = addon.version .. ";" .. msgType .. ";" .. frame['fullName'] .. ";" .. (frame['isAlly'] and '1' or '0') .. ";" .. frame['class'] .. ";" .. (zone or "")
-- local distribution
-- local target
-- local inInstance, instanceType = IsInInstance()
-- if inInstance and (instanceType == "pvp" or instanceType == "arena") then
-- distribution = "INSTANCE_CHAT"
-- else
-- distribution = "WHISPER"
-- target = UnitName('player')
-- end
-- addon:SendCommMessage("TFC", msg, distribution, target)
-- addon:Debug("SendCommMessage:", msgType, frame.fullName)
-- end
-- function addon:DecodeMsg(msg)
-- local data = addon.utils:splitString(msg, ';')
-- local msgType, player, version = '', {}, nil
-- version, msgType, player['fullName'], player['isAlly'], player['class'], player['zone'] = data[1], data[2], data[3], data[4], data[5], data[6]
-- player['isAlly'] = (player['isAlly'] == '1') and true or false
-- if not player['zone'] or player['zone'] == "" then
-- player['zone'] = nil
-- else
-- player['zone'] = addon:getZoneId(player['zone'])
-- end
-- player['fullName'] = addon:getFullName(player['fullName'])
-- return msgType, player
-- end
-- Define mapping tables for msgType and class
local msgTypeCodes = {
update = '1',
add = '2',
remove = '3',
dead = '4',
}
local msgTypeCodesReverse = {
['1'] = 'update',
['2'] = 'add',
['3'] = 'remove',
['4'] = 'dead',
}
local classCodes = {
WARRIOR = '1',
PALADIN = '2',
HUNTER = '3',
ROGUE = '4',
PRIEST = '5',
DEATHKNIGHT = '6',
SHAMAN = '7',
MAGE = '8',
WARLOCK = '9',
MONK = '10',
DRUID = '11',
DEMONHUNTER = '12',
EVOKER = '13',
}
local classCodesReverse = {}
for k, v in pairs(classCodes) do
classCodesReverse[v] = k
end
-- Updated SendMsg function
function addon:SendMsg(frame, msgType)
local zone = addon:getZoneId()
if selfPlayer['isDead'] then
zone = nil
end
-- Use version '2' for the new encoding
local version = '2'
-- Encode msgType and class
local msgTypeCode = msgTypeCodes[msgType] or msgType
local classCode = classCodes[frame['class']] or frame['class']
local isAllyCode = frame['isAlly'] and '1' or '0'
local zoneCode = zone or ""
-- Construct the message with encoded fields
local msg = table.concat({version, msgTypeCode, frame['fullName'], isAllyCode, classCode, zoneCode}, ";")
local distribution
local target
local prio = "ALERT"
local inInstance, instanceType = IsInInstance()
if inInstance and (instanceType == "pvp" or instanceType == "arena") then
distribution = "INSTANCE_CHAT"
else
distribution = "WHISPER"
target = UnitName('player')
end
addon:SendCommMessage("TFC", msg, distribution, target, prio)
messageCounts['sent'] = (messageCounts['sent'] or 0) + 1
addon:Debug("SendCommMessage:", msgType, frame.fullName)
end
-- Updated DecodeMsg function
function addon:DecodeMsg(msg)
local data = addon.utils:splitString(msg, ';')
local version = data[1]
local msgType, player = '', {}
if not tonumber(version) then
-- Old version, adjust indexes
version = nil
msgType = data[1]
player['fullName'] = data[2]
player['isAlly'] = data[3]
player['class'] = data[4]
player['zone'] = data[5]
else
msgType = data[2]
player['fullName'] = data[3]
player['isAlly'] = data[4]
player['class'] = data[5]
player['zone'] = data[6]
end
player['isAlly'] = (player['isAlly'] == '1')
if not player['zone'] or player['zone'] == "" then
player['zone'] = nil
else
player['zone'] = addon:getZoneId(player['zone'])
end
player['fullName'] = addon:getFullName(player['fullName'])
-- Decode msgType and class if version >= 2
if version and tonumber(version) >= 2 then
msgType = msgTypeCodesReverse[msgType] or msgType
player['class'] = classCodesReverse[player['class']] or player['class']
end
return msgType, player
end
--------------------------------------------
--Converts zone to numberic zone ID if zone is passed. Otherwise return current players zone ID.
function addon:getZoneId(zone)
if zone == nil then
addon:refreshMap()
zone = GetSubZoneText()
end
if tonumber(zone) then return tonumber(zone) end
POIList = addon:getPOIs()
if POIList[zone] then
return tonumber(POIList[zone]['id'])
end
return nil
end
function addon:updateSelfPlayer(force)
local doUpdate = false
local player = { fullName = addon:getFullName(GetUnitName('player') .. '-' .. (GetRealmName() or "")), name = GetUnitName('player'), realm = GetRealmName(), isAlly = true }
player['class'] = select(2, UnitClass('player'))
player['isDead'] = UnitIsDeadOrGhost('player')
--check if any data about player has changed
if force or not selfPlayer then
doUpdate = true
else
for k, v in pairs(player) do
if selfPlayer[k] ~= v then
doUpdate = true
break
end
end
end
if doUpdate then
local updateType = player['isDead'] and 'remove' or 'update'
addon:Debug('Self Update', player.fullName, player.isDead, player.class, updateType)
selfPlayer = player
addon:SendMsg(player, updateType)
end
end
-- Update groups based on all player counters. Groups become the teamfight counts.
function addon:updateGroups()
local next = next
--Make a list of remaining counters that we can modify on the fly
local remainingCounters = {}
for i, counter in pairs(counters) do
if next(counter.players) ~= nil then
table.insert(remainingCounters, counter)
end
end
--Ensure we have up to date player data for full BG. Needed for enemy class tracking
addon:getBattlegroundPlayerData()
missingEnemies = {}
for i, player in pairs(playerData.enemy) do
if deadEnemies[player.fullName] == nil then
missingEnemies[player.fullName] = player
end
end
if next(remainingCounters) == nil then
-- addon:Debug('No counters')
addon:cleanGroupFrames('frame', true)
addon:cleanGroupFrames('map', true)
groups = {}
return
end
--First off, clear groups and populate with the first counter
groups = { addon.utils:deepCopy(table.remove(remainingCounters, 1)) }
--Keep checking counters until we remove all of them
while next(remainingCounters) ~= nil do
for i, group in pairs(groups) do
--loop all counters and see if one can be added to a group.
local stop = false
while not stop do
stop = true
for j, counter in pairs(remainingCounters) do
--check if any players in counter are in group
if addon:hasOverlap(group, counter) then
for k, player in pairs(counter.players) do
group:addPlayer(player)
end
if counter.zone then
group.zone = counter.zone
end
if counter.isSelfOwned then
group.isSelfOwned = true
end
table.remove(remainingCounters, j)
stop = false
end
end
end
end
--do we have any counters left?
if next(remainingCounters) ~= nil then
--we went through all groups already, so now make a new group for the remaining counters
table.insert(groups, addon.utils:deepCopy(table.remove(remainingCounters, 1)))
end
end
--Build player list and update missing enemies.
playerList = {}
flagCarriers.groups = {}
for i, group in pairs(groups) do
group['id'] = i
group['flagCarriers'] = {}
-- loop players in group and check zone
for j, player in pairs(group.players) do
if flagCarriers[player.fullName] ~= nil then
--track flag carriers
if group.zone == nil then
group.zone = 'Flag' --flagCarriers[player.fullName]
end
group.flagCarriers[player.fullName] = flagCarriers[player.fullName]
--track flag carriers in flagCarriers.groups
flagCarriers['groups'][i] = group
end
playerList[player.fullName] = true
--remove from remaining enemy
if missingEnemies[player.fullName] then
missingEnemies[player.fullName] = nil
end
end
end
--Now that we have the group teamfight counts, render them to screen
addon:showGroups()
addon:showGroupsOnMap()
-- Update BGE with group counts
addon:updateBGE()
end
function addon:updateBGE()
-- Access the BattlegroundEnemies addon
local battlegroundEnemies = _G['BattleGroundEnemies']
local enemyMainFrame = battlegroundEnemies and battlegroundEnemies['Enemies']
if not enemyMainFrame then
-- BGE is not loaded or not in a battleground
return
end
if not addon.settings.showBGE then
-- BGE integration is disabled. Ensure frame is hidden.
for playerName, playerButton in pairs(enemyMainFrame.Players) do
if playerButton.groupTextFrame then
playerButton.groupTextFrame:Hide()
end
end
return
end
local groups = groups
if addon.settings.testBGE then
-- Testing: Add some test groups
groups = {
{
allyCount = 3,
enemyCount = 2,
players = {
["PlayerOne-RealmName"] = true,
["Enemy2-Realm2"] = true,
},
},
{
allyCount = 1,
enemyCount = 1,
players = {
["Enemy1-Realm1"] = true,
},
},
{
allyCount = 1,
enemyCount = 4,
players = {
["Enemy3-Realm3"] = true,
},
},
}
end
-- Loop over all enemy players in BGE
for playerName, playerButton in pairs(enemyMainFrame.Players) do
-- Check if this player is in any of our groups
local groupFound = false
for _, group in pairs(groups) do
if group.players[playerName] then
groupFound = true
-- Create or update the text next to the player
if not playerButton.groupTextFrame then
addon:makeBGEFrame(playerButton)
end
-- Position the text within the groupTextFrame
playerButton.groupTextFrame:SetPoint('LEFT', playerButton, 'RIGHT', addon.settings.bgeXOffset, 0)
-- Set the group count text
local text = group.allyCount .. "v" .. group.enemyCount
playerButton.groupText:SetText(text)
-- Set the color green or red depending on ally vs enemy
if group.allyCount > group.enemyCount then
playerButton.groupText:SetTextColor(unpack(addon.settings.winColor))
elseif group.allyCount < group.enemyCount then
playerButton.groupText:SetTextColor(unpack(addon.settings.loseColor))
else
playerButton.groupText:SetTextColor(1, 1, 1, 1) -- White
end
-- Show Frame
playerButton.groupTextFrame:Show()
break -- No need to check other groups
end
end
-- If the player is not in any group, remove any existing text
if not groupFound and playerButton.groupTextFrame then
playerButton.groupTextFrame:Hide()
end
end
end
function addon:makeBGEFrame(playerButton)
-- Create a new Frame attached to playerButton with BackdropTemplate
playerButton.groupTextFrame = CreateFrame('Frame', nil, playerButton, 'BackdropTemplate')
-- Set frame strata and level higher than the playerButton
playerButton.groupTextFrame:SetFrameStrata(playerButton:GetFrameStrata())
playerButton.groupTextFrame:SetFrameLevel(playerButton:GetFrameLevel() + 10) -- Ensure it's above other elements
-- Set size for the frame
playerButton.groupTextFrame:SetSize(50, 20) -- Adjust width and height as needed
-- Position the groupTextFrame relative to the playerButton
playerButton.groupTextFrame:SetPoint('LEFT', playerButton, 'RIGHT', 0, 0)
-- Create the FontString attached to the new frame
playerButton.groupText = playerButton.groupTextFrame:CreateFontString(nil, 'OVERLAY', 'GameFontNormal')
-- Position the text within the groupTextFrame
playerButton.groupText:SetPoint('CENTER', playerButton.groupTextFrame, 'CENTER', 0, 0)
-- Set the backdrop to add a background and border
playerButton.groupTextFrame:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", -- Simple background texture
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", -- Default UI border texture
tile = false,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
-- Set backdrop color (background) and border color
playerButton.groupTextFrame:SetBackdropColor(0, 0, 0, 0.9) -- Semi-transparent black background
playerButton.groupTextFrame:SetBackdropBorderColor(1, 1, 1, 1) -- Solid white border
end
function addon:showMissingEnemies()
if displayFrame['missingEnemyFrame'] == nil then
displayFrame['missingEnemyFrame'] = CreateFrame("Frame", 'missingEnemyFrame', displayFrame)
displayFrame['missingEnemyFrame']:SetPoint("CENTER", displayFrame:GetName(), "TOP", 0, 0)
displayFrame['missingEnemyFrame']:SetWidth(50)
displayFrame['missingEnemyFrame']:SetHeight(10)
end
if addon.settings.showMissing then
displayFrame['missingEnemyFrame']:Show()
else
displayFrame['missingEnemyFrame']:Hide()
return
end
addon:showClassBlips({ players = missingEnemies }, displayFrame['missingEnemyFrame'], 'missing')
end
function addon:showMissingEnemiesOnMap()
if _G['missingEnemyMapFrame'] == nil then
_G['missingEnemyMapFrame'] = CreateFrame("Frame", 'missingEnemyMapFrame', _G['missingEnemyMapFrame'])
_G['missingEnemyMapFrame']:SetFrameLevel(16)
_G['missingEnemyMapFrame']:SetWidth(50)
_G['missingEnemyMapFrame']:SetHeight(10)
_G['missingEnemyMapFrame']:SetPoint("CENTER", 'REPorterFrame', "TOP", 0, -5)
end
if addon.settings.showMissing then
_G['missingEnemyMapFrame']:Show()
else
_G['missingEnemyMapFrame']:Hide()
return
end
addon:showClassBlips({ players = missingEnemies }, _G['missingEnemyMapFrame'], 'missing')
end
function addon:showGroups()
addon:cleanGroupFrames('frame')
local height = -30
local blipWidth = 6
-- for i, group in pairs(groups) do
for i, group in addon.utils:spairs(groups, function(t, a, b) return t[a].isSelfOwned end) do
-- addon:Debug('Showing group', i)
local msg = ""
msg = msg .. group.allyCount .. "v" .. group.enemyCount .. ""
local xMain, yMain = 0, -15 + (i - 1) * height
if displayFrame['displayGroup' .. i] == nil then
displayFrame['displayGroup' .. i] = CreateFrame("Frame", 'TFCGroupCounter' .. i, displayFrame)
displayFrame['displayGroup' .. i]:SetPoint("CENTER", displayFrame:GetName(), "TOP", xMain, yMain)
displayFrame['displayGroup' .. i]:SetWidth(50)
displayFrame['displayGroup' .. i]:SetHeight(height)
local groupCounterFrame = displayFrame['displayGroup' .. i]
if groupCounterFrame['groupText'] == nil then
groupCounterFrame['groupText'] = groupCounterFrame:CreateFontString(nil, "OVERLAY", "GameTooltipText")
end
local groupText = groupCounterFrame['groupText']
groupText:SetPoint("CENTER", 0, 0)
groupText:SetTextColor(0.5, 0.5, 0.5, 1)
groupText:SetText('1v0')
end
local groupCounterFrame = displayFrame['displayGroup' .. i]
local groupText = groupCounterFrame['groupText']
groupText:SetFont("Fonts\\FRIZQT__.TTF", 14*addon.settings.textScale, "OUTLINE")
--set color depending on ally vs enemy
if group.allyCount > group.enemyCount then
groupText:SetTextColor(unpack(addon.settings.winColor))
elseif group.allyCount < group.enemyCount then
groupText:SetTextColor(unpack(addon.settings.loseColor))
else
groupText:SetTextColor(0.5, 0.5, 0.5, 1)
end
groupText:SetText(msg)
groupCounterFrame:Show()
addon:showClassBlips(group, groupCounterFrame)
end
addon:showMissingEnemies()
end
function addon:showGroupsOnMap()
addon:cleanGroupFrames('map')
--have they selected to only use on node maps?
if addon.settings.showFrame and addon.settings.frameOnBaselessMaps then
--is this map nodeless?
addon:getPOIs()
if not POIList or next(POIList) == nil then return end
end
if _G['REPorterFrame'] == nil or not _G['REPorterFrame']:IsShown() then
-- addon:Debug('Debug: ReporterFrame not available')
return
end
local topFrames = {}
-- for i, group in pairs(groups) do
for i, group in addon.utils:spairs(groups, function(t, a, b) return t[a].isSelfOwned end) do
if group.zone then
local x, y = addon:getGroupPosition(group)
-- addon:Debug('Group has zone:', group.zone, x, y)
local result = addon:showGroupOnMap(group, x, y, 'REPorterFrameCorePOI')
else
-- addon:Debug('Group no zone:', group.zone, x, y)
table.insert(topFrames, group)
end
end
local topCount, width, height = #topFrames, 35, 15
local xStart = width - topCount * width
local yStart = -20
for i, group in pairs(topFrames) do
-- local x = xStart + (i - 1) * width
-- local y = -25
local x = 0
local y = yStart - (i - 1) * height
addon:showGroupOnMap(group, x, y, 'REPorterFrame')
end
addon:showMissingEnemiesOnMap()
end
function addon:showGroupOnMap(group, x, y, parentFrameName)
local fontSize = group.zone and 16 or 12
local alpha = group.zone and 1 or 0.75
local frameName = "TFCGroupFrame" .. parentFrameName .. group['id']
group.frameName, group.parentFrameName = frameName, parentFrameName
if _G[frameName] == nil then
local frameMain = CreateFrame("Frame", frameName, _G[parentFrameName])
frameMain:SetFrameLevel(16) --was 10
frameMain:SetWidth(50)
frameMain:SetHeight(50)
_G[frameName] = frameMain
end
local frameMain = _G[frameName]
if parentFrameName == 'REPorterFrame' then
--Show at top of map
frameMain:SetPoint("CENTER", parentFrameName, "TOP", x, y)
else
--Show at base or flag position.
-- addon:Debug('ShowGroupOnMap: ', x, y, frameName, parentFrameName)
frameMain:SetPoint("CENTER", parentFrameName, "TOPLEFT", x, y)
end
frameMain:Show()
local textName = "TFCGroupText" .. group['id']
if frameMain[textName] == nil then
local frameText = frameMain:CreateFontString(nil, nil, nil)
frameText:SetFont("Fonts\\FRIZQT__.TTF", fontSize*addon.settings.textScale, "OUTLINE")
frameText:SetPoint("CENTER", 0, 0)
frameMain[textName] = frameText
end
local frameText = frameMain[textName]
local msg = group.allyCount .. "v" .. group.enemyCount
frameText:SetText(msg)
if group.allyCount > group.enemyCount then
frameText:SetTextColor(0, 1, 0, alpha)
elseif group.allyCount < group.enemyCount then
frameText:SetTextColor(1, 0, 0, alpha)
else
frameText:SetTextColor(0.5, 0.5, 0.5, alpha)
end
addon:showClassBlips(group, frameMain, group.zone and 'enemy' or nil)
end
function addon:showClassBlips(group, parentFrame, reaction)
--first clear all blips
if parentFrame['blips'] == nil then
parentFrame['blips'] = {}
end
for i, blip in pairs(parentFrame.blips) do
blip:Hide()
end
if not addon.settings.showClasses and reaction ~= 'missing' then
return
end
local ally, enemy = {}, {}
if reaction ~= "missing" then
for i, player in pairs(group.players) do
if player.isAlly then
table.insert(ally, player)
else
table.insert(enemy, player)
end
end
end
local x, y
local blipWidth = 6*addon.settings.blipScale
if not reaction or reaction == 'ally' then
local playerNum = 1
for i, player in addon.utils:spairs(ally, function(t, a, b) return (addon.classOrder[t[b].class] or 0) < (addon.classOrder[t[a].class] or 0) end) do
if player.class then
playerNum = playerNum + 1
x, y = (-15) - blipWidth * playerNum, 0
addon:showClassBlip(parentFrame, player, x, y, 'ally', playerNum)
end
end
end
if not reaction or reaction == 'enemy' then
local playerNum = 1
for i, player in addon.utils:spairs(enemy, function(t, a, b) return (addon.classOrder[t[b].class] or 0) < (addon.classOrder[t[a].class] or 0) end) do
if player.class then
playerNum = playerNum + 1
x, y = (13) + blipWidth * playerNum, 0
addon:showClassBlip(parentFrame, player, x, y, 'enemy', playerNum)
end
end
end
if reaction and reaction == 'missing' then
local playerNum = 0
--counter number of players
local playerCount = 0
for i, player in pairs(group.players) do
if player.class then
playerCount = playerCount + 1
end
end
for i, player in addon.utils:spairs(group.players, function(t, a, b) return (addon.classOrder[t[b].class] or 0) < (addon.classOrder[t[a].class] or 0) end) do
if player.class then
playerNum = playerNum + 1
x, y = -(blipWidth * (playerCount + 1)) / 2 + blipWidth * playerNum, 0
addon:showClassBlip(parentFrame, player, x, y, 'enemy', playerNum, "BlipCombat")
end
end
end
end
function addon:showClassBlip(parentFrame, player, x, y, faction, playerNum, texture)
local textureName = "TFCBlipTexture" .. faction .. playerNum
if parentFrame.blips[textureName] == nil then
parentFrame.blips[textureName] = parentFrame:CreateTexture("TFCBlipTexture" .. parentFrame:GetName() .. faction .. playerNum)
if not texture then
parentFrame.blips[textureName]:SetTexture(addon.texturePath .. "BlipNormal")
else
parentFrame.blips[textureName]:SetTexture(addon.texturePath .. texture)
end
parentFrame.blips[textureName]:SetWidth(10*addon.settings.blipScale)
parentFrame.blips[textureName]:SetHeight(10*addon.settings.blipScale)
end
local texture = parentFrame.blips[textureName]
texture:SetPoint("CENTER", parentFrame, x, y)
local r, g, b = GetClassColor(player.class)
texture:SetVertexColor(r, g, b, 0.7)
texture:Show()
parentFrame.blips[textureName] = texture
end
function addon:getGroupPosition(group)
--check zone of group. Loop players and select first zone
addon:refreshMap()
local verticalOffset = 0.04
local zone = group.zone
local flagTextures = {['Horde Flag']= 137218, ['Alliance Flag']= 137200, ['Orange Orb']=137200, ['Flag']=137200}
if zone then
--Flags
if flagTextures[zone] ~= nil then
--loop Flag carriers
local desiredFlagTexture = nil
for flagCarrier, flagType in pairs(group.flagCarriers) do
--debug
addon:Debug("Flag carrier: " .. flagCarrier .. " flagType: " .. flagType)
if flagTextures[flagType] ~= nil then
desiredFlagTexture = flagTextures[flagType]
end
end
for i = 1, 4 do
local x, y, flagTexture = C_PvP.GetBattlefieldFlagPosition(i, Map)
if desiredFlagTexture == flagTexture then
if x == nil or y == nil then
addon:Debug("Flag possition is nil: ", zone, x, y, flagTexture)
break
end
addon:Debug("Flag possition (GroupUpdate): ", x, y, flagTexture)
return addon:getRealCoords(x, y - verticalOffset)
end
end
end
--Bases
addon:getPOIs()
local POIinfo = POIList[zone]
if POIinfo then
local x, y = POIinfo.position:GetXY()
return addon:getRealCoords(x, y - verticalOffset)
end
end
return nil, nil
end
function addon:updateFlagPosition()
local map = addon:refreshMap()
if map ~= 1339 and map ~= 206 then
return
end
if flagCarriers.groups == nil then
return
end
--First check flag positions
local hordeFlagTexture, allianceFlagTexture = 137218, 137200
local hordeFlags, allianceFlags = {}, {}
for i = 1, 4 do
local x, y, flagTexture = C_PvP.GetBattlefieldFlagPosition(i, map)
if flagTexture == hordeFlagTexture and x ~= nil and y~=nil then
table.insert(hordeFlags, {['x']=x, ['y']=y})
elseif flagTexture == allianceFlagTexture and x ~= nil and y~=nil then
table.insert(allianceFlags, {['x']=x, ['y']=y})
end
end
--I need to know which groups have flags, how many flags, and who has them (faction).
for group_id, group in pairs(flagCarriers.groups) do
local frameName = group.frameName
local frameMain = _G[frameName]
local parentFrameName = group.parentFrameName
--If its showing at top, don't update.
if parentFrameName ~= 'REPorterFrame' then
local x, y = 0, 0
local flagCount = 0
for playerName, flagType in pairs(group.flagCarriers) do
--get the position of flags
if flagType == 'Horde Flag' and #hordeFlags > 0 then
x = x + hordeFlags[1].x
y = y + hordeFlags[1].y
flagCount = flagCount + 1
elseif flagType == 'Alliance Flag' and #allianceFlags > 0 then
x = x + allianceFlags[1].x
y = y + allianceFlags[1].y
flagCount = flagCount + 1
end
end
if flagCount ~= 0 then
x = x / flagCount
y = y / flagCount
--now update group positions.
x, y = addon:getRealCoords(x, y - 0.04)
frameMain:SetPoint("CENTER", parentFrameName, "TOPLEFT", x, y)
else
end
end
end
end
--Copied from REPorter. Converts co-ordinates to values used by the map
function addon:getRealCoords(rawX, rawY)
return rawX * 783, -rawY * 522
end
function addon:cleanGroupFrames(groupType, excludeEnemyBlips)
for i = 1, 10 do
if groupType == 'map' then
if _G['TFCGroupFrame' .. 'REPorterFrame' .. i] then _G['TFCGroupFrame' .. 'REPorterFrame' .. i]:Hide() end
if _G['TFCGroupFrame' .. 'REPorterFrameCorePOI' .. i] then _G['TFCGroupFrame' .. 'REPorterFrameCorePOI' .. i]:Hide() end
elseif groupType == 'frame' then
if displayFrame['displayGroup' .. i] then displayFrame['displayGroup' .. i]:Hide() end
end
end
--Hide enemy blips below, but only if we need to.
if excludeEnemyBlips then
return
else
if groupType == 'frame' and displayFrame['missingEnemyFrame'] then
displayFrame['missingEnemyFrame']:Hide()
end
if groupType == 'map' and _G['missingEnemyMapFrame'] then
_G['missingEnemyMapFrame']:Hide()
end
end
end
--Gets points of interest for the map. These are the bases.
function addon:getPOIs(refresh)
if not (select(2, IsInInstance()) == "pvp") then POIList = {} return {} end
if refresh or (POIList == nil) then
addon:Debug("Loading POIs")