-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtraButton.lua
More file actions
2149 lines (1619 loc) · 42.7 KB
/
Copy pathExtraButton.lua
File metadata and controls
2149 lines (1619 loc) · 42.7 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
local ADDON_NAME = ...
local PB = {}
_G.PartyButtons = PB
-- ============================================================
-- Configuration
-- ============================================================
local CONFIG = {
buttonWidth = 118,
buttonHeight = 32,
spacing = 6,
topOffset = -48,
-- Raid markers:
-- 1 = Star
-- 2 = Circle
-- 3 = Diamond
-- 4 = Triangle
-- 5 = Moon
-- 6 = Square
-- 7 = Cross
-- 8 = Skull
tankMarker = 6, -- Square
healerMarker = 4, -- Triangle
greetings = {
"Hi",
"yo",
"o/",
},
bloodlustIcon =
"Interface\\Icons\\Spell_Nature_BloodLust",
-- ========================================================
-- Lust spell IDs
-- ========================================================
bloodlustSpellID = 2825,
heroismSpellID = 32182,
timeWarpSpellID = 80353,
primalRageSpellID = 264667,
furyAspectsSpellID = 390386,
harriersCrySpellID = 466904,
}
-- ============================================================
-- Frames
-- ============================================================
local mainFrame
local markButton
local hiButton
local heroButton
-- ============================================================
-- Secure update state
-- ============================================================
local needsMarkMacroUpdate = true
local needsHeroMacroUpdate = true
-- ============================================================
-- Hunter inspection state
-- ============================================================
local inspectQueue = {}
local inspectInProgress = false
local inspectUnit = nil
-- ============================================================
-- Utility
-- ============================================================
local function Print(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage(
"|cff55ccffPartyButtons|r: " ..
tostring(msg)
)
end
end
-- ============================================================
-- Group units
-- ============================================================
local function GetGroupUnits()
local units = {}
-- Player
if UnitExists("player") then
table.insert(
units,
"player"
)
end
-- Raid
if IsInRaid() then
local count = GetNumGroupMembers()
for i = 1, count do
local unit = "raid" .. i
if UnitExists(unit) then
table.insert(
units,
unit
)
end
end
-- Party
elseif IsInGroup() then
for i = 1, 4 do
local unit = "party" .. i
if UnitExists(unit) then
table.insert(
units,
unit
)
end
end
end
return units
end
-- ============================================================
-- Party role detection
-- ============================================================
local function GetPartyRoleUnits()
local tank
local healer
for _, unit in ipairs(GetGroupUnits()) do
if UnitExists(unit) then
local role =
UnitGroupRolesAssigned(unit)
if role == "TANK"
and not tank then
tank = unit
elseif role == "HEALER"
and not healer then
healer = unit
end
if tank and healer then
break
end
end
end
return tank, healer
end
-- ============================================================
-- Unit validity
-- ============================================================
local function IsUnitValidForLust(unit)
if not UnitExists(unit) then
return false
end
if not UnitIsConnected(unit) then
return false
end
if UnitIsDeadOrGhost(unit) then
return false
end
return true
end
-- ============================================================
-- Spell link
-- ============================================================
local function GetSpellLinkSafe(spellID)
if not spellID then
return nil
end
local link =
C_Spell.GetSpellLink(spellID)
if link and link ~= "" then
return link
end
local info =
C_Spell.GetSpellInfo(spellID)
if info and info.name then
return info.name
end
return nil
end
-- ============================================================
-- Get spell name
-- ============================================================
local function GetSpellNameSafe(spellID)
if not spellID then
return nil
end
local name =
C_Spell.GetSpellName(spellID)
if name then
return name
end
local info =
C_Spell.GetSpellInfo(spellID)
if info then
return info.name
end
return nil
end
-- ============================================================
-- Player specialization
-- Modern C_SpecializationInfo API
-- ============================================================
local function GetPlayerSpecID()
local specIndex =
C_SpecializationInfo.GetSpecialization()
if not specIndex then
return nil
end
local specID =
C_SpecializationInfo.GetSpecializationInfo(
specIndex
)
return specID
end
-- ============================================================
-- Player's own Hunter pet specialization
-- ============================================================
local function GetOwnPetSpecID()
local petSpecIndex =
C_SpecializationInfo.GetSpecialization(
false,
true
)
if not petSpecIndex then
return nil
end
local petSpecID =
C_SpecializationInfo.GetSpecializationInfo(
petSpecIndex,
false,
true
)
return petSpecID
end
-- ============================================================
-- Own Shaman lust
-- ============================================================
local function GetOwnShamanLustSpellID()
if IsPlayerSpell(
CONFIG.bloodlustSpellID
) then
return CONFIG.bloodlustSpellID
end
if IsPlayerSpell(
CONFIG.heroismSpellID
) then
return CONFIG.heroismSpellID
end
return nil
end
-- ============================================================
-- Own Hunter lust
-- ============================================================
local function GetOwnHunterLustSpellID()
local specID =
GetPlayerSpecID()
if not specID then
return nil
end
-- --------------------------------------------------------
-- Beast Mastery
-- --------------------------------------------------------
if specID == 253 then
if not IsPlayerSpell(
CONFIG.primalRageSpellID
) then
return nil
end
if not UnitExists("pet") then
return nil
end
if UnitIsDeadOrGhost("pet") then
return nil
end
local petSpecID =
GetOwnPetSpecID()
-- 1 = Ferocity
if petSpecID == 1 then
return CONFIG.primalRageSpellID
end
return nil
end
-- --------------------------------------------------------
-- Marksmanship
-- --------------------------------------------------------
if specID == 254 then
if IsPlayerSpell(
CONFIG.harriersCrySpellID
) then
return CONFIG.harriersCrySpellID
end
return nil
end
-- --------------------------------------------------------
-- Survival
-- --------------------------------------------------------
if specID == 255 then
if not IsPlayerSpell(
CONFIG.primalRageSpellID
) then
return nil
end
if not UnitExists("pet") then
return nil
end
if UnitIsDeadOrGhost("pet") then
return nil
end
local petSpecID =
GetOwnPetSpecID()
if petSpecID == 1 then
return CONFIG.primalRageSpellID
end
return nil
end
return nil
end
-- ============================================================
-- Get own lust
-- ============================================================
local function GetOwnLustSpellID()
-- Shaman
local shamanSpell =
GetOwnShamanLustSpellID()
if shamanSpell then
return shamanSpell
end
-- Mage
if IsPlayerSpell(
CONFIG.timeWarpSpellID
) then
return CONFIG.timeWarpSpellID
end
-- Evoker
if IsPlayerSpell(
CONFIG.furyAspectsSpellID
) then
return CONFIG.furyAspectsSpellID
end
-- Hunter
local _, classFile =
UnitClass("player")
if classFile == "HUNTER" then
return GetOwnHunterLustSpellID()
end
return nil
end
-- ============================================================
-- Get pet unit for group member
-- ============================================================
local function GetPetUnitForGroupUnit(unit)
if not unit then
return nil
end
if unit:match("^party%d+$") then
return unit:gsub(
"^party",
"partypet"
)
end
if unit:match("^raid%d+$") then
return unit:gsub(
"^raid",
"raidpet"
)
end
return nil
end
-- ============================================================
-- Inspect queue
-- ============================================================
local function ProcessInspectQueue()
if inspectInProgress then
return
end
local nextUnit
for unit in pairs(inspectQueue) do
nextUnit = unit
break
end
if not nextUnit then
return
end
inspectQueue[nextUnit] = nil
if not UnitExists(nextUnit) then
C_Timer.After(
0.05,
ProcessInspectQueue
)
return
end
if UnitIsDeadOrGhost(nextUnit) then
C_Timer.After(
0.05,
ProcessInspectQueue
)
return
end
if not CanInspect(nextUnit) then
-- Try again later.
inspectQueue[nextUnit] = true
C_Timer.After(
0.5,
ProcessInspectQueue
)
return
end
inspectInProgress = true
inspectUnit = nextUnit
NotifyInspect(nextUnit)
end
local function QueueHunterInspect(unit)
if not UnitExists(unit) then
return
end
if UnitIsUnit(unit, "player") then
return
end
local _, classFile =
UnitClass(unit)
if classFile ~= "HUNTER" then
return
end
inspectQueue[unit] = true
ProcessInspectQueue()
end
-- ============================================================
-- Get inspected player's specialization
-- ============================================================
local function GetInspectedSpecID(unit)
if not unit then
return nil
end
if not UnitExists(unit) then
return nil
end
local specID =
GetInspectSpecialization(unit)
if specID and specID ~= 0 then
return specID
end
return nil
end
-- ============================================================
-- Get group Hunter lust
-- ============================================================
local function GetGroupHunterLustSpellID(unit)
if not IsUnitValidForLust(unit) then
return nil, true
end
local specID =
GetInspectedSpecID(unit)
if not specID then
QueueHunterInspect(unit)
return nil, false
end
-- --------------------------------------------------------
-- Marksmanship
-- --------------------------------------------------------
if specID == 254 then
return CONFIG.harriersCrySpellID, true
end
-- --------------------------------------------------------
-- Beast Mastery / Survival
-- --------------------------------------------------------
if specID == 253
or specID == 255 then
local petUnit =
GetPetUnitForGroupUnit(unit)
if not petUnit then
return nil, true
end
if not UnitExists(petUnit) then
return nil, true
end
if UnitIsDeadOrGhost(petUnit) then
return nil, true
end
-- For another Hunter we cannot read arbitrary spellbook
-- state like our own pet's IsSpellKnown(..., true).
--
-- What we CAN reliably confirm:
-- Hunter spec = BM / Survival
-- active pet exists
-- active pet is alive
--
-- For Ferocity detection we use inspected pet
-- specialization if available.
local petSpecIndex =
C_SpecializationInfo.GetSpecialization(
true,
true
)
if petSpecIndex then
local petSpecID =
C_SpecializationInfo.GetSpecializationInfo(
petSpecIndex,
true,
true,
unit
)
-- 1 = Ferocity
if petSpecID == 1 then
return CONFIG.primalRageSpellID, true
end
return nil, true
end
-- Pet specialization isn't available yet.
return nil, false
end
return nil, true
end
-- ============================================================
-- Get lust from any group member
-- ============================================================
local function GetGroupMemberLustSpellID(unit)
if not IsUnitValidForLust(unit) then
return nil, true
end
local _, classFile =
UnitClass(unit)
if not classFile then
return nil, true
end
-- ========================================================
-- Shaman
-- ========================================================
if classFile == "SHAMAN" then
local faction =
UnitFactionGroup(unit)
if faction == "Horde" then
return CONFIG.bloodlustSpellID, true
end
if faction == "Alliance" then
return CONFIG.heroismSpellID, true
end
-- Very unusual fallback.
local playerFaction =
UnitFactionGroup("player")
if playerFaction == "Alliance" then
return CONFIG.heroismSpellID, true
end
if playerFaction == "Horde" then
return CONFIG.bloodlustSpellID, true
end
return nil, true
end
-- ========================================================
-- Mage
-- ========================================================
if classFile == "MAGE" then
return CONFIG.timeWarpSpellID, true
end
-- ========================================================
-- Evoker
-- ========================================================
if classFile == "EVOKER" then
return CONFIG.furyAspectsSpellID, true
end
-- ========================================================
-- Hunter
-- ========================================================
if classFile == "HUNTER" then
return GetGroupHunterLustSpellID(unit)
end
return nil, true
end
-- ============================================================
-- Build Heroism announcement
-- ============================================================
local function BuildLustAnnouncement()
local links = {}
-- Each GROUP MEMBER gets at most ONE link.
local addedUnits = {}
local function AddUnitSpell(unit, spellID)
if not unit or not spellID then
return
end
if addedUnits[unit] then
return
end
local link =
GetSpellLinkSafe(spellID)
if not link then
return
end
addedUnits[unit] = true
table.insert(
links,
link
)
end
-- --------------------------------------------------------
-- Player
-- --------------------------------------------------------
local ownSpellID =
GetOwnLustSpellID()
if ownSpellID then
local link =
GetSpellLinkSafe(
ownSpellID
)
if link then
table.insert(
links,
link
)
end
end
-- --------------------------------------------------------
-- Group members
-- --------------------------------------------------------
for _, unit in ipairs(
GetGroupUnits()
) do
if not UnitIsUnit(
unit,
"player"
) then
local spellID, ready =
GetGroupMemberLustSpellID(
unit
)
if spellID then
AddUnitSpell(
unit,
spellID
)
elseif not ready then
-- Hunter inspection isn't ready yet.
QueueHunterInspect(unit)
end
end
end
-- --------------------------------------------------------
-- Build result
-- --------------------------------------------------------
if #links == 0 then
return "Macros: Press Heroism"
end
return "Macros: Press " ..
table.concat(
links,
" "
)
end
-- ============================================================
-- Build own cast macro
-- ============================================================
local function BuildOwnLustCastMacro()
local spellID =
GetOwnLustSpellID()
if not spellID then
return nil
end
local spellName =
GetSpellNameSafe(
spellID
)
if not spellName then
return nil
end
return "/cast " ..
spellName
end
-- ============================================================
-- Update Mark macro
-- ============================================================
local function BuildMarkMacroBody()
local tank, healer =
GetPartyRoleUnits()
local lines = {}
if tank and UnitExists(tank) then
table.insert(
lines,
"/tm [@" ..
tank ..
"] " ..
CONFIG.tankMarker
)
end
if healer
and UnitExists(healer)
and healer ~= tank then
table.insert(
lines,
"/tm [@" ..
healer ..
"] " ..
CONFIG.healerMarker
)
end
if #lines == 0 then
return "/stopmacro"
end
return table.concat(
lines,
"\n"
)
end
local function UpdateMarkMacro()
if not markButton then
return
end
if InCombatLockdown() then
needsMarkMacroUpdate = true
return
end
local body =
BuildMarkMacroBody()
markButton:SetAttribute(
"type1",
"macro"
)
markButton:SetAttribute(
"macrotext1",
body
)
needsMarkMacroUpdate = false
end
-- ============================================================
-- Greeting macro
-- ============================================================
local function UpdateChatMacro()
if not hiButton then
return
end
if InCombatLockdown() then
return
end
-- Normal
hiButton:SetAttribute(
"type1",
"macro"
)
hiButton:SetAttribute(
"macrotext1",
"/p " ..
CONFIG.greetings[1]
)
-- Shift
hiButton:SetAttribute(
"shift-type1",
"macro"
)
hiButton:SetAttribute(
"shift-macrotext1",
"/p " ..
CONFIG.greetings[2]
)