-
Notifications
You must be signed in to change notification settings - Fork 1
/
Core.lua
1845 lines (1476 loc) · 66.9 KB
/
Core.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
--[=[
H.H.T.D. World of Warcraft Add-on
Copyright (c) 2009-2018 by John Wellesz (hhtd@2072productions.com)
All rights reserved
Version @project-version@
In World of Warcraft healers have to die. This is a cruel truth that you're
taught very early in the game. This add-on helps you influence this unfortunate
destiny in a way or another depending on the healer's side...
More information: https://www.wowace.com/projects/h-h-t-d
-----
Core.lua
-----
--]=]
--========= NAMING Convention ==========
-- VARIABLES AND FUNCTIONS (upvalues excluded)
-- global variable == _NAME_WORD2 (underscore + full uppercase)
-- semi-global (file locals) == NAME_WORD2 (full uppercase)
-- locals to closures or members == NameWord2
-- locals to functions == nameWord2
--
-- TABLES
-- globals == NAME__WORD2
-- locals == name_word2
-- members == Name_Word2
-- Debug templates
local ERROR = 1;
local WARNING = 2;
local INFO = 3;
local INFO2 = 4;
local UNPACKAGED = "@pro" .. "ject-version@";
local VERSION = "@project-version@";
local ADDON_NAME, T = ...;
local GetAddOnMetadata = _G.C_AddOns and _G.C_AddOns.GetAddOnMetadata or _G.GetAddOnMetadata;
T._FatalError = function (TheError)
if not StaticPopupDialogs["HHTD_ERROR_FRAME"] then
StaticPopupDialogs["HHTD_ERROR_FRAME"] = {
text = "|cFFFF0000HHTD Fatal Error:|r\n\n%s",
button1 = "OK",
OnAccept = function()
T._FatalError_Diaplayed = false;
return false;
end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1,
preferredIndex = 3,
};
end
if not T._FatalError_Diaplayed then
StaticPopup_Show ("HHTD_ERROR_FRAME", TheError);
if T._DiagStatus then
T._FatalError_Diaplayed = true;
end
end
end
T._MessageBox = function (message)
if not StaticPopupDialogs["HHTD_MESSAGE_FRAME"] then
StaticPopupDialogs["HHTD_MESSAGE_FRAME"] = {
text = "|cFFFF1020H.H.T.D. Message|r\n\n%s",
button1 = "OK",
OnAccept = function()
T._MessageBox_Diaplayed = false;
return false;
end,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
showAlert = true,
preferredIndex = 3,
};
end
if not T._MessageBox_Diaplayed then
StaticPopup_Show ("HHTD_MESSAGE_FRAME", message);
end
end
local _, _, _, tocversion = GetBuildInfo();
T._tocversion = tocversion;
-- === Add-on basics and variable declarations {{{
T.HHTD = LibStub("AceAddon-3.0"):NewAddon("H.H.T.D.", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0");
local HHTD = T.HHTD;
--@debug@
_HHTD_DEBUG = HHTD;
--@end-debug@
HHTD.Localized_Text = LibStub("AceLocale-3.0"):GetLocale("H.H.T.D.", true);
local L = HHTD.Localized_Text;
HHTD.Constants = {};
local HHTD_C = HHTD.Constants;
HHTD_C.WOWC = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE
--[=[
HHTD_C.Healing_Classes = { -- unused
["PRIEST"] = true,
["PALADIN"] = true,
["DRUID"] = true,
["SHAMAN"] = true,
["MONK"] = true,
};
--]=]
HHTD_C.MaxTOC = tonumber(GetAddOnMetadata("HHTD", "X-Max-Interface") or math.huge);
-- Build translation table for classes spec to role
-- needed because WoW API (GetBattlefieldScore) returns a localized specName
do
-- /spew _HHTD_DEBUG.Constants.CLASS_SPEC_TO_ROLE
HHTD_C.CLASS_SPEC_TO_ROLE = {}
local classInfo, classTag, userSpecNum, specID, specName, role
local foundClass = 0;
local classID = 0;
while foundClass < MAX_CLASSES do -- in WOWC class ids are not continuous
classID = classID + 1;
classInfo = C_CreatureInfo.GetClassInfo(classID)
if classInfo then
classTag = classInfo.classFile
foundClass = foundClass + 1;
HHTD_C.CLASS_SPEC_TO_ROLE[classTag] = {}
if not HHTD_C.WOWC then -- disable for now since WOWC has no easy way to do that... We are back to hardcoded localized values *sigh*
userSpecNum = 1
repeat
specID, specName = GetSpecializationInfoForClassID(classID, userSpecNum)
role = specID and GetSpecializationRoleByID(specID) or nil
if role then
HHTD_C.CLASS_SPEC_TO_ROLE[classTag][specName] = role
userSpecNum = userSpecNum + 1
end
until not role
end
end
end
end
-- The header for HHTD key bindings
BINDING_HEADER_HHTD = "H.H.T.D.";
BINDING_NAME_HHTDP = L["OPT_POST_ANNOUNCE_ENABLE"];
HHTD.Friendly_Healers_Attacked_by_GUID = {};
HHTD.LOGS = {
[true] = {}, -- [guid] = healer_log_template
[false] = {}, -- [guid] = healer_log_template
};
HHTD.DelayedFunctionCallsCount = 0;
HHTD.DelayedFunctionCalls = {};
do
local _, _, _, interface = GetBuildInfo();
HHTD.MOP = (interface >= 50000);
end
--[=[
local healer_template = {
guid = "",
name = "unknown",
isUnique = true,
isTrueHeal = false,
isHuman = true,
healDone = 0,
rank = -1,
_lastSort = 0,
};
--]=]
HHTD.Registry_by_GUID = {
[true] = {}, -- [guid] = healer_template
[false] = {}, -- [guid] = healer_template
}
HHTD.Registry_by_Name = {
[true] = {}, -- [name] = healer_template
[false] = {}, -- [name] = healer_template
}
-- upvalues {{{
local _G = _G;
local UnitIsPlayer = _G.UnitIsPlayer;
local UnitIsDead = _G.UnitIsDead;
local UnitFactionGroup = _G.UnitFactionGroup;
local UnitGUID = _G.UnitGUID;
local UnitIsUnit = _G.UnitIsUnit;
local UnitClass = _G.UnitClass;
local UnitName = _G.UnitName;
local UnitInRaid = _G.UnitInRaid;
local UnitInParty = _G.UnitInParty;
local UnitSetRole = _G.UnitSetRole;
local UnitGroupRolesAssigned = _G.UnitGroupRolesAssigned;
local GetTime = _G.GetTime;
local pairs = _G.pairs;
local ipairs = _G.ipairs;
local unpack = _G.unpack;
local select = _G.select;
local InCombatLockdown = _G.InCombatLockdown;
local UnitIsFriend = _G.UnitIsFriend;
-- }}}
function HHTD:HHTD_HEALER_GONE(selfevent, isFriend, healer)
self.Friendly_Healers_Attacked_by_GUID[healer.guid] = nil;
self.Registry_by_GUID[isFriend][healer.guid] = nil;
self.Registry_by_Name[isFriend][healer.name] = nil;
-- test if there are others with the same name... *sigh* this sucks
for guid, healerRecord in pairs (self.Registry_by_GUID[isFriend]) do
if healerRecord.name == healer.name then
self.Registry_by_Name[isFriend][healer.name] = healerRecord;
self:Debug(INFO, "replaced record for", healer.name);
break;
end
end
end
function HHTD:HHTD_HEALER_BORN(selfevent, isFriend, healer)
self:Debug(INFO, "HHTD:HHTD_HEALER_BORN()");
HHTD.Registry_by_GUID[isFriend][healer.guid] = healer;
HHTD.Registry_by_Name[isFriend][healer.name] = healer;
--@alpha@
if InCombatLockdown() then
self:AddDelayedFunctionCall('test', self.Debug, self, INFO2, "After combat lock down test");
end
--@end-alpha@
-- if the player is human and friendly and is part of our group, set his/her role to HEALER
if self.db.global.SetFriendlyHealersRole and not HHTD_C.WOWC then
if isFriend and healer.isHuman and (UnitInRaid(healer.fullName) or UnitInParty(healer.fullName)) and UnitGroupRolesAssigned(healer.fullName) == 'NONE' then
if (select(2, GetRaidRosterInfo(UnitInRaid("player") or 1))) > 0 then
self:Debug(INFO, "Setting role to HEALER for", healer.fullName);
if InCombatLockdown() then
self:AddDelayedFunctionCall("SetRole_"..healer.fullName, UnitSetRole, healer.fullName, 'HEALER');
else
UnitSetRole(healer.fullName, 'HEALER'); -- fails in combat, has become protected in 5.2
end
end
end
end
end
-- local function REGISTER_HEALERS_ONLY_SPELLS_ONCE () -- {{{
local function REGISTER_HEALERS_ONLY_SPELLS_ONCE ()
if HHTD_C.Healers_Only_Spells_ByName then
return;
end
local Healers_Only_Spells_ByID = {
-- Priests
-- Discipline
[047540] = "PRIEST", -- Penance
[109964] = "PRIEST", -- Spirit shell -- not seen in disc
[033206] = "PRIEST", -- Pain Suppression
[000527] = "PRIEST", -- Purify
[081749] = "PRIEST", -- Atonement
-- [132157] = "PRIEST", -- Holy Nova -- removed in 10.2.5
-- Holy
[000596] = "PRIEST", -- Prayer of Healing
[014914] = "PRIEST", -- Holy Fire
[002060] = "PRIEST", -- Heal
[034861] = "PRIEST", -- Circle of Healing
[064843] = "PRIEST", -- Divine Hymn
[047788] = "PRIEST", -- Guardian Spirit
[290112] = "PRIEST", -- Binding Heal
[077485] = "PRIEST", -- Mastery: Echo of Light -- the passibe ability
-- [077489] = "PRIEST", -- Echo of Light -- the aura applied by the afformentioned
-- [000139] = "PRIEST", -- Renew
-- Druids - Restauration
--[018562] = "DRUID", -- Swiftmend -- (also available through restoration afinity talent)
[102342] = "DRUID", -- Ironbark
[033763] = "DRUID", -- Lifebloom
[088423] = "DRUID", -- Nature's Cure
-- [008936] = "DRUID", -- Regrowth -- (also available through restoration afinity talent)
[033891] = "DRUID", -- Incarnation: Tree of Life
-- [048438] = "DRUID", -- Wild Growth -- disabled in WoW8: In the feral talents, level 45, you can choose Restoration Affinity, which includes Rejuv, Swiftmend, Wild Growth.
[000740] = "DRUID", -- Tranquility
-- [145108] = "DRUID", -- Ysera's Gift -- (also available through restoration afinity talent)
-- [000774] = "DRUID", -- Rejuvination -- (also available through restoration afinity talent)
-- Shamans - Restauration
[061295] = "SHAMAN", -- Riptide
[077472] = "SHAMAN", -- Healing Wave
[098008] = "SHAMAN", -- Spirit link totem
[073920] = "SHAMAN", -- Healing Rain
-- Paladins - Holy
[020473] = "PALADIN", -- Holy Shock
[053563] = "PALADIN", -- Beacon of Light
[082326] = "PALADIN", -- Holy Light
[085222] = "PALADIN", -- Light of Dawn
-- Monks - Mistweaver
-- [115175] = "MONK", -- Soothing Mist
[115310] = "MONK", -- Revival
--[116670] = "MONK", -- Vivify all monks have it in WoW8
[116680] = "MONK", -- Thunder Focus Tea
[116849] = "MONK", -- Life Cocoon
-- [119611] = "MONK", -- Renewing mist
[364343] = "EVOKER", -- Echo (talent)
[355936] = "EVOKER", -- Dream Breath (talent)
[363534] = "EVOKER", -- Rewind (talent)
[373861] = "EVOKER", -- Temporal Anomaly (talent)
[359816] = "EVOKER", -- Dream Flight (talent)
--@debug@
-- test bad spell mitigation
-- those are not healer specific
-- [031842] = "PALADIN", -- Avenging Wrath - removed in WOW8
[019750] = "PALADIN", -- Flash of light
[002061] = "PRIEST", -- Flash Heal
-- [005185] = "DRUID", -- Healing Touch - removed in WOW8
--@end-debug@
};
if HHTD_C.WOWC then
Healers_Only_Spells_ByID = {
-- Druid Restoration
[18562] = "DRUID", -- SwiftMend
-- Priest Holy
[00724] = "PRIEST", -- Lightwell
-- Shaman Restoration
-- [16178] = "SHAMAN", -- Purification --ct removed
[29206] = "SHAMAN", -- Healing way
[001064] = "SHAMAN", -- Chain Heal
}
-- OK, this feature makes no sense in WoW classic...
end
HHTD_C.Healers_Only_Spells_ByName = {};
-- /spew _HHTD_DEBUG.Constants.Healers_Only_Spells_ByName
-- /spew GetSpellInfo(077485)
local debug_SpellNumber = 0;
for spellID, class in pairs(Healers_Only_Spells_ByID) do
if (GetSpellInfo(spellID)) then
HHTD_C.Healers_Only_Spells_ByName[(GetSpellInfo(spellID))] = class;
debug_SpellNumber = debug_SpellNumber + 1;
else
HHTD:Debug(ERROR, "Missing spell (you should check if there is an updated version of HHTD):", spellID);
end
end
HHTD:Debug(INFO, ("%d spells registered!"):format(debug_SpellNumber));
end -- }}}
-- Modules standards configurations {{{
-- Configure default libraries for modules
HHTD:SetDefaultModuleLibraries( "AceConsole-3.0", "AceEvent-3.0")
-- Set the default prototype for modules
HHTD.MODULE_PROTOTYPE = {
OnEnable = function(self) self:Debug(INFO, "prototype OnEnable called!") end,
OnDisable = function(self) self:Debug(INFO, "prototype OnDisable called!") end,
OnInitialize = function(self)
self:Debug(INFO, "prototype OnInitialize called!");
end,
Debug = function(self, ...) HHTD.Debug(self, ...) end,
Error = function(self, m) HHTD.Error (self, m) end,
}
HHTD:SetDefaultModulePrototype( HHTD.MODULE_PROTOTYPE )
-- Set modules' default state to "false"
HHTD:SetDefaultModuleState( false )
-- }}}
-- }}}
-- modules handling functions {{{
function HHTD:SetModulesStates ()
for moduleName, module in self:IterateModules() do
self:Debug(INFO2, 'enabling module:', moduleName);
module:SetEnabledState(self.db.global.Modules[moduleName].Enabled);
end
end
-- }}}
-- 03 Ghosts I
-- == Options and defaults {{{
do
local AceOptionAntiStupidity = 0;
local FormattedLogs = "";
local function FormatLogs()
if GetTime() - AceOptionAntiStupidity < 0.1 then
HHTD:Debug(INFO, "AceOption is stupid");
return FormattedLogs;
else
AceOptionAntiStupidity = GetTime();
end
local output = "";
for _, isFriend in ipairs({false,true}) do
local tmp = {};
for guid, log in HHTD:pairs_ordered(HHTD.LOGS[isFriend], true, 'healDone') do
local isActive = HHTD.Registry_by_GUID[isFriend][guid];
local spellsStats = {}
local j = 1;
for spell, spellcount in HHTD:pairs_ordered(log.spells, true) do
spellsStats[j] = (" %s (|cFFAA0000%d|r)"):format(HHTD:ColorText(spell, HHTD_C.Healers_Only_Spells_ByName[spell] and "FFC000C0" or "FFC0C0C0"), spellcount);
j = j + 1;
end
tmp[#tmp + 1] = ("%s (|cff00dd00%s|r)%s [|cffbbbbbb%s|r]: %s\n%s\n"):format(
(HHTD:ColorText("#(%s)|r '%s'", log.isFriend and "FF00FF00" or "FFFF0000")):format(
isActive and isActive.rank or '-',
HHTD:ColorText(log.name, log.isTrueHeal and HHTD:GetClassHexColor(log.isTrueHeal) or "FFAAAAAA" )
),
tostring(log.healDone > 0 and log.healDone or L["NO_DATA"]),
log.healDone > HHTD.HealThreshold and "" or L["LOG_BELOW_THRESHOLD"],
log.isHuman and L["HUMAN"] or L["NPC"],
HHTD:ColorText(isActive and L["LOG_ACTIVE"] or L["LOG_IDLE"], isActive and "FF00EE00" or "FFEE0000"),
table.concat(spellsStats, '\n')
);
end
output = output .. table.concat(tmp, '\n') .. '\n';
end
FormattedLogs = output;
return output;
end
local function GetCoreOptions() -- {{{
return {
type = 'group',
get = function (info) return HHTD.db.global[info[#info]]; end,
set = function (info, value) HHTD:SetHandler(HHTD, info, value) end,
disabled = function () return not HHTD:IsEnabled(); end,
childGroups = 'tab',
name = "H.H.T.D.",
args = {
Description = {
type = 'description',
name = L["DESCRIPTION"],
order = 0,
},
On = {
type = 'toggle',
name = L["OPT_ON"],
desc = L["OPT_ON_DESC"],
set = function(info) HHTD.db.global.Enabled = true; HHTD:Enable(); return HHTD.db.global.Enabled; end,
get = function(info) return HHTD:IsEnabled(); end,
hidden = function() return HHTD:IsEnabled(); end,
disabled = false,
order = 1,
},
Off = {
type = 'toggle',
name = L["OPT_OFF"],
desc = L["OPT_OFF_DESC"],
set = function(info) HHTD.db.global.Enabled = not HHTD:Disable(); return not HHTD.db.global.Enabled; end,
get = function(info) return not HHTD:IsEnabled(); end,
guiHidden = true,
hidden = function() return not HHTD:IsEnabled(); end,
order = -1,
},
Debug = {
type = 'toggle',
name = L["OPT_DEBUG"],
desc = L["OPT_DEBUG_DESC"],
guiHidden = true,
disabled = false,
order = -2,
},
DebugLevel = {
type = 'range',
name = L["OPT_DEBUGLEVEL"],
desc = L["OPT_DEBUGLEVEL_DESC"],
min = 1,
max = 3,
guiHidden = true,
disabled = false,
order = -3,
},
Version = {
type = 'execute',
name = L["OPT_VERSION"],
desc = L["OPT_VERSION_DESC"],
guiHidden = true,
func = function () HHTD:Print(L["VERSION"], '@project-version@,', L["RELEASE_DATE"], '@project-date-iso@') end,
order = -5,
},
ShowGUI = {
type = 'execute',
name = L["OPT_GUI"],
desc = L["OPT_GUI_DESC"],
guiHidden = true,
func = function () LibStub("AceConfigDialog-3.0"):Open(tostring(HHTD)) end,
order = -6,
},
core = {
type = 'group',
name = L["OPT_CORE_OPTIONS"],
order = 1,
args = {
Info_Header = {
type = 'header',
name = L["VERSION"] .. ' @project-version@ -- ' .. L["RELEASE_DATE"] .. ' @project-date-iso@',
order = 1,
},
Pve = {
type = 'toggle',
name = L["OPT_PVE"],
desc = L["OPT_PVE_DESC"],
order = 200,
},
PvpHSpecsOnly = {
type = 'toggle',
width = 'double',
name = L["OPT_PVPHEALERSSPECSONLY"],
desc = L["OPT_PVPHEALERSSPECSONLY_DESC"],
disabled = function() return HHTD_C.WOWC end,
order = 300,
},
Log = {
type = 'toggle',
name = L["OPT_LOG"],
desc = L["OPT_LOG_DESC"],
disabled = false,
order = 350,
},
ShowChatCommandReminder = {
type = 'toggle',
name = L["OPT_SHOW_CHAT_COMMAND_REMINDER"],
desc = L["OPT_SHOW_CHAT_COMMAND_REMINDER_DESC"],
width = 'double',
order = 352,
},
testOnTarget = {
type = 'execute',
width = 'double',
name = L["OPT_TESTONTARGET"],
desc = L["OPT_TESTONTARGET_DESC"],
func = function ()
if (UnitGUID("target")) then
HHTD:MakeDummyEvent("target");
else
HHTD:Print( L["OPT_TESTONTARGET_ENOTARGET"] );
end
end,
order = 355,
},
Modules = {
type = 'group',
name = L["OPT_MODULES"],
inline = true,
handler = {
["hidden"] = function () return not HHTD:IsEnabled(); end,
["disabled"] = function () return not HHTD:IsEnabled(); end,
["get"] = function (handler, info) return (HHTD:GetModule(info[#info])):IsEnabled(); end,
["set"] = function (handler, info, value)
HHTD.db.global.Modules[info[#info]].Enabled = value;
local result;
if value then
result = HHTD:EnableModule(info[#info]);
if result then
HHTD:Print(info[#info], HHTD:ColorText(L["OPT_ON"], "FF00FF00"));
end
else
result = HHTD:DisableModule(info[#info]);
if result then
HHTD:Print(info[#info], HHTD:ColorText(L["OPT_OFF"], "FFFF0000"));
end
end
return result;
end,
},
-- Enable-modules-check-boxes (filled by modules)
args = {},
order = 900,
},
Header1 = {
type = 'header',
name = "|cFFDD0000"..L["OPT_HEADER_GLOBAL_ENEMY_HEALER_OPTIONS"].."|r",
order = 400,
},
HFT = {
type = "range",
name = L["OPT_HEALER_FORGET_TIMER"],
desc = L["OPT_HEALER_FORGET_TIMER_DESC"],
min = 10,
max = 60 * 10,
step = 1,
bigStep = 5,
order = 500,
},
UHMHAP = {
type = "toggle",
width = 'double',
name = L["OPT_USE_HEALER_MINIMUM_HEAL_AMOUNT"],
desc = L["OPT_USE_HEALER_MINIMUM_HEAL_AMOUNT_DESC"],
order = 600,
},
HMHAP = {
type = "range",
width = 'double',
disabled = function() return not HHTD.db.global.UHMHAP or not HHTD:IsEnabled(); end,
name = function() HHTD:UpdateHealThresholds(); return (L["OPT_HEALER_MINIMUM_HEAL_AMOUNT"]):format(HHTD.HealThreshold) end,
desc = L["OPT_HEALER_MINIMUM_HEAL_AMOUNT_DESC"],
min = 0.01,
max = 6,
softMax = 3,
step = 0.01,
bigStep = 0.03,
order = 650,
isPercent = true,
set = function (info, value)
HHTD:SetHandler(HHTD, info, value);
HHTD:UpdateHealThresholds();
end,
},
Header2 = {
type = 'header',
name = "|cFF00DD00"..L["OPT_HEADER_GLOBAL_FRIENDLY_HEALER_OPTIONS"].."|r",
order = 655,
},
SetFriendlyHealersRole = {
type = 'toggle',
width = 'double',
name = L["OPT_SET_FRIENDLY_HEALERS_ROLE"],
desc = L["OPT_SET_FRIENDLY_HEALERS_ROLE_DESC"],
disabled = function () return HHTD_C.WOWC end,
order = 660,
},
HealerUnderAttackAlerts = {
type = 'toggle',
name = L["OPT_HEALER_UNDER_ATTACK_ALERTS"],
desc = function() HHTD:UpdateHealThresholds(); return (L["OPT_HEALER_UNDER_ATTACK_ALERTS_DESC"]):format(HHTD.ProtectDamageThreshold) end,
order = 670,
},
PHMDAP = {
type = "range",
width = 'double',
disabled = function() return not HHTD.db.global.HealerUnderAttackAlerts or not HHTD:IsEnabled(); end,
name = function() HHTD:UpdateHealThresholds(); return (L["OPT_PROTECT_HEALER_MINIMUM_DAMAGE_AMOUNT"]):format(HHTD.ProtectDamageThreshold) end,
desc = L["OPT_PROTECT_HEALER_MINIMUM_DAMAGE_AMOUNT_DESC"],
min = 0.01,
max = 6,
softMax = 3,
step = 0.01,
bigStep = 0.03,
order = 675,
isPercent = true,
set = function (info, value)
HHTD:SetHandler(HHTD, info, value);
HHTD:UpdateHealThresholds();
end,
},
Header1000 = {
type = 'header',
name = '',
order = 999,
},
},
},
Logs = {
type = 'group',
name = L["OPT_LOGS"],
desc = L["OPT_LOGS_DESC"],
order = -1,
hidden = function() return not HHTD.db.global.Log end,
args = {
clear = {
type = 'execute',
name = L["OPT_CLEAR_LOGS"],
confirm = true,
func = function ()
HHTD.LOGS[true] = {};
HHTD.LOGS[false] = {};
end,
order = 0,
},
AccusationFacts = { -- {{{
type = 'description',
name = FormatLogs,
order = 1,
}, -- }}}
},
},
},
};
end -- }}}
-- Used in Ace3 option table to get feedback when setting options through command line
function HHTD:SetHandler (module, info, value)
module.db.global[info[#info]] = value;
if info["uiType"] == "cmd" then
if value == true then
value = L["OPT_ON"];
elseif value == false then
value = L["OPT_OFF"];
end
self:Print(HHTD:ColorText(HHTD:GetOPtionPath(info), "FF00DD00"), "=>", HHTD:ColorText(value, "FF3399EE"));
end
end
local Enable_Module_CheckBox = {
type = 'toggle',
name = function (info) return L[info[#info]] end, -- it should be the localized module name
desc = function (info) return L[info[#info] .. "_DESC"] end,
get = "get",
set = "set",
disabled = "disabled",
};
-- get the option tables feeding it with the core options and adding modules options
function HHTD.GetOptions()
local options = GetCoreOptions();
-- Add modules enable/disable checkboxes
for moduleName, module in HHTD:IterateModules() do
if not options.args.core.args.Modules.args[moduleName] then
options.args.core.args.Modules.args[moduleName] = Enable_Module_CheckBox;
else
error("HHTD: module name collision!");
end
-- Add modules specific options
if module.GetOptions then
if module:IsEnabled() then
if not options.plugins then options.plugins = {} end;
options.plugins[moduleName] = module:GetOptions();
end
end
end
return options;
end
end
local DEFAULT__CONFIGURATION = {
global = {
Modules = {
['**'] = {
Enabled = true, -- Modules are enabled by default
},
},
HFT = 60,
Enabled = true,
Debug = false,
DebugLevel = 1,
--@alpha@
Debug = true,
DebugLevel = 2,
--@end-alpha@
Log = false,
Pve = true,
PvpHSpecsOnly = false,
UHMHAP = true,
HMHAP = 0.5,
PHMDAP = 0.20,
SetFriendlyHealersRole = (not HHTD_C.WOWC) and true or false,
HealerUnderAttackAlerts = true,
ShowChatCommandReminder = true,
},
};
-- }}}
-- = Add-on Management functions {{{
do
local oldName = "Healers-Have-To-Die"
local oldAce3Name = "Healers Have To Die"
local oldSV = "Healers_Have_To_Die"
local function transmuteSettings()
-- I've chosen to rename this add-on, let's handle this decision properly
-- so that it'll be transparent to the users.
local function disableOldName()
local old = LibStub("AceAddon-3.0"):GetAddon(oldAce3Name, true);
if old then
-- if it's the full add-on turn it off properly
old:Disable();
end
HHTD:Debug(WARNING, "the old " .. oldName .. " has been disabled for this character");
-- disable oldName only on the current character
-- DisableAddOn(oldName); -- on a second thought it's best to do
-- nothing here, it's soft disabled already, that's enough, this
-- allows to retain the enable/disable state through settings
-- resets without causing strange unexpected things...
end
--
-- 1 - check if the old name is loaded and running
-- 2 - import its settings
-- 3 - disable it
if GetAddOnEnableState(UnitName("player"), oldName) == 2 then
if type(_G[oldSV]) == 'table' then
if not _G[oldSV].global then
_G[oldSV].global = {};
end
-- have we already transferred the settings?
if not HHTD_SavedVariables or not HHTD_SavedVariables.global or not HHTD_SavedVariables.global.settingsMigrated
or not _G[oldSV].global.settingsTransmuted then
HHTD:Debug(WARNING, "Getting settings from " .. oldName .. "...");
if not HHTD_SavedVariables then
HHTD_SavedVariables = {};
end
HHTD:tcopy(HHTD_SavedVariables, _G[oldSV]);
HHTD_SavedVariables.global.settingsMigrated = true;
HHTD_SavedVariables.global.Enabled = true;
HHTD:tcopy(_G[oldSV].global, {["settingsTransmuted"] = "settings switched to new H.H.T.D add-on", ["Enabled"] = false})
HHTD:Debug(WARNING, "done. Now disabling " .. oldName .. "...");
disableOldName();
elseif _G[oldSV].global and _G[oldSV].global.settingsTransmuted then
HHTD:Debug(WARNING, "Settings already tranferred from " .. oldName);
disableOldName();
_G[oldSV].global.Enabled = false;
end
else
-- oldName was enabled but no settings were found.
-- Either there are none or oldName has not been loaded yet...
return false;
end
return true;
end
end
function HHTD:OnInitialize()
-- Catch people updating add-ons while WoW is running before they post "it doesn't work!!!!" comments.
local versionInTOC = GetAddOnMetadata("HHTD", "Version");
if versionInTOC and versionInTOC ~= VERSION and versionInTOC ~= UNPACKAGED and VERSION ~= UNPACKAGED then
T._DiagStatus = 2;
T._Diagmessage = "You have updated H.H.T.D while WoW was still running in the background.\n\nYou need to restart WoW completely or you might experience various issues with your add-ons until you do.";
T._FatalError(T._Diagmessage);
end
local oldNameGState = select(5, GetAddOnInfo(oldName));
local oldNameGEnableState = GetAddOnEnableState(nil, oldName);
local oldNameLState = GetAddOnEnableState(UnitName("player"), oldName);
local TSsuccess, TSstatus = pcall(transmuteSettings);
if not TSsuccess then
T._DiagStatus = 2;
T._Diagmessage = "Settings transfer from '" .. oldName .. "' to '" .. ADDON_NAME .. "' failed. " .. ADDON_NAME ..
" will stay disabled. Error was: " .. TSstatus .. "\n\n" .. debugstack(2,1,1);
T._FatalError(T._Diagmessage);
return false;
elseif TSstatus then
self:Debug(WARNING, "Previous settings were successfully transferred.");
end
self.db = LibStub("AceDB-3.0"):New("HHTD_SavedVariables", DEFAULT__CONFIGURATION);
-- store once the status of the oldName
if self.db.global.oldNameEnableState == nil then
self.db.global.oldNameEnableState = oldNameGEnableState; -- 0 == disabled everywhere, 1 partially, 2 globally enabled
end
if TSstatus and not self.db.char.settingsMigrated then
T._MessageBox((L["HHTD_IS_NOW_KNOWN_AS_H.H.T.D."]):format(oldName, oldName));
self.db.char.settingsMigrated = true;
end
LibStub("AceConfig-3.0"):RegisterOptionsTable(tostring(self), self.GetOptions, {"hhtd", "H.H.T.D."});
--LibStub("AceConfigDialog-3.0"):AddToBlizOptions(tostring(self));
self:RegisterChatCommand('hhtdg', function() LibStub("AceConfigDialog-3.0"):Open(tostring(self)) end, true);
self:CreateClassColorTables();
-- if the user previously disabled the oldName then we don't want to intrude
-- NOTE: once the old add-on is disabled on all characters and the user
-- reset their settings then this code will be triggered :/
-- Just make sure that it can be triggered only once...
-- maybe add a delay?
if oldNameGState == "DISABLED" and self.db.global.settingsMigrated == nil then
self:Debug(WARNING, oldName .. " was already disabled for all characters, quitting.");
self:SetEnabledState(false);
DisableAddOn(ADDON_NAME, true); -- disable globaly as the oldName was
self:Debug(WARNING, "globally disabled");
elseif oldNameGState ~= "DISABLED" and oldNameLState == 0 and self.db.char.settingsMigrated == nil
-- and there was actually a per character emable/disable setting
and self.db.global.oldNameEnableState == 1 then
-- The oldName was already disabled for this specific character
self:SetEnabledState(false);
self:Debug(WARNING, "disabled for this character as", oldName, "was already disabled for", (UnitName("player")));
DisableAddOn(ADDON_NAME);
else
self:SetEnabledState(self.db.global.Enabled);
end
-- if we manage to run once on this character make sure that any
-- disable action on the oldName will not trigger the above code
if self.db.char.settingsMigrated == nil then
self.db.char.settingsMigrated = false;
end