-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPVPSound.lua
More file actions
1419 lines (1272 loc) · 49.9 KB
/
PVPSound.lua
File metadata and controls
1419 lines (1272 loc) · 49.9 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
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
--[[
_ _ _ _ _ _ _ _
_/\\___ _ /\\ _/\\___ /\\__ __/\\___ ___ /\\ _/\\___ __/\\___
(_ _ _))/ \\ \\(_ _ _)) / \\(_ _))/ //\ \\ (_ ))(_ ____))
/ |))\\ \:'/ // / |))\\ _\ \_// / _ \\ \:.\\_\ \\ / : \\ / _ \\
/:. ___// \ // /:. ___//// \:.\ /:.(_)) \\ \ :. ///:. | ///:. |_\ \\
\_ \\ (_ _))\_ \\ \\__ / \ _____//(_ ___))\___| // \ _____//
\// \// \// \\/ \// \//5.1.0 \// \//
PVPSound
Copyright (c) 2010-2020 Resperger Dániel (Resike)
E-Mail: reske@gmail.com
All rights reserved.
See the accompanying "!Licence.txt" for more information.
The addon can be found at:
http://www.curse.com/addons/wow/pvpsound
http://www.wowinterface.com/downloads/info19569-PVPSound.html
--]]
local addon, ns = ...
local PVPSound = ns.PVPSound
local PVPSoundOptions = ns.PVPSoundOptions
local PS = ns.PS
local L = ns.L
local bit = bit
local ceil = ceil
local floor = floor
local getglobal = getglobal
local pairs = pairs
local print = print
local select = select
local string = string
local table = table
local unpack = table.unpack or unpack
local tonumber = tonumber
local tostring = tostring
local C_ChatInfo = C_ChatInfo
local C_Map = C_Map
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local CreateFrame = CreateFrame
local GetAddOnCPUUsage = GetAddOnCPUUsage
local GetAddOnMemoryUsage = GetAddOnMemoryUsage
local GetTime = GetTime
local IsInGroup = IsInGroup
local IsInInstance = IsInInstance
local PlaySoundFile = PlaySoundFile
local SendChatMessage = SendChatMessage
local UnitExists = UnitExists
local UnitGUID = UnitGUID
local UnitHealth = UnitHealth
local UnitHealthMax = UnitHealthMax
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local UnitIsEnemy = UnitIsEnemy
local UnitIsPlayer = UnitIsPlayer
local UnitName = UnitName
local UnitSex = UnitSex
local UpdateAddOnCPUUsage = UpdateAddOnCPUUsage
local UpdateAddOnMemoryUsage = UpdateAddOnMemoryUsage
local CombatLog_Object_IsA = CombatLog_Object_IsA
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
--[[local GetBuildInfo = GetBuildInfo
local GetMapLandmarkInfo = GetMapLandmarkInfo
local SendChatMessage = SendChatMessage
local GetTime = GetTime
local UnitGUID = UnitGUID
local UnitName = UnitName]]
-- Settings
local TimerReset
local ResetTime
local MultiKillTime
local RankStep
-- Player
local MyGender
-- Zones
local InstanceType
local CurrentInstId
local CurrentZoneId
-- Kills
local MultiKills
local CurrentStreak
local LastKill
local FirstKill
local FirstMultiKill
-- Deaths
local KilledMe
local KilledBy
local KilledWho
local GotKilledBy
-- Enemys
local ToEnemy
local FromEnemy
local ToEnemyNPC
local FromEnemyNPC
local ToEnemyPlayer
local ToEnemyPlayerAndNPC
local FromMyPets
local FromEnemyPlayer
local FromEnemyPlayerAndNPC
--addon modules table
PVPSound.modules = { }
-- WOW Version check
PS.isRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local PVPSoundFrame = CreateFrame("Frame", nil)
PVPSoundFrame:RegisterEvent("ADDON_LOADED")
local PVPSoundFrameBG
local PVPSoundFrameExecute
local PVPSoundFrameKills
local PVPSoundFrameData
function PVPSound:LoadBG()
if PS_EnableAddon == true and PS_BattlegroundSound == true then
if not PVPSoundFrameBG then
PVPSoundFrameBG = CreateFrame("Frame", nil)
end
PVPSoundFrameBG:RegisterEvent("PLAYER_ENTERING_WORLD")
PVPSoundFrameBG:RegisterEvent("ZONE_CHANGED_NEW_AREA")
PVPSoundFrameBG:SetScript("OnEvent", PVPSound.OnEventBG)
CurrentZoneId = C_Map.GetBestMapForUnit("player")
InstanceType = (select(2, IsInInstance()))
CurrentInstId = (select(8, GetInstanceInfo()))
PVPSound.API:LoadModules(CurrentZoneId, InstanceType, CurrentInstId)
PVPSound:Debug("!BG Events Loaded")
end
end
-- If this function will be called during DG, nothng happens, but the next BG will not be loaded.
function PVPSound:UnloadBG()
if PVPSoundFrameBG then
PVPSoundFrameBG:UnregisterEvent("PLAYER_ENTERING_WORLD")
PVPSoundFrameBG:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
PVPSound.API:UnregisterAllEvents()
PVPSound.API:UnloadModules()
PVPSound:Debug("!BG Events Unloaded")
end
end
function PVPSound:LoadExecute()
if PS_EnableAddon == true and PS_Execute == true then
if not PVPSoundFrameExecute then
PVPSoundFrameExecute = CreateFrame("Frame", nil)
end
PVPSoundFrameExecute:RegisterEvent("PLAYER_TARGET_CHANGED")
PVPSoundFrameExecute:RegisterEvent("UNIT_HEALTH")
PVPSoundFrameExecute:RegisterEvent("UNIT_MAXHEALTH")
PVPSoundFrameExecute:SetScript("OnEvent", PVPSound.OnEventExecute)
PVPSound:Debug("!Execute Events Loaded")
end
end
function PVPSound:UnloadExecute()
if PVPSoundFrameExecute then
PVPSoundFrameExecute:UnregisterEvent("PLAYER_TARGET_CHANGED")
PVPSoundFrameExecute:UnregisterEvent("UNIT_HEALTH")
PVPSoundFrameExecute:UnregisterEvent("UNIT_MAXHEALTH")
PVPSound:Debug("!Execute Events Unloaded")
end
end
local PVPSound_ScoreRequestElapsed = 0
local PVPSound_LastScoreRequest = 0
function PVPSound:LoadKills()
if not PVPSoundFrameKills then
PVPSoundFrameKills = CreateFrame("Frame", nil)
end
if (PS_KillSound == true or PS_MultiKillSound == true or PS_PaybackSound == true) and PS_EnableAddon == true then
-- WoW 12.0+: some clients can flag Frame:RegisterEvent() as protected for certain scoreboard events.
-- Polling the scoreboard avoids ADDON_ACTION_FORBIDDEN while keeping killing blow detection working.
PVPSoundFrameKills:SetScript("OnUpdate", function(_, elapsed) PVPSound:KillsOnUpdate(elapsed) end)
PVPSound:ResetScoreTracking()
PVPSound:Debug("Kills poller loaded")
else
PVPSound:Debug("Kills not enabled")
end
end
function PVPSound:UnloadKills()
if PVPSoundFrameKills then
if (PS_KillSound == false and PS_MultiKillSound == false and PS_PaybackSound == false) or PS_EnableAddon == false then
PVPSoundFrameKills:SetScript("OnUpdate", nil)
PVPSound:Debug("!Kills poller unloaded")
end
end
end
-- ===== WoW 12.0 PvP kill detection helpers (scoreboard + safe PARTY_KILL debug) =====
function PVPSound:ResetScoreTracking()
PVPSound._LastKB = nil
PVPSound._LastDeaths = nil
PVPSound_ScoreRequestElapsed = 0
PVPSound_LastScoreRequest = 0
local _, _, _, _, _, _, _, _, killCount = GetAchievementCriteriaInfoByID(1487, 0)
PVPSound._LastKillStat = PVPSound_SafeNumber(killCount) or 0
PVPSound._FastKillTimestamp = 0
end
local function PVPSound_ScrubSecretValue(v)
if v == nil then return nil end
if type(scrubsecretvalues) == "function" then
local ok, scrubbed = pcall(scrubsecretvalues, v)
if ok then
if type(scrubbed) == "table" then
v = scrubbed[1]
else
v = scrubbed
end
else
local okTable, scrubbedTable = pcall(scrubsecretvalues, { v })
if okTable and type(scrubbedTable) == "table" then
v = scrubbedTable[1]
else
return nil
end
end
end
if v == nil then return nil end
if type(issecretvalue) == "function" then
local ok, isSecret = pcall(issecretvalue, v)
if ok and isSecret then
return nil
end
end
return v
end
function PVPSound_SafeNumber(v)
v = PVPSound_ScrubSecretValue(v)
if v == nil then return nil end
return tonumber(v)
end
local function PVPSound_SafeString(v)
v = PVPSound_ScrubSecretValue(v)
if v == nil then return nil end
local ok, s = pcall(tostring, v)
if ok then
return s
end
return nil
end
local function PVPSound_GetSafeHealthPercent(unit)
local health = PVPSound_SafeNumber(UnitHealth(unit))
local maxHealth = PVPSound_SafeNumber(UnitHealthMax(unit))
if not health or not maxHealth or maxHealth <= 0 then
return nil
end
return health / maxHealth
end
function PVPSound:HandlePartyKill(killerGUID, victimGUID)
local _, _, _, _, _, _, _, _, currentKillStatRaw = GetAchievementCriteriaInfoByID(1487, 0)
local currentKillStat = PVPSound_SafeNumber(currentKillStatRaw) or 0
if not PVPSound._LastKillStat then
PVPSound._LastKillStat = currentKillStat
end
local statIncreased = currentKillStat > (PVPSound._LastKillStat or 0)
local isMyKill = false
local myGUID = PVPSound_SafeString(UnitGUID("player"))
local killerGUIDSafe = PVPSound_SafeString(killerGUID)
if killerGUIDSafe and myGUID and killerGUIDSafe == myGUID then
isMyKill = true
elseif statIncreased then
isMyKill = true
end
if isMyKill then
if PS_Debug then
PVPSound:Debug("FAST PATH: Kill Detected via " .. (statIncreased and "Stat" or "GUID"))
end
PVPSound._LastKillStat = currentKillStat
PVPSound._FastKillTimestamp = GetTime()
PVPSound:HandleKillingBlowInternal("PARTY_KILL")
end
end
function PVPSound:KillsOnUpdate(elapsed)
if PS_EnableAddon == false then return end
local inInst, instType = IsInInstance()
if not (inInst and (instType == "pvp" or instType == "arena")) then
PVPSound._ScoreInInstance = nil
return
end
PVPSound._ScoreInInstance = true
-- Reset tracking on instance/map changes (prevents stale deltas when queueing/porting).
local mapID = (C_Map and C_Map.GetBestMapForUnit) and C_Map.GetBestMapForUnit("player") or nil
if PVPSound._ScoreLastMapID ~= mapID or PVPSound._ScoreLastInstType ~= instType then
PVPSound._ScoreLastMapID = mapID
PVPSound._ScoreLastInstType = instType
PVPSound:ResetScoreTracking()
end
PVPSound_ScoreRequestElapsed = PVPSound_ScoreRequestElapsed + elapsed
if PVPSound_ScoreRequestElapsed < 0.5 then
return
end
PVPSound_ScoreRequestElapsed = 0
if type(RequestBattlefieldScoreData) == "function" then
pcall(RequestBattlefieldScoreData)
end
-- Without UPDATE_BATTLEFIELD_SCORE events (12.0 restrictions), we compute deltas by polling.
PVPSound:HandleScoreUpdate()
end
function PVPSound:GetMyScoreInfo()
local myGUID = PVPSound_SafeString(UnitGUID("player"))
if not myGUID then return nil end
if C_PvP and C_PvP.GetScoreInfoByPlayerGuid then
local ok, info = pcall(C_PvP.GetScoreInfoByPlayerGuid, myGUID)
if ok and type(info) == "table" then
return {
guid = PVPSound_SafeString(info.guid),
killingBlows = PVPSound_SafeNumber(info.killingBlows),
deaths = PVPSound_SafeNumber(info.deaths),
}
end
end
if C_PvP and C_PvP.GetScoreInfo and GetNumBattlefieldScores then
local n = GetNumBattlefieldScores()
for i = 1, n do
local info = C_PvP.GetScoreInfo(i)
if info and PVPSound_SafeString(info.guid) == myGUID then
return {
guid = myGUID,
killingBlows = PVPSound_SafeNumber(info.killingBlows),
deaths = PVPSound_SafeNumber(info.deaths),
}
end
end
end
return nil
end
function PVPSound:HandleScoreUpdate()
local inInst, instType = IsInInstance()
if not (inInst and (instType == "pvp" or instType == "arena")) then
return
end
local _, _, _, _, _, _, _, _, currentKBRaw = GetAchievementCriteriaInfoByID(1487, 0)
local currentKB = PVPSound_SafeNumber(currentKBRaw) or 0
if PVPSound._LastKillStat == nil then
PVPSound._LastKillStat = currentKB
return
end
local deltaKB = currentKB - (PVPSound._LastKillStat or 0)
PVPSound._LastKillStat = currentKB
if deltaKB and deltaKB > 0 then
local now = GetTime()
if PVPSound._FastKillTimestamp and (now - PVPSound._FastKillTimestamp) < 3.0 then
if PS_Debug then
PVPSound:Debug("SCORE_DELTA: Ignored duplicate (Fast Path handled it)")
end
deltaKB = deltaKB - 1
PVPSound._FastKillTimestamp = 0
end
if deltaKB > 0 then
if PS_Debug == true then
PVPSound:Debug("SCORE_DELTA killingBlows +"..tostring(deltaKB).." total="..tostring(currentKB))
end
for _ = 1, deltaKB do
PVPSound:HandleKillingBlowInternal("SCORE")
end
end
end
end
function PVPSound:HandleKillingBlowInternal(source)
-- Minimal, safe killing-blow pipeline for 12.0 BG/Arena scoreboard deltas
-- NOTE: We do not have reliable victim identity here (12.0 secret-value restrictions),
-- so PaybackKill identity-based features are intentionally skipped.
local t = GetTime()
local KillSoundLengthTable = getglobal("PVPSound_"..PS.KillSoundPack.."KillDurations")
local maxKillRank = KillSoundLengthTable and table.getn(KillSoundLengthTable) or 10
-- First kill or after long reset
if LastKill == nil or (t - LastKill) > ResetTime or TimerReset == true then
CurrentStreak = 1
MultiKills = 1
PVPSound:TriggerKill("Kill", CurrentStreak)
LastKill = t
TimerReset = false
return
end
-- Streak rank (within KillTime)
if (t - LastKill) <= PS.KillTime then
CurrentStreak = (CurrentStreak or 1) + (1 / RankStep)
if CurrentStreak > maxKillRank then
CurrentStreak = maxKillRank
end
CurrentStreak = floor(CurrentStreak + 0.5)
else
CurrentStreak = 1
end
PVPSound:TriggerKill("Kill", CurrentStreak)
-- Multi-kill (within MultiKillTime)
if PS_MultiKillSound == true then
if (t - LastKill) <= MultiKillTime then
MultiKills = (MultiKills or 1) + 1
local MultiKillSoundLengthTable = getglobal("PVPSound_"..PS.KillSoundPack.."MultiKillDurations")
local maxMultiRank = MultiKillSoundLengthTable and table.getn(MultiKillSoundLengthTable) or 5
local rank = MultiKills - 1
if rank > maxMultiRank then rank = maxMultiRank end
if rank >= 1 then
PVPSound:TriggerKill("MultiKill", rank)
end
else
MultiKills = 1
end
end
LastKill = t
end
function PVPSound:DumpCurrentPOIs()
if not (C_Map and C_Map.GetBestMapForUnit and C_AreaPoiInfo and C_AreaPoiInfo.GetAreaPOIForMap and C_AreaPoiInfo.GetAreaPOIInfo) then
print("PVPSound: POI APIs not available")
return
end
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then
print("PVPSound: mapID unavailable")
return
end
local ids = C_AreaPoiInfo.GetAreaPOIForMap(mapID)
if not ids then
print("PVPSound: no POIs for map "..tostring(mapID))
return
end
print("PVPSound: POIs for map "..tostring(mapID).." ("..tostring(#ids)..")")
for _, id in ipairs(ids) do
local info = C_AreaPoiInfo.GetAreaPOIInfo(mapID, id)
local name = info and info.name or ""
local atlas = info and info.atlasName or ""
local tex = info and info.textureIndex or ""
print(" POI "..tostring(id).." name="..tostring(name).." atlas="..tostring(atlas).." textureIndex="..tostring(tex))
end
-- If a module for this map exists and exposes DumpPOIs(), call it too
if PVPSound.API and PVPSound.API.modules and PVPSound.API.modules[mapID] and PVPSound.API.modules[mapID].DumpPOIs then
PVPSound.API.modules[mapID]:DumpPOIs()
end
end
function PVPSound:LoadDeathShare()
if PS_EnableAddon == true and (PS_DeathMessage == true or PS_DataShare ==true) then
if not PVPSoundFrameData then
PVPSoundFrameData = CreateFrame("Frame", nil)
end
PVPSoundFrameData:RegisterEvent("PLAYER_DEAD")
PVPSoundFrameData:SetScript("OnEvent", PVPSound.OnEventData)
PVPSound:Debug("!DeathShare Events Loaded")
end
end
function PVPSound:UnloadDeathShare()
if PVPSoundFrameData then
if (PS_DeathMessage == false and PS_DataShare ==false) or PS_EnableAddon == false then
PVPSoundFrameData:UnregisterEvent("PLAYER_DEAD")
PVPSound:Debug("!DeathShare Events Unloaded")
end
end
end
function PVPSound:RegisterEvents()
PVPSound:LoadBG()
PVPSound:LoadExecute()
PVPSound:LoadKills()
PVPSound:LoadDeathShare()
PVPSound:Debug("!All Events Loaded")
end
function PVPSound:UnregisterEvents()
PVPSound:UnloadBG()
PVPSound:UnloadExecute()
PVPSound:UnloadKills()
PVPSound:UnloadDeathShare()
PVPSound:Debug("!All Events Unloaded")
end
-- Killing Settings
function PVPSound:KillingSettings()
TimerReset = false -- Resets every timer and counter
ResetTime = 1800 -- Automatically resets everything when no kills made in 30 minutes
MultiKillTime = 16 -- If you get the Multi Kills in 16 sec difference you gain a Multi Kill rank, else resets
RankStep = 1 -- How many kills need for the next rank after the First Blood
PS.KillTime = 60 -- If you get the Kills in 60 sec difference you gain a rank, else just replays your last rank and rank gaining continuing from that rank
PS.PaybackKillTime = 90 -- The time you can revenge the players they killed you, or the players can revenge you whom you killed
PS.RecentlyKilledTime = 1.500 -- The time in you cant gain more then one kill on the same target
PS.RecentlyPaybackTime = 1.500 -- The time in you cant gain more then one payback and retribution kill
end
-- Default Settings
function PVPSound:DefaultSettings()
if PS_EnableAddon == nil then
PS_EnableAddon = true
end
if PS_AddonLanguage == nil then
PS_AddonLanguage = "English"
PVPSound:English()
end
if PS_Mode == nil then
PS_Mode = "PVP"
end
if PS_Emote == nil then
PS_Emote = true
end
if PS_EmoteMode == nil then
PS_EmoteMode = true
end
if PS_DeathMessage == nil then
PS_DeathMessage = true
end
if PS_KillSound == nil then
PS_KillSound = true
end
if PS_MultiKillSound == nil then
PS_MultiKillSound = true
end
if PS_PetKill == nil then
PS_PetKill = true
end
if PS_PaybackSound == nil then
PS_PaybackSound = true
end
if PS_BattlegroundSound == nil then
PS_BattlegroundSound = true
end
if PS_SoundEffect == nil then
PS_SoundEffect = true
end
if PS_KillSoundEngine == nil then
PS_KillSoundEngine = true
end
if PS_Debug == nil then
PS_Debug = false
end
if PS_PoiDebug == nil then
PS_PoiDebug = false
end
debug = PS_Debug
if PS_BattlegroundSoundEngine == nil then
PS_BattlegroundSoundEngine = true
end
if PS_DataShare == nil then
PS_DataShare = true
end
if PS_KillSct == nil then
PS_KillSct = true
end
if PS_MultiKillSct == nil then
PS_MultiKillSct = true
end
if PS_PaybackSct == nil then
PS_PaybackSct = true
end
if PS_SctEngine == nil then
PS_SctEngine = true
end
if PS_ShowKillTextWithName == nil then
PS_ShowKillTextWithName = true
end
-- Intended name
if PSSctFrame == nil then
if MikSBT then
PSSctFrame = "Notification"
elseif Parrot then
PSSctFrame = "Notification"
elseif SCT then
PSSctFrame = "Frame 1"
elseif xCT then
PSSctFrame = "Frame 3"
elseif xCT_Plus then
PSSctFrame = "General"
end
end
if PSSctFrame == nil then
PSSctFrame = "RaidWarning"
end
if PS_HideServerName == nil then
PS_HideServerName = true
end
if PS_Channel == nil then
PS_Channel = "Master"
end
if PS_KillSoundPackName == nil then
PS_KillSoundPackName = "UnrealTournament3"
end
if PS_KillSoundPackLanguage == nil then
PS_KillSoundPackLanguage = "Eng"
end
if PS_SoundPackName == nil then
PS_SoundPackName = "UnrealTournament3"
end
if PS_SoundPackLanguage == nil then
PS_SoundPackLanguage = "Eng"
end
-- Data Share Register
if PS_DataShare == true then
C_ChatInfo.RegisterAddonMessagePrefix("PVPSound")
end
--finish him/her sounds
if PS_Execute == nil then
PS_Execute = false
end
end
function PVPSound:SetAddonLanguage()
if PS_AddonLanguage == "English" then
PVPSound:English()
elseif PS_AddonLanguage == "German" then
PVPSound:German()
elseif PS_AddonLanguage == "Spanish" then
PVPSound:Spanish()
elseif PS_AddonLanguage == "LatinAmericanSpanish" then
PVPSound:LatinAmericanSpanish()
elseif PS_AddonLanguage == "French" then
PVPSound:French()
elseif PS_AddonLanguage == "Italian" then
PVPSound:Italian()
elseif PS_AddonLanguage == "Korean" then
PVPSound:Korean()
elseif PS_AddonLanguage == "Portuguese" then
PVPSound:Portuguese()
elseif PS_AddonLanguage == "Russian" then
PVPSound:Russian()
elseif PS_AddonLanguage == "SimplifiedChinese" then
PVPSound:SimplifiedChinese()
elseif PS_AddonLanguage == "TraditionalChinese" then
PVPSound:TraditionalChinese()
end
end
-- resetting queries
function PVPSound:TimerReset()
TimerReset = true
end
function PVPSound:KillersReset()
KilledMe = nil
KilledBy = nil
end
-- Addon error messages function
function PVPSound:Error(msg)
if type(msg) ~= "string" then
msg = tostring(msg)
end
print("|cFFf44336PVPSound ERROR:|r |cFF1688f1"..msg.."|r")
end
-- Addon debug messages function on/off switcher
local debug = false
-- Switch debug
function PVPSound:SwitchDebug()
PS_Debug = not PS_Debug
debug = PS_Debug
return debug
end
function PVPSound:SwitchPoiDebug()
PS_PoiDebug = not PS_PoiDebug
return PS_PoiDebug
end
-- Addon debug messages function
function PVPSound:Debug(msg)
if debug == true then
if type(msg) ~= "string" then
msg = tostring(msg)
end
print("|cFFff9a00PVPSound Debug:|r |cFF7FFF00"..msg.."|r")
end
end
-- Addon metadata compatibility (WoW 12.0 / The War Within)
function PVPSound:GetAddonMetadata(field)
if not field then return "" end
-- Retail 12.0+ uses C_AddOns
if C_AddOns and C_AddOns.GetAddOnMetadata then
local ok, val = pcall(C_AddOns.GetAddOnMetadata, "PVPSound", field)
if ok and val ~= nil then
return val
end
end
-- Fallback for older clients / Classic
if GetAddOnMetadata then
local ok, val = pcall(GetAddOnMetadata, "PVPSound", field)
if ok and val ~= nil then
return val
end
end
return ""
end
--addon performanse info dump
function PVPSound:perfDump()
PVPSound:Debug(addon)
UpdateAddOnMemoryUsage()
UpdateAddOnCPUUsage()
local mem = GetAddOnMemoryUsage(addon)
local cpu = GetAddOnCPUUsage(addon)
print("current memory usege: ", mem)
print("current CPU usege: ", cpu)
end
-- configuration info dump
function PVPSound:ConfigDump()
print("Addon cofig:")
print("Retail: ", PS.isRetail)
print("Addon language: ", PS_AddonLanguage)
print("Kill soundpack name: ", PS_KillSoundPackName)
print("Kill soundpack language: ", PS_KillSoundPackLanguage)
print("Soundpack name: ", PS_SoundPackName)
print("Soundpack language: ", PS_SoundPackLanguage)
print("Mode: ", PS_Mode)
print("Emote: ",PS_Emote)
print("Emote mode: ",PS_EmoteMode)
print("Death message: ",PS_DeathMessage)
print("Kill sounds: ",PS_KillSound)
print("MultiKill Sound: ", PS_MultiKillSound)
print("PetKill: ", PS_PetKill)
print("PaybackSound: ", PS_PaybackSound)
print("BattlegroundSound: ", PS_BattlegroundSound)
print("SoundEffect: ", PS_SoundEffect)
print("KillSoundEngine: ", PS_KillSoundEngine)
print("BattlegroundSoundEngine: ", PS_BattlegroundSoundEngine)
print("Datashare: ", PS_DataShare)
print("Kill SCT: ", PS_KillSct)
print("MultiKill SCT: ", PS_MultiKillSct)
print("Payback SCT: ", PS_PaybackSct)
print("SCT engine: ", PS_SctEngine)
print("SCT Frame: ", PSSctFrame)
print("Hide server name: ", PS_HideServerName)
print("Sound channel name: ", PS_Channel)
print("Finishing sounds: ", PS_Execute)
print("Reset time: ",ResetTime)
print("Multikill time: ",MultiKillTime)
print("Payback time: ",PS.PaybackKillTime)
print("Recently killed penalty time: ",PS.RecentlyKilledTime)
print("Recently payback penalty time: ",PS.RecentlyPaybackTime)
print("Rank step for kills: ", RankStep)
print("Debug output trigger: ", debug)
end
-- Table and functions for execute sounds
local TargetHealthObjectives = {Percent = nil}
local function TargetHealthGetObjective(healthPercent)
if healthPercent then
return "Percent"
else
return false
end
end
local function TargetHealthState(healthPercent)
if healthPercent then
if healthPercent >= 0.2 then
return 1
elseif healthPercent < 0.2 and UnitIsDeadOrGhost("target") ~= 1 then
return 2
else
return false
end
end
end
function PVPSound:OnEvent(event, ...)
if event == "ADDON_LOADED" then
local Addon = ...
if Addon == "PVPSound" then
PVPSound:KillingSettings()
PVPSound:DefaultSettings()
PVPSound:SetAddonLanguage()
-- SoundPack Settings
if PS_KillSoundPackName == "DevilMayCry" then
PS.KillSoundPackDirectory = "Interface\\Addons\\PVPSound\\Sounds\\"..PS_KillSoundPackName
elseif PS_KillSoundPackName == "Dota2" then
PS.KillSoundPackDirectory = "Interface\\Addons\\PVPSound\\Sounds\\"..PS_KillSoundPackName
elseif PS_KillSoundPackName == "Halo4" then
PS.KillSoundPackDirectory = "Interface\\Addons\\PVPSound\\Sounds\\"..PS_KillSoundPackName
elseif PS_KillSoundPackName == "UnrealTournament3" then
PS.KillSoundPackDirectory = "Interface\\Addons\\PVPSound\\Sounds\\"..PS_KillSoundPackName
elseif PS_KillSoundPackName == "Custom" then
PS.KillSoundPackDirectory = "Interface\\Addons\\PVPSound_CustomSoundPack\\Sounds\\"..PS_KillSoundPackName
end
if PS_SoundPackName == "UnrealTournament3" then
PS.SoundPackDirectory = "Interface\\Addons\\PVPSound\\Sounds\\"..PS_SoundPackName
elseif PS_SoundPackName == "Custom" then
PS.SoundPackDirectory = "Interface\\Addons\\PVPSound_CustomSoundPack\\Sounds\\"..PS_SoundPackName
end
PS.KillSoundPack = PS_KillSoundPackName..""..PS_KillSoundPackLanguage
PS.SoundPack = PS_SoundPackName..""..PS_SoundPackLanguage
if PS_EnableAddon == true then
PVPSound:RegisterEvents()
end
PVPSoundOptions:OptionsAddonIsLoaded()
-- Addon loaded message
-- print("|cFF50C0FFPVPSound |cFFFFA500"..GetAddOnMetadata("PVPSound", "Version").."|cFF50C0FF loaded.|r")
end
end
end
PVPSoundFrame:SetScript("OnEvent", PVPSound.OnEvent)
function PVPSound:OnEventBG(event, ...)
if PS_EnableAddon == true then
--------------------------------------
-- modules loading routine
-- each module must have 2 functions
-- initialize and unload
-- these funcs called from event handler of PVPSound frame
-- each time ZONE_CHANGED_NEW_AREA or PLAYER_ENTERING_WORLD fires
-- unload function of each "loaded" (loaded parameter setted to true in initialize function) module should be called
-- it needed to release all events and resourses before initializing new module, and to avoid conflicts like
-- calling unload function of module right after calling intialize function (such problem occures when unload function called on
-- ZONE_CHANGED_NEW_AREA event on API frame and init function called on ZONE_CHANGED_NEW_AREA event in PVPSound frame)
-- If module don,t have initialize function, it will not be loaded
-- If module don't have unload function, all events of API frame will automaticlly be unregistered
-- Also, on each ZONE_CHANGED_NEW_AREA or PLAYER_ENTERING_WORLD event, if module is existed for new zone, PVPSound timer and killing qoueues will be resetted
--------------------------------------
if event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_ENTERING_WORLD" then
-- on initial login (and when you use portals or smth like this) both events fired, but PLAYER_ENTERING_WORLD fires with wrong zone id (id of parent map)
-- on TP using both events fired, but PLAYER_ENTERING_WORLD fires with wrong zone id (id of parent map)
-- on /reload fires only PLAYER_ENTERING_WORLD, but with correct zone id
-- instance id can be used for BGs, but then, we can't use this code open world battlefields as is
CurrentZoneId = C_Map.GetBestMapForUnit("player")
InstanceType = (select(2, IsInInstance())) -- check it to aviod uncorrect returm value of GetBestMapForUnit after PLAYER_ENTERING_WORLD event
CurrentInstId = (select(8, GetInstanceInfo()))
-- Player's Gender
if UnitSex("player") == 2 then
MyGender = "Male"
elseif UnitSex("player") == 3 then
MyGender = "Female"
end
PS.PaybackKillTime = 90
PVPSound.API:UnloadModules(CurrentZoneId, InstanceType, CurrentInstId)
PVPSound.API:LoadModules(CurrentZoneId, InstanceType, CurrentInstId)
end
end
end
function PVPSound:OnEventData(event, ...)
if PS_EnableAddon == true then
if event == "PLAYER_DEAD" then
local Channel = "INSTANCE_CHAT"
KilledBy = PVPSound_SafeString(KilledBy)
-- Death Data Share
if KilledBy ~= nil then
if PS_DataShare == true then
if CurrentStreak ~= nil then
local KillSoundLengthTable = getglobal("PVPSound_"..PS.KillSoundPack.."KillDurations")
local Message
if CurrentStreak <= table.getn(KillSoundLengthTable) then
Message = KillSoundLengthTable[CurrentStreak].name
else
Message = KillSoundLengthTable[table.getn(KillSoundLengthTable)].name
end
if string.find(KilledBy, "!") then
GotKilledBy = string.sub(KilledBy, 1, string.len(KilledBy) - 1)
else
GotKilledBy = tostring(KilledBy)
end
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and IsInInstance() then
if InstanceType == "pvp" or InstanceType == "arena" or InstanceType == "raid" or InstanceType == "party" or InstanceType == nil then
C_ChatInfo.SendAddonMessage("PVPSound", Message..":"..GotKilledBy, Channel)
end
else
C_ChatInfo.SendAddonMessage("PVPSound", Message..":"..GotKilledBy, "RAID")
end
end
end
-- Death Messages
if PS_DeathMessage == true then
if string.sub(KilledBy, -1) == "!" then
GotKilledBy = string.sub(KilledBy, 1, string.len(KilledBy) - 1)
else
if string.find(KilledBy, "-") and PS_HideServerName ~= false then
GotKilledBy = tostring(string.match(KilledBy, "(.+)-"))
if GotKilledBy and string.find(GotKilledBy, "-") then
GotKilledBy = tostring(string.match(GotKilledBy, "(.+)-"))
end
else
GotKilledBy = tostring(KilledBy)
end
end
if GotKilledBy ~= nil then
print("|cFFFF4500"..L["You got killed by"].." "..GotKilledBy.."!|r")
end
GotKilledBy = nil
end
KilledBy = nil
end
TimerReset = true
end
end
end
function PVPSound:OnEventExecute(event, ...)
if PS_EnableAddon == true then
-- execute sounds can not be places in ideology of kill or bg sounds
-- because it is more about an dueling announcement
-- so it can not be placed in any sound engine queues
-- so i just play the sound file without a queues
local unit = ...
if (event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH") and unit ~= "target" then
return
end
if (event == "PLAYER_TARGET_CHANGED" or event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH") and PS_Execute == true then
local isEnemy = UnitIsEnemy("target", "player")
if UnitExists("target") and isEnemy == true and UnitIsDeadOrGhost("target") == false then
local TargetGender
if UnitSex("target") == 1 then
TargetGender = "Unknown"
elseif UnitSex("target") == 2 then
TargetGender = "Male"
elseif UnitSex("target") == 3 then
TargetGender = "Female"
end
local TargetHealthPercent = PVPSound_GetSafeHealthPercent("target")
if not TargetHealthPercent then
return
end
if PS_Mode == "PVP" then
if UnitIsPlayer("target") == true then
local type = TargetHealthGetObjective(TargetHealthPercent)
if type then
if TargetHealthState(TargetHealthObjectives[type]) == 1 and TargetHealthState(TargetHealthPercent) == 2 then
if TargetGender == "Male" or TargetGender == "Unknown" then
PlaySoundFile("Interface\\Addons\\PVPSound\\Sounds\\MortalKombat\\Eng\\Execute\\FinishHim.mp3", PS_Channel)
elseif TargetGender == "Female" then
PlaySoundFile("Interface\\Addons\\PVPSound\\Sounds\\MortalKombat\\Eng\\Execute\\FinishHer.mp3", PS_Channel)
end
end
TargetHealthObjectives[type] = TargetHealthPercent