-
Notifications
You must be signed in to change notification settings - Fork 1
/
Prediction.lib
1608 lines (1459 loc) · 63.7 KB
/
Prediction.lib
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
--[[
Author: Ark223
Prediction library powered by BruhWalker
________________________________________
prediction_input:
> source - the unit that the skillshot will be launched from [game_object/vec3]
> hitbox - indicates if the unit bounding radius should be included in calculations [boolean]
> speed - the skillshot speed in units per second [number]
> range - the skillshot range in units [number]
> delay - the skillshot initial delay before release [number]
> radius - the skillshot radius (for non-conic skillshots) [number]
> angle - the skillshot angle (for conic skillshots) [number]
> collision - determines the collision flags for the skillshot [table]:
({"minion", "ally_hero", "enemy_hero", "wind_wall", "terrain_wall"})
> type - the skillshot type: ("linear", "circular", "conic") [string]
prediction_output:
> cast_pos - the skillshot cast position [vec3]
> pred_pos - the predicted unit position [vec3]
> hit_chance - the calculated skillshot hit chance [number]
> hit_count - the area of effect hit count [number]
> time_to_hit - the total skillshot arrival time [number]
hit_chance:
> -2 - impossible prediction, the unit is unpredictable
> -1 - the skillshot is colliding other units on the path
> 0 - the predicted position is out of the skillshot range
> (0.01 - 0.99) - the solution has been found for given input
> 1 - the unit is immobile or skillshot will land for sure
> 2 - the unit is dashing or blinking
attack_data (health prediction):
> processed - indicates if sent attack has been completed [boolean]
> timer - the start time of launched attack [number]
> source - the source which has launched the attack [game_object]
> target - the target which is going to take a damage [game_object]
> windup_time - the source attack windup time [number]
> animation_time - the source attack animation time [number]
> speed - the projectile speed of sent attack [number]
> damage - the predicted attack damage to target [number]
API:
> calc_auto_attack_damage(game_object source, game_object unit) [number]
> get_aoe_prediction(prediction_input input, game_object unit) [prediction_output]
> get_aoe_position(prediction_input input, table<game_object/vec3> units, game_object/vec3 star = nil) [{position, hit_count}]
> get_collision(prediction_input input, vec3 end_pos, game_object exclude = nil) [table<game_object/vec3>]
> get_fast_prediction(game_object/vec3 source, game_object unit, number speed, number delay) [vec3]
> get_health_prediction(game_object unit, number delta, number delay = 0) [number]
> get_lane_clear_health_prediction(game_object unit, number delta) [number]
> get_position_after(game_object unit, number delta, boolean skip_latency = false) [vec3]
> get_prediction(prediction_input input, game_object unit) [prediction_output]
> get_hero_aggro(game_object unit) [table<attack_data>]
> get_immobile_duration(game_object unit) [number]
> get_invulnerable_duration(game_object unit) [number]
> get_invisible_duration(game_object unit) [number]
> get_minion_aggro(game_object unit) [table<attack_data>]
> get_movement_speed(game_object unit) [number]
> get_turret_aggro(game_object unit) [table<attack_data>]
> get_waypoints(game_object unit) [table<vec3>]
> is_loaded() [boolean]
> set_collision_buffer(number buffer)
> set_internal_delay(number delay)
--]]
local Version = 0.2
local function AutoUpdate()
local url = "https://raw.githubusercontent.com/Banthors/Bruhwalker/main/"
http:get_async(url .. "Prediction.version", function(success, response)
if not success then
return console:log("[GET ERR] Prediction.lib")
end
if response and response ~= "" and tonumber(response) > Version then
http:download_file_async(url .. "Prediction.lib", "Prediction.lib", function(success2)
if not success2 then
return console:log("[DOWNLOAD ERR] Prediction.lib")
end
client:force_reload()
end)
end
end)
end
local Class = function(...)
local cls = {}; cls.__index = cls
cls.__call = function(_, ...) return cls:New(...) end
function cls:New(...)
local instance = setmetatable({}, cls)
cls.__init(instance, ...)
return instance
end
return setmetatable(cls, {__call = cls.__call})
end
----------------
-- Local data --
local load = loadstring or load
local myHero = game.local_player
local Blinks = {
["Ezreal"] = {
["EzrealE"] = {name = "Arcane Shift", range = 475, windup = 0.25}
},
["FiddleSticks"] = {
["FiddleSticksR"] = {name = "Crowstorm", range = 800, windup = 1.5}
},
["Kassadin"] = {
["Riftwalk"] = {name = "Riftwalk", range = 500, windup = 0.25}
},
["Katarina"] = {
["KatarinaEWrapper"] = {name = "Shunpo", range = 725, windup = 0.125}
},
["Pyke"] = {
["PykeR"] = {name = "Death from Below", range = 750, windup = 0.5}
},
["Shaco"] = {
["Deceive"] = {name = "Deceive", range = 400, windup = 0.25}
},
["Viego"] = {
["ViegoR"] = {name = "Heartbreaker", range = 500, windup = 0.5}
},
["Zoe"] = {
["ZoeR"] = {name = "Portal Jump", range = 575, windup = 0.25}
}
}
local PreDashes = {
["Galio"] = {
["GalioE"] = {name = "Justice Punch", windup = 0.4, offset = -250}
},
["Shyvana"] = {
["ShyvanaTransformCast"] = {name = "Dragon's Descent", windup = 0.25, offset = 0}
},
["Tristana"] = {
["TristanaW"] = {name = "Rocket Jump", windup = 0.25, offset = 0}
}
}
local ChanneledSpells = {
["Caitlyn"] = {id = "caitlynheadshot", name = "Ace in the Hole", buff = true},
["FiddleSticks"] = {id = "Crowstorm", name = "Crowstorm", buff = true},
["Janna"] = {id = "ReapTheWhirlwind", name = "Monsoon", buff = true},
["Jhin"] = {id = "JhinRShot", name = "Curtain Call", buff = false},
["Karthus"] = {id = "karthusfallenonecastsound", name = "Requiem", buff = true},
["Katarina"] = {id = "katarinarsound", name = "Death Lotus", buff = true},
["Lucian"] = {id = "LucianR", name = "The Culling", buff = true},
["Malzahar"] = {id = "alzaharnethergraspsound", name = "Nether Grasp", buff = true},
["MissFortune"] = {id = "missfortunebulletsound", name = "Bullet Time", buff = true},
["Nunu"] = {id = "NunuR_Recast", name = "Absolute Zero", buff = false},
["TwistedFate"] = {id = "Gate", name = "Gate", buff = true},
["Velkoz"] = {id = "VelkozR", name = "Life Form Disintegration Ray", buff = true},
["Warwick"] = {id = "infiniteduresssound", name = "Infinite Duress", buff = true},
["Xerath"] = {id = "XerathLocusOfPower2", name = "Rite of the Arcane", buff = true}
}
local BuffType = {
Internal = 0, Aura = 1, CombatEnchancer = 2, CombatDehancer = 3, SpellShield = 4,
Stun = 5, Invisibility = 6, Silence = 7, Taunt = 8, Berserk = 9, Polymorph = 10,
Slow = 11, Snare = 12, Damage = 13, Heal = 14, Haste = 15, SpellImmunity = 16,
PhysicalImmunity = 17, Invulnerability = 18, AttackSpeedSlow = 19, NearSight = 20,
Currency = 21, Fear = 22, Charm = 23, Poison = 24, Suppression = 25, Blind = 26,
Counter = 27, Shred = 28, Flee = 29, Knockup = 30, Knockback = 31, Disarm = 32,
Grounded = 33, Drowsy = 34, Asleep = 35, Obscured = 36, Clickproof = 37, UnKillable = 38
}
local CrowdControls = {
[BuffType.Charm] = true, [BuffType.Fear] = true,
[BuffType.Flee] = true, [BuffType.Knockup] = true,
[BuffType.Snare] = true, [BuffType.Stun] = true,
[BuffType.Suppression] = true, [BuffType.Taunt] = true
}
local MinionFilter = {
["HA_ChaosMinionMelee"] = math.huge, ["HA_ChaosMinionRanged"] = 650, ["HA_ChaosMinionSiege"] = 1200,
["HA_ChaosMinionSuper"] = math.huge, ["HA_OrderMinionMelee"] = math.huge, ["HA_OrderMinionRanged"] = 650,
["HA_OrderMinionSiege"] = 1200, ["HA_OrderMinionSuper"] = math.huge, ["SRU_Baron"] = 0, ["SRU_Blue"] = 0,
["Sru_Crab"] = 0, ["SRU_Dragon_Air"] = 0, ["SRU_Dragon_Chemtech"] = 0, ["SRU_Dragon_Earth"] = 0,
["SRU_Dragon_Elder"] = 0, ["SRU_Dragon_Fire"] = 0, ["SRU_Dragon_Hextech"] = 0, ["SRU_Dragon_Water"] = 0,
["SRU_ChaosMinionMelee"] = math.huge, ["SRU_ChaosMinionRanged"] = 650, ["SRU_ChaosMinionSiege"] = 1200,
["SRU_ChaosMinionSuper"] = math.huge, ["SRU_Gromp"] = 0, ["SRU_Krug"] = true, ["SRU_KrugMini"] = true,
["SRU_KrugMiniMini"] = true, ["SRU_Murkwolf"] = 0, ["SRU_MurkwolfMini"] = 0,
["SRU_OrderMinionMelee"] = math.huge, ["SRU_OrderMinionRanged"] = 650, ["SRU_OrderMinionSiege"] = 1200,
["SRU_OrderMinionSuper"] = math.huge, ["SRU_Razorbeak"] = 0, ["SRU_RazorbeakMini"] = 0, ["SRU_Red"] = 0,
["SRU_RiftHerald"] = 0, ["AnnieTibbers"] = 0, ["IvernMinion"] = 0, ["YorickWGhoul"] = 0,
["YorickGhoulMelee"] = 0, ["YorickBigGhoul"] = 0, ["HeimerTYellow"] = 0, ["HeimerTBlue"] = 0,
["ZyraThornPlant"] = 0, ["ZyraGraspingPlant"] = 0, ["ShacoBox"] = 0, ["MalzaharVoidling"] = 0,
["KalistaSpawn"] = 0, ["EliseSpiderling"] = 0
}
-- --------------------------------
-- Language INtegrated Query (LINQ)
local function ParseFunc(func)
if func == nil then return function(x) return x end end
if type(func) == "function" then return func end
local index = string.find(func, "=>")
local arg = string.sub(func, 1, index - 1)
local func = string.sub(func, index + 2, #func)
return load(string.format("return function"
.. " %s return %s end", arg, func))()
end
----------------------------------------------------------------------------------------
local function Linq(tab)
return setmetatable(tab or {}, {__index = table})
end
----------------------------------------------------------------------------------------
function table.Aggregate(source, func, seed)
local result = seed or 0
local func = ParseFunc(func)
for index, value in ipairs(source) do
result = func(result, value)
end
return result
end
----------------------------------------------------------------------------------------
function table.All(source, func)
local func = ParseFunc(func)
for index, value in ipairs(source) do
if not func(value, index) then
return false
end
end
return true
end
----------------------------------------------------------------------------------------
function table.Any(source, func)
local func = ParseFunc(func)
for index, value in ipairs(source) do
if func(value, index) then
return true
end
end
return false
end
----------------------------------------------------------------------------------------
function table.Average(source, func)
local result, count = 0, 0
local func = ParseFunc(func)
for _, value in ipairs(source) do
local temp = func(value)
if type(temp) == "number" then
result = result + temp
count = count + 1
end
end
return count == 0 and 0 or result / count
end
----------------------------------------------------------------------------------------
function table.Concat(first, second)
local result, index = Linq(), 0
for _, value in ipairs(first) do
index = index + 1
result[index] = value
end
for _, value in ipairs(second) do
index = index + 1
result[index] = value
end
return result
end
----------------------------------------------------------------------------------------
function table.ForEach(source, func)
for index, value in pairs(source) do
func(value, index)
end
end
----------------------------------------------------------------------------------------
function table.RemoveWhere(source, func)
local size = #source
local func = ParseFunc(func)
for index = size, 1, -1 do
local value = source[index]
if func(value, index) then
source:remove(index)
end
end
return size ~= #source
end
----------------------------------------------------------------------------------------
function table.Select(source, func)
local result = Linq()
local func = ParseFunc(func)
for index, value in ipairs(source) do
result[index] = func(value, index)
end
return result
end
----------------------------------------------------------------------------------------
function table.Where(source, func)
local result, iteration = Linq(), 0
local func = ParseFunc(func)
for index, value in ipairs(source) do
if func(value, index) then
iteration = iteration + 1
result[iteration] = value
end
end
return result
end
-----------------
-- Point class --
local function IsPoint(p)
return p and p.x and type(p.x) == "number"
and p.y and type(p.y) == "number"
and p.type and p.type == "Point"
end
-----------------------------------------------------------------------------------------------
local function IsUnit(p)
return p ~= nil and type(p) ~= "number" and (p.path
and p.path.server_pos ~= nil or p.origin ~= nil)
end
-----------------------------------------------------------------------------------------------
local function Round(v)
return floor(v + 0.5) -- always positive number
end
-----------------------------------------------------------------------------------------------
local Point = Class()
function Point:__init(x, y)
self.type = "Point"
if x and IsUnit(x) then
local p = x.path ~= nil and
x.path.server_pos or x.origin
self.x, self.y = p.x, p.z or p.y
elseif x and y then
self.x, self.y = x, y
elseif x and not y then
self.x, self.y = x.x, x.z or x.y
else
self.x, self.y = 0, 0
end
end
-----------------------------------------------------------------------------------------------
function Point:__tostring()
return string.format("%d %d", self.x, self.y)
end
----------------------------------------------------------------------------------------
function Point:__eq(p)
return math.abs(self.x - p.x) < 1
and math.abs(self.y - p.y) < 1
end
-----------------------------------------------------------------------------------------------
function Point:__add(p)
return Point:New(self.x + p.x, self.y + p.y)
end
-----------------------------------------------------------------------------------------------
function Point:__sub(p)
return Point:New(self.x - p.x, self.y - p.y)
end
-----------------------------------------------------------------------------------------------
function Point.__mul(a, b)
if type(a) == "number" and IsPoint(b) then
return Point:New(b.x * a, b.y * a)
elseif type(b) == "number" and IsPoint(a) then
return Point:New(a.x * b, a.y * b)
end
error("Multiplication error!")
end
-----------------------------------------------------------------------------------------------
function Point.__div(a, b)
if type(a) == "number" and IsPoint(b) then
return Point:New(a / b.x, a / b.y)
elseif type(b) == "number" and IsPoint(a) then
return Point:New(a.x / b, a.y / b)
end
error("Division error!")
end
-----------------------------------------------------------------------------------------------
function Point:__tostring()
return string.format("(%f, %f)", self.x, self.y)
end
-----------------------------------------------------------------------------------------------
function Point:AngleBetween(p1, p2)
local angle = math.deg(
math.atan(p2.y - self.y, p2.x - self.x) -
math.atan(p1.y - self.y, p1.x - self.x))
if angle < 0 then angle = angle + 360 end
return angle > 180 and 360 - angle or angle
end
-----------------------------------------------------------------------------------------------
function Point:Append(p, dist)
if dist == 0 then return p:Clone() end
return p + (p - self):Normalize() * dist
end
-----------------------------------------------------------------------------------------------
function Point:Clone()
return Point:New(self.x, self.y)
end
-----------------------------------------------------------------------------------------------
function Point:ClosestOnSegment(s1, s2)
local ap, ab = self - s1, s2 - s1
local t = ap:DotProduct(ab) / ab:LengthSquared()
return t < 0 and s1 or t > 1 and s2 or (s1 + ab * t)
end
-----------------------------------------------------------------------------------------------
function Point:CrossProduct(p)
return self.x * p.y - self.y * p.x
end
-----------------------------------------------------------------------------------------------
function Point:DistanceSquared(p)
local dx, dy = p.x - self.x, p.y - self.y
return dx * dx + dy * dy
end
-----------------------------------------------------------------------------------------------
function Point:Distance(p)
return math.sqrt(self:DistanceSquared(p))
end
-----------------------------------------------------------------------------------------------
function Point:DotProduct(p)
return self.x * p.x + self.y * p.y
end
-----------------------------------------------------------------------------------------------
function Point:Extend(p, dist)
if dist == 0 then return self:Clone() end
return self + (p - self):Normalize() * dist
end
-----------------------------------------------------------------------------------------------
function Point:InPolygon(poly)
local size, result = #poly, false
for i = 1, size do
local a, b = poly[i], poly[i % size + 1]
if a.y <= self.y and b.y >= self.y or
b.y <= self.y and a.y >= self.y then
local ap, ab = self - a, b - a
if a.x + ap.y / ab.y * ab.x <= self.x then
result = not result
end
end
end
return result
end
-----------------------------------------------------------------------------------------------
function Point:Intersection(a2, b1, b2)
local a, b = a2 - self, b2 - b1
local axb = a:CrossProduct(b)
if axb == 0 then return nil end
local bsa = b1 - self
local t1 = bsa:CrossProduct(b) / axb
local t2 = bsa:CrossProduct(a) / axb
return t1 >= 0 and t1 <= 1 and t2 >= 0
and t2 <= 1 and self + a * t1 or nil
end
-----------------------------------------------------------------------------------------------
function Point:IsZero()
return self.x == 0 and self.y == 0
end
-----------------------------------------------------------------------------------------------
function Point:LengthSquared(p)
local p = p and p:Clone() or self
return p.x * p.x + p.y * p.y
end
-----------------------------------------------------------------------------------------------
function Point:Length(p)
return math.sqrt(self:LengthSquared(p))
end
-----------------------------------------------------------------------------------------------
function Point:Negate()
return Point:New(-self.x, -self.y)
end
-----------------------------------------------------------------------------------------------
function Point:Normalize()
local len = self:Length()
if len == 0 then return Point:New() end
return Point:New(self.x / len, self.y / len)
end
-----------------------------------------------------------------------------------------------
function Point:Perpendicular()
return Point:New(-self.y, self.x)
end
-----------------------------------------------------------------------------------------------
function Point:Perpendicular2()
return Point:New(self.y, -self.x)
end
-----------------------------------------------------------------------------------------------
function Point:Rotate(phi, p)
local c = math.cos(phi)
local s = math.sin(phi)
local p = p or Point:New()
local d = self - p
local x = c * d.x - s * d.y + p.x
local y = s * d.x + c * d.y + p.y
return Point:New(x, y)
end
-----------------------------------------------------------------------------------------------
function Point:To3D(y)
local y = y or myHero.origin.y
return vec3.new(self.x, y, self.y)
end
--------------------------------
-- Prediction input structure --
local PredictionInput = Class()
function PredictionInput:__init(data)
self.source = data.source or nil
self.speed = data.speed or math.huge
self.range = data.range or 25000
self.delay = data.delay or 0.25
self.radius = data.radius or 1
self.angle = data.angle or 0
self.hitbox = data.hitbox or false
self.collision = data.collision or {}
self.type = data.type or "linear"
end
---------------------------------
-- Prediction output structure --
local PredictionOutput = Class()
function PredictionOutput:__init()
self.cast_pos = nil
self.pred_pos = nil
self.hit_chance = -2
self.hit_count = 0
self.time_to_hit = 0
end
-------------------
-- Prediction class
local Pred = Class()
function Pred:__init(delay)
self.allyMinions = Linq()
self.attacks = Linq()
self.data = Linq()
self.enemyMinions = Linq()
self.futureAttacks = Linq()
self.windwalls = Linq()
self.targets = {}
self.internalDelay = delay or 0.0167
self.units = Linq(game.players):Where(
function(u) return u.object_id ~= myHero.object_id end)
self.enemies = self.units:Where(function(u) return u.is_enemy end)
for _, unit in ipairs(self.units) do self:ResetData(unit) end
self.menu = menu:add_category("Prediction v" .. tostring(Version))
self.drawPoints = menu:add_checkbox("Draw Waypoints", self.menu, 0)
self.options = menu:add_subcategory("Measure Options", self.menu)
self.buffer = menu:add_slider("Collision Buffer", self.menu, 0, 50, 30)
self.drawSpell = menu:add_checkbox("Draw Skillshot", self.options, 0)
self.dummyBox = menu:add_checkbox("Draw Dummy Hitbox", self.options, 1)
self.fixedRange = menu:add_checkbox("Use Fixed Range", self.options, 1)
self.range = menu:add_slider("Range", self.options, 0, 1500, 1150)
self.radius = menu:add_slider("Radius", self.options, 0, 500, 60)
self.angle = menu:add_slider("Angle", self.options, 0, 180, 50)
self.type = menu:add_combobox("Type", self.options, {"Line", "Circle", "Cone"}, 0)
client:set_event_callback("on_tick", function(...) self:OnTick(...) end)
client:set_event_callback("on_draw", function(...) self:OnDraw(...) end)
client:set_event_callback("on_new_path", function(...) self:OnNewPath(...) end)
client:set_event_callback("on_process_spell", function(...) self:OnProcessSpell(...) end)
client:set_event_callback("on_stop_cast", function(...) self:OnStopCast(...) end)
self.loaded = true
end
-----------------------------------------------------------------------------------------------
function Pred:CutPath(path, distance)
if distance < 0 then return path end
local count, result = #path, Linq()
local distance = distance
for i = 1, count - 1 do
local dist = path[i]:Distance(path[i + 1])
if dist > distance then
result[#result + 1] = path[i]
:Extend(path[i + 1], distance)
for j = i + 1, count do
result[#result + 1] = path[j]
end break
end
distance = distance - dist
end
return #result > 0 and result or {path[count]}
end
-----------------------------------------------------------------------------------------------
function Pred:CalcAutoAttackDamage(source, unit)
local amount = source.total_attack_damage
if source.champ_name == "Kalista" then
amount = amount * 0.9
elseif source.champ_name == "Graves" then
local percent = 0.68235 + source.level * 0.01765
amount = amount * percent
end
local armor = unit.armor
if source.is_turret then
local max = unit.max_health
local name = unit.champ_name
if name:find("Siege") then
local percent = name:find("1") and 0.14
or name:find("2") and 0.11 or 0.08
return math.floor(max * percent)
elseif name:find("Ranged") then
return math.floor(max * 0.7)
elseif name:find("Melee") then
return math.floor(max * 0.45)
elseif name:find("Super") then
return math.floor(max * 0.05)
end
elseif armor < 0 then
local reduction = 2 - 100 / (100 - armor)
return math.floor(amount * reduction)
end
local bonusArmor = unit.bonus_armor
local armorPen = source.percent_armor_penetration
local bonusPen = source.percent_bonus_armor_penetration
local lethality = source.lethality * (0.6 + 0.4 * source.level / 18)
if source.is_minion then armorPen, bonusPen, lethality = 1, 1, 0 end
if source.is_turret then armorPen, bonusPen, lethality = 0.7, 1, 0 end
local res = armor * armorPen - (bonusArmor * (1 - bonusPen)) - lethality
return math.floor(amount * (res < 0 and 1 or 100 / (100 + res)))
end
-----------------------------------------------------------------------------------------------
function Pred:DistanceToCollision(p1, p2, pos, hitbox, buffer)
local dir, buffer = (p2 - p1):Normalize(), buffer or 0
local p1, p2 = p1 - dir * buffer, p2 + dir * buffer
local perp = dir:Perpendicular() * (hitbox + buffer)
local polygon = {p1 + perp, p1 - perp, p2 - perp, p2 + perp}
if pos:InPolygon(polygon) then return 0.0 end
local distance = math.huge
for i = 1, 4 do
local a, b = polygon[i], polygon[i % 4 + 1]
local pt = pos:ClosestOnSegment(a, b)
local dist = pos:DistanceSquared(pt)
if dist < distance then distance = dist end
end
return distance
end
-----------------------------------------------------------------------------------------------
function Pred:DrawCircle(pos, radius, color)
local pos = pos:To3D(myHero.origin.y)
local c = color or {r = 255, g = 255, b = 255, a = 240}
renderer:draw_circle(pos.x, pos.y, pos.z, radius, c.r, c.g, c.b, c.a)
end
-----------------------------------------------------------------------------------------------
function Pred:DrawPath(path)
local size = #path
if size < 2 then return end
local y = myHero.origin.y
for i = 1, size - 1 do
local p1, p2 = path[i], path[i + 1]
local a = game:world_to_screen_2(p1.x, y, p1.y)
local b = game:world_to_screen_2(p2.x, y, p2.y)
renderer:draw_line(a.x, a.y, b.x, b.y, 1, 255, 255, 255, 192)
end
renderer:draw_circle(path[#path].x, y, path[#path].y, 25, 255, 255, 0, 192)
end
-----------------------------------------------------------------------------------------------
function Pred:DrawPolygon(polygon)
local size = #polygon
if size < 3 then return end
local y = myHero.origin.y
for i = 1, size do
local p1, p2 = polygon[i], polygon[i % size + 1]
local a = game:world_to_screen_2(p1.x, y, p1.y)
local b = game:world_to_screen_2(p2.x, y, p2.y)
renderer:draw_line(a.x, a.y, b.x, b.y, 1, 255, 255, 255, 240)
end
end
-----------------------------------------------------------------------------------------------
function Pred:GetMovementSpeed(unit)
local path = unit.path
return path and path.is_dashing and
path.dash_speed or unit.move_speed
end
-----------------------------------------------------------------------------------------------
function Pred:GetPathIndex(path, pos)
if #path <= 2 then return 2 end
local result = {distance = math.huge,
index = 0, point = Point:New()}
for i = 1, #path - 1 do
local a, b = path[i], path[i + 1]
local pt = pos:ClosestOnSegment(a, b)
local dist = pos:DistanceSquared(pt)
if dist < result.distance then
result = {distance = dist,
index = i + 1, point = pt}
end
end
pos = result.point
return result.index
end
-----------------------------------------------------------------------------------------------
function Pred:GetWaypoints(unit)
local result = Linq()
local data = self.data[unit.object_id]
result[1] = data and data.serverPos
or Point:New(unit.path.server_pos)
local path = data and data.path or
Linq(unit.path.waypoints):Select(
function(w) return Point:New(w.x, w.z) end)
local index = self:GetPathIndex(path, result[1])
for i = index, #path do result[#result + 1] = path[i] end
if data and data.miaTimer > 0 then
local speed = self:GetMovementSpeed(unit)
result = self:CutPath(result, speed *
(game.game_time - data.miaTimer))
end
return result
end
-----------------------------------------------------------------------------------------------
function Pred:Interception(startPos, endPos, source, speed, mspeed, delay)
-- dynamic circle-circle collision:
-- https://stackoverflow.com/questions/2248876/2d-game-fire-at-a-
-- moving-target-by-predicting-intersection-of-projectile-and-u
local dir = endPos - startPos
local magn = dir:Length()
local vel = dir * speed / magn
dir = startPos - source
local a = vel:LengthSquared() - mspeed * mspeed
local b = 2 * vel:DotProduct(dir)
local c = dir:LengthSquared()
local delta = b * b - 4 * a * c
if delta >= 0 then
local delta, t = math.sqrt(delta), 0
local t1 = (-b + delta) / (2 * a)
local t2 = (-b - delta) / (2 * a)
if t2 >= delay then
t = t1 >= delay and math.min(
t1, t2) or math.max(t1, t2)
end
return t, startPos + vel * t
end
return 0, nil
end
----------------------------------------------------------------------------------------
function Pred:IsInserted(unit)
return self.attacks:Any(function(a)
local delay = a.animation_time - 0.05
return unit.object_id == a.network_id
and game.game_time - a.timer < delay
end)
end
----------------------------------------------------------------------------------------
function Pred:IsValid(unit)
return unit and unit.is_valid and
unit.is_visible and unit.is_alive
end
----------------------------------------------------------------------------------------
function Pred:Latency()
return game.ping * 0.001
end
----------------------------------------------------------------------------------------
function Pred:ResetData(unit)
self.data[unit.object_id] = {
blink = {}, -- the stored data of unit's blink usage
dashing = false, -- indicates if the unit is dashing
dashSpeed = 0, -- the unit last dashing speed
castEndTimer = 0, -- the last AA or spell cast timer
miaTimer = -1, -- the last invisibility timer
path = Linq(), -- the unit's path
pathTimer = 0, -- the last path change timer
preDash = {}, -- the data of unit's pre-dash state
serverPos = nil, -- the unit's server position
waypoints = Linq() -- the unit's waypoints
}
end
------------
-- Events --
function Pred:OnTick()
-- update data for all heroes
for _, unit in ipairs(self.units) do
local data = self.data[unit.object_id]
if self:IsValid(unit) then data.miaTimer = 0
data.path = Linq(unit.path.waypoints):Select(
function(w) return Point:New(w.x, w.z) end)
data.serverPos = Point:New(unit.path.server_pos)
elseif data.miaTimer == 0 then data.miaTimer =
game.game_time - self.internalDelay end
if unit.is_recalling then data.path = Linq() end
if data.blink.pos and data.blink.endTime <
game.game_time then data.blink = {} end
if data.preDash.pos and data.preDash.endTime <
game.game_time then data.preDash = {} end
data.waypoints = self:GetWaypoints(unit)
if data.dashing and #data.waypoints < 2
then data.dashing = false end
end
-- mark completed attacks as processed
self.attacks:ForEach(function(a)
if a.processed == true then return end
local target = Point:New(a.target.origin)
local dist = a.start_pos:Distance(target)
if not self:IsValid(a.source)
or not self:IsValid(a.target) or
a.timer + dist / a.speed + a.windup_time <
game.game_time then a.processed = true end
end)
-- remove old processed attacks and windwalls
self.attacks:RemoveWhere(function(a)
return a.processed and game.game_time -
a.timer + 0.1 > a.animation_time end)
self.windwalls:ForEach(function(w)
return game.game_time - w.timer > 4 end)
for networkId, data in pairs(self.targets) do
if game.game_time - data.timer > 3 or
not self:IsValid(data.target) then
self.targets[networkId] = nil
end
end
-- collect candidates for future minion attacks
local heroPos = Point:New(myHero.origin)
self.allyMinions = Linq(game.minions):Where(
function(m) return self:IsValid(m) and not m.is_enemy
and not self:IsInserted(m) and m.champ_name:find("Minion")
and heroPos:Distance(Point:New(m.origin)) <= 1500 end)
self.enemyMinions = Linq(game.minions):Where(
function(m) return self:IsValid(m) == true and
m.is_enemy and m.champ_name:find("Minion") and
heroPos:Distance(Point:New(m.origin)) <= 1500 end)
-- predict future minion attacks for lane clear
self.futureAttacks = Linq()
if #self.enemyMinions == 0 then return end
self.allyMinions:ForEach(function(ally)
if self.attacks:Any(
function(a) return a.network_id ==
ally.object_id end) then return end
local pa = Point:New(ally.path.server_pos)
local data = self.targets[ally.object_id]
local targets = data ~= nil and
{data.target} or self.enemyMinions
for _, target in ipairs(targets) do
local pe = Point:New(target.path.server_pos)
local dist = math.max(pa:Distance(pe) - ally.attack_range
- ally.bounding_radius - target.bounding_radius, 0)
local arrival = dist / ally.move_speed - self.internalDelay
if arrival > 3 then goto continue end
self.futureAttacks[#self.futureAttacks + 1] = {
processed = true,
timer = game.game_time + arrival,
source = ally, target = target,
start_pos = pa:Extend(pe, dist),
network_id = ally.object_id,
windup_time = ally.attack_cast_delay,
animation_time = ally.attack_delay,
speed = MinionFilter[ally.champ_name],
damage = self:CalcAutoAttackDamage(ally, target)
} ::continue::
end
end)
end
----------------------------------------------------------------------------------------
function Pred:OnDraw()
for _, unit in ipairs(self.enemies:Where("(u) => u.is_alive")) do
if unit.is_visible and menu:get_value(self.dummyBox) == 1
and unit.champ_name:find("Practice") ~= nil then
local color = {r = 255, g = 255, b = 0, a = 200}
local pos = Point:New(unit.origin)
self:DrawCircle(pos, 65, color)
self:DrawCircle(pos, 3, color)
elseif menu:get_value(self.drawPoints) == 1
and self.data[unit.object_id] ~= nil then
self:DrawPath(self.data[unit.object_id].waypoints)
end
end
if menu:get_value(self.drawSpell) == 0 then return end
local type = menu:get_value(self.type)
local range = menu:get_value(self.range)
local radius = menu:get_value(self.radius)
local mousePos = Point:New(game.mouse_pos)
local p1 = Point:New(myHero.origin)
local p2 = menu:get_value(self.fixedRange) == 1
and p1:Extend(mousePos, range) or mousePos
if type == 0 then
local dir = (p2 - p1):Normalize()
local perp = dir:Perpendicular() * radius
self:DrawPolygon({p1 + perp, p1 -
perp, p2 - perp, p2 + perp})
elseif type == 1 then
self:DrawCircle(p2, radius)
elseif type == 2 then
local angle = menu:get_value(self.angle)
local angle = math.rad(angle)
local length = p1:Distance(p2) * angle
if length < 35 then return end
local steps = math.floor(length / 50)
local phi, polygon = -angle * 0.5, {}
for i = 1, steps + 1 do
local pos = p2:Rotate(phi, p1)
polygon[#polygon + 1] = pos
phi = i == steps and angle *
0.5 or phi + angle / steps
end
polygon[#polygon + 1] = p1
self:DrawPolygon(polygon)
end
end
----------------------------------------------------------------------------------------
function Pred:OnNewPath(unit)
if unit.team == myHero.team or not
unit.is_hero then return end
local data = self.data[unit.object_id]
if not data then return end
data.dashing = unit.path.is_dashing
data.dashSpeed = unit.path.dash_speed
data.pathTimer = game.game_time
end
----------------------------------------------------------------------------------------
function Pred:OnProcessSpell(unit, args)
if not unit.is_valid or not unit.is_alive then return end
local charName, name = unit.champ_name, args.spell_name
if unit.is_hero and self.data[unit.object_id]
and unit.object_id ~= myHero.object_id then
local data = self.data[unit.object_id]
if args.cast_delay and args.cast_delay > 0 then
data.castEndTimer = game.game_time + args.cast_delay
data.pathTimer = game.game_time
end
if Blinks[charName] and Blinks[charName][name] then
local blink = Blinks[charName][name]
local startPos = Point:New(args.start_pos)
local endPos = Point:New(args.end_pos)
endPos = startPos:Extend(endPos, math.min(
blink.range, startPos:Distance(endPos)))
data.blink = {pos = endPos, endTime =
game.game_time + blink.windup}
elseif PreDashes[charName] and PreDashes[charName][name] then
local preDash = PreDashes[charName][name]
local startPos = Point:New(args.start_pos)
local endPos = Point:New(args.end_pos)
local dir = (endPos - startPos):Normalize()
local pos = startPos + dir * preDash.offset
data.preDash = {pos = pos, endTime =
game.game_time + preDash.windup}
elseif name == "YasuoW" then
local startPos = Point:New(args.start_pos)
local endPos = Point:New(args.end_pos)
local dir = (endPos - startPos):Normalize()
local pos = startPos + dir * 350
local perp = dir:Perpendicular()