-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPvpAlerts_Utility_Functions.lua
1313 lines (1130 loc) · 41.5 KB
/
PvpAlerts_Utility_Functions.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 PVP = PVP_Alerts_Main_Table
local PVP_DIMMED_AD_COLOR = PVP:GetGlobal('PVP_DIMMED_AD_COLOR')
local PVP_BRIGHT_AD_COLOR = PVP:GetGlobal('PVP_BRIGHT_AD_COLOR')
local PVP_DIMMED_EP_COLOR = PVP:GetGlobal('PVP_DIMMED_EP_COLOR')
local PVP_BRIGHT_EP_COLOR = PVP:GetGlobal('PVP_BRIGHT_EP_COLOR')
local PVP_DIMMED_DC_COLOR = PVP:GetGlobal('PVP_DIMMED_DC_COLOR')
local PVP_BRIGHT_DC_COLOR = PVP:GetGlobal('PVP_BRIGHT_DC_COLOR')
local PVP_STAMINA_COLOR = PVP:GetGlobal('PVP_STAMINA_COLOR')
local PVP_MAGICKA_COLOR = PVP:GetGlobal('PVP_MAGICKA_COLOR')
local PVP_HYBRID_COLOR = PVP:GetGlobal('PVP_HYBRID_COLOR')
local PVP_SPACER_ICON = PVP:GetGlobal('PVP_SPACER_ICON')
local PVP_GUILD_ICON = PVP:GetGlobal('PVP_GUILD_ICON')
local PVP_GROUP_ICON = PVP:GetGlobal('PVP_GROUP_ICON')
local PVP_GROUPLEADER_ICON = PVP:GetGlobal('PVP_GROUPLEADER_ICON')
local PVP_FRIEND_ICON = PVP:GetGlobal('PVP_FRIEND_ICON')
local PVP_COOL_ICON = PVP:GetGlobal('PVP_COOL_ICON')
local PVP_IMPORTANT_ICON = PVP:GetGlobal('PVP_IMPORTANT_ICON')
local PVP_EYE_ICON = PVP:GetGlobal('PVP_EYE_ICON')
local PVP_KILLING_BLOW = PVP:GetGlobal('PVP_KILLING_BLOW')
local PVP_ATTACKER = PVP:GetGlobal('PVP_ATTACKER')
local PVP_EMPEROR = PVP:GetGlobal('PVP_EMPEROR')
local PVP_RESURRECT = PVP:GetGlobal('PVP_RESURRECT')
local PVP_6STAR = PVP:GetGlobal('PVP_6STAR')
local PVP_FIGHT_ADEP = PVP:GetGlobal('PVP_FIGHT_ADEP')
local PVP_FIGHT_ADDC = PVP:GetGlobal('PVP_FIGHT_ADDC')
local PVP_FIGHT_EPAD = PVP:GetGlobal('PVP_FIGHT_EPAD')
local PVP_FIGHT_EPDC = PVP:GetGlobal('PVP_FIGHT_EPDC')
local PVP_FIGHT_DCAD = PVP:GetGlobal('PVP_FIGHT_DCAD')
local PVP_FIGHT_DCEP = PVP:GetGlobal('PVP_FIGHT_DCEP')
local PVP_ID_RETAIN_TIME = PVP:GetGlobal('PVP_ID_RETAIN_TIME')
local PVP_ID_RETAIN_TIME_EFFECT = PVP:GetGlobal('PVP_ID_RETAIN_TIME_EFFECT')
local sqrt = zo_sqrt
local databaseIntegrityCheck = {}
function PVP:RGBtoHEX(rgb)
local hexadecimal = ''
for key, value in pairs(rgb) do
local hex = ''
-- d("RGB: " .. key .. " " .. value)
while (value > 0) do
local index = zo_mod(value, 16) + 1
value = zo_floor(value / 16)
hex = zo_strsub('0123456789ABCDEF', index, index) .. hex
end
-- d(value .. ' : ' .. hex)
if (zo_strlen(hex) == 0) then
hex = '00'
elseif (zo_strlen(hex) == 1) then
hex = '0' .. hex
end
-- d("hex: " .. hex)
hexadecimal = hexadecimal .. hex
-- d("hexadecimal: " .. hexadecimal)
end
return hexadecimal
end
function PVP:HSVToRGB(hue, saturation, value)
if saturation == 0 then
return value, value, value
end
;
-- Get the hue sector
local hue_sector = zo_floor(hue / 60)
local hue_sector_offset = (hue / 60) - hue_sector
local p = value * (1 - saturation)
local q = value * (1 - saturation * hue_sector_offset)
local t = value * (1 - saturation * (1 - hue_sector_offset))
if hue_sector == 0 then
return value, t, p
elseif hue_sector == 1 then
return q, value, p
elseif hue_sector == 2 then
return p, value, t
elseif hue_sector == 3 then
return p, q, value
elseif hue_sector == 4 then
return t, p, value
elseif hue_sector == 5 then
return value, p, q
end
end
function PVP:RGBToHSV(red, green, blue)
local hue, saturation, value
local min_value = zo_min(red, green, blue)
local max_value = zo_max(red, green, blue)
value = max_value;
local value_delta = max_value - min_value
if max_value ~= 0 then
saturation = value_delta / max_value
else
saturation = 0
hue = -1
return hue, saturation, value
end
if red == max_value then
hue = (green - blue) / value_delta;
elseif green == max_value then
hue = 2 + (blue - red) / value_delta;
else
hue = 4 + (red - green) / value_delta;
end
hue = hue * 60;
if hue < 0 then
hue = hue + 360;
end
return hue, saturation, value
end
function PVP:GetColorBrightnessAdjusted(originalColor, percent)
-- local red = zo_strsub(originalColor, 1, 2)
-- local green = zo_strsub(originalColor, 3, 4)
-- local blue = zo_strsub(originalColor, 5, 6)
local hue, saturation, value = self:RGBToHSV(self:HtmlToColor(originalColor))
-- d(hue)
-- d(saturation)
-- d(value)
local red, green, blue = self:HSVToRGB(hue, saturation, value * percent / 100)
-- d(red)
-- d(green)
-- d(blue)
return PVP:RGBtoHEX({ red * 255, green * 255, blue * 255 })
end
function PVP:GetTimeFadedColor(color, id, currentTime)
if (not self.detailedTooltipCalc) or (not self.totalPlayers[id]) then return color end
local timeDelta = currentTime - self.totalPlayers[id]
if (timeDelta < PVP_ID_RETAIN_TIME) then return color end
local bottomPercent = 10
local percent = bottomPercent +
(100 - bottomPercent) * (PVP_ID_RETAIN_TIME_EFFECT - timeDelta) /
(PVP_ID_RETAIN_TIME_EFFECT - PVP_ID_RETAIN_TIME)
if (percent < bottomPercent) then percent = bottomPercent end
return self:GetColorBrightnessAdjusted(color, percent)
end
function PVP:IsInPVPZone()
return IsPlayerInAvAWorld() or IsActiveWorldBattleground()
-- return IsUnitPvPFlagged('player') and GetDuelInfo() ~= 3
end
function PVP:IsValidBattlegroundContext(battlegroundContext)
return battlegroundContext == 1 or battlegroundContext == 3
end
function PVP:IsScrollTemple(zoneName)
local startIndex, endIndex = zo_strfind(zoneName, 'Scroll Temple')
if startIndex then
zoneName = zo_strsub(zoneName, startIndex, endIndex) ..
' of' .. zo_strsub(zoneName, endIndex + 1, zo_strlen(zoneName))
end
return zoneName
end
function PVP:ReanchorControl(control, newOffsetX, newOffsetY)
local _, point, relativeTo, relativePoint, offsetX, offsetY = control:GetAnchor()
control:ClearAnchors()
control:SetAnchor(point, relativeTo, relativePoint, newOffsetX, newOffsetY)
end
function PVP:CombineAllianceInfo(alliance1, alliance2)
local alliance
if alliance1 and alliance1 ~= 0 then
alliance = alliance1
elseif alliance2 and alliance2 ~= 0 then
alliance = alliance2
else
alliance = 0
end
return alliance
end
function PVP:StringStart(String, Start)
return zo_strsub(String, 1, zo_strlen(Start)) == Start
end
function PVP:StringEnd(String, End)
return End == '' or zo_strsub(String, -zo_strlen(End)) == End
end
function PVP:Colorize(text, color)
local combineTable = { "|c", color, tostring(text), "|r" }
return table.concat(combineTable)
end
function PVP:HtmlToColor(html, isDark, isBright)
local r, g, b
r = tonumber(zo_strsub(html, 1, 2), 16) / 255
g = tonumber(zo_strsub(html, 3, 4), 16) / 255
b = tonumber(zo_strsub(html, 5, 6), 16) / 255
if isDark then
return 0.5 * r, 0.5 * g, 0.5 * b
elseif isBright then
local ratio = 0.9 / zo_max(zo_max(r, g), b)
if ratio < 1 then ratio = 1 / zo_max(zo_max(r, g), b) end
return ratio * r, ratio * g, ratio * b
else
return r, g, b
end
end
function PVP:DeaccentString(inputString)
if (not inputString) or (inputString == "") then return end
for k, v in pairs(self.accents) do
inputString = zo_strgsub(inputString, k, v)
end
return inputString
end
function PVP:PointIsInsideOfTrapezoid(districtId, pointX, pointY)
local trap1, trap2, trap3, trap4, trap12, trap23, trap34, trap41, trapArea = PVP.ICtrapeziods[districtId].trap1,
PVP.ICtrapeziods[districtId].trap2, PVP.ICtrapeziods[districtId].trap3, PVP.ICtrapeziods[districtId].trap4,
PVP.ICtrapeziods[districtId].trap12, PVP.ICtrapeziods[districtId].trap23, PVP.ICtrapeziods[districtId].trap34,
PVP.ICtrapeziods[districtId].trap41, PVP.ICtrapeziods[districtId].trapArea
local pointToTrap1 = PVP:GetCoordsDistance2D(pointX, pointY, trap1.x, trap1.y)
local pointToTrap2 = PVP:GetCoordsDistance2D(pointX, pointY, trap2.x, trap2.y)
local pointToTrap3 = PVP:GetCoordsDistance2D(pointX, pointY, trap3.x, trap3.y)
local pointToTrap4 = PVP:GetCoordsDistance2D(pointX, pointY, trap4.x, trap4.y)
local function triangleArea(side1, side2, side3)
local p = 0.5 * (side1 + side2 + side3)
local area = sqrt(p * (p - side1) * (p - side2) * (p - side3))
return area
end
local pointTrapArea = triangleArea(trap12, pointToTrap1, pointToTrap2) +
triangleArea(trap23, pointToTrap2, pointToTrap3) + triangleArea(trap34, pointToTrap3, pointToTrap4) +
triangleArea(trap41, pointToTrap4, pointToTrap1)
local PVP_GRACE_TRAP_AREA = 0.1
return pointTrapArea <= trapArea
end
function PVP:PlayLoudSound(sound)
PlaySound(SOUNDS[sound])
PlaySound(SOUNDS[sound])
end
function PVP:IsWorldMapHidden()
return WORLD_MAP_SCENE:GetState() == "hidden"
end
function PVP:AllianceToColor(alliance, passive)
if alliance == 1 then
if passive then return PVP_DIMMED_AD_COLOR else return PVP_BRIGHT_AD_COLOR end
elseif alliance == 2 then
if passive then return PVP_DIMMED_EP_COLOR else return PVP_BRIGHT_EP_COLOR end
elseif alliance == 3 then
if passive then return PVP_DIMMED_DC_COLOR else return PVP_BRIGHT_DC_COLOR end
else
return 'FFFFFF'
end
end
function PVP:NameToAllianceColor(unitName, passive, overrideBgColor)
if not overrideBgColor and IsActiveWorldBattleground() and PVP.bgNames and PVP.bgNames[unitName] then
return PVP
:BgAllianceToHexColor(PVP.bgNames[unitName])
end
local unitAlliance
if self.SV.playersDB[unitName] then
unitAlliance = self.SV.playersDB[unitName].unitAlliance
end
return PVP:AllianceToColor(unitAlliance, passive)
end
function PVP:IdToAllianceColor(unitId, passive)
local unitName = self.idToName[unitId]
if IsActiveWorldBattleground() and PVP.bgNames and PVP.bgNames[unitName] then
return PVP:BgAllianceToHexColor(PVP
.bgNames[unitName])
end
if unitName and self.SV.playersDB[unitName] and self.SV.playersDB[unitName].unitAlliance then
return self:NameToAllianceColor(unitName, passive)
else
return false
end
end
function PVP:GetUnitAllianceFromDb(unitId)
local unitName = self.idToName[unitId]
if unitName and self.SV.playersDB[unitName] and self.SV.playersDB[unitName].unitAlliance then
return self.SV.playersDB[unitName].unitAlliance
else
return false
end
end
function PVP:GetUnitSpecColor(playerName)
local specFromDB, color
local isPlayer = playerName == self.playerName
if not isPlayer and self.SV.playersDB[playerName] then
specFromDB = self.SV.playersDB[playerName].unitSpec
end
if specFromDB then
if specFromDB == "stam" then
color = PVP_STAMINA_COLOR
elseif specFromDB == "mag" then
color = PVP_MAGICKA_COLOR
else
color = PVP_HYBRID_COLOR
end
else
color = "FFFFFF"
end
return ZO_ColorDef:New(color)
end
function PVP:GetFormattedClassIcon(playerName, dimension, allianceColor, isDeadorResurrect, isTargetFrame,
isTargetNameFrame, unitClass, id, currentTime, unitAvARank, playerDbRecord)
local classIcon, isPlayer
isPlayer = playerName == self.playerName
playerDbRecord = playerDbRecord or self.SV.playersDB[playerName]
if not playerDbRecord and not isPlayer and not unitClass then
if unitAvARank and not isPlayer then
return self:GetFormattedAvaRankIcon(unitAvARank, allianceColor, dimension, playerName)
else
return ""
end
end
dimension = dimension or 29
if isTargetNameFrame then dimension = 45 end
local specFromDB, color
if not isPlayer and playerDbRecord then
specFromDB = playerDbRecord.unitSpec
end
if specFromDB then
if specFromDB == "stam" then
color = PVP_STAMINA_COLOR
elseif specFromDB == "mag" then
color = PVP_MAGICKA_COLOR
else
color = PVP_HYBRID_COLOR
end
else
color = "808080"
end
if isDeadorResurrect then color = "808080" end
local startSpacer, endSpacer = "", ""
if not unitClass then
if isPlayer then
unitClass = GetUnitClassId('player')
else
unitClass = playerDbRecord and playerDbRecord.unitClass
end
end
if not isTargetFrame then
if unitClass == 2 then
dimension = dimension - 3
startSpacer = zo_iconFormat(PVP_SPACER_ICON, 2, 2)
endSpacer = zo_iconFormat(PVP_SPACER_ICON, 2, 2)
elseif unitClass == 1 then
dimension = dimension - 2
startSpacer = zo_iconFormat(PVP_SPACER_ICON, 2, 2)
endSpacer = zo_iconFormat(PVP_SPACER_ICON, 1, 1)
elseif unitClass == 6 then
startSpacer = zo_iconFormat(PVP_SPACER_ICON, 1, 1)
end
end
local mundus = ""
if playerDbRecord and playerDbRecord.mundus then
local mundusColor = ""
if self.mundusColors[playerDbRecord.mundus] then
mundusColor = self.mundusColors[playerDbRecord.mundus]
else
mundusColor = "FFFFFF"
end
local mundusDimension = 0
if isTargetNameFrame then
mundusDimension = 32
else
mundusDimension = 21
end
mundus = zo_iconFormatInheritColor("PvpAlerts/textures/" .. playerDbRecord.mundus .. "m.dds",
mundusDimension, mundusDimension)
if id and currentTime then
mundusColor = self:GetTimeFadedColor(mundusColor, id, currentTime)
end
mundus = self:Colorize(mundus, mundusColor)
end
if unitClass then
classIcon = zo_iconFormatInheritColor(self.classIcons[unitClass], dimension, dimension)
-- classIcon = self:Colorize(zo_iconFormatInheritColor(self.classIcons[unitClass], dimension, dimension), color)
else
classIcon = ""
end
local avaRankIcon = ""
if unitAvARank then
avaRankIcon = self:Colorize(zo_iconFormatInheritColor(GetAvARankIcon(unitAvARank), dimension, dimension),
allianceColor)
elseif playerDbRecord and playerDbRecord.unitAvARank then
unitAvARank = playerDbRecord.unitAvARank
avaRankIcon = self:Colorize(zo_iconFormatInheritColor(GetAvARankIcon(unitAvARank), dimension, dimension),
allianceColor)
else
avaRankIcon = ""
end
if id and currentTime then
color = self:GetTimeFadedColor(color, id, currentTime)
end
classIcon = self:Colorize(classIcon, color)
return startSpacer .. mundus .. classIcon .. endSpacer .. avaRankIcon
end
function PVP:GetFormattedAvaRankIcon(unitAvARank, allianceColor, dimension, playerName)
local avaRankIcon
dimension = dimension or 29
if unitAvARank then
avaRankIcon = self:Colorize(zo_iconFormatInheritColor(GetAvARankIcon(unitAvARank), dimension, dimension),
allianceColor)
elseif self.SV.playersDB[playerName] and self.SV.playersDB[playerName].unitAvARank then
unitAvARank = self.SV.playersDB[playerName].unitAvARank
avaRankIcon = self:Colorize(zo_iconFormatInheritColor(GetAvARankIcon(unitAvARank), dimension, dimension),
allianceColor)
else
avaRankIcon = ""
end
return avaRankIcon
end
function PVP:GetFormattedName(playerName, truncate)
local formattedName = zo_strformat(SI_UNIT_NAME, playerName)
if truncate then
local iconsCutOff
if truncate == 1 then
iconsCutOff = 3
elseif truncate == 2 then
iconsCutOff = 6
elseif truncate == 0 then
iconsCutOff = 0
end
local cutOff = 22 - iconsCutOff
local substringCutOff
local _, accentedSymbolsIndice = PVP:FindUTFIndice(formattedName)
if accentedSymbolsIndice == {} then
substringCutOff = cutOff - 1
else
local numberSpecial = 0
for i = 1, #accentedSymbolsIndice do
if accentedSymbolsIndice[i] <= (cutOff - 1) then
numberSpecial = numberSpecial + 1
end
end
substringCutOff = cutOff + numberSpecial - 1
end
if zo_strlen(formattedName) >= cutOff then
formattedName = zo_strsub(formattedName, 1, substringCutOff) .. ".."
end
end
return formattedName
end
function PVP:GetFormattedCharNameLink(playerName, truncate)
return ZO_LinkHandler_CreateLinkWithoutBrackets(self:GetFormattedName(playerName, truncate), nil, CHARACTER_LINK_TYPE,
playerName)
end
function PVP:GetFormattedClassNameLink(playerName, allianceColor, truncate, isDeadorResurrect, isTargetFrame,
isTargetNameFrame, unitClass, id, currentTime, unitAvARank)
return self:GetFormattedClassIcon(playerName, nil, allianceColor, isDeadorResurrect, isTargetFrame, isTargetNameFrame,
unitClass, id, currentTime, unitAvARank) ..
self:Colorize(self:GetFormattedCharNameLink(playerName, truncate), allianceColor)
end
function PVP:GetFormattedAccountNameLink(accName, color)
return self:Colorize(ZO_LinkHandler_CreateLinkWithoutBrackets(accName, nil, DISPLAY_NAME_LINK_TYPE, accName), color)
end
function PVP:GetReticleFormattedName(playerName)
return self:GetFormattedClassIcon(playerName, nil, self:NameToAllianceColor(playerName)) ..
self:Colorize(self:GetFormattedName(playerName), self:NameToAllianceColor(playerName))
end
function PVP:GetGroupIcon(dimension)
dimension = dimension or 24
return self:Colorize(zo_iconFormatInheritColor(PVP_GROUP_ICON, dimension, dimension), "40BB40") --C59B00
end
function PVP:GetGroupLeaderIcon(dimension)
dimension = dimension or 24
return self:Colorize(zo_iconFormatInheritColor(PVP_GROUPLEADER_ICON, dimension, dimension), "40BB40") --C59B00
end
function PVP:GetIcon(icon, dimension, color)
dimension = dimension or 50
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(icon, dimension, dimension), color)
end
function PVP:GetFriendIcon(dimension)
dimension = dimension or 20
return self:Colorize(zo_iconFormatInheritColor(PVP_FRIEND_ICON, dimension, dimension), "40BB40")
end
function PVP:GetGuildIcon(dimension, color)
dimension = dimension or 20
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(PVP_GUILD_ICON, dimension, dimension), color)
end
function PVP:GetCoolIcon(dimension, dimmed)
dimension = dimension or 20
local color
if dimmed then color = "30AA30" else color = "40BB40" end
return self:Colorize(zo_iconFormatInheritColor(PVP_COOL_ICON, dimension, dimension), "40BB40")
end
function PVP:GetKOSIcon(dimension, color)
dimension = dimension or 30
color = color or "BB4040"
return self:Colorize(zo_iconFormatInheritColor(PVP_IMPORTANT_ICON, dimension, dimension), color)
end
function PVP:GetEyeIcon(dimension, color)
dimension = dimension or 20
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(PVP_EYE_ICON, dimension, dimension), color)
end
function PVP:GetDeathIcon(dimension, color)
dimension = dimension or 28
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(PVP_KILLING_BLOW, dimension, dimension), color)
end
function PVP:GetAttackerIcon(dimension, color)
dimension = dimension or 30
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(PVP_ATTACKER, dimension, dimension), color)
end
function PVP:GetEmperorIcon(dimension, color)
dimension = dimension or 20
color = color or "FFFFFF"
return self:Colorize(zo_iconFormatInheritColor(PVP_EMPEROR, dimension, dimension), color)
end
-- function PVP:GetTargetIcon(dimension, color)
-- dimension = dimension or 22
-- color = color or "FFFFFF"
-- return self:Colorize(zo_iconFormatInheritColor(PVP_STAMINA, dimension, dimension), color)
-- end
function PVP:GetFightIcon(dimension, color, targetAlliance)
dimension = dimension or 24
color = color or "FFFFFF"
local icon = ""
if self.allianceOfPlayer == 1 then
if targetAlliance == 2 then
icon = PVP_FIGHT_ADEP
elseif targetAlliance == 3 then
icon = PVP_FIGHT_ADDC
end
elseif self.allianceOfPlayer == 2 then
if targetAlliance == 1 then
icon = PVP_FIGHT_EPAD
elseif targetAlliance == 3 then
icon = PVP_FIGHT_EPDC
end
elseif self.allianceOfPlayer == 3 then
if targetAlliance == 1 then
icon = PVP_FIGHT_DCAD
elseif targetAlliance == 2 then
icon = PVP_FIGHT_DCEP
end
end
return self:Colorize(zo_iconFormatInheritColor(icon, dimension, dimension), color)
end
function PVP:GetResurrectIcon(dimension, color)
dimension = dimension or 32
color = color or "AAAAAA"
return self:Colorize(zo_iconFormatInheritColor(PVP_RESURRECT, dimension, dimension), color)
end
function PVP:ScaleControls(control, textControl, defaultFontSize, scale, ratioX)
ratioX = ratioX or 1
textControl:SetWidth(control:GetWidth() * ratioX)
textControl:SetHeight(control:GetHeight())
local fontSize = zo_round(defaultFontSize * scale)
local font = "$(BOLD_FONT)|$(KB_" .. fontSize .. ")|soft-shadow-thick"
textControl:SetFont(font)
end
function PVP:FindUTFIndice(name)
local indice, indiceAccented = {}, {}
local substring = name
local before, after, skip
local count = 0
for i = 1, zo_strlen(name) - 1 do
if zo_strlen(substring) == zo_strlen(PVP:DeaccentString(substring)) then break end
if not skip then
before = zo_strlen(PVP:DeaccentString(substring))
substring = zo_strsub(substring, 2, zo_strlen(substring))
after = zo_strlen(PVP:DeaccentString(substring))
if after - before == 0 then
table.insert(indice, (i - count))
table.insert(indiceAccented, i)
count = count + 1
skip = true
end
else
substring = zo_strsub(substring, 2, zo_strlen(substring))
skip = false
end
end
return indice, indiceAccented
end
function PVP:TableConcat(t1, t2)
if next(t2) == nil then return t1 end
for i = 1, #t2 do
t1[#t1 + 1] = t2[i]
end
return t1
end
function PVP:IsPlayerCCImmune(graceTimeInSec)
if not graceTimeInSec then graceTimeInSec = 0 end
for i = 1, GetNumBuffs('player') do
local buffName, timeStarted, timeEnding, _, _, _, _, _, _, _, abilityId, _, castByPlayer = GetUnitBuffInfo(
'player', i)
if buffName == "CC Immunity" or buffName == "Crowd Control Immunity" or buffName == "Unstoppable" or buffName == "Immovable" then
if timeEnding - GetFrameTimeSeconds() >= graceTimeInSec then
return true
end
end
end
return false
end
function PVP:InsertAnimationType(animHandler, animType, control, animDuration, animDelay, animEasing, ...)
if not animHandler then return end
local animation, startValues, endValues
if animType == ANIMATION_SCALE then
animation, startValues, endValues = animHandler:InsertAnimation(ANIMATION_SCALE, control, animDelay), ...
if select(4, ...) then
startValues = startValues * self.SV.controlScale
endValues = endValues * self.SV.controlScale
end
animation:SetScaleValues(startValues, endValues)
elseif animType == ANIMATION_ALPHA then
animation, startValues, endValues = animHandler:InsertAnimation(ANIMATION_ALPHA, control, animDelay), ...
animation:SetAlphaValues(startValues, endValues)
elseif animType == ANIMATION_TRANSLATE then
animation, startValues, endValues = animHandler:InsertAnimation(ANIMATION_TRANSLATE, control, animDelay), ...
animation:SetTranslateOffsets(startValues, endValues)
elseif animType == ANIMATION_ROTATE3D then
animation, startValues, endValues = animHandler:InsertAnimation(ANIMATION_ROTATE3D, control, animDelay), ...
animation:SetRotationValues(startValues, endValues)
elseif animType == ANIMATION_COLOR then
animation, startValues, endValues = animHandler:InsertAnimation(ANIMATION_COLOR, control, animDelay), ...
animation:SetRotationValues(startValues, endValues)
end
if animation then
animation:SetDuration(animDuration)
animation:SetEasingFunction(animEasing)
end
end
function PVP:ProcessLengths(namesTable, maxLength, addedLength)
-- local function GetTextWidthInPixels(text)
-- PVP_Counter_TestWidth:SetFont("ZoFontWinH5")
-- PVP_Counter_TestWidth:SetText(text)
-- local width = PVP_Counter_TestWidth:GetTextWidth()
-- return width
-- return zo_strlen(text) * 2
-- end
-- local maxLength=0
addedLength = addedLength or 0
for i = 1, #namesTable do
if self:StringEnd(namesTable[i], "+") then
if addedLength < 35 then addedLength = 35 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 1))
elseif self:StringEnd(namesTable[i], "%") then
if addedLength < 45 then addedLength = 45 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 1))
elseif self:StringEnd(namesTable[i], "%*") then
if addedLength < 65 then addedLength = 65 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 2))
elseif self:StringEnd(namesTable[i], "+*") then
if addedLength < 55 then addedLength = 55 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 2))
elseif self:StringEnd(namesTable[i], "%**") then
if addedLength < 75 then addedLength = 75 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 3))
elseif self:StringEnd(namesTable[i], "+**") then
if addedLength < 65 then addedLength = 65 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 3))
elseif self:StringEnd(namesTable[i], "**") then
if addedLength < 45 then addedLength = 45 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 2))
elseif self:StringEnd(namesTable[i], "*") then
if addedLength < 40 then addedLength = 40 end
namesTable[i] = zo_strsub(namesTable[i], 1, (zo_strlen(namesTable[i]) - 1))
end
end
return 6 * maxLength + 90 + addedLength
-- return 6*maxLength + 70 + addedLength
end
function PVP:ShouldShowCampFrame()
return self.SV.showCampFrame and not IsActiveWorldBattleground()
end
function PVP:IsNPCAbility(abilityId)
return self.excludedAbilityIds[abilityId] and true or false
end
function PVP:CheckName(unitName)
return (self.SV.playersDB[unitName] or self:StringEnd(unitName, "^Mx") or self:StringEnd(unitName, "^Fx")) and true or
false
end
function PVP:GetTrueAllianceColors(alliance)
return GetAllianceColor(alliance):UnpackRGB()
end
function PVP:GetTrueAllianceColorsHex(alliance)
return GetAllianceColor(alliance):ToHex()
end
function PVP:IsMalformedName(name)
return not (PVP:StringEnd(name, '^Mx') or PVP:StringEnd(name, '^Fx'))
end
function PVP:GetValidName(name)
if not name or name == '' then return end
if not PVP:IsMalformedName(name) then return name end
-- if not PVP.bgNames then return end
if PVP.bgNames and PVP.bgNames[name .. '^Mx'] then return name .. '^Mx' end
if PVP.bgNames and PVP.bgNames[name .. '^Fx'] then return name .. '^Fx' end
end
function PVP:GetRootNames(name)
if not name or name == '' then return "" end
local rootName = name:gsub("%s*%^[MF]x%s*$", "")
return rootName or ""
end
function PVP:UpdatePlayerDbAccountName(unitCharName, unitAccName, oldUnitAccName)
local nameChangeNote = " (AutoNote: Previous name " .. oldUnitAccName .. ")"
local isOnList
local oldCP = PVP.SV.CP[oldUnitAccName]
local newCP = PVP.SV.CP[unitAccName]
if oldCP then
if not newCP or (newCP == 0) then
PVP.SV.CP[unitAccName] = oldCP
PVP.SV.CP[oldUnitAccName] = nil
elseif oldCP > newCP then
if databaseIntegrityCheck[unitCharName] then return end
PVP.CHAT:Printf(
"Possible player name change from %s to %s, seen for character %s, but this requires a CP decrease.",
self:GetFormattedAccountNameLink(oldUnitAccName, "FFFFFF"),
self:GetFormattedAccountNameLink(unitAccName, "FFFFFF"),
self:GetFormattedCharNameLink(unitCharName))
databaseIntegrityCheck[unitCharName] = true
return
end
PVP.SV.CP[oldUnitAccName] = nil
end
for k, v in pairs(PVP.SV.playersDB) do
if v.unitAccName == oldUnitAccName then
PVP.SV.playersDB[k].unitAccName = unitAccName
end
end
for k, v in ipairs(PVP.SV.KOSList) do
if v.unitAccName == oldUnitAccName then
PVP.SV.KOSList[k].unitAccName = unitAccName
isOnList = true
end
end
for k, v in pairs(PVP.SV.coolList) do
if v == oldUnitAccName then
PVP.SV.coolList[k] = unitAccName
isOnList = true
end
end
if PVP.SV.playerNotes[oldUnitAccName] then
local oldNote = PVP.SV.playerNotes[oldUnitAccName] or ""
local currentNote = PVP.SV.playerNotes[unitAccName] or ""
local combinedNote = ((oldNote ~= "" and oldNote) or "")
combinedNote = combinedNote .. ((currentNote ~= "" and " " .. currentNote) or "")
combinedNote = combinedNote .. ((nameChangeNote ~= "" and " " .. nameChangeNote) or "")
PVP.SV.playerNotes[unitAccName] = combinedNote
PVP.SV.playerNotes[oldUnitAccName] = nil
else
if isOnList then
PVP.SV.playerNotes[unitAccName] = nameChangeNote
end
end
PVP.CHAT:Printf("Name Change! Player %s was previously known as %s",
self:GetFormattedAccountNameLink(unitAccName, "76BCC3"), self:Colorize(oldUnitAccName, "FFFFFF"))
end
function PVP:BgAllianceToHexColor(bgAlliance)
return ZO_ColorDef:New(GetBattlegroundAllianceColor(bgAlliance)):ToHex()
end
-- 255, 45, 30 alliance 1 color
-- 255, 73, 147 alliance 3 color
function PVP:GetPlayerMarkerBgAllianceHexColor(bgAlliance)
-- local allianceColor = ZO_ColorDef:New(GetBattlegroundAllianceColor(bgAlliance)):ToHex()
local r, g, b
if bgAlliance == 1 then
r = 255 / 255
g = 60 / 255
b = 35 / 255
elseif bgAlliance == 3 then
r = 255 / 255
g = 73 / 255
b = 147 / 255
elseif bgAlliance == 2 then
r, g, b = ZO_ColorDef:New(GetBattlegroundAllianceColor(bgAlliance)):UnpackRGB()
end
return ZO_ColorDef:New(r, g, b, 1):ToHex()
end
function PVP:GetBattlegroundTeamBadgeIcon(alliance)
local icon
if alliance == 1 then
icon = "EsoUI/Art/Stats/battleground_alliance_badge_Fire_Drakes.dds"
elseif alliance == 2 then
icon = "EsoUI/Art/Stats/battleground_alliance_badge_Pit_Daemons.dds"
elseif alliance == 3 then
icon = "EsoUI/Art/Stats/battleground_alliance_badge_Storm_Lords.dds"
end
return icon
end
function PVP:GetBattlegroundTeamBadgeTextFormattedIcon(alliance, dimensionX, dimensionY)
dimensionX = dimensionX or 32
dimensionY = dimensionY or 32
local icon = PVP:GetBattlegroundTeamBadgeIcon(alliance)
-- return ZO_ColorDef:New(GetBattlegroundAllianceColor(alliance)):Colorize(zo_iconFormatInheritColor(icon, dimensionX, dimensionY))
return zo_iconFormatInheritColor(icon, dimensionX, dimensionY)
end
function PVP:ColorizeToBgTeamColor(alliance, text)
return ZO_ColorDef:New(GetBattlegroundAllianceColor(alliance)):Colorize(text)
end
function PVP:GetBattlegroundTypeText(battlegroundGameType)
local battlegroundTypeString
if battlegroundGameType == BATTLEGROUND_GAME_TYPE_CAPTURE_THE_FLAG then
battlegroundTypeString = "Capture The Flag"
elseif battlegroundGameType == BATTLEGROUND_GAME_TYPE_DEATHMATCH then
battlegroundTypeString = "Deathmatch"
elseif battlegroundGameType == BATTLEGROUND_GAME_TYPE_DOMINATION then
battlegroundTypeString = "Domination"
else
battlegroundTypeString = ""
end
return battlegroundTypeString
end
function PVP_Test_Scale(scale)
PVP.testScale = scale
PVP:FullReset3DIcons()
PVP:InitControls()
end
function PVP_GetIDs()
for i = 1, GetNumObjectives() do
local keepId, objectiveId, bgContext = GetObjectiveIdsForIndex(i)
local name = GetObjectiveInfo(keepId, objectiveId, bgContext)
if keepId == 0 and bgContext == BGQUERY_LOCAL and DoesObjectiveExist(keepId, objectiveId, bgContext) then
d('objectiveId: ' .. tostring(objectiveId) .. ' name: ' .. tostring(name))
end
end
end
function PVP_GetIDCoords()
for i = 1, GetNumObjectives() do
local keepId, objectiveId, bgContext = GetObjectiveIdsForIndex(i)
local name = GetObjectiveInfo(keepId, objectiveId, bgContext)
if keepId == 0 and bgContext == BGQUERY_LOCAL and DoesObjectiveExist(keepId, objectiveId, bgContext) then
local pin, X, Y = GetObjectivePinInfo(keepId, objectiveId, bgContext)
d('objectiveId: ' .. tostring(objectiveId) .. ' name: ' .. tostring(name))
d('X: ' .. tostring(X) .. ' Y: ' .. tostring(Y))
end
end
end
function PVP:IsSupportedBattlegroundId(battlegroundId)
-- return PVP.ullaraIds[battlegroundId] or PVP.foyadaIds[battlegroundId] or PVP.aldIds[battlegroundId] or PVP.arcaneIds[battlegroundId]
if PVP.ullaraIds[battlegroundId] or PVP.foyadaIds[battlegroundId] or PVP.aldIds[battlegroundId] then
return true
else
return false
end
-- return PVP.ullaraIds[battlegroundId] or PVP.foyadaIds[battlegroundId] or PVP.aldIds[battlegroundId]
end
function PVP:IsInSupportedBattleground()
return IsActiveWorldBattleground() and PVP:IsSupportedBattlegroundId(GetCurrentBattlegroundId())
end
function PVP:IsInSupportedBattlegroundGametype()
local supportedGametypes = {
[BATTLEGROUND_GAME_TYPE_CAPTURE_THE_FLAG] = true,
[BATTLEGROUND_GAME_TYPE_DEATHMATCH] = true,
[BATTLEGROUND_GAME_TYPE_DOMINATION] = true,
}
local function isSupportedGametype(battlegroundId)
return supportedGametypes[GetBattlegroundGameType(battlegroundId)]
end
return IsActiveWorldBattleground() and isSupportedGametype(GetCurrentBattlegroundId())
end
function PVP:GetBgBaseInfo(battlegroundId)
if not battlegroundId then return nil end
if PVP.ullaraIds[battlegroundId] then
return PVP.bgTeamBasesFull.ul
elseif PVP.foyadaIds[battlegroundId] then
return PVP.bgTeamBasesFull.foya
elseif PVP.aldIds[battlegroundId] then
return PVP.bgTeamBasesFull.ald