-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BronCena.lua
764 lines (669 loc) · 28.4 KB
/
BronCena.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
local _, ns = ...
local APPNAME = "BronCena"
local APPDESC = "Bron Cena"
BronCena = LibStub("AceAddon-3.0"):NewAddon(APPNAME, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(APPNAME)
local LSM = LibStub("LibSharedMedia-3.0")
local ACD = LibStub("AceConfigDialog-3.0")
-- Library constants
local SOUND = LSM.MediaType and LSM.MediaType.SOUND or "sound"
local isInitialized = false
-- Hidden tooltip used to parse summoned unit tooltips for things like name
local parsingTooltip = nil;
local soundOptions = {
custom = "<Custom Sound>",
random = "BronCena: Surprise me! (Random)",
broncena = "BronCena: Default",
broncenafull = "BronCena: Full Length",
shoryuken = "BronCena: Shoryuken",
shouryureppa = "BronCena: Shouryureppa",
metalgear = "BronCena: Metal Gear Alert",
yaketysax = "BronCena: Yakety Sax (Benny Hill)",
darkness = "BronCena: Sound of Silence",
}
local soundPaths = {
[soundOptions.broncena] = "Interface/AddOns/BronCena/Media/Sounds/broncena.ogg",
[soundOptions.broncenafull] = "Interface/AddOns/BronCena/Media/Sounds/broncena-full.ogg",
[soundOptions.shoryuken] = "Interface/AddOns/BronCena/Media/Sounds/shoryuken.ogg",
[soundOptions.shouryureppa] = "Interface/AddOns/BronCena/Media/Sounds/shouryureppa.ogg",
[soundOptions.metalgear] = "Interface/AddOns/BronCena/Media/Sounds/metalgear.ogg",
[soundOptions.yaketysax] = "Interface/AddOns/BronCena/Media/Sounds/yakety-sax.ogg",
[soundOptions.darkness] = "Interface/AddOns/BronCena/Media/Sounds/darkness.ogg"
}
local soundChannels = {
["default"] = "Default",
["ambience"] = "Ambience",
["dialog"] = "Dialog",
["master"] = "Master",
["music"] = "Music",
["sfx"] = "Sound"
}
local sharedSoundOptions = nil
local CHANNEL_DEFAULT = "default"
function BronCena:Verbose(...)
if self.db.profile.verbose == false then return end
self:Printf(...)
end
function BronCena:Debug(...)
if self.db.profile.debug == false then return end
self:Printf(...)
end
local function CompanionDefaults(disabled, id, name, desc, soundId, message, delay, eventType)
return {
id = id,
name = name,
desc = desc,
disabled = disabled or false,
zones = { party = nil, raid = nil, pvp = nil, arena = nil, scenario = nil, world = nil },
owners = { player = nil, party = nil, raid = nil, friendly = nil, hostile = nil },
delay = delay or nil,
soundDisabled = false,
soundId = soundId or nil,
soundPath = nil,
soundChannel = CHANNEL_DEFAULT,
message = message or nil,
messageDisabled = false,
eventType = eventType or "SPELL_SUMMON"
}
end
-- Spells that by default should only trigger for just the player
local function CompanionPlayerDefaults(disabled, id, name, desc, soundId, message, delay, eventType)
return {
id = id,
name = name,
desc = desc,
disabled = disabled or false,
zones = { party = nil, raid = nil, pvp = nil, arena = nil, scenario = nil, world = nil },
owners = { player = true, party = false, raid = false, friendly = false, hostile = false },
delay = delay or nil,
soundDisabled = false,
soundId = soundId or nil,
soundPath = nil,
soundChannel = CHANNEL_DEFAULT,
message = message or nil,
messageDisabled = false,
eventType = eventType or "SPELL_SUMMON"
}
end
-- Companions
-- 324739 Summon Steward (unit: Steward)
-- ITEM_PUSH: 463534 (Phial of Serenity)
-- 221745 - Judgement's Gaze (Lothraxion)
-- UNIT_SPELLCAST_SUCCEEDED: Summoning pets
local defaults = {
profile = {
-- General
disabled = false,
unlocked = false, -- Enable or disable dragging of the UI elements
debug = false,
soundChannel = CHANNEL_DEFAULT, -- Default sound channel
enableOverlap = false, -- Allow sounds to overlap each other
-- Enable / disable for zones
zones = {
party = true,
raid = true,
pvp = true,
arena = true,
scenario = true,
world = true
},
-- Enable / disable for owners
owners = {
player = true,
party = true,
raid = true,
friendly = true,
hostile = true
},
-- Default companions
companions = {
["1"] = CompanionDefaults(false, "1", "Level Up", "", soundOptions.broncena, "DING! Bron Cena says grats on level %s!", nil, "PLAYER_LEVEL_UP"),
["333961"] = CompanionDefaults(false, "333961", "Bron Cena", "", soundOptions.broncena, "And his name is BRON CENA!"),
["324739"] = CompanionDefaults(true, "324739", "Kyrian Steward", "", soundOptions.metalgear, "A wild %s appears!", 0.8),
["368241"] = CompanionPlayerDefaults(true, "368241", "Wo Speed Buff", "", soundOptions.yaketysax, nil, nil, "SPELL_AURA_APPLIED"),
["883"] = CompanionDefaults(true, "883", "Hunter Pet 1", "", soundOptions.metalgear, "A wild %s appears!", 0.8),
["1297"] = CompanionDefaults(true, "1297", "Revive Pet", "", soundOptions.metalgear, "A wild %s appears!", 0.8),
["196718"] = CompanionDefaults(true, "196718", "Darkness", "", soundOptions.darkness, "Hello Darkness my old friend...", nil, "SPELL_CAST_SUCCESS"),
}
}
}
local options = {
name = APPDESC,
handler = BronCena,
type = "group",
childGroups = "tab",
desc = APPDESC,
get = "GetConfig",
set = "SetConfig",
args = {
general = {
type = "group",
name = "General",
order = 1,
args={
general = {
type = "group",
name = "General Options",
order = 10,
inline = true,
args = {
disabled = {
order = 10,
type = "toggle",
name = L["Disabled"],
desc = L["Disables or enables the addon"]
},
unlocked = {
order = 20,
type = "toggle",
name = L["Unlock"],
desc = L["Enables or disables moving UI"]
},
soundChannel = {
order = 30,
type = "select",
name = L["Channel"],
desc = L["Default sound channel"],
values = "SoundChannels"
},
debug = {
order = 40,
type = "toggle",
name = L["Debug"],
desc = L["Enables or disables debug logging"]
},
enableOverlap = {
order = 50,
type = "toggle",
width = "double",
name = L["Enable overlapping sounds"],
desc = L["Enables or disables sounds to play over each other when triggered multiple times"]
},
}
},
zones = {
order = 20,
type = "multiselect",
name = L["Zones"],
values = "GetZoneOptions",
get = "GetMultiSelectConfig",
set = "SetMultiSelectConfig"
},
owners = {
order = 30,
type = "multiselect",
name = L["Owners"],
values = "GetOwnerOptions",
get = "GetMultiSelectConfig",
set = "SetMultiSelectConfig"
}
}
},
companions = {
name = "Companions",
type = "group",
childGroups = "select",
args = {
general = {
type = "description",
name = "Choose a companion from the drop-down"
},
-- add = {
-- name = "Add",
-- desc = "Add a new companion",
-- type = "execute"
-- },
}
}
}
}
function BronCena:InitializeOptions(root)
for k,v in pairs(self.db.profile.companions) do
local node = {
type = "group",
name = v.name,
desc = v.description,
get = "GetCompanionConfig",
set = "SetCompanionConfig",
childGroups = "tab",
args = {
disabled = {
order = 1,
type = "toggle",
name = L["Disabled"],
desc = "Disable or enable this companion",
width = "full",
get = function ()
return v.disabled
end
},
id = {
disabled = true,
order = 10,
width = "normal",
type = "input",
name = "ID",
desc = "The spell id that summons this companion",
get = function ()
return v.id
end
},
name = {
width = "normal",
order = 20,
disabled = true,
type = "input",
name = "Name",
desc = "The name for this companion",
get = function ()
return v.name
end
},
message = {
width = "full",
order = 25,
type = "input",
name = "Message",
desc = "The message for this companion. %s will be substituted with the companion's name.",
get = function (info)
return v.message
end,
set = function(info, value)
v.message = value
end
},
soundId = {
order = 30,
width = "double",
type = "select",
name = "Sound",
desc = "The sound to play",
values = "GetSoundOptions",
get = function (info) return v.soundId end,
set = function (info, value)
self:Debug("Set soundId to %s", tostring(value))
v.soundId = value
end
},
soundChannel = {
width = "normal",
order = 40,
type = "select",
name = L["Channel"],
desc = L["Default sound channel"],
values = "SoundChannels",
get = function (info) return v.soundChannel end,
set = function (info, value) v.soundChannel = value end
},
soundPath = {
order = 50,
type = "input",
name = "Path",
desc = "The sound to play",
width = "full",
get = function (info)
if tostring(v.soundId) == tostring(soundOptions.custom) then
return v.soundPath
else
self:Debug("Fetching %s", v.soundId)
return tostring(LSM:Fetch(SOUND, v.soundId, false) or v.soundId)
end
end,
set = function (info, value)
v.soundPath = tostring(value)
end,
disabled = function ()
self:Debug("soundId=%s", v.soundId)
if tostring(v.soundId) == tostring(soundOptions.custom) then
return false
else
return true
end
end
},
playSound = {
order = 60,
type = "execute",
width = "half",
name = "Test",
func = function()
-- Default to the custom path
local sound = v.soundPath
-- If we're using a selected option, we have to find the path / soundkit id
if tostring(v.soundId) == tostring(soundOptions.custom) then
self:Debug("Using custom sound path")
else
self:Debug("Shared media id: %s", tostring(v.soundId))
sound = LSM:Fetch(SOUND, v.soundId, false) or v.soundId
end
local soundChannel = v.soundChannel or CHANNEL_DEFAULT
if soundChannel == CHANNEL_DEFAULT then soundChannel = soundChannels.dialog end
if not sound then
self:Debug("No sound path to play")
else
if v.message then
local message = string.format(v.message, "<Unknown>")
BronCenaMessageFrame:AddMessage(message, 1.0, 1.0, 1.0);
end
self:Debug("Playing %s", sound)
-- Stop this companion's sound if it's already playing to prevent annoying overlaps
if v.handle then
-- Users can allow overlapping sounds for hilarity
if not self.db.profile.enableOverlap == true then
StopSound(v.handle)
end
end
local willPlay, handle = PlaySoundFile(sound, soundChannel)
if willPlay then
v.handle = handle
end
end
end
},
stopSound = {
order = 70,
type = "execute",
width = "half",
name = "Stop",
func = function()
if v.handle then
StopSound(v.handle)
end
end
},
zones = {
order = 80,
type = "multiselect",
name = L["Zones"],
values = "GetZoneOptions",
tristate = true,
get = "GetCompanionMultiSelectConfig",
set = "SetCompanionMultiSelectConfig"
},
owners = {
order = 90,
type = "multiselect",
name = L["Owners"],
values = "GetOwnerOptions",
tristate = true,
get = "GetCompanionMultiSelectConfig",
set = "SetCompanionMultiSelectConfig"
}
}
}
root.args.companions.args[k] = node
end
root.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db);
return root
end
function BronCena:GetMultiSelectConfig(info, key)
self:Debug("GetMultiSelectConfig %s, %s", info[#info], tostring(key))
return self.db.profile[info[#info]][key]
end
function BronCena:SetMultiSelectConfig(info, key, value)
self:Debug("SetMultiSelectConfig %s.%s=%s", info[#info], key, tostring(value))
self.db.profile[info[#info]][key] = value
end
function BronCena:GetConfig(info)
self:Debug("GetConfig %s", tostring(info[#info]))
--self:Debug("GetConfig %s", tostring(info[#info]))
return self.db.profile[info[#info]]
end
function BronCena:SetConfig(info, value)
self:Debug("SetConfig %s=%s", tostring(info[#info]), tostring(value))
self.db.profile[info[#info]] = value
self:ApplyOptions()
end
function BronCena:GetCompanionConfig(info)
local id = info[#info-1]
local companion = self.db.profile.companions[id]
if companion then
self:Debug("GetCompanionConfig %s", tostring(info[#info]))
return companion[info[#info]]
end
end
function BronCena:SetCompanionConfig(info, value)
local id = info[#info-1]
local companion = self.db.profile.companions[id]
self:Debug("SetCompanionConfig companion.%s=%s", tostring(info[#info]), tostring(value))
companion[info[#info]] = value
end
function BronCena:GetCompanionMultiSelectConfig(info, key)
local id = info[#info-1]
local companion = self.db.profile.companions[id]
if companion then
self:Debug("GetCompanionMultiSelectConfig %s.%s", tostring(info[#info]), tostring(key))
return companion[info[#info]][key]
end
end
function BronCena:SetCompanionMultiSelectConfig(info, key, value)
local id = info[#info-1]
local companion = self.db.profile.companions[id]
self:Debug("SetCompanionMultiSelectConfig companion.%s.%s=%s", tostring(info[#info]), tostring(key), tostring(value))
companion[info[#info]][key] = value
end
function BronCena:ApplyOptions()
-- Do we need to toggle visibility of the draggable anchor frame?
if not BronCenaMessageAnchor:IsVisible() == self.db.profile.unlocked then
self:Debug("Unlocked status was changed")
if self.db.profile.unlocked == true then
BronCenaMessageAnchor:Show()
else
BronCenaMessageAnchor:Hide()
end
end
end
function BronCena:SoundChannels()
return soundChannels
end
function BronCena:GetSoundOptions()
if self.sharedSoundOptions == nil then
self.sharedSoundOptions = {
-- Place our BronCena options at the top
[soundOptions.custom] = soundOptions.custom,
[soundOptions.broncena] = soundOptions.broncena,
[soundOptions.broncenafull] = soundOptions.broncenafull,
[soundOptions.shoryuken] = soundOptions.shoryuken,
[soundOptions.shouryureppa] = soundOptions.shouryureppa,
[soundOptions.metalgear] = soundOptions.metalgear,
[soundOptions.yaketysax] = soundOptions.yaketysax,
[soundOptions.darkness] = soundOptions.darkness,
};
-- Now we add all the non-BronCena sounds from shared media
for k,v in pairs(LSM:HashTable(SOUND)) do
if not string.find(k, "BronCena") then
self.sharedSoundOptions[k] = k
end
end
end
return self.sharedSoundOptions
end
function BronCena:GetZoneOptions()
return {
party = L["Dungeon"],
raid = L["Raid"],
pvp = L["PvP"],
arena = L["Arena"],
scenario = L["Scenario"],
world = L["World"],
}
end
function BronCena:GetZoneValues(info, key)
return self.db.profile.zones[key]
end
function BronCena:SetZoneValues(info, key, value)
self.db.profile.zones[key] = value;
end
function BronCena:GetOwnerOptions()
return {
player = L["Player"],
party = L["Party"],
raid = L["Raid"],
friendly = L["Friendly"],
hostile = L["Hostile"]
}
end
function BronCena:GetOwnerValues(info, key)
return self.db.profile.owners[key]
end
function BronCena:SetOwnerValues(info, key, value)
self.db.profile.owners[key] = value;
end
function BronCena:OnInitialize()
if self.isInitialized == true then
return
end
self.db = LibStub("AceDB-3.0"):New("BronCenaDB", defaults, true)
LSM:Register(SOUND, soundOptions.broncena, "Interface/AddOns/BronCena/Media/Sounds/broncena.ogg")
LSM:Register(SOUND, soundOptions.broncenafull, "Interface/AddOns/BronCena/Media/Sounds/broncena-full.ogg")
LSM:Register(SOUND, soundOptions.shoryuken, "Interface/AddOns/BronCena/Media/Sounds/shoryuken.ogg")
LSM:Register(SOUND, soundOptions.shouryureppa, "Interface/AddOns/BronCena/Media/Sounds/shouryureppa.ogg")
LSM:Register(SOUND, soundOptions.metalgear, "Interface/AddOns/BronCena/Media/Sounds/metalgear.ogg")
LSM:Register(SOUND, soundOptions.yaketysax, "Interface/AddOns/BronCena/Media/Sounds/yakety-sax.ogg")
LSM:Register(SOUND, soundOptions.darkness, "Interface/AddOns/BronCena/Media/Sounds/darkness.ogg")
if self.options == nil then
self.options = self:InitializeOptions(options)
LibStub("AceConfig-3.0"):RegisterOptionsTable(APPNAME, options)
self.optionsFrame = ACD:AddToBlizOptions(APPNAME, APPDESC)
end
self:ApplyOptions()
self:RegisterChatCommand("broncena", "ChatCommand")
self:RegisterChatCommand("bron", "ChatCommand")
self.isInitialized = true
end
function BronCena:ChatCommand()
self:Debug("/bron or /broncena was invoked")
InterfaceOptionsFrame_OpenToCategory(APPDESC)
InterfaceOptionsFrame_OpenToCategory(APPDESC)
end
function BronCena:OnEnable()
BronCena:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
BronCena:RegisterEvent("PLAYER_LEVEL_UP")
if self.parsingTooltip == nil then
self.parsingTooltip = CreateFrame("GameTooltip", APPNAME.."Tooltip", WorldFrame, "GameTooltipTemplate")
end
end
function BronCena:OnDisable()
self:Debug("OnDisable")
BronCena:UnregisterEvent("PLAYER_LEVEL_UP")
BronCena:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
local getOwner = function(sourceFlags)
if sourceFlags == nill then return nill end
if bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE then return "hostile" end
if bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_PARTY) == COMBATLOG_OBJECT_AFFILIATION_PARTY then return "party" end
if bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_RAID) == COMBATLOG_OBJECT_AFFILIATION_RAID then return "raid" end
if bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) == COMBATLOG_OBJECT_AFFILIATION_MINE then return "player" end
if bit.band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == COMBATLOG_OBJECT_AFFILIATION_OUTSIDER then return "friendly" end
return nil
end
function BronCena:PLAYER_LEVEL_UP(subevent, newLevel)
self:TriggerBron(1, subevent, tostring(newLevel), nil)
end
function BronCena:COMBAT_LOG_EVENT_UNFILTERED(...)
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellId, spellName = CombatLogGetCurrentEventInfo()
self:TriggerBron(spellId, subevent, destName, sourceFlags)
end
function BronCena:TriggerBron(spellId, subevent, destName, sourceFlags)
if self.db.profile.disabled == true then
--self:Debug("Add-on is disabled")
return
end
-- See if this spellId is supported
local companion = self.db.profile.companions[tostring(spellId)]
if not companion then
return
elseif companion.disabled == true then
self:Debug("Disabled for this companion")
return
end
if companion.eventType ~= subevent then
-- The type of event doesn't match what we want, so skip this
return
end
-- Spell blocklist (Consecration)
if spellId == 26573 then
return
end
-- Types: "Creature", "Pet", "GameObject", "Vehicle", "Vignette"
-- [unitType]-0-[serverID]-[instanceID]-[zoneUID]-[ID]-[spawnUID]
-- local unitID = tonumber(string.match(unitGUID, "Creature%-.-%-.-%-.-%-.-%-(.-)%-"));
local owner = getOwner(sourceFlags);
if owner and companion.owners[owner] == false or (companion.owners[owner] == nil and self.db.profile.owners[owner] == false) then
self:Debug("Disabled for %s", owner)
return
end
local instanceName, instanceType, difficultyId, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceId, instanceGroupSize, lfgDungeonId = GetInstanceInfo()
if not instanceType or instanceType == 'none' then
instanceType = 'world';
end
if self.db.profile.zones[instanceType] == false then
self:Debug("Disabled for " .. instanceType)
return
end
if companion.zones[instanceType] == false then
self:Debug("Disabled for " .. instanceType)
return
end
-- Figure out the sound to play
self:Debug("soundPath=%s,soundId=%s", tostring(companion.soundPath), tostring(companion.soundId))
-- Default to the custom path
local sound = companion.soundPath
-- If we're using a selected option, we have to find the path / soundkit id
if tostring(companion.soundId) == tostring(soundOptions.custom) then
self:Debug("Using custom sound path")
else
self:Debug("Shared media id: %s", tostring(companion.soundId))
sound = LSM:Fetch(SOUND, companion.soundId, false) or companion.soundId
end
local soundChannel = companion.soundChannel or CHANNEL_DEFAULT
if soundChannel == CHANNEL_DEFAULT then soundChannel = soundChannels.dialog end
-- Is there a delay on this companion? We can do this to line up the message or sounds to
-- the companion's timings, or use it to give the game engine time to get the unit's descriptive name
-- e.g. "Farah" instead of "Kyrian Steward"
if companion.delay == nil or companion.delay <= 0 then
-- Add the message
if companion.message then
local name = destName
local message = string.format(companion.message, name or "Unknown")
BronCenaMessageFrame:AddMessage(message, 1.0, 1.0, 1.0);
end
-- Stop this companion's sound if it's already playing to prevent annoying overlaps
if companion.handle then
-- Users can allow overlapping sounds for hilarity
if not self.db.profile.enableOverlap == true then
StopSound(companion.handle)
end
end
-- Play the sound
self:Debug("Playing %s", tostring(sound))
local willPlay, handle = PlaySoundFile(sound, soundChannel)
if willPlay then
companion.handle = handle
end
else
-- Delay the message to be able to get the unit's name
self:ScheduleTimer(function (...)
if companion.message then
self.parsingTooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
self.parsingTooltip:SetHyperlink('unit:'..destGUID)
local unitName = _G[APPNAME.."Tooltip".."TextLeft1"]:GetText()
local message = string.format(companion.message, unitName or destName or "Unknown")
BronCenaMessageFrame:AddMessage(message, 1.0, 1.0, 1.0);
end
-- Stop this companion's sound if it's already playing to prevent annoying overlaps
if companion.handle then
-- Users can allow overlapping sounds for hilarity
if not self.db.profile.enableOverlap == true then
StopSound(companion.handle)
end
end
-- Play the sound
self:Debug("Playing %s", tostring(sound))
local willPlay, handle = PlaySoundFile(sound, soundChannel)
if willPlay then
companion.handle = handle
end
end, companion.delay)
end
end