-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAlpha.lua
More file actions
6135 lines (5690 loc) · 162 KB
/
Alpha.lua
File metadata and controls
6135 lines (5690 loc) · 162 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
if _G.Alpha then return end
_G.Alpha =
{
Menu = nil,
Geometry = nil,
ObjectManager = nil,
DamageManager = nil,
ItemManager = nil,
BuffManager = nil,
}
local LocalOSClock = os.clock;
local LocalVector = Vector;
local LocalCallbackAdd = Callback.Add;
local LocalCallbackDel = Callback.Del;
local LocalGameTimer = Game.Timer;
local LocalGameHeroCount = Game.HeroCount;
local LocalGameHero = Game.Hero;
local LocalGameMinionCount = Game.MinionCount;
local LocalGameMinion = Game.Minion;
local LocalGameParticleCount = Game.ParticleCount;
local LocalGameParticle = Game.Particle;
local LocalGameMissileCount = Game.MissileCount;
local LocalGameMissile = Game.Missile;
local LocalGameTurretCount = Game.TurretCount;
local LocalGameTurret = Game.Turret;
local LocalPairs = pairs;
local LocalType = type;
local LocalStringFind = string.find
local LocalInsert = table.insert
local LocalSort = table.sort
local LocalSqrt = math.sqrt
local LocalAtan2 = math.atan2
local LocalAbs = math.abs
local LocalHuge = math.huge
local LocalPi = math.pi
local LocalMax = math.max
local LocalMin = math.min
local LocalFloor = math.floor
local LocalRandom = math.random
local LocalCos = math.cos
local LocalSin = math.sin
local DAMAGE_TYPE_TRUE = 0
local DAMAGE_TYPE_PHYSICAL = 1
local DAMAGE_TYPE_MAGICAL = 2
local BUFF_STUN = 5
local BUFF_SILENCE = 7
local BUFF_TAUNT = 8
local BUFF_SLOW = 10
local BUFF_ROOT = 11
local BUFF_FEAR = 21
local BUFF_CHARM = 22
local BUFF_POISON = 23
local BUFF_SURPRESS = 24
local BUFF_BLIND = 25
local BUFF_KNOCKUP = 29
local BUFF_KNOCKBACK = 30
local BUFF_DISARM = 31
local TARGET_TYPE_SINGLE = 0
local TARGET_TYPE_LINE = 1
local TARGET_TYPE_CIRCLE = 2
local TARGET_TYPE_ARC = 3
local TARGET_TYPE_BOX = 4
local TARGET_TYPE_RING = 5
local Geometry = nil
local ObjectManager = nil
local DamageManager = nil
local ItemManager = nil
local BuffManager = nil
class "__Geometry"
function __Geometry:VectorPointProjectionOnLineSegment(v1, v2, v)
assert(v1 and v2 and v, "VectorPointProjectionOnLineSegment: wrong argument types (3 <Vector> expected)")
local cx, cy, ax, ay, bx, by = v.x, (v.z or v.y), v1.x, (v1.z or v1.y), v2.x, (v2.z or v2.y)
local rL = ((cx - ax) * (bx - ax) + (cy - ay) * (by - ay)) / ((bx - ax) * (bx - ax) + (by - ay) * (by - ay))
local pointLine = { x = ax + rL * (bx - ax), y = ay + rL * (by - ay) }
local rS = rL < 0 and 0 or (rL > 1 and 1 or rL)
local isOnSegment = rS == rL
local pointSegment = isOnSegment and pointLine or { x = ax + rS * (bx - ax), y = ay + rS * (by - ay) }
return pointSegment, pointLine, isOnSegment
end
function __Geometry:RotateAroundPoint(v1,v2, angle)
local c, s = LocalCos(angle), LocalSin(angle)
local x = ((v1.x - v2.x) * c) - ((v1.z - v2.z) * s) + v2.x
local z = ((v1.z - v2.z) * c) + ((v1.x - v2.x) * s) + v2.z
return Vector(x, v1.y, z or 0)
end
function __Geometry:GetDistanceSqr(p1, p2)
if not p1 or not p2 then
local dInfo = debug.getinfo(2)
print("Undefined GetDistanceSqr target. Please report. Method: " .. dInfo.name .. " Line: " .. dInfo.linedefined)
return LocalHuge
end
return (p1.x - p2.x) * (p1.x - p2.x) + ((p1.z or p1.y) - (p2.z or p2.y)) * ((p1.z or p1.y) - (p2.z or p2.y))
end
function __Geometry:GetDistance(p1, p2)
if not p1 or not p2 then
local dInfo = debug.getinfo(2)
print("Undefined GetDistance target. Please report. Method: " .. dInfo.name .. " Line: " .. dInfo.linedefined)
return LocalHuge
end
return LocalSqrt(self:GetDistanceSqr(p1, p2))
end
function __Geometry:IsPointInArc(source, origin, target, angle, range)
local deltaAngle = LocalAbs(self:Angle(origin, target) - self:Angle(source, origin))
if deltaAngle < angle and self:IsInRange(origin,target,range) then
return true
end
return false
end
function __Geometry:Angle(A, B)
local deltaPos = A - B
local angle = LocalAtan2(deltaPos.x, deltaPos.z) * 180 / LocalPi
if angle < 0 then angle = angle + 360 end
return angle
end
function __Geometry:IsInRange(p1, p2, range)
if not p1 or not p2 or not p1.x or not p2.x then
local dInfo = debug.getinfo(2)
print("Undefined IsInRange target. Please report. Method: " .. dInfo.name .. " Line: " .. dInfo.linedefined)
return false
end
return (p1.x - p2.x) * (p1.x - p2.x) + ((p1.z or p1.y) - (p2.z or p2.y)) * ((p1.z or p1.y) - (p2.z or p2.y)) < range * range
end
function __Geometry:GetLineTargetCount(source, aimPos, delay, speed, width, targetAllies)
local targetCount = 0
for i = 1, LocalGameHeroCount() do
local t = LocalGameHero(i)
if t and t.pos and t.alive and t.health > 0 and t.visible and t.isTargetable and ( targetAllies or t.isEnemy) then
local predictedPos = self:PredictUnitPosition(t, delay+ self:GetDistance(source, t.pos) / speed)
local proj1, pointLine, isOnSegment = self:VectorPointProjectionOnLineSegment(source, aimPos, predictedPos)
if proj1 and isOnSegment and self:IsInRange(predictedPos, proj1, t.boundingRadius + width) then
targetCount = targetCount + 1
end
end
end
return targetCount
end
function __Geometry:GetLineMinionTargetCount(source, aimPos, delay, speed, width)
local targetCount = 0
for i = 1, LocalGameMinionCount() do
local t = LocalGameMinion(i)
if t and t.pos and t.alive and t.health > 0 and t.visible and t.isTargetable then
local predictedPos = self:PredictUnitPosition(t, delay+ self:GetDistance(source, t.pos) / speed)
local proj1, pointLine, isOnSegment = self:VectorPointProjectionOnLineSegment(source, aimPos, predictedPos)
if proj1 and isOnSegment and self:IsInRange(predictedPos, proj1, t.boundingRadius + width) then
targetCount = targetCount + 1
end
end
end
return targetCount
end
function __Geometry:GetLineFarmCastPosition(source, range, delay, speed, width)
local castOffset = (mousePos - myHero.pos):Normalized()
local targetCount = 0
local aimPosition = source
--Check 20 possible angles for best target count
for i = 0, 360, 18 do
local castDir = castOffset:Rotated(0,i,0)
local castTargets = self:GetLineMinionTargetCount(source, source + castDir*range, delay, speed, width)
if castTargets > targetCount then
aimPosition = myHero.pos + castDir * 500
targetCount = castTargets
end
end
return targetCount, aimPosition
end
function __Geometry:GetArcFarmCastPosition(range, delay, speed, width)
local castOffset = (mousePos - myHero.pos):Normalized()
local targetCount = 0
local castPosition = myHero.pos
--Check 20 possible angles for best target count
for i = 0, 360, 18 do
local castDir = castOffset:Rotated(0,i,0)
local castPos = myHero.pos + castDir * range
local castAngle = LocalGeometry:Angle(myHero.pos, castPos)
local hitCount = 0
for i = 1, LocalGameMinionCount() do
local t = LocalGameMinion(i)
if t and t.pos and t.alive and t.health > 0 and t.visible and t.isTargetable then
local predictedPosition = self:PredictUnitPosition(t, delay+ self:GetDistance(myHero.pos, t.pos) / speed)
if self:IsInRange(myHero.pos, predictedPosition, range) then
local deltaAngle = math.abs(self:Angle(myHero.pos, predictedPosition) - castAngle)
if deltaAngle <= 15 then
hitCount = hitCount + 1
end
end
end
end
if hitCount > targetCount then
targetCount = hitCount
castPosition = castPos
end
end
return targetCount, castPosition
end
function __Geometry:GetCastPosition(source, target, range, delay, speed, radius, checkCollision, isLine)
local hitChance = 1
if not self:IsInRange(source.pos, target.pos, range) then hitChance = -1 end
local aimPosition = target.pos
if hitChance > 0 then
local reactionTime = self:PredictReactionTime(target, .15)
local interceptTime = self:InterceptTime(source, target, delay, speed)
aimPosition = self:PredictUnitPosition(target, interceptTime)
if not target.pathing or not target.pathing.hasMovePath then
hitChance = 2
end
if isLine then
local pathVector = aimPosition - target.pos
local castVector = (aimPosition - myHero.pos):Normalized()
if pathVector.x + pathVector.z ~= 0 then
pathVector = pathVector:Normalized()
if pathVector:DotProduct(castVector) < -.85 or pathVector:DotProduct(castVector) > .85 then
hitChance = 3
end
end
end
local origin,movementRadius = self:UnitMovementBounds(target, interceptTime, reactionTime)
if movementRadius <= radius then
if target.activeSpell and target.activeSpell.valid and not target.activeSpell.spellWasCast then
adjustedDelay = LocalGameTimer() - target.activeSpell.startTime + target.activeSpell.windup
if adjustedDelay > 0 then
aimPosition = self:PredictUnitPosition(target, interceptTime- adjustedDelay)
end
end
hitChance = 3
end
--Check if the cast time wont let them walk out before the spell lands and isn't an auto attack. If so consider it accuracy 4 for shit sake
if target.pathing.hasMovePath and target.pathing.isDashing and target.pathing.dashSpeed>500 then
hitChance = 4
end
if self:GetImmobileTime(target) >= interceptTime then
hitChance = 5
end
if not self:IsInRange(source.pos, aimPosition, range) then hitChance = -1 end
if checkCollision then
if self:CheckMinionCollision(source.pos, aimPosition, delay, speed, radius) then
hitChance = -1
end
end
end
return aimPosition, hitChance
end
function __Geometry:InterceptTime(source, target, delay, speed)
local relativePosition = target.pos - source.pos
local relativeVelocity = (self:NextPath(source) - source.pos):Normalized() * self:GetTargetMS(source) -(self:NextPath(target) - target.pos):Normalized() * self:GetTargetMS(target)
if relativeVelocity.x ~= relativeVelocity.x then
relativeVelocity = LocalVector(0,0,0)
end
local velocitySquared = self:GetSqrMagnitude(relativeVelocity)
local a = velocitySquared - speed * speed
if LocalAbs(a) < .001 then
local t = - self:GetSqrMagnitude(relativePosition) / (2*relativeVelocity:DotProduct(relativePosition))
return delay + LocalMax(t, 0)
end
local b = 2*relativeVelocity:DotProduct(relativePosition)
local c = self:GetSqrMagnitude(relativePosition)
local d = b * b - 4*a*c
if d > 0 then
local t1 = (-b + LocalSqrt(d)) / (2*a)
local t2 = (-b - LocalSqrt(d)) / (2*a)
if t1 > 0 then
if t2 > 0 then
return delay+ LocalMin(t1, t2)
else
return delay+ t1
end
else
return delay + LocalMax(t2, 0)
end
elseif d < 0 then
return delay
else
return delay + LocalMax(-b/2*a, 0)
end
end
function __Geometry:NextPath(unit)
if unit.pathing.hasMovePath then
return unit:GetPath(1)
else
return unit.pos
end
end
function __Geometry:GetSqrMagnitude(vector)
return vector.x * vector.x + vector.y * vector.y + vector.z * vector.z
end
function __Geometry:GetImmobileTime(unit)
local duration = 0
for i = 0, unit.buffCount do
local buff = unit:GetBuff(i)
if buff and buff.count > 0 and buff.duration> duration and (buff.type == BUFF_STUN or buff.type == BUFF_ROOT or buff.type == BUFF_SURPRESS or buff.type == BUFF_KNOCKUP ) then
duration = buff.duration
end
end
return duration
end
function __Geometry:PredictReactionTime(unit, minimumReactionTime)
if not minimumReactionTime then minimumReactionTime = .15 end
local reactionTime = minimumReactionTime
if unit.activeSpell and unit.activeSpell.valid then
local windupRemaining = unit.activeSpell.startTime + unit.activeSpell.windup - Game.Timer()
if windupRemaining > 0 then
reactionTime = windupRemaining
if unit.activeSpell.isAutoAttack then
reactionTime = reactionTime / 3
end
end
end
if unit.pathing.hasMovePath and unit.pathing.isDashing and unit.pathing.dashSpeed>500 then
reactionTime = self:GetDistance(unit.pos, unit:GetPath(1)) / unit.pathing.dashSpeed
end
return reactionTime
end
function __Geometry:UnitMovementBounds(unit, delay, reactionTime)
local startPosition = self:PredictUnitPosition(unit, delay)
local radius = 0
local deltaDelay = delay -reactionTime- self:GetImmobileTime(unit)
if (deltaDelay >0) then
radius = self:GetTargetMS(unit) * deltaDelay
end
return startPosition, radius
end
function __Geometry:GetSpellInterceptTime(startPos, endPos, delay, speed)
local interceptTime = Game.Latency()/2000 + delay + self:GetDistance(startPos, endPos) / speed
return interceptTime
end
function __Geometry:CheckMinionCollision(origin, endPos, delay, speed, radius, frequency)
if not frequency then
frequency = radius
end
local directionVector = (endPos - origin):Normalized()
local checkCount = self:GetDistance(origin, endPos) / frequency
for i = 1, checkCount do
local checkPosition = origin + directionVector * i * frequency
local checkDelay = delay + self:GetDistance(origin, checkPosition) / speed
if self:IsMinionIntersection(checkPosition, radius, checkDelay, radius * 3) then
return true
end
end
return false
end
function __Geometry:IsMinionIntersection(location, radius, delay, maxDistance)
if not maxDistance then
maxDistance = 500
end
for i = 1, LocalGameMinionCount() do
local minion = LocalGameMinion(i)
if minion and self:CanTarget(minion) and self:IsInRange(minion.pos, location, maxDistance) then
local predictedPosition = self:PredictUnitPosition(minion, delay)
if self:IsInRange(location, predictedPosition, radius + minion.boundingRadius) then
return true
end
end
end
return false
end
function __Geometry:CanTarget(target, allowInvisible)
return target.isEnemy and target.alive and target.health > 0 and target.visible and target.isTargetable
end
function __Geometry:CanTarget(target, allowInvisible)
return target.isEnemy and target.alive and target.health > 0 and target.visible and target.isTargetable
end
--Returns where the unit will be when the delay has passed given current pathing information. This assumes the target makes NO CHANGES during the delay.
function __Geometry:PredictUnitPosition(unit, delay)
local predictedPosition = unit.pos
local timeRemaining = delay
local pathNodes = self:GetPathNodes(unit)
for i = 1, #pathNodes -1 do
local nodeDistance = self:GetDistance(pathNodes[i], pathNodes[i +1])
local nodeTraversalTime = nodeDistance / self:GetTargetMS(unit)
if timeRemaining > nodeTraversalTime then
--This node of the path will be completed before the delay has finished. Move on to the next node if one remains
timeRemaining = timeRemaining - nodeTraversalTime
predictedPosition = pathNodes[i + 1]
else
local directionVector = (pathNodes[i+1] - pathNodes[i]):Normalized()
predictedPosition = pathNodes[i] + directionVector * self:GetTargetMS(unit) * timeRemaining
break;
end
end
return predictedPosition
end
--Returns all existing path nodes
function __Geometry:GetPathNodes(unit)
local nodes = {}
nodes[#nodes+1] = unit.pos
if unit.pathing.hasMovePath then
for i = unit.pathing.pathIndex, unit.pathing.pathCount do
path = unit:GetPath(i)
nodes[#nodes+1] = path
end
end
return nodes
end
function __Geometry:GetTargetMS(target)
local ms = target.pathing.isDashing and target.pathing.dashSpeed or target.ms
return ms
end
class "__ObjectManager"
--Initialize the object manager
function __ObjectManager:__init()
LocalCallbackAdd('Tick', function() self:Tick() end)
--LocalCallbackAdd('Draw', function() self:Draw() end)
self.CachedBuffs = {}
self.OnBuffAddedCallbacks = {}
self.OnBuffRemovedCallbacks = {}
self.CachedMissiles = {}
self.OnMissileCreateCallbacks = {}
self.OnMissileDestroyCallbacks = {}
self.CachedParticles = {}
self.OnParticleCreateCallbacks = {}
self.OnParticleDestroyCallbacks = {}
self.OnBlinkCallbacks = {}
self.BlinkParticleLookupTable =
{
"global_ss_flash_02.troy",
"Lissandra_Base_E_Arrival.troy",
"LeBlanc_Base_W_return_activation.troy",
"Zed_Base_CloneSwap",
}
self.CachedSpells = {}
self.OnSpellCastCallbacks = {}
self.NextCacheMissiles = GetTickCount()
self.LastMissileCount = 0
self.NextCacheParticles = GetTickCount()
self.LastParticleCount = 0
self.NextCacheBuffs = GetTickCount()
end
--Register Buff Added Event
function __ObjectManager:OnBuffAdded(cb)
ObjectManager.OnBuffAddedCallbacks[#ObjectManager.OnBuffAddedCallbacks+1] = cb
end
--Trigger Buff Added Event
function __ObjectManager:BuffAdded(target, buff)
for i = 1, #self.OnBuffAddedCallbacks do
self.OnBuffAddedCallbacks[i](target, buff);
end
end
--Register Buff Removed Event
function __ObjectManager:OnBuffRemoved(cb)
ObjectManager.OnBuffRemovedCallbacks[#ObjectManager.OnBuffRemovedCallbacks+1] = cb
end
--Trigger Buff Removed Event
function __ObjectManager:BuffRemoved(target, buff)
for i = 1, #self.OnBuffRemovedCallbacks do
self.OnBuffRemovedCallbacks[i](target, buff);
end
end
--Register Missile Create Event
function __ObjectManager:OnMissileCreate(cb)
ObjectManager.OnMissileCreateCallbacks[#ObjectManager.OnMissileCreateCallbacks+1] = cb
end
--Trigger Missile Create Event
function __ObjectManager:MissileCreated(missile)
for i = 1, #self.OnMissileCreateCallbacks do
self.OnMissileCreateCallbacks[i](missile);
end
end
--Register Missile Destroy Event
function __ObjectManager:OnMissileDestroy(cb)
ObjectManager.OnMissileDestroyCallbacks[#ObjectManager.OnMissileDestroyCallbacks+1] = cb
end
--Trigger Missile Destroyed Event
function __ObjectManager:MissileDestroyed(missile)
for i = 1, #self.OnMissileDestroyCallbacks do
self.OnMissileDestroyCallbacks[i](missile);
end
end
--Register Particle Create Event
function __ObjectManager:OnParticleCreate(cb)
ObjectManager.OnParticleCreateCallbacks[#ObjectManager.OnParticleCreateCallbacks+1] = cb
end
--Trigger Particle Created Event
function __ObjectManager:ParticleCreated(particle)
--print("particle: " .. particle.name)
for i = 1, #self.OnParticleCreateCallbacks do
self.OnParticleCreateCallbacks[i](particle);
end
end
--Register Particle Destroy Event
function __ObjectManager:OnParticleDestroy(cb)
ObjectManager.OnParticleDestroyCallbacks[#ObjectManager.OnParticleDestroyCallbacks+1] = cb
end
--Trigger particle Destroyed Event
function __ObjectManager:ParticleDestroyed(particle)
for i = 1, #self.OnParticleDestroyCallbacks do
self.OnParticleDestroyCallbacks[i](particle);
end
end
--Register On Blink Event
function __ObjectManager:OnBlink(cb)
--If there are no on particle callbacks we need to add one or it might never run!
if #self.OnBlinkCallbacks == 0 then
self:OnParticleCreate(function(particle) self:CheckIfBlinkParticle(particle) end)
end
ObjectManager.OnBlinkCallbacks[#ObjectManager.OnBlinkCallbacks+1] = cb
end
--Trigger Blink Event
function __ObjectManager:Blinked(target)
for i = 1, #self.OnBlinkCallbacks do
self.OnBlinkCallbacks[i](target);
end
end
--Register On Spell Cast Event
function __ObjectManager:OnSpellCast(cb)
ObjectManager.OnSpellCastCallbacks[#ObjectManager.OnSpellCastCallbacks+1] = cb
end
--Trigger Spell Cast Event
function __ObjectManager:SpellCast(data)
for i = 1, #self.OnSpellCastCallbacks do
self.OnSpellCastCallbacks[i](data);
end
end
local particleDuration = 0
local missileDuration= 0
local buffDuration= 0
function __ObjectManager:Draw()
Draw.Text("PARTICLES: " .. particleDuration, 14, 200, 100)
Draw.Text("MISSILES: " .. missileDuration, 14, 200, 125)
Draw.Text("BUFFS: " .. buffDuration, 14, 200, 150)
end
--Search for changes in particle or missiles in game. trigger the appropriate events.
function __ObjectManager:Tick()
--Check if we have any buff added/removed callbacks before querying
if (#self.OnBuffAddedCallbacks > 0 or #self.OnBuffRemovedCallbacks > 0) and GetTickCount() > self.NextCacheBuffs then
local t = LocalOSClock()
self.NextCacheBuffs = GetTickCount() + BUFF_CACHE_DELAY
--KNOWN ISSUE: Certain skills use buffs... but constantly tweak their start/end time: EG Aatrox Q. I have no way to reliably handle this currently.
for _, buff in LocalPairs(self.CachedBuffs) do
if not buff or not buff.valid then
if buff and buff.owner and buff.data then
self:BuffRemoved(buff.owner, buff.data)
end
self.CachedBuffs[_] = nil
else
buff.valid = false
end
end
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and LocalType(target) == "userdata" then
for i = 0, target.buffCount do
local buff = target:GetBuff(i)
if buff.duration >0 and buff.expireTime > LocalGameTimer() and buff.startTime <= LocalGameTimer() then
local key = target.networkID..buff.name
if self.CachedBuffs[key] then
self.CachedBuffs[key].valid = true
else
local buffData = {valid = true, owner = target, data = buff, expireTime = buff.expireTime}
self.CachedBuffs[key] = buffData
self:BuffAdded(target, buff)
end
end
end
end
end
buffDuration = LocalOSClock() - t;
end
if #self.OnSpellCastCallbacks > 0 then
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and LocalType(target) == "userdata" then
if target.activeSpell and target.activeSpell.valid then
if not self.CachedSpells[target.networkID] or self.CachedSpells[target.networkID].name ~= target.activeSpell.name then
local spellData = {owner = target.networkID, isEnemy = target.isEnemy,handle = target.handle, name = target.activeSpell.name, data = target.activeSpell, windupEnd = target.activeSpell.startTime + target.activeSpell.windup}
self.CachedSpells[target.networkID] =spellData
self:SpellCast(spellData)
end
elseif self.CachedSpells[target.networkID] then
self.CachedSpells[target.networkID] = nil
end
end
end
end
--Cache Particles ONLY if a create or destroy event is registered: If not it's a waste of processing
if (#self.OnParticleCreateCallbacks > 0 or #self.OnParticleDestroyCallbacks > 0) and GetTickCount() > self.NextCacheParticles then
local t = LocalOSClock()
self.NextCacheParticles = GetTickCount() + PARTICLE_CACHE_DELAY
for _, particle in LocalPairs(self.CachedParticles) do
if not particle or not particle.valid then
if particle then
self:ParticleDestroyed(particle)
end
self.CachedParticles[_] = nil
else
particle.valid = false
end
end
for i = 1, LocalGameParticleCount() do
local particle = LocalGameParticle(i)
if particle ~= nil and LocalType(particle) == "userdata" then
if self.CachedParticles[particle.networkID] then
self.CachedParticles[particle.networkID].valid = true
else
local particleData = { valid = true, networkID = particle.networkID, pos = particle.pos, name = particle.name, data = particle}
self.CachedParticles[particle.networkID] =particleData
self:ParticleCreated(particleData)
end
end
end
particleDuration = LocalOSClock() - t
end
--Cache Missiles ONLY if a create or destroy event is registered: If not it's a waste of processing
if (#self.OnMissileCreateCallbacks > 0 or #self.OnMissileDestroyCallbacks > 0) and GetTickCount() > self.NextCacheMissiles then
local t = LocalOSClock()
self.NextCacheMissiles = GetTickCount() + MISSILE_CACHE_DELAY
for _, missile in LocalPairs(self.CachedMissiles) do
if not missile or not missile.data or missile.dead or not missile.valid then
if missile and missile.data then
self:MissileDestroyed(missile)
end
self.CachedMissiles[_] = nil
else
missile.valid = false
end
end
for i = 1, LocalGameMissileCount() do
local missile = LocalGameMissile(i)
if missile ~= nil and LocalType(missile) == "userdata" and missile.missileData then
if self.CachedMissiles[missile.networkID] then
self.CachedMissiles[missile.networkID].valid = true
else
--We need a direct reference to the missile so we can query its current position later. If not we'd have to calculate it using speed/start/end data
local missileData =
{
valid = true,
name = missile.name,
forward = Vector(
missile.missileData.endPos.x -missile.missileData.startPos.x,
missile.missileData.endPos.y -missile.missileData.startPos.y,
missile.missileData.endPos.z -missile.missileData.startPos.z):Normalized(),
networkID = missile.networkID,
data = missile,
endTime = LocalGameTimer() + Geometry:GetDistance(missile.missileData.endPos, missile.missileData.startPos) / missile.missileData.speed,
}
if DamageManager.MissileNames[missile.name] and DamageManager.MissileNames[missile.name].MissileTime then
missileData.endTime = LocalGameTimer() + DamageManager.MissileNames[missile.name].MissileTime
end
self.CachedMissiles[missile.networkID] =missileData
self:MissileCreated(missileData)
end
end
end
missileDuration = LocalOSClock() - t
end
end
function __ObjectManager:CheckIfBlinkParticle(particle)
for i = 1, #self.BlinkParticleLookupTable do
if self.BlinkParticleLookupTable[i] == particle.name then
local target = self:GetPlayerByPosition(particle.pos)
if target then
self:Blinked(target)
end
end
end
end
--Lets us find a particle's owner because the particle and the player will have the same position (IE: Flash)
function __ObjectManager:GetPlayerByPosition(position)
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and target.pos and Geometry:IsInRange(position, target.pos,50) then
return target
end
end
end
function __ObjectManager:GetHeroByID(id)
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and target.networkID == id then
return target
end
end
end
function __ObjectManager:GetHeroByHandle(handle)
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and target.handle == handle then
return target
end
end
end
function __ObjectManager:GetObjectByHandle(handle)
for i = 1, LocalGameHeroCount() do
local target = LocalGameHero(i)
if target and target.handle == handle then
return target
end
end
for i = 1, LocalGameMinionCount() do
local target = LocalGameMinion(i)
if target and target.handle == handle then
return target
end
end
for i = 1, LocalGameTurretCount() do
local target = LocalGameTurret(i)
if target and target.handle == handle then
return target
end
end
end
class "__DamageManager"
--Credits LazyXerath for extra dmg reduction methods
function __DamageManager:__init()
self.IMMOBILE_TYPES = {[BUFF_KNOCKUP]="true",[BUFF_SURPRESS]="true",[BUFF_ROOT]="true",[BUFF_STUN]="true", [BUFF_CHARM] = "true"}
self.OnIncomingCCCallbacks = {}
self.SiegeMinionList = {"Red_Minion_MechCannon", "Blue_Minion_MechCannon"}
self.NormalMinionList = {"Red_Minion_Wizard", "Blue_Minion_Wizard", "Red_Minion_Basic", "Blue_Minion_Basic"}
self.DamageReductionTable =
{
["Braum"] = {buff = "BraumShieldRaise", amount = function(target) return 1 - ({0.3, 0.325, 0.35, 0.375, 0.4})[target:GetSpellData(_E).level] end},
["Urgot"] = {buff = "urgotswapdef", amount = function(target) return 1 - ({0.3, 0.4, 0.5})[target:GetSpellData(_R).level] end},
["Alistar"] = {buff = "Ferocious Howl", amount = function(target) return ({0.5, 0.4, 0.3})[target:GetSpellData(_R).level] end},
["Galio"] = {buff = "GalioIdolOfDurand", amount = function(target) return 0.5 end},
["Garen"] = {buff = "GarenW", amount = function(target) return 0.7 end},
["Gragas"] = {buff = "GragasWSelf", amount = function(target) return ({0.1, 0.12, 0.14, 0.16, 0.18})[target:GetSpellData(_W).level] end},
["Annie"] = {buff = "MoltenShield", amount = function(target) return 1 - ({0.16,0.22,0.28,0.34,0.4})[target:GetSpellData(_E).level] end},
["Malzahar"] = {buff = "malzaharpassiveshield", amount = function(target) return 0.1 end}
}
self.AlliedHeroes = {}
self.AlliedDamage = {}
self.EnemyHeroes = {}
self.EnemyDamage = {}
self.IgnoredCollisions = {}
for i = 1, Game.HeroCount() do
local target = Game.Hero(i)
if target.isAlly then
self.AlliedDamage[target.handle] = {}
self.AlliedHeroes[target.handle] = target
else
self.EnemyDamage[target.handle] = {}
self.EnemyHeroes[target.handle] = target
end
end
--Stores the missile instances of active skillshots
self.EnemySkillshots = {}
self.AlliedSkillshots = {}
--Simple table for missile names we want to track
self.MissileNames = {}
--Simple table for particles we want to track
self.ParticleNames = {}
--Simple table for buffs we want to track
self.BuffNames = {}
--Simple table for skills we want to track
self.Skills = {}
--Collection for all skills loaded
self.AllSkills = {}
--Master lookup table. NOT WHAT IS USED FOR ACTUAL MATCHING. It's used for loading
self.MasterSkillLookupTable =
{
--[Item calculations]--
--Bilgewater Cutlass: 3144
[3144] =
{
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_SINGLE,
Damage = 100,
Range = 550,
},
--Blade of the Ruined King: 3153
[3153] =
{
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_SINGLE,
Damage = 100,
Range = 550,
},
--Hextech Gunblade: 3146
[3146] =
{
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_SINGLE,
Damage = {175,180,184,189,193,198,203,207,212,216,221,225,230,235,239,244,248,253},
APScaling = .3,
Range = 700,
},
--Tiamat: 3077
[3077] =
{
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_CIRCLE,
Damage = 0,
ADScaling = .6,
Range = 400,
},
--Ravenous Hydra: 3074
[3074] =
{
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_CIRCLE,
Damage = 0,
ADScaling = .6,
Range = 400,
},
--Titanic Hydra: 3748
[3748] =
{
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_ARC,
Damage = 40,
MaximumHealth = .1,
Range = 700,
},
--[AATROX SKILLS]--
--AatroxQ can't be handled properly. It's dealt with using a BUFF (to make him untargetable I guess) AatroxQDescent triggers when he's attacking
["AatroxQ"] =
{
HeroName = "Aatrox",
SpellSlot = _Q,
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_CIRCLE,
Radius = 275,
Damage = {25,50,80,110,150},
ADScaling = 1.10,
Danger = 3,
BuffName = "AatroxQDescent"
},
["AatroxE"] =
{
HeroName = "Aatrox",
SpellSlot = _Q,
MissileName = "AatroxEConeMissile",
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_LINE,
Radius = 120,
Damage = {80,120,160,200,240},
ADScaling = .7,
Danger = 2,
CCType = BUFF_SLOW,
},
["AatroxR"] =
{
HeroName = "Aatrox",
SpellSlot = _Q,
DamageType = DAMAGE_TYPE_PHYSICAL,
TargetType = TARGET_TYPE_CIRCLE,
Radius = 550,
Damage = {200,300,400},
APScaling = 1.0,
Danger = 3,
},
--[AHRI SKILLS]--
["AhriOrbofDeception"] =
{
HeroName = "Ahri",
SpellName = "Orb of Deception",
SpellSlot = _Q,
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_LINE,
Radius = 100,
Damage = {40,65,90,115,140},
APScaling = .35,
Danger = 2,
},
["AhriFoxFire"] =
{
HeroName = "Ahri",
SpellName = "Fox-Fire",
SpellSlot = _W,
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_SINGLE,
MissileName = "AhriFoxFireMissileTwo",
Damage = {40,65,90,115,140},
APScaling = .3,
Danger = 1,
},
["AhriSeduce"] =
{
HeroName = "Ahri",
SpellName = "Charm",
SpellSlot = _E,
MissileName="AhriSeduceMissile",
DamageType = DAMAGE_TYPE_MAGICAL,
TargetType = TARGET_TYPE_LINE,
Collision = 1,
Radius = 80,
Damage = {60,90,120,150,180},
APScaling = .4,
Danger = 4,
CCType = BUFF_CHARM,
},