forked from Dicebar/Raven
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditions.lua
More file actions
2470 lines (2416 loc) · 73.6 KB
/
Conditions.lua
File metadata and controls
2470 lines (2416 loc) · 73.6 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
-- Raven is an addon to monitor auras and cooldowns, providing timer bars and icons plus helpful notifications.
-- Conditions.lua contains routines to test auras and status info to generate notifications.
-- Exported functions:
-- Raven:InitializeCondition(name, condition) adds a condition (or overwrites a default one) during initialization
-- Raven:CheckCondition(name) evaluates a condition and returns its current value
-- Raven:GetConditionSpell(name) returns the spell associated with a condition
-- Raven:GetConditionText(name) returns a string containing a detailed description of the condition
local MOD = Raven
local SHIM = MOD.SHIM
local L = LibStub("AceLocale-3.0"):GetLocale("Raven")
local LSPELL = MOD.LocalSpellNames
local timeEvents = {} -- table of times at which to trigger a simulated event during update processing
local classificationList = { normal = L["Normal"], worldboss = L["Boss"], elite = L["Elite"], rare = L["Rare"], rlite = L["Rare Elite"] }
local classifications = { "normal", "worldboss", "elite", "rare", "rlite" }
local unitList = {
player = "Player",
pet = "Pet",
target = "Target",
focus = "Focus",
mouseover = "Mouseover",
pettarget = "Pet's Target",
targettarget = "Target's Target",
focustarget = "Focus's Target",
}
-- Saved variables don't handle being set to nil properly so need to use alternate value to indicate an option has been turned off
local Off = 0 -- value used to designate an option is turned off
local function IsOff(value)
return value == nil or value == Off
end -- return true if option is turned off
local function IsOn(value)
return value ~= nil and value ~= Off
end -- return true if option is turned on
-- Initialization settings for each test type (note that nil values are placeholders for documentation purposes)
MOD.conditionTests = {
["Player Status"] = {
enable = false,
inCombat = nil,
isResting = nil,
hasPet = nil,
isStealthed = nil,
isMounted = nil,
inGroup = nil,
inParty = nil,
inRaid = nil,
isPvP = nil,
inInstance = nil,
inArena = nil,
inBattleground = nil,
hasMainHand = nil,
levelMainHand = 1,
hasOffHand = nil,
levelOffHand = 1,
checkSpec = nil,
spec = nil,
checkSpell = nil,
spell = nil,
checkTalent = nil,
talent = nil,
checkLevel = nil,
level = 85,
checkStance = nil,
stance = nil,
checkHealth = nil,
minHealth = 100,
checkPower = nil,
minPower = 100,
checkHolyPower = nil,
minHolyPower = 1,
checkShards = nil,
minShards = 1,
checkChi = nil,
minChi = 1,
checkLunarPower = nil,
minLunarPower = 1,
checkInsanity = nil,
minInsanity = 100,
checkMaelstrom = nil,
minMaelstrom = 150,
checkArcane = nil,
minArcane = 1,
checkComboPoints = nil,
minComboPoints = 5,
checkRunes = nil,
minRunes = 1,
checkTotems = nil,
totem = nil,
checkEssence = nil,
minEssence = 1,
},
["Pet Status"] = {
enable = false,
exists = nil,
inCombat = nil,
checkTarget = nil,
checkHealth = nil,
minHealth = 100,
checkPower = nil,
minPower = 100,
checkFamily = nil,
family = nil,
checkSpec = nil,
spec = nil,
},
["Target Status"] = {
enable = false,
exists = nil,
isPlayer = nil,
isEnemy = nil,
isFriend = nil,
isNeutral = nil,
inRange = nil,
isSteal = nil,
isDead = nil,
checkHealth = nil,
minHealth = 100,
checkMaxHealth = nil,
maxHealth = nil,
checkPower = nil,
minPower = 100,
classify = nil,
classification = "normal",
},
["Target's Target Status"] = {
enable = false,
exists = nil,
isPlayer = nil,
isEnemy = nil,
isFriend = nil,
inRange = nil,
isSteal = nil,
isDead = nil,
checkHealth = nil,
minHealth = 100,
checkMaxHealth = nil,
maxHealth = nil,
checkPower = nil,
minPower = 100,
classify = nil,
classification = "normal",
},
["Focus Status"] = {
enable = false,
exists = nil,
isPlayer = nil,
isEnemy = nil,
isFriend = nil,
inRange = nil,
isSteal = nil,
isDead = nil,
checkHealth = nil,
minHealth = 100,
checkPower = nil,
minPower = 100,
classify = nil,
classification = "normal",
},
["Focus's Target Status"] = {
enable = false,
exists = nil,
isPlayer = nil,
isEnemy = nil,
isFriend = nil,
inRange = nil,
isSteal = nil,
isDead = nil,
checkHealth = nil,
minHealth = 100,
checkPower = nil,
minPower = 100,
classify = nil,
classification = "normal",
},
["All Buffs"] = { enable = false, unit = "player", auras = nil, isMine = nil, toggle = false },
["Any Buffs"] = { enable = false, unit = "player", auras = nil, isMine = nil, toggle = false },
["Buff Time Left"] = { enable = false, unit = "player", aura = nil, timeLeft = 10, isMine = nil, toggle = false },
["Buff Count"] = { enable = false, unit = "player", aura = nil, count = 1, isMine = nil, toggle = false },
["Buff Type"] = { enable = false, hasBuff = nil, toggle = false },
["All Debuffs"] = { enable = false, unit = "target", auras = nil, isMine = nil, toggle = false },
["Any Debuffs"] = { enable = false, unit = "target", auras = nil, isMine = nil, toggle = false },
["Debuff Time Left"] = { enable = false, unit = "target", aura = nil, timeLeft = 10, isMine = nil, toggle = false },
["Debuff Count"] = { enable = false, unit = "player", aura = nil, count = 1, isMine = nil, toggle = false },
["Debuff Type"] = { enable = false, hasDebuff = nil, toggle = false },
["All Cooldowns"] = { enable = false, notUsable = false, spells = nil, timeLeft = 10, toggle = Off },
["Spell Ready"] = { enable = false, spell = nil, inRange = nil, notUsable = false, checkCharges = nil, charges = 1 },
["Spell Casting"] = { enable = false, spell = nil, unit = "player" },
["Item Ready"] = { enable = false, item = nil, toggle = nil, checkCount = nil, count = 1, checkCharges = nil, charges = 1 },
}
MOD.testOrder = {
"Player Status",
"Pet Status",
"Target Status",
"Target's Target Status",
"Focus Status",
"Focus's Target Status",
"All Buffs",
"Any Buffs",
"Buff Time Left",
"Buff Count",
"Buff Type",
"All Debuffs",
"Any Debuffs",
"Debuff Time Left",
"Debuff Count",
"Debuff Type",
"All Cooldowns",
"Spell Ready",
"Spell Casting",
"Item Ready",
}
local testNames = {
["Player Status"] = L["Player Status"],
["Pet Status"] = L["Pet Status"],
["Target Status"] = L["Target Status"],
["Target's Target Status"] = L["Target's Target Status"],
["Focus Status"] = L["Focus Status"],
["Focus's Target Status"] = L["Focus's Target Status"],
["All Buffs"] = L["All Buffs"],
["Any Buffs"] = L["Any Buffs"],
["Buff Time Left"] = L["Buff Time Left"],
["Buff Count"] = L["Buff Count"],
["Buff Type"] = L["Buff Type"],
["All Debuffs"] = L["All Debuffs"],
["Any Debuffs"] = L["Any Debuffs"],
["Debuff Time Left"] = L["Debuff Time Left"],
["Debuff Count"] = L["Debuff Count"],
["Debuff Type"] = L["Debuff Type"],
["All Cooldowns"] = L["All Cooldowns"],
["Spell Ready"] = L["Spell Ready"],
["Spell Casting"] = L["Spell Casting"],
["Item Ready"] = L["Item Ready"],
}
-- Initialize data used by this module, and restore any default test settings
function MOD:InitializeConditions()
local conditions = MOD.db.profile.Conditions[MOD.myClass]
if conditions then
for _, c in pairs(conditions) do
if IsOn(c) and c.tests then
for ttype, test in pairs(c.tests) do
local ct = MOD.conditionTests[ttype]
if ct then
for k, v in pairs(ct) do
if test[k] == nil then
test[k] = v
end
end
end
if test.classification == "rareelite" then
test.classification = "rlite"
end -- fix to support multiple classifications
end
end
end
else
MOD.db.profile.Conditions[MOD.myClass] = {}
end
for _, c in pairs(MOD.db.global.SharedConditions) do
if IsOn(c) and c.tests then
for ttype, test in pairs(c.tests) do
local ct = MOD.conditionTests[ttype]
if ct then
for k, v in pairs(ct) do
if test[k] == nil then
test[k] = v
end
end
end
end
end
end
end
-- Finalize conditions by stripping out unnecessary values, updating shared conditions, removing default test settings
function MOD:FinalizeConditions()
local conditions = MOD.db.profile.Conditions[MOD.myClass]
if conditions then
for _, c in pairs(conditions) do
if IsOn(c) then
c.result = nil
c.testResult = nil -- these values are left over from evaluations
if c.tests then
for ttype, test in pairs(c.tests) do
local ct = MOD.conditionTests[ttype]
if ct then
for k, v in pairs(ct) do
if test[k] == v then
test[k] = nil
end
end
end
end
end
if c.shared and c.name then
local t = MOD.CopyTable(c)
t.shared = false
MOD.db.global.SharedConditions["[" .. MOD.myClass .. "] " .. c.name] = t
end
end
end
end
for _, c in pairs(MOD.db.global.SharedConditions) do
if IsOn(c) and c.tests then
for ttype, test in pairs(c.tests) do
local ct = MOD.conditionTests[ttype]
if ct then
for k, v in pairs(ct) do
if test[k] == v then
test[k] = nil
end
end
end
end
end
end
end
-- Add a time event for a condition that needs to be tested at a specific future time
local function AddTimeEvent(name, timeLeft)
timeEvents[name] = GetTime() + timeLeft
end
-- Check if any time events have been reached, remove expired time events
function MOD:CheckTimeEvents()
local now = GetTime()
for name, t in pairs(timeEvents) do
if t < now then
timeEvents[name] = nil
return true
end
end
return false
end
-- Generate a localized string from a classification list
local function ClassificationList(cl)
local s, d = "", ""
for _, v in pairs(classifications) do
if string.find(cl, v) ~= nil then
s = s .. d .. classificationList[v]
d = " | "
end
end
return s
end
-- Check if a classification list contains a classification, return true if it does
local function CheckClassification(v, cl)
if v == "rareelite" then
v = "rlite"
end
return string.find(cl or "", v) ~= nil
end
-- Check if a spell is ready to be cast by the player, if rangeCheck then make sure in range of unit too
local function CheckSpellReady(spell, unit, usable, checkCharges, charges)
if not spell or (spell == "") then
return true
end
if string.find(spell, "^#%d+") then -- check if name is in special format for specific spell id (i.e., #12345)
local id = tonumber(string.sub(spell, 2)) -- extract the spell id and get the name
spell = SHIM:GetSpellInfo(id)
if not spell or (spell == "") then
return false
end
end
if usable and not MOD:CheckSpellStatus(spell, true) then
return false
end -- checks player has learned the spell, has mana and/or reagents, and reactive conditions are met
if IsOn(checkCharges) then -- optionally check for remaining spell charges (can't count on the value of cd if not on cooldown)
local n = SHIM:GetSpellChargesByID(spell) -- this has to be done separate from cooldown check in order to correctly handle the check for "less than"
if not n then
n = 0
end
if not charges then
charges = 1 -- set to default value used in options panel
end
if checkCharges == true then
if n >= charges then
return false
end
else
if n < charges then
return false
end
end
else
local cd = MOD:CheckCooldown(spell) -- checks if spell is on cooldown (note this should correctly ignore DK rune cooldowns)
if cd and ((cd[4] ~= nil) and (not cd[9] or cd[9] == 0)) then
return false
end -- verify is on cooldown and has a valid duration and no charges remaining
end
return true
end
-- Check if a specified spell is currently being cast or channeled by the unit
local function CheckSpellCast(spell, unit)
if IsOff(unit) or not spell or (spell == "") then
return true
end
spell = MOD.spellOverrides[spell] or spell
local sp = UnitCastingInfo(unit)
if (sp ~= nil) and (spell == sp) then
return true
end
sp = UnitChannelInfo(unit)
if (sp ~= nil) and (spell == sp) then
return true
end
return false
end
-- Check if an item is ready to be used by the player, can be either itemID (number) or item name (string)
-- The item must be in the player's bag for this to work properly
local function CheckItemReady(item, ready, checkCount, count, checkCharges, charges)
if not item or (item == "") then
return true
end
local id, n = tonumber(item), 0
if IsOn(ready) then
local isReady = true
if id then -- in 4.0.2 GetItemCooldown was changed to only work with item IDs
local start, duration
start, duration = SHIM:GetItemCooldown(id)
if (start > 0) and (duration > 0) then
isReady = false
end
else -- so have to fallback to looking in internal cooldown tables
local cd = MOD:CheckCooldown(item)
if cd and (cd[1] ~= nil) then
isReady = false
end
end
if isReady ~= ready then
return false
end
end
if id then
item = id
end
if IsOn(checkCount) then
n = SHIM:GetItemCount(item, false, false)
if not n then
n = 0
end
if not count then
count = 1
end -- set to default value used in options panel
if checkCount == true then
if n >= count then
return false
end
else
if n < count then
return false
end
end
end
if IsOn(checkCharges) then
n = SHIM:GetItemCount(item, false, true)
if not n then
n = 0
end
if not charges then
charges = 1
end -- set to default value used in options panel
if checkCharges == true then
if n >= charges then
return false
end
else
if n < charges then
return false
end
end
end
return true
end
-- Check for either at least one active aura (hasAll is false) or all active auras (hasAll is true)
-- If isMine true then cast by the player, if false then cast by other, if nil cast by anyone
local function CheckAuras(unit, auras, hasAll, isMine, buff, toggle)
if IsOff(unit) or not auras then
return true
end -- no test
if (unit == "target") and MOD.status.noTarget then
return not toggle
end
if (unit == "focus") and MOD.status.noFocus then
return not toggle
end
local found = false
for _, aname in pairs(auras) do -- look for each aura and check if buff/debuff and cast by player
local foundThis = false
local auraList = MOD:CheckAura(unit, aname, buff)
if #auraList > 0 then
for _, aura in pairs(auraList) do
if (buff == false or aura[11] == "buff") and (IsOff(isMine) or (isMine == (aura[6] == "player"))) then -- check cast by setting
found = true -- found at least one of the auras
foundThis = true -- found this particular aura
end
end
end
if hasAll and not foundThis then
return toggle
end -- not all are found
end
if toggle then
return not found
end -- flip result if necessary
return found
end
-- Check an aura on the unit to see if active and either expiration time is less than or equal or count is greater
-- If isMine true then cast by the player, if false then cast by other, if nil cast by anyone
local function CheckAuraValue(unit, aname, timeLeft, count, isMine, buff, toggle)
if IsOff(unit) or not aname or (aname == "") or (IsOff(timeLeft) and IsOff(count)) then
return true
end -- no test
if (unit == "target") and MOD.status.noTarget then
return not toggle
end
if (unit == "focus") and MOD.status.noFocus then
return not toggle
end
local auraList = MOD:CheckAura(unit, aname, buff)
for _, aura in pairs(auraList) do
if IsOff(isMine) or (isMine == (aura[6] == "player")) then -- check if found one with right cast by setting
if timeLeft then
local when = aura[2] - timeLeft
if when >= 0 then
AddTimeEvent(aname, when)
return not toggle
end
end -- check expiration time
if count and (aura[3] >= count) then
return not toggle
end -- check count is greater or equal
end
end
return toggle
end
-- Return true only if all spells in the list are on cooldown and have at least the specified amount of time left.
-- If toggle is true then check if they all have less than the specified time left instead.
-- If ready is true then check player has mana and/or reagents, and reactive conditions are met and, if not, consider it on long cooldown
-- as long as it is in the spell book (always return false if the player does not know the spell).
-- If a spell is not ready for some other reason (e.g., too much target HP ala Kill Shot) then consider it on long cooldown.
local function CheckAllCooldowns(spells, ready, timeLeft, toggle)
if not timeLeft then
timeLeft = 10
end
for _, spell in pairs(spells) do -- look for each spell and check if on cooldown
local cdt = 0
if ready and not MOD:CheckSpellStatus(spell, true, true) then
if not MOD:CheckSpellStatus(spell) then
return false
end
cdt = 3600
end
local cd = MOD:CheckCooldown(spell) -- look up in the active cooldowns table
if cd and (cd[1] ~= nil) and ((cd[4] ~= nil) and (not cd[9] or cd[9] == 0)) then
cdt = cd[1]
if timeLeft < cdt then
AddTimeEvent(spell, cdt - timeLeft)
end
end
if toggle == true then
if cdt >= timeLeft then
return false
end
else
if cdt < timeLeft then
return false
end
end
end
return true
end
-- Return the current stance or "none" if not in one
local function GetStance()
local form, _ = "none", nil
local index = GetShapeshiftForm(nil)
if index > 0 then
_, form = GetShapeshiftFormInfo(index)
end
return form
end
-- Return whether the specified talent (either spell name or spell id) is active in current spec
function MOD.CheckTalent(talent)
local id = tonumber(talent)
if id then
talent = SHIM:GetSpellInfo(id)
if talent == "" then
talent = nil
end
end -- translate spell id
if talent then
local t = MOD.talents[talent]
if t and t.active then
return true
end
end
return nil
end
-- Check if mounted, complicated by having to test for druid flight form
local function CheckMounted()
local flying = false
if MOD.myClass == "DRUID" then
local form = GetShapeshiftForm(true)
if form ~= 0 then
if MOD.isClassic then
local _, fname = GetShapeshiftFormInfo(form)
flying = (fname == LSPELL["Flight Form"]) or (fname == LSPELL["Swift Flight Form"])
else
flying = form == 3
end
end
end
return IsMounted() or flying
end
-- Check all totem slots for a specific active totem
local function CheckTotem(totem)
if MOD.myClass == "SHAMAN" then
local now = GetTime()
for i = 1, MAX_TOTEMS do
local haveTotem, name, startTime, duration = GetTotemInfo(i)
local exists = haveTotem and name and name ~= "" and now <= (startTime + duration) -- true only if a valid totem is in the slot
if exists and (name == totem) then
return true
end
end
end
return false
end
-- Check if target matches the specified type
local function CheckTarget(targetType, unit)
local m = not UnitExists(unit)
if targetType == "none" then
m = not m
end
if targetType == "player" then
m = m or not UnitIsUnit("target", unit)
end
return not m
end
-- Check if weapon equipped with at least the minimum specified item level
local function CheckWeapon(islot, level)
local id = GetInventoryItemLink("player", islot)
if id and level then
local iname, _, _, ilevel = SHIM:GetItemInfo(id)
if iname and (ilevel >= level) then
return true
end
end
return false
end
-- Check current specialization against the first argument (or the optional second argument, which is a table of specialization names or numbers)
function MOD.CheckSpec(spec, specList)
local stat = MOD.status
local currentSpec = stat.specialization
local currentName = currentSpec and (MOD.ExpansionIsOrAbove(LE_EXPANSION_MISTS_OF_PANDARIA) and select(2, SHIM:GetSpecializationInfo(currentSpec))) or "none"
if specList then
for _, name in pairs(specList) do
local id = tonumber(name)
if id then
if currentSpec == id then
return true
end
else
if name == currentName then
return true
end
end
end
return false
end
if not spec then
spec = "none"
end
local id = tonumber(spec)
if id then
return currentSpec == id
end
return spec == currentName
end
-- Check current pet talent tree, including workaround for API returning nil for hunter's ferocity pets
local function CheckPetSpec(spec)
if not spec then
spec = "none"
end
local currentName = "none"
local ferocity = SHIM:GetSpellInfo(4154) -- hack workaround to localize Ferocity, fingers crossed it works in all languages, spell id must be valid
if UnitExists("pet") then
currentName = GetPetTalentTree() or ((MOD.myClass == "HUNTER") and ferocity) or "none"
end
return spec == currentName
end
-- Check current pet creature family
local function CheckPetFamily(family)
if not family then
family = "none"
end
local currentName = "none"
if UnitExists("pet") then
currentName = UnitCreatureFamily("pet") or "none"
end
return family == currentName
end
-- Make sure the table contains at least one entry
local function HasTable(t)
if IsOn(t) and (type(t) == "table") and (next(t) ~= nil) then
return true
end
return false
end
-- Check the value of one test with logical AND between all enabled subtests
local function CheckTestAND(ttype, t)
local toggle = (t.toggle == true)
local stat = MOD.status
if ttype == "Player Status" then
if IsOn(t.inCombat) and (t.inCombat ~= stat.inCombat) then
return false
end
if IsOn(t.inGroup) and (t.inGroup ~= stat.inGroup) then
return false
end
if IsOn(t.inParty) and (t.inParty ~= stat.inParty) then
return false
end
if IsOn(t.inRaid) and (t.inRaid ~= stat.inRaid) then
return false
end
if IsOn(t.inInstance) and (t.inInstance ~= stat.inInstance) then
return false
end
if IsOn(t.inArena) and (t.inArena ~= stat.inArena) then
return false
end
if IsOn(t.inBattleground) and (t.inBattleground ~= stat.inBattleground) then
return false
end
if IsOn(t.isResting) and (t.isResting ~= stat.isResting) then
return false
end
if IsOn(t.isStealthed) and (t.isStealthed ~= stat.isStealthed) then
return false
end
if IsOn(t.isMounted) and (t.isMounted ~= stat.isMounted) then
return false
end
if IsOn(t.isPvP) and (t.isPvP ~= stat.isPvP) then
return false
end
if IsOn(t.checkLevel) and IsOn(t.level) and (t.checkLevel ~= (stat.level >= t.level)) then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (t.checkHealth ~= (stat.health >= t.minHealth)) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (t.checkPower ~= (stat.power >= t.minPower)) then
return false
end
if IsOn(t.checkHolyPower) and IsOn(t.minHolyPower) and (t.checkHolyPower ~= (stat.holyPower >= t.minHolyPower)) then
return false
end
if IsOn(t.checkEssence) and IsOn(t.minEssence) and (t.checkEssence ~= (stat.essence >= t.minEssence)) then
return false
end
if IsOn(t.checkInsanity) and IsOn(t.minInsanity) and (t.checkInsanity ~= (stat.insanity >= t.minInsanity)) then
return false
end
if IsOn(t.checkMaelstrom) and IsOn(t.minMaelstrom) and (t.checkMaelstrom ~= (stat.maelstrom >= t.minMaelstrom)) then
return false
end
if IsOn(t.checkChi) and IsOn(t.minChi) and (t.checkChi ~= (stat.chi >= t.minChi)) then
return false
end
if IsOn(t.checkShards) and IsOn(t.minShards) and (t.checkShards ~= (stat.shards >= t.minShards)) then
return false
end
if IsOn(t.checkLunarPower) and IsOn(t.minLunarPower) and (t.checkLunarPower ~= (stat.lunarPower >= t.minLunarPower)) then
return false
end
if IsOn(t.checkArcane) and IsOn(t.minArcane) and (t.checkArcane ~= (stat.arcane >= t.minArcane)) then
return false
end
if IsOn(t.checkComboPoints) and IsOn(t.minComboPoints) and (t.checkComboPoints ~= (stat.combo >= t.minComboPoints)) then
return false
end
if IsOn(t.hasPet) and (t.hasPet ~= HasPetUI()) then
return false
end
if IsOn(t.checkStance) and IsOn(t.stance) and (t.stance ~= stat.stance) then
return false
end
if IsOn(t.checkRunes) and IsOn(t.minRunes) and (t.checkRunes ~= (MOD.runeCount >= t.minRunes)) then
return false
end
if IsOn(t.checkTotems) and IsOn(t.totem) and not CheckTotem(t.totem) then
return false
end
if IsOn(t.checkTalent) and IsOn(t.talent) and not MOD.CheckTalent(t.talent) then
return false
end
if IsOn(t.checkSpec) and IsOn(t.spec) and not MOD.CheckSpec(t.spec, t.specList) then
return false
end
if IsOn(t.checkSpell) and IsOn(t.spell) and not MOD:CheckSpellStatus(t.spell) then
return false
end
if IsOn(t.hasMainHand) and not CheckWeapon(INVSLOT_MAINHAND, t.levelMainHand) then
return false
end
if IsOn(t.hasOffHand) and not CheckWeapon(INVSLOT_OFFHAND, t.levelOffHand) then
return false
end
elseif ttype == "Pet Status" then -- pet must exist for these tests to be true
if IsOn(t.exists) and (t.exists == stat.noPet) then
return false
end
if IsOn(t.inCombat) and (t.inCombat ~= stat.petCombat) then
return false
end
if IsOn(t.checkTarget) and not CheckTarget(t.checkTarget, "pettarget") then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (stat.noPet or (t.checkHealth ~= (stat.petHealth >= t.minHealth))) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (stat.noPet or (t.checkPower ~= (stat.petPower >= t.minPower))) then
return false
end
if IsOn(t.checkFamily) and IsOn(t.family) and not CheckPetFamily(t.family) then
return false
end
if IsOn(t.checkSpec) and IsOn(t.spec) and not CheckPetSpec(t.spec) then
return false
end
elseif ttype == "Target Status" then -- target must exist for these tests to be true
if IsOn(t.exists) and (t.exists == stat.noTarget) then
return false
end
if IsOn(t.isPlayer) and (stat.noTarget or (t.isPlayer ~= stat.targetPlayer)) then
return false
end
if IsOn(t.isEnemy) and (stat.noTarget or (t.isEnemy ~= stat.targetEnemy)) then
return false
end
if IsOn(t.isFriend) and (stat.noTarget or (t.isFriend ~= stat.targetFriend)) then
return false
end
if IsOn(t.isNeutral) and (stat.noTarget or (t.isNeutral ~= stat.targetNeutral)) then
return false
end
if IsOn(t.isDead) and (stat.noTarget or (t.isDead ~= stat.targetDead)) then
return false
end
if IsOn(t.isSteal) and (stat.noTarget or (t.isSteal ~= MOD:UnitHasBuff("target", "Steal"))) then
return false
end
if IsOn(t.classify) and (not t.classification or t.classification == "" or stat.noTarget or not CheckClassification(stat.targetClassification, t.classification)) then
return false
end
if IsOn(t.checkMaxHealth) and (stat.noTarget or (tonumber(t.maxHealth or 0) or 0) > stat.targetMaxHealth) then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (stat.noTarget or (t.checkHealth ~= (stat.targetHealth >= t.minHealth))) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (stat.noTarget or (t.checkPower ~= (stat.targetPower >= t.minPower))) then
return false
end
elseif ttype == "Target's Target Status" then -- target's target must exist for these tests to be true
if IsOn(t.exists) and (t.exists == stat.noTargetTarget) then
return false
end
if IsOn(t.isPlayer) and (stat.noTargetTarget or (t.isPlayer ~= stat.targetTargetPlayer)) then
return false
end
if IsOn(t.isEnemy) and (stat.noTargetTarget or (t.isEnemy ~= stat.targetTargetEnemy)) then
return false
end
if IsOn(t.isFriend) and (stat.noTargetTarget or (t.isFriend ~= stat.targetTargetFriend)) then
return false
end
if IsOn(t.isDead) and (stat.noTargetTarget or (t.isDead ~= stat.targetTargetDead)) then
return false
end
if IsOn(t.isSteal) and (stat.noTargetTarget or (t.isSteal ~= MOD:UnitHasBuff("targettarget", "Steal"))) then
return false
end
if
IsOn(t.classify) and (not t.classification or t.classification == "" or stat.noTargetTarget or not CheckClassification(stat.targetTargetClassification, t.classification))
then
return false
end
if IsOn(t.checkMaxHealth) and (stat.noTargetTarget or (tonumber(t.maxHealth or 0) or 0) > stat.targetTargetMaxHealth) then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (stat.noTargetTarget or (t.checkHealth ~= (stat.targetTargetHealth >= t.minHealth))) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (stat.noTargetTarget or (t.checkPower ~= (stat.targetTargetPower >= t.minPower))) then
return false
end
elseif ttype == "Focus Status" then -- focus must exist for these tests to be true
if IsOn(t.exists) and (t.exists == stat.noFocus) then
return false
end
if IsOn(t.isPlayer) and (stat.noFocus or (t.isPlayer ~= stat.focusPlayer)) then
return false
end
if IsOn(t.isEnemy) and (stat.noFocus or (t.isEnemy ~= stat.focusEnemy)) then
return false
end
if IsOn(t.isFriend) and (stat.noFocus or (t.isFriend ~= stat.focusFriend)) then
return false
end
if IsOn(t.isDead) and (stat.noFocus or (t.isDead ~= stat.focusDead)) then
return false
end
if IsOn(t.isSteal) and (stat.noFocus or (t.isSteal ~= MOD:UnitHasBuff("focus", "Steal"))) then
return false
end
if IsOn(t.classify) and (not t.classification or t.classification == "" or stat.noFocus or not CheckClassification(stat.focusClassification, t.classification)) then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (stat.noFocus or (t.checkHealth ~= (stat.focusHealth >= t.minHealth))) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (stat.noFocus or (t.checkPower ~= (stat.focusPower >= t.minPower))) then
return false
end
elseif ttype == "Focus's Target Status" then -- focus target must exist for these tests to be true
if IsOn(t.exists) and (t.exists == stat.noFocusTarget) then
return false
end
if IsOn(t.isPlayer) and (stat.noFocusTarget or (t.isPlayer ~= stat.focusTargetPlayer)) then
return false
end
if IsOn(t.isEnemy) and (stat.noFocusTarget or (t.isEnemy ~= stat.focusTargetEnemy)) then
return false
end
if IsOn(t.isFriend) and (stat.noFocusTarget or (t.isFriend ~= stat.focusTargetFriend)) then
return false
end
if IsOn(t.isDead) and (stat.noFocusTarget or (t.isDead ~= stat.focusTargetDead)) then
return false
end
if IsOn(t.isSteal) and (stat.noFocusTarget or (t.isSteal ~= MOD:UnitHasBuff("focustarget", "Steal"))) then
return false
end
if IsOn(t.classify) and (not t.classification or t.classification == "" or stat.noFocusTarget or not CheckClassification(stat.focusTargetClassification, t.classification)) then
return false
end
if IsOn(t.checkHealth) and IsOn(t.minHealth) and (stat.noFocusTarget or (t.checkHealth ~= (stat.focusTargetHealth >= t.minHealth))) then
return false
end
if IsOn(t.checkPower) and IsOn(t.minPower) and (stat.noFocusTarget or (t.checkPower ~= (stat.focusTargetPower >= t.minPower))) then
return false
end
elseif ttype == "All Buffs" then
if HasTable(t.auras) and not CheckAuras(t.unit, t.auras, true, t.isMine, true, toggle) then
return false
end
elseif ttype == "Any Buffs" then
if HasTable(t.auras) and not CheckAuras(t.unit, t.auras, false, t.isMine, true, toggle) then
return false
end
elseif ttype == "Buff Time Left" then
if not CheckAuraValue(t.unit, t.aura, t.timeLeft, nil, t.isMine, true, toggle) then
return false