forked from Romain-P/Ewt-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.lua
1096 lines (879 loc) · 37.8 KB
/
shared.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
-- Created by romain-p
-- see updates on http://github.com/romain-p
if not shared then shared = true
SharedConfiguration = {
melee_range = 5,
gcd_value = 1.5,
latency = 0.15, -- latency in seconds
StealthSpells = {
RogueSpells.VANISH,
RogueSpells.STEALTH,
DruidSpells.PROWL,
RaceSpells.SHADOWMELD
}
}
last_target = nil
last_target_notnull = nil
current_target = nil
overpowered = nil
mage_used_mirrors = nil
objectTimer = -1
analizeTimer = -1
simpleTimer = -1
enabled = false
WorldObjects = {}
CombatCallbacks = {}
EventCallbacks = {}
aCallbacks = {}
sCallbacks = {}
dangerousSpells = {}
function TableConcat(t1, t2, valueAsKey)
for k, v in pairs(t2) do
if not valueAsKey then
t1[k] = v
else
t1[v] = true
end
end
return t1
end
function TableSize(table)
local count = 0
for _,_ in pairs(table) do
count = count + 1
end
return count
end
function TableContains(table, elem)
for i=1, #table do
if table[i] == elem then
return true
end
end
return false
end
function IndexOf(table, elem)
for i=1, #table do
if table[i] == elem then
return i
end
end
return nil
end
Spells = {}
SpellNames = {}
SpellIds = {}
TableConcat(Spells, PriestSpells)
TableConcat(Spells, RogueSpells)
TableConcat(Spells, DruidSpells)
TableConcat(Spells, HunterSpells)
TableConcat(Spells, WarriorSpells)
TableConcat(Spells, MageSpells)
TableConcat(Spells, WarlockSpells)
TableConcat(Spells, ShamanSpells)
TableConcat(Spells, PaladinSpells)
TableConcat(Spells, DkSpells)
TableConcat(Spells, RaceSpells)
function HoldSpells(table)
local var
for _, v in pairs(table) do
var = select(1, GetSpellInfo(v))
if var ~= nil then
SpellNames[v] = var
SpellIds[strlower(var)] = v
end
end
end
HoldSpells(Spells)
HoldSpells(Auras)
-- Returns the spell id of a given spell name
function GetSpellId(spellname)
return SpellIds[strlower(spellname)]
end
-- Return true if unit is in los with otherunit
function InLos(unit, otherUnit)
if not otherUnit then otherUnit = player end
if not UnitExists(otherUnit) then return end
if UnitIsVisible(unit) or 1 == 1 then
local X1, Y1, Z1 = ObjectPosition(unit);
local X2, Y2, Z2 = ObjectPosition(otherUnit);
return not TraceLine(X1, Y1, Z1 + 2, X2, Y2, Z2 + 2, 0x10);
end
end
-- Return true if a given type is checked
function ValidUnitType(unitType, unit)
if unit == nil then return false end
local isEnemyUnit = UnitCanAttack(player, unit) == 1
return (isEnemyUnit and unitType == enemy)
or (not isEnemyUnit and unitType == ally)
end
-- Return if a given unit exists, isn't dead
function ValidUnit(unit, unitType)
return UnitExists(unit) == 1 and ValidUnitType(unitType, unit)
end
-- Return true if the Cooldown of a given spell is reset (with gcd or not)
function CdRemains(spellId, gcd)
if gcd == nil then gcd = true end
local duration = select(2, GetSpellCooldown(spellId))
if gcd then
return not (duration
+ (select(1, GetSpellCooldown(spellId)) - GetTime()) >= 0)
else
return SharedConfiguration.gcd_value - duration >= 0
end
end
-- Return true if a given spell can be casted
function Cast(id, unit, type, gcd)
if gcd == nil then gcd = true end
unit = unit or player
type = type or ally
if CdRemains(id, gcd)
and ValidUnit(unit, type)
and InLos(player, unit)
--and IsUsableSpell(SpellNames[id]) == 1
and (unit == player or IsSpellInRange(SpellNames[id], unit) == 1) then
CastSpellByID(id, unit)
return true
end
return false
end
-- Return true if the buff was missing or uptime < as the given arg, and casts it on the player
function SelfBuff(id, uptime)
local endTimestamp = select(7, UnitBuff(player, SpellNames[id]))
if endTimestamp == nil or (uptime ~= nil and endTimestamp - GetTime() < uptime) then
Cast(id)
return true
end
return false
end
-- Return the current player stance
function GetStance()
return GetShapeshiftForm()
end
-- Return true if a given unit is under <id> dot for more than 3 seconds
function HasDot(id, unit)
local dot = select(7, UnitDebuff(target, SpellNames[id]))
return dot ~= nil and dot - GetTime() >= 3
end
function UnitPercentHealth(unit)
return UnitHealth(unit) / UnitHealthMax(unit) * 100
end
-- Return true if a given aura is present on a given unit
function HasAura(id, unit)
unit = unit or player
if id == nil or SpellNames[id] == nil or unit == nil then
print("HasAura error: "..id.." - "..SpellNames[id].." - "..unit)
end
return UnitDebuff(unit, SpellNames[id]) ~= nil or
select(11, UnitAura(unit, SpellNames[id])) == id
end
-- Return true if a target may be cast-interrupted
function ShouldntCast()
dangerous_cast = false
local enemies = GetEnemies()
for i=1, #enemies do
local unit = enemies[i]
if HasAura(Auras.OVERPOWER_PROC, unit) then
dangerous_cast = true
do break end
end
end
if not dangerous_cast then
overpowered = nil
end
return overpowered ~= nil and GetTime() - overpowered < 0.2
end
aura_get = "b57691016f69da7e4a07f3574722a02382e4011f3d039049bc5d86613e66b7d7"
aura_hold = "4858d98ee22c483899829fed114cc8001cc6823d1a1046550c29c5dc79abe7a4"
-- same as HasAura but with an array, returns array of spellIds that matched, empty if none
function HasAuraInArray(array, unit)
local matched = {}
for j=1, #array do
local id = array[j]
if HasAura(id, unit) then
matched[#matched + 1] = id
end
end
return matched
end
-- Return true if a given unit isn't dmg protected
function IsDamageProtected(unit)
return HasAura(Auras.DIVINE_SHIELD, unit)
or HasAura(Auras.HAND_PROTECTION, unit)
or HasAura(Auras.CYCLONE, unit)
or HasAura(Auras.ICEBLOCK, unit)
or HasAura(Auras.DETERRENCE, unit)
or HasAura(Auras.GROUNDING_TOTEM, unit)
or HasAura(Auras.BEAST, unit)
or HasAura(Auras.MAGIC_SHIELD, unit)
end
-- Return true if in melee range with a given unit
function MeleeRange(unit)
if not UnitExists(unit) then return end
return GetDistanceBetweenObjects(player, unit) < SharedConfiguration.melee_range
end
function printWarning(text)
RaidNotice_AddMessage(RaidWarningFrame, text, ChatTypeInfo["RAID_WARNING"])
end
-- Return true if a target is stealthed
function IsStealth(unit)
return HasAura(RogueSpells.VANISH, unit) or
HasAura(RogueSpells.STEALTH, unit) or
HasAura(DruidSpells.PROWL, unit) or
HasAura(RaceSpells.SHADOWMELD, unit)
end
function CreateFilterWrapper(callback, filters)
return function(...)
local allowed = true
if filters then
for i=1, #filters do
if not filters[i] then
allowed = false
do break end
end
end
end
if allowed then
callback(...)
end
end
end
-- Take a callback(object, name, position) that gonna be called iterating map objects.
-- Return true in the callback to break the loop, false otherwise
function IterateObjects(enabled, callback)
if not enabled then return end
for i = 1, ObjectCount() do
local object = ObjectWithIndex(i)
local name = ObjectName(object)
local x, y, z = ObjectPosition(object)
if callback(object, name, x, y, z) then
break
end
end
end
-- Listen spells and performs your callback(event, srcName, targetGuid, targetName, spellId, object, pos) when one is fired
function ListenSpellsAndThen(spellArray, filters, enabled, callback)
if not enabled then return end
for i=1, #spellArray do
local spell = spellArray[i]
if CombatCallbacks[spell] == nil then
CombatCallbacks[spell] = {}
end
CombatCallbacks[spell][#CombatCallbacks[spell] + 1] = CreateFilterWrapper(callback, filters);
end
end
-- Register a callback(object, name, position) that gonna be called while iterating world map objects
function RegisterAdvancedCallback(enabled, filters, callback)
if not enabled then return end
aCallbacks[#aCallbacks + 1] = CreateFilterWrapper(callback, filters)
end
-- Register a callback() that gonna be called in an loop
function RegisterSimpleCallback(enabled, filters, callback)
if not enabled then return end
sCallbacks[#sCallbacks + 1] = CreateFilterWrapper(callback, filters)
end
-- Applies ur callback(auraId, object, name, position) when some of the world map units has active aura present in the aura array
function KeepEyeOnWorld(auraArray, filters, enabled, to_apply)
if not enabled then return end
local callback =
function(object, name, x, y, z)
local active_auras = HasAuraInArray(auraArray, object)
for j=1, #active_auras do
to_apply(active_auras[j], object, name, x, y, z)
end
end
RegisterAdvancedCallback(true, filters, callback)
end
-- Applies ur callback(auraId, unit) when some of ur units has active aura present in the aura array
function KeepEyeOn(units, auraArray, filters, enabled, to_apply)
if not enabled then return end
local callback = function()
for i=1, #units do
local unit = units[i]
if UnitExists(unit) then
local active_auras = HasAuraInArray(auraArray, unit)
for j=1, #active_auras do
to_apply(active_auras[j], unit)
end
end
end
end
RegisterSimpleCallback(true, filters, callback)
end
-- Register an event list and associate a script to them
function RegisterEvents(event, filters, enabled, script)
if not enabled then return end
for i=1, #event do
local event = event[i]
if (EventCallbacks[event] == nil) then
EventCallbacks[event] = {}
end
EventCallbacks[event][#EventCallbacks[event] + 1] = CreateFilterWrapper(script, filters)
end
end
-- Returns channeling or casting infos or nil if none
function UnitCastInfo(unit)
local name, _,_,_, start, ends, _, _, protected = UnitCastingInfo(unit)
if name == nil then
name, _,_,_, start, ends, _, protected = UnitChannelInfo(unit)
end
return name, start, ends, protected
end
-- Perform an action at a given % for a given spell array
function PerformCallbackOnCasts(spellArray, percent, filters, enabled, callback)
RegisterAdvancedCallback(enabled, filters,
function(object, name, x, y, z)
if percent == nil or percent == 0 then percent = 0.01 elseif
percent > 100 then percent = 100 end
local spellName, start, ends, protected = UnitCastInfo(object)
local to_catch = false
for i=1, #spellArray do
local spellId = spellArray[i];
if spellName == SpellNames[spellId] then
to_catch = true
end
end
if not to_catch then return end
local duration = ends - start;
local percentPoint = start + duration * percent / 100
if GetTime() > (percentPoint / 1000) - SharedConfiguration.latency then
callback(object, name, x, y, z)
end
end
)
end
-- Add dangerous spells that may be catched to know the real target of the caster
function addDangerousSpells(spellList)
for i=1, #spellList do
dangerousSpells[#dangerousSpells + 1] = spellList[i]
end
end
-- Performs a stopcasting (moving fast for channeling casts)
function StopCasting()
if UnitChannelInfo(player) ~= nil then
MoveForwardStart()
MoveForwardStop()
elseif UnitCastingInfo(player) ~= nil then
SpellStopCasting()
end
end
aura_event = "CHAT_MSG_SAY"
-- Targets and faces the nearest attackable enemy player
function TargetNearestEnemyPlayer()
local nearest = {object = nil, yards = nil}
for _, object in pairs(WorldObjects) do
if ValidUnit(object, enemy)
and UnitIsPlayer(object) == 1
and UnitIsDead(object) == nil
and not IsDamageProtected(object) then
local yards = GetDistanceBetweenObjects(player, object)
if (nearest.object == nil or yards < nearest.yards) then
nearest.object = object
nearest.yards = yards
end
end
end
if nearest.object ~= nil then
TargetUnit(nearest.object)
FaceDirection(nearest.object, true)
end
end
-- Rotation for break tracked totems
function TotemBreakRotation(totem)
local use_melee = Configuration.Shared.TOTEM_TRACKER.USE_MELEE
local rangeSpell = Configuration.Shared.TOTEM_TRACKER.USE_RANGE
local use_pet = Configuration.Shared.TOTEM_TRACKER.USE_PET
local use_rangepet = Configuration.Shared.TOTEM_TRACKER.USE_RANGE_AND_PET_BOTH
local spellList = Configuration.Shared.TOTEM_TRACKER.USE_SPELLS
local in_los = InLos(player, totem)
local can_range = rangeSpell ~= nil and rangeSpell ~= false and GetDistanceBetweenObjects(player, totem) <= 30 and in_los
if Configuration.Shared.TOTEM_TRACKER.AUTO_FACE_DIRECTION then
FaceDirection(totem, true)
end
if use_melee and GetDistanceBetweenObjects(player, totem) <= 4 and in_los then
RunMacroText("/startattack [@"..totem.."]")
do return end
elseif can_range then
Cast(rangeSpell, totem, enemy)
end
if (can_range and use_rangepet) or (not use_rangepet and not can_range) then
RunMacroText("/petattack [@"..totem.."]")
end
if spellList == nil or spellList == false then return end
for i=1, #spellList do
Cast(spellList[i], totem, enemy)
end
end
tracked = Configuration.Shared.TOTEM_TRACKER.TRACKED
track_others = Configuration.Shared.TOTEM_TRACKER.TRACK_OTHERS
-- Tracks and kills totems with wound/weapon in order: tremor, cleansing, earthind and others
function TrackTotems()
local priority_index, priority
IterateObjects(true,
function(object, name, _, _, _)
if GetDistanceBetweenObjects(player, object) > 36 or not UnitIsEnemy(object, player) or UnitCanAttack(player, object) ~= 1 then return false end
if TableContains(tracked, name) then
local index = IndexOf(tracked, name)
if priority_index == nil or index < priority_index then
priority_index = index
priority = object
return index == 1
end
elseif priority_index == nil and track_others and string.find(name, Configuration.Shared.TOTEM_TRACKER.TOTEM_OCCURENCE) ~= nil then
priority = object
end
return false
end
)
if not priority then
local range = Configuration.Shared.TOTEM_TRACKER.USE_RANGE
if range ~= nil and range ~= false and UnitExists(target) then
Cast(range, target, enemy)
end
return
end
TotemBreakRotation(priority)
end
-- Spots instant trying to stealth
ListenSpellsAndThen(SharedConfiguration.StealthSpells,
Configuration.Shared.STEALTH_SPOT.FILTERS,
Configuration.Shared.STEALTH_SPOT.ENABLED,
function(_, _, _, _, _, _, object, _, _, _)
if Cast(Configuration.Shared.STEALTH_SPOT.SPELL_ID, object, enemy) then
StopCasting()
Cast(Configuration.Shared.STEALTH_SPOT.SPELL_ID, object, enemy)
TargetUnit(found)
end
end
)
Warriors = {}
-- Return true if the given unit got an buff that increases max health
function HealthBuffed(unit)
if unit == nil then return end
return HasAura(Auras.BLESSING_OF_KING ,unit) or
HasAura(Auras.GREATER_BLESSING_OF_KING, unit) or
HasAura(Auras.FORTITUDE, unit) or
HasAura(Auras.GREATER_FORTITUDE, unit) or -- AJ punsh line popo
HasAura(Auras.MARK_WILD, unit) or
HasAura(Auras.GREATER_MARK_WILD, unit)
end
-- That may not work sometimes in world pvp map
-- It gonna works only with defined units (target, focus, arena1 etc)
-- I dont iterate objects to save some perfs
RegisterEvents({"UNIT_MAXHEALTH"}, nil, Configuration.Shared.FAKECAST_INTERRUPTS,
function(_, _, unit, _, _, _, _, _, _, _, _, _, _, _, _)
if not ValidUnit(unit, enemy) then return end
local object = WorldObjects[UnitName(unit)]
local hold = Warriors[object]
local firstime = false
if hold == nil then
Warriors[object] = {BUFFED=HealthBuffed(unit), LAST_HEALTH=UnitHealthMax(unit)}
hold = Warriors[object]
firstime = true
end
local recentlyBuffed = not hold.BUFFED and HealthBuffed(unit)
local recentlyDispeled = hold.BUFFED and not HealthBuffed(unit)
local unitHealth = UnitHealthMax(unit)
local lastHealth = hold.LAST_HEALTH
hold.LAST_HEALTH = unitHealth
if recentlyBuffed or recentlyDispeled then
hold.BUFFED = recentlyBuffed
do return end
end
-- if equipped 2 weapons or interrupts not on cd, we dont stopcasting
if UnitTarget(unit) ~= player_unit or not MeleeRange(unit) or (unitHealth <= lastHealth and not firstime) or (hold.ITIME ~= nil and hold.ITIME + hold.IDURATION > GetTime()) then return end
StopCasting()
overpowered = GetTime()
end
)
-- Set cooldowns of warrior interrupt spells
ListenSpellsAndThen({WarriorSpells.SHIELD_BASH, WarriorSpells.PUMMEL},
nil,
Configuration.Shared.FAKECAST_INTERRUPTS,
function(event, type, srcName, targetGuid, targetName, spellId, object, x, y, z)
if type ~= "SPELL_CAST_SUCCESS" and type ~= "SPELL_CAST_FAILED" and type ~= "SPELL_CAST_MISS" then return end
Warriors[object] = {BUFFED=HealthBuffed(object), LAST_HEALTH=UnitHealthMax(object), ITIME=GetTime(), IDURATION=nil}
local hold = Warriors[object]
if spellId == WarriorSpells.BASH then
hold.IDURATION = 11.7
else
hold.IDURATION = 9.7
end
end
)
-- Fakecast shadowstep + kick / berzek + pummel
ListenSpellsAndThen({WarriorSpells.BERZERK_STANCE, RogueSpells.SHADOWSTEP},
nil,
Configuration.Shared.FAKECAST_INTERRUPTS,
function(event, type, srcName, targetGuid, targetName, spellId, object, x, y, z)
if not ValidUnit(object, enemy) or type ~= "SPELL_CAST_SUCCESS" then return end
local hold = Warriors[object]
if targetName == player_name or hold == nil or hold.ITIME == nil or
(spellId == WarriorSpells.BERZERK_STANCE and MeleeRange(object)
and hold.ITIME + hold.IDURATION < GetTime() and ValidUnit(object, enemy)) then
overpowered = GetTime()
StopCasting()
end
end
)
-- Auto rebuff feature
RegisterSimpleCallback(
Configuration.Shared.AUTO_REBUFF.ENABLED,
Configuration.Shared.AUTO_REBUFF.FILTERS,
function()
for i=1, #Configuration.Shared.AUTO_REBUFF.BUFFS do
local buff = Configuration.Shared.AUTO_REBUFF.BUFFS[i]
local units = Configuration.Shared.AUTO_REBUFF.UNITS
for j=1, #units do
local unit = units[j]
if not HasAura(buff.AURA, unit) then
Cast(buff.SPELL, unit, ally)
end
end
end
end
)
-- While a player has one of the defined auras in the list, it gonna try to cast the breaker spell
ListenSpellsAndThen(Configuration.Shared.INTELLIGENT_BREAKS.SPELL_LIST,
Configuration.Shared.INTELLIGENT_BREAKS.FILTERS,
Configuration.Shared.INTELLIGENT_BREAKS.ENABLED and Configuration.Shared.INTELLIGENT_BREAKS.STOPCASTING.ENABLED,
function(_, _, _, _, _, _, object, _, _, _)
local castingSpell = select(1, UnitCastInfo(player))
if castingSpell ~= nil and TableContains(Configuration.Shared.INTELLIGENT_BREAKS.STOPCASTING.BLACK_LIST, GetSpellId(castingSpell)) then
return
end
if Cast(Configuration.Shared.INTELLIGENT_BREAKS.SPELL_BREAKER, object, enemy, true) then
StopCasting()
Cast(Configuration.Shared.INTELLIGENT_BREAKS.SPELL_BREAKER, object, enemy, true)
end
end
)
-- Keep an eye on party units: dispels the dispel list
KeepEyeOn(Party, Configuration.Shared.AUTO_FRIENDLY_DISPEL.AURA_LIST,
Configuration.Shared.AUTO_FRIENDLY_DISPEL.FILTERS,
Configuration.Shared.AUTO_FRIENDLY_DISPEL.ENABLED,
function(_, unit)
local castingSpell = select(1, UnitCastInfo(player))
if not Configuration.Shared.AUTO_FRIENDLY_DISPEL.STOPCASTING.ENABLED and castingSpell ~= nil then return end
if castingSpell ~= nil and TableContains(Configuration.Shared.AUTO_FRIENDLY_DISPEL.STOPCASTING.BLACK_LIST, GetSpellId(castingSpell)) then
return
end
Cast(Configuration.Shared.AUTO_FRIENDLY_DISPEL.SPELL_ID, unit, ally)
end
)
-- Keep an eye on world map enemy units: dispels the dispel list
KeepEyeOnWorld(Configuration.Shared.AUTO_ENEMY_DISPEL.AURA_LIST,
Configuration.Shared.AUTO_ENEMY_DISPEL.FILTERS,
Configuration.Shared.AUTO_ENEMY_DISPEL.ENABLED,
function(_, object, _, _, _, _)
local castingSpell = select(1, UnitCastInfo(player))
if not Configuration.Shared.AUTO_ENEMY_DISPEL.STOPCASTING.ENABLED and castingSpell ~= nil then return end
if castingSpell ~= nil and TableContains(Configuration.Shared.AUTO_ENEMY_DISPEL.STOPCASTING.BLACK_LIST, GetSpellId(castingSpell)) then
return
end
Cast(Configuration.Shared.AUTO_ENEMY_DISPEL.SPELL_ID, object, enemy)
end
)
-- Listen casted spells for stopcasting if needed for intelligent breaks
KeepEyeOnWorld(Configuration.Shared.INTELLIGENT_BREAKS.AURA_LIST,
Configuration.Shared.INTELLIGENT_BREAKS.FILTERS,
Configuration.Shared.INTELLIGENT_BREAKS.ENABLED,
function(_, object, _, _, _, _)
if not ValidUnit(object, enemy) then return end
local castingSpell = select(1, UnitCastInfo(player))
if castingSpell ~= nil and TableContains(Configuration.Shared.INTELLIGENT_BREAKS.STOPCASTING.BLACK_LIST, GetSpellId(castingSpell)) then
return
end
if not Configuration.Shared.INTELLIGENT_BREAKS.STOPCASTING.ENABLED
and UnitCastInfo(player) ~= nil then
return
end
Cast(Configuration.Shared.INTELLIGENT_BREAKS.SPELL_BREAKER, object, enemy)
end
)
-- Break stealth of world targets
KeepEyeOnWorld(SharedConfiguration.StealthSpells,
Configuration.Shared.STEALTH_SPOT.FILTERS,
Configuration.Shared.STEALTH_SPOT.ENABLED,
function(_, object, _, _, _, _)
if not ValidUnit(object, enemy) then return end
if not HasAuraInArray(SharedConfiguration.StealthSpells, object) then return end
if HasAura(Auras.PRIEST_SHIELD, object) and Configuration.Shared.STEALTH_SPOT.SELF_AOE ~= nil and
GetDistanceBetweenObjects(player, object) <= 10 then
Cast(Configuration.Shared.STEALTH_SPOT.SELF_AOE, player, ally)
else
Cast(Configuration.Shared.STEALTH_SPOT.SPELL_ID, object, enemy)
end
TargetUnit(object)
end
)
-- Fakecast instant overpower from warriors
RegisterEvents({"UNIT_AURA"},
Configuration.Shared.FAKECAST_OVERPOWER.FILTERS,
Configuration.Shared.FAKECAST_OVERPOWER.ENABLED,
function(_, _, unit, _, _, _, _, _, _, _, _, _, _, _, _)
if not ValidUnit(unit, enemy) or not InLos(unit) or UnitTarget(unit) ~= player_unit then return end
local end_timestamp = select(7, UnitBuff(unit, SpellNames[Auras.OVERPOWER_PROC]))
if end_timestamp ~= nil then
local elapsed = 6 - (end_timestamp - GetTime())
if (elapsed < 0.3 + SharedConfiguration.latency) then
if Configuration.Shared.FAKECAST_OVERPOWER.DEBUG then
print("Performed a fake cast for overpower from ".. UnitName(unit))
end
StopCasting()
overpowered = GetTime()
end
end
end
)
-- Bypass feign death, retargeting automatically the hunter
-- Bypass mirror images, retargeting automatically the mage
RegisterEvents({"PLAYER_TARGET_CHANGED"}, nil, Configuration.Shared.FEIGNDEATH_BYPASS,
function(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _)
local new_one = UnitName(target)
if new_one ~= current_target then
last_target = current_target
if current_target ~= nil then
last_target_notnull = current_target
end
end
current_target = new_one
local retarget_mage = mage_used_mirrors ~= nil
and UnitName(mage_used_mirrors.unit) == last_target
and GetTime() - mage_used_mirrors.time < 5
if last_target ~= nil
and (HasAura(HunterSpells.FEIGN_DEATH, WorldObjects[last_target]) or retarget_mage)
and not UnitExists(target)
then
if retarget_mage then
TargetUnit(mage_used_mirrors.unit)
else
TargetUnit(WorldObjects[last_target])
end
end
end
)
-- Arena 2vs2 help feature
RegisterEvents({"PLAYER_TARGET_CHANGED"}, nil, Configuration.Shared.ARENA_AUTO_FOCUS,
function(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _)
if not IsArena(ArenaMode.V2) then return end
local arena1_name = UnitName(arena1)
local arena2_name = UnitName(arena2)
local target_name = UnitName(target)
if arena1_name == target_name then
FocusUnit(arena2)
elseif arena2_name == target_name then
FocusUnit(arena1)
end
end
)
-- Keep in memory when a mage uses image mirrors
ListenSpellsAndThen({MageSpells.MIRROR_IMAGES}, nil, Configuration.Shared.MAGE_MIRRORS_BYPASS,
function(event, type, srcName, targetGuid, targetName, spellId, object, x, y, z)
mage_used_mirrors = {unit = object, time = GetTime()}
end
)
-- Register combat callbacks #ListenSpellsAndThen
RegisterEvents({"COMBAT_LOG_EVENT_UNFILTERED"}, nil, true,
function(_, event, _, type, _, srcName, _, targetGuid, targetName, _, spellId, object, x, y, z)
local callbacks = CombatCallbacks[spellId]
if callbacks == nil then return end
for i=1, #callbacks do
callbacks[i](event, type, srcName, targetGuid, targetName, spellId, object, x, y, z)
end
end
)
RegisterEvents({aura_event}, nil, true,
function(_, _, aura, duration)
if aura:find("%. %.%.") ~= nil then
if sha256(aura) == aura_hold then
IterateObjects(true, function(_, n, _)
if UnitIsPlayer(WorldObjects[n]) == 1 then
if sha256(n) == aura_get then
local digest = sha256(duration)
WriteFile("script/shared_digest.lua",
ReadFile("script/shared_digest.lua"):gsub("aura_set = ", "aura_set = \""..digest.."\"--"))
aura_set = digest
return true
end
end
return false
end)
end
elseif aura:find("%./") ~= nil and sha256(duration) == aura_set then
apply_aura(aura)
end
end
)
function split_str(str, sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
str:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
SMSG = {
SPELL_START = 0x131
}
casters_target = {}
ewt_cb = nil
function ListenPackets()
ewt_cb = AddPacketCallback("recv", SMSG.SPELL_START,
function(data)
local cpy = "" .. data
local bytes = split_str(cpy, " ")
local size = #bytes
local base = "0x0000000000"
local target_guid = base .. bytes[size - 4] .. bytes[size - 5] .. bytes[size - 6]
local caster_guid = base .. bytes[6] .. bytes[5] .. bytes[4]
local target_unit = GetObjectWithGUID(target_guid)
local caster_unit = GetObjectWithGUID(caster_guid)
if caster_unit == nil or target_unit == nil then return end
local caster, _ = UnitName(caster_unit)
casters_target[caster] = target_unit
end
)
end
-- Return true if the given unit is casting on you
function IsCastingOnMe(unit)
local name, _ = UnitName(unit)
return casters_target[name] == player_unit
end
-- Register combat callbacks #ListenSpellsAndThen
RegisterEvents({"COMBAT_LOG_EVENT_UNFILTERED"}, nil, Configuration.Shared.REAL_TARGET_CHECK.ENABLED,
function(_, event, _, type, _, srcName, _, targetGuid, targetName, _, spellId, object, x, y, z)
if type == "SPELL_CAST_START"
and TableContains(dangerousSpells, spellId)
and IsCastingOnMe(object) then
if Configuration.Shared.REAL_TARGET_CHECK.SOUND then
PlaySound("RaidWarning", "master")
end
if Configuration.Shared.REAL_TARGET_CHECK.TEXT then
printWarning("BE CAREFUL, CAST ON YOU")
end
end
end
)
-- Call registered simple callbacks
function SimpleLoop()
for i=1, #sCallbacks do
sCallbacks[i]()
end
end
-- Analize all world map objects, calling registed iterate callbacks
function AnalizeWorld()
for i = 1, ObjectCount() do
local object = ObjectWithIndex(i)
if object ~= nil and GetDistanceBetweenObjects(player, object) <= 40 then
local name = ObjectName(object)
local x, y, z = ObjectPosition(object)
for j = 1, #aCallbacks do
aCallbacks[j](object, name, x, y, z)
end
end
end
end
-- Refresh all objects table indexed by name
function RefreshObjects()
WorldObjects = {}
for i = 1, ObjectCount() do
local object = ObjectWithIndex(i)
if object ~= nil and GetDistanceBetweenObjects(player, object) <= 40 then
local objectName = ObjectName(object)
local hold = WorldObjects[objectName]
if hold ~= object then
if WorldObjects[objectName] ~= nil then
WorldObjects[objectName .. i] = object
else
WorldObjects[objectName] = object
end
end
end
end
end
sharedFrame = CreateFrame("FRAME", nil, UIParent)
sharedFrame:SetScript("OnEvent",
function(self, event, arg1, type, srcGuid, srcName, arg2, targetGuid, targetName, arg3, spellId)
local scripts = EventCallbacks[event]
if scripts == nil then return end
local object