forked from LeagueSharp/LeagueSharp.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prediction.cs
1623 lines (1403 loc) · 57.7 KB
/
Prediction.cs
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
namespace LeagueSharp.Common
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using SharpDX;
/// <summary>
/// Represents the chance of hitting an enemy.
/// </summary>
public enum HitChance
{
/// <summary>
/// The target is immobile.
/// </summary>
Immobile = 8,
/// <summary>
/// The unit is dashing.
/// </summary>
Dashing = 7,
/// <summary>
/// Very high probability of hitting the target.
/// </summary>
VeryHigh = 6,
/// <summary>
/// High probability of hitting the target.
/// </summary>
High = 5,
/// <summary>
/// Medium probability of hitting the target.
/// </summary>
Medium = 4,
/// <summary>
/// Low probability of hitting the target.
/// </summary>
Low = 3,
/// <summary>
/// Impossible to hit the target.
/// </summary>
Impossible = 2,
/// <summary>
/// The target is out of range.
/// </summary>
OutOfRange = 1,
/// <summary>
/// The target is blocked by other units.
/// </summary>
Collision = 0
}
/// <summary>
/// The type of skillshot.
/// </summary>
public enum SkillshotType
{
/// <summary>
/// The skillshot is linear.
/// </summary>
SkillshotLine,
/// <summary>
/// The skillshot is circular.
/// </summary>
SkillshotCircle,
/// <summary>
/// The skillshot is conical.
/// </summary>
SkillshotCone
}
/// <summary>
/// Objects that cause collision to the spell.
/// </summary>
public enum CollisionableObjects
{
/// <summary>
/// Minions.
/// </summary>
Minions,
/// <summary>
/// Enemy heroes.
/// </summary>
Heroes,
/// <summary>
/// Yasuo's Wind Wall (W)
/// </summary>
YasuoWall,
/// <summary>
/// Walls.
/// </summary>
Walls,
/// <summary>
/// Ally heroes.
/// </summary>
Allies
}
/// <summary>
/// Contains information necessary to calculate the prediction.
/// </summary>
public class PredictionInput
{
#region Fields
/// <summary>
/// If set to <c>true</c> the prediction will hit as many enemy heroes as posible.
/// </summary>
public bool Aoe = false;
/// <summary>
/// <c>true</c> if the spell collides with units.
/// </summary>
public bool Collision = false;
/// <summary>
/// Array that contains the unit types that the skillshot can collide with.
/// </summary>
public CollisionableObjects[] CollisionObjects =
{
CollisionableObjects.Minions, CollisionableObjects.YasuoWall
};
/// <summary>
/// The skillshot delay in seconds.
/// </summary>
public float Delay;
/// <summary>
/// The skillshot width's radius or the angle in case of the cone skillshots.
/// </summary>
public float Radius = 1f;
/// <summary>
/// The skillshot range in units.
/// </summary>
public float Range = float.MaxValue;
/// <summary>
/// The skillshot speed in units per second.
/// </summary>
public float Speed = float.MaxValue;
/// <summary>
/// The skillshot type.
/// </summary>
public SkillshotType Type = SkillshotType.SkillshotLine;
/// <summary>
/// The unit that the prediction will made for.
/// </summary>
public Obj_AI_Base Unit = ObjectManager.Player;
/// <summary>
/// Set to true to increase the prediction radius by the unit bounding radius.
/// </summary>
public bool UseBoundingRadius = true;
/// <summary>
/// The position that the skillshot will be launched from.
/// </summary>
private Vector3 _from;
/// <summary>
/// The position to check the range from.
/// </summary>
private Vector3 _rangeCheckFrom;
#endregion
#region Public Properties
/// <summary>
/// The position from where the skillshot missile gets fired.
/// </summary>
/// <value>From.</value>
public Vector3 From
{
get
{
return this._from.To2D().IsValid() ? this._from : ObjectManager.Player.ServerPosition;
}
set
{
this._from = value;
}
}
/// <summary>
/// The position from where the range is checked.
/// </summary>
/// <value>The range check from.</value>
public Vector3 RangeCheckFrom
{
get
{
return this._rangeCheckFrom.To2D().IsValid()
? this._rangeCheckFrom
: (this.From.To2D().IsValid() ? this.From : ObjectManager.Player.ServerPosition);
}
set
{
this._rangeCheckFrom = value;
}
}
#endregion
#region Properties
/// <summary>
/// Gets the real radius.
/// </summary>
/// <value>The real radius.</value>
internal float RealRadius
{
get
{
return this.UseBoundingRadius ? this.Radius + this.Unit.BoundingRadius : this.Radius;
}
}
#endregion
}
/// <summary>
/// The output after calculating the prediction.
/// </summary>
public class PredictionOutput
{
#region Fields
/// <summary>
/// The list of the targets that the spell will hit (only if aoe was enabled).
/// </summary>
public List<Obj_AI_Hero> AoeTargetsHit = new List<Obj_AI_Hero>();
/// <summary>
/// The list of the units that the skillshot will collide with.
/// </summary>
public List<Obj_AI_Base> CollisionObjects = new List<Obj_AI_Base>();
/// <summary>
/// Returns the hitchance.
/// </summary>
public HitChance Hitchance = HitChance.Impossible;
/// <summary>
/// The AoE target hit.
/// </summary>
internal int _aoeTargetsHitCount;
/// <summary>
/// The input
/// </summary>
internal PredictionInput Input;
/// <summary>
/// The calculated cast position
/// </summary>
private Vector3 _castPosition;
/// <summary>
/// The predicted unit position
/// </summary>
private Vector3 _unitPosition;
#endregion
#region Public Properties
/// <summary>
/// The number of targets the skillshot will hit (only if aoe was enabled).
/// </summary>
/// <value>The aoe targets hit count.</value>
public int AoeTargetsHitCount
{
get
{
return Math.Max(this._aoeTargetsHitCount, this.AoeTargetsHit.Count);
}
}
/// <summary>
/// The position where the skillshot should be casted to increase the accuracy.
/// </summary>
/// <value>The cast position.</value>
public Vector3 CastPosition
{
get
{
return this._castPosition.IsValid() && this._castPosition.To2D().IsValid()
? this._castPosition.SetZ()
: this.Input.Unit.ServerPosition;
}
set
{
this._castPosition = value;
}
}
/// <summary>
/// The position where the unit is going to be when the skillshot reaches his position.
/// </summary>
/// <value>The unit position.</value>
public Vector3 UnitPosition
{
get
{
return this._unitPosition.To2D().IsValid() ? this._unitPosition.SetZ() : this.Input.Unit.ServerPosition;
}
set
{
this._unitPosition = value;
}
}
#endregion
}
/// <summary>
/// Class used for calculating the position of the given unit after a delay.
/// </summary>
public static class Prediction
{
#region Static Fields
private static Menu _menu;
#endregion
#region Public Methods and Operators
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="delay">The delay.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(Obj_AI_Base unit, float delay)
{
return GetPrediction(new PredictionInput { Unit = unit, Delay = delay });
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="delay">The delay.</param>
/// <param name="radius">The radius.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(Obj_AI_Base unit, float delay, float radius)
{
return GetPrediction(new PredictionInput { Unit = unit, Delay = delay, Radius = radius });
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="delay">The delay.</param>
/// <param name="radius">The radius.</param>
/// <param name="speed">The speed.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(Obj_AI_Base unit, float delay, float radius, float speed)
{
return GetPrediction(new PredictionInput { Unit = unit, Delay = delay, Radius = radius, Speed = speed });
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="delay">The delay.</param>
/// <param name="radius">The radius.</param>
/// <param name="speed">The speed.</param>
/// <param name="collisionable">The collisionable objects.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(
Obj_AI_Base unit,
float delay,
float radius,
float speed,
CollisionableObjects[] collisionable)
{
return
GetPrediction(
new PredictionInput
{ Unit = unit, Delay = delay, Radius = radius, Speed = speed, CollisionObjects = collisionable });
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(PredictionInput input)
{
return GetPrediction(input, true, true);
}
/// <summary>
/// Initializes this instance.
/// </summary>
public static void Initialize()
{
CustomEvents.Game.OnGameLoad += eventArgs =>
{
_menu = new Menu("Prediction", "Prediction");
var slider = new MenuItem("PredMaxRange", "Max Range %").SetValue(new Slider(100, 70, 100));
_menu.AddItem(slider);
CommonMenu.Instance.AddSubMenu(_menu);
};
}
public static void Shutdown()
{
Menu.Remove(_menu);
}
#endregion
#region Methods
/// <summary>
/// Gets the dashing prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
internal static PredictionOutput GetDashingPrediction(PredictionInput input)
{
var dashData = input.Unit.GetDashInfo();
var result = new PredictionOutput { Input = input };
//Normal dashes.
if (!dashData.IsBlink)
{
//Mid air:
var endP = dashData.Path.Last();
var dashPred = GetPositionOnPath(
input,
new List<Vector2> { input.Unit.ServerPosition.To2D(), endP },
dashData.Speed);
if (dashPred.Hitchance >= HitChance.High
&& dashPred.UnitPosition.To2D().Distance(input.Unit.Position.To2D(), endP, true) < 200)
{
dashPred.CastPosition = dashPred.UnitPosition;
dashPred.Hitchance = HitChance.Dashing;
return dashPred;
}
//At the end of the dash:
if (dashData.Path.PathLength() > 200)
{
var timeToPoint = input.Delay / 2f + input.From.To2D().Distance(endP) / input.Speed - 0.25f;
if (timeToPoint
<= input.Unit.Distance(endP) / dashData.Speed + input.RealRadius / input.Unit.MoveSpeed)
{
return new PredictionOutput
{
CastPosition = endP.To3D(), UnitPosition = endP.To3D(),
Hitchance = HitChance.Dashing
};
}
}
result.CastPosition = dashData.Path.Last().To3D();
result.UnitPosition = result.CastPosition;
//Figure out where the unit is going.
}
return result;
}
/// <summary>
/// Gets the immobile prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="remainingImmobileT">The remaining immobile t.</param>
/// <returns>PredictionOutput.</returns>
internal static PredictionOutput GetImmobilePrediction(PredictionInput input, double remainingImmobileT)
{
var timeToReachTargetPosition = input.Delay + input.Unit.Distance(input.From) / input.Speed;
if (timeToReachTargetPosition <= remainingImmobileT + input.RealRadius / input.Unit.MoveSpeed)
{
return new PredictionOutput
{
CastPosition = input.Unit.ServerPosition, UnitPosition = input.Unit.Position,
Hitchance = HitChance.Immobile
};
}
return new PredictionOutput
{
Input = input, CastPosition = input.Unit.ServerPosition,
UnitPosition = input.Unit.ServerPosition, Hitchance = HitChance.High
/*timeToReachTargetPosition - remainingImmobileT + input.RealRadius / input.Unit.MoveSpeed < 0.4d ? HitChance.High : HitChance.Medium*/
};
}
/// <summary>
/// Gets the position on path.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="path">The path.</param>
/// <param name="speed">The speed.</param>
/// <returns>PredictionOutput.</returns>
internal static PredictionOutput GetPositionOnPath(PredictionInput input, List<Vector2> path, float speed = -1)
{
speed = (Math.Abs(speed - (-1)) < float.Epsilon) ? input.Unit.MoveSpeed : speed;
if (path.Count <= 1)
{
return new PredictionOutput
{
Input = input, UnitPosition = input.Unit.ServerPosition,
CastPosition = input.Unit.ServerPosition, Hitchance = HitChance.VeryHigh
};
}
var pLength = path.PathLength();
//Skillshots with only a delay
if (pLength >= input.Delay * speed - input.RealRadius
&& Math.Abs(input.Speed - float.MaxValue) < float.Epsilon)
{
var tDistance = input.Delay * speed - input.RealRadius;
for (var i = 0; i < path.Count - 1; i++)
{
var a = path[i];
var b = path[i + 1];
var d = a.Distance(b);
if (d >= tDistance)
{
var direction = (b - a).Normalized();
var cp = a + direction * tDistance;
var p = a
+ direction
* ((i == path.Count - 2)
? Math.Min(tDistance + input.RealRadius, d)
: (tDistance + input.RealRadius));
return new PredictionOutput
{
Input = input, CastPosition = cp.To3D(), UnitPosition = p.To3D(),
Hitchance =
PathTracker.GetCurrentPath(input.Unit).Time < 0.1d
? HitChance.VeryHigh
: HitChance.High
};
}
tDistance -= d;
}
}
//Skillshot with a delay and speed.
if (pLength >= input.Delay * speed - input.RealRadius
&& Math.Abs(input.Speed - float.MaxValue) > float.Epsilon)
{
var d = input.Delay * speed - input.RealRadius;
if (input.Type == SkillshotType.SkillshotLine || input.Type == SkillshotType.SkillshotCone)
{
if (input.From.Distance(input.Unit.ServerPosition, true) < 200 * 200)
{
d = input.Delay * speed;
}
}
path = path.CutPath(d);
var tT = 0f;
for (var i = 0; i < path.Count - 1; i++)
{
var a = path[i];
var b = path[i + 1];
var tB = a.Distance(b) / speed;
var direction = (b - a).Normalized();
a = a - speed * tT * direction;
var sol = Geometry.VectorMovementCollision(a, b, speed, input.From.To2D(), input.Speed, tT);
var t = (float)sol[0];
var pos = (Vector2)sol[1];
if (pos.IsValid() && t >= tT && t <= tT + tB)
{
if (pos.Distance(b, true) < 20) break;
var p = pos + input.RealRadius * direction;
if (input.Type == SkillshotType.SkillshotLine && false)
{
var alpha = (input.From.To2D() - p).AngleBetween(a - b);
if (alpha > 30 && alpha < 180 - 30)
{
var beta = (float)Math.Asin(input.RealRadius / p.Distance(input.From));
var cp1 = input.From.To2D() + (p - input.From.To2D()).Rotated(beta);
var cp2 = input.From.To2D() + (p - input.From.To2D()).Rotated(-beta);
pos = cp1.Distance(pos, true) < cp2.Distance(pos, true) ? cp1 : cp2;
}
}
return new PredictionOutput
{
Input = input, CastPosition = pos.To3D(), UnitPosition = p.To3D(),
Hitchance =
PathTracker.GetCurrentPath(input.Unit).Time < 0.1d
? HitChance.VeryHigh
: HitChance.High
};
}
tT += tB;
}
}
var position = path.Last();
return new PredictionOutput
{
Input = input, CastPosition = position.To3D(), UnitPosition = position.To3D(),
Hitchance = HitChance.Medium
};
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="ft">if set to <c>true</c>, will add extra delay to the spell..</param>
/// <param name="checkCollision">if set to <c>true</c>, checks collision.</param>
/// <returns>PredictionOutput.</returns>
internal static PredictionOutput GetPrediction(PredictionInput input, bool ft, bool checkCollision)
{
PredictionOutput result = null;
if (!input.Unit.IsValidTarget(float.MaxValue, false))
{
return new PredictionOutput();
}
if (ft)
{
//Increase the delay due to the latency and server tick:
input.Delay += Game.Ping / 2000f + 0.06f;
if (input.Aoe)
{
return AoePrediction.GetPrediction(input);
}
}
//Target too far away.
if (Math.Abs(input.Range - float.MaxValue) > float.Epsilon
&& input.Unit.Distance(input.RangeCheckFrom, true) > Math.Pow(input.Range * 1.5, 2))
{
return new PredictionOutput { Input = input };
}
//Unit is dashing.
if (input.Unit.IsDashing())
{
result = GetDashingPrediction(input);
}
else
{
//Unit is immobile.
var remainingImmobileT = UnitIsImmobileUntil(input.Unit);
if (remainingImmobileT >= 0d)
{
result = GetImmobilePrediction(input, remainingImmobileT);
}
else
{
input.Range = input.Range * CommonMenu.Instance.Item("PredMaxRange").GetValue<Slider>().Value / 100f;
}
}
//Normal prediction
if (result == null)
{
result = GetStandardPrediction(input);
}
//Check if the unit position is in range
if (Math.Abs(input.Range - float.MaxValue) > float.Epsilon)
{
if (result.Hitchance >= HitChance.High
&& input.RangeCheckFrom.Distance(input.Unit.Position, true)
> Math.Pow(input.Range + input.RealRadius * 3 / 4, 2))
{
result.Hitchance = HitChance.Medium;
}
if (input.RangeCheckFrom.Distance(result.UnitPosition, true)
> Math.Pow(input.Range + (input.Type == SkillshotType.SkillshotCircle ? input.RealRadius : 0), 2))
{
result.Hitchance = HitChance.OutOfRange;
}
if (input.RangeCheckFrom.Distance(result.CastPosition, true) > Math.Pow(input.Range, 2))
{
if (result.Hitchance != HitChance.OutOfRange)
{
result.CastPosition = input.RangeCheckFrom
+ input.Range
* (result.UnitPosition - input.RangeCheckFrom).To2D().Normalized().To3D();
}
else
{
result.Hitchance = HitChance.OutOfRange;
}
}
}
//Check for collision
if (checkCollision && input.Collision)
{
var positions = new List<Vector3> { result.UnitPosition, result.CastPosition, input.Unit.Position };
var originalUnit = input.Unit;
result.CollisionObjects = Collision.GetCollision(positions, input);
result.CollisionObjects.RemoveAll(x => x.NetworkId == originalUnit.NetworkId);
result.Hitchance = result.CollisionObjects.Count > 0 ? HitChance.Collision : result.Hitchance;
}
return result;
}
/// <summary>
/// Gets the standard prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
internal static PredictionOutput GetStandardPrediction(PredictionInput input)
{
var speed = input.Unit.MoveSpeed;
if (input.Unit.Distance(input.From, true) < 200 * 200)
{
//input.Delay /= 2;
speed /= 1.5f;
}
var result = GetPositionOnPath(input, input.Unit.GetWaypoints(), speed);
if (result.Hitchance >= HitChance.High && input.Unit is Obj_AI_Hero)
{
}
return result;
}
/// <summary>
/// Gets the time the unit is immobile untill.
/// </summary>
/// <param name="unit">The unit.</param>
/// <returns>System.Double.</returns>
internal static double UnitIsImmobileUntil(Obj_AI_Base unit)
{
var result =
unit.Buffs.Where(
buff =>
buff.IsActive && Game.Time <= buff.EndTime
&& (buff.Type == BuffType.Charm || buff.Type == BuffType.Knockup || buff.Type == BuffType.Stun
|| buff.Type == BuffType.Suppression || buff.Type == BuffType.Snare))
.Aggregate(0d, (current, buff) => Math.Max(current, buff.EndTime));
return (result - Game.Time);
}
#endregion
}
/// <summary>
/// Calculates area of effect prediction.
/// </summary>
internal static class AoePrediction
{
#region Public Methods and Operators
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(PredictionInput input)
{
switch (input.Type)
{
case SkillshotType.SkillshotCircle:
return Circle.GetPrediction(input);
case SkillshotType.SkillshotCone:
return Cone.GetPrediction(input);
case SkillshotType.SkillshotLine:
return Line.GetPrediction(input);
}
return new PredictionOutput();
}
#endregion
#region Methods
/// <summary>
/// Gets the possible targets.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>List<PossibleTarget>.</returns>
internal static List<PossibleTarget> GetPossibleTargets(PredictionInput input)
{
var result = new List<PossibleTarget>();
var originalUnit = input.Unit;
foreach (var enemy in
HeroManager.Enemies.FindAll(
h =>
h.NetworkId != originalUnit.NetworkId
&& h.IsValidTarget((input.Range + 200 + input.RealRadius), true, input.RangeCheckFrom)))
{
input.Unit = enemy;
var prediction = Prediction.GetPrediction(input, false, false);
if (prediction.Hitchance >= HitChance.High)
{
result.Add(new PossibleTarget { Position = prediction.UnitPosition.To2D(), Unit = enemy });
}
}
return result;
}
#endregion
/// <summary>
/// Represents a circular skillshot.
/// </summary>
public static class Circle
{
#region Public Methods and Operators
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(PredictionInput input)
{
var mainTargetPrediction = Prediction.GetPrediction(input, false, true);
var posibleTargets = new List<PossibleTarget>
{
new PossibleTarget
{
Position = mainTargetPrediction.UnitPosition.To2D(),
Unit = input.Unit
}
};
if (mainTargetPrediction.Hitchance >= HitChance.Medium)
{
//Add the posible targets in range:
posibleTargets.AddRange(GetPossibleTargets(input));
}
while (posibleTargets.Count > 1)
{
var mecCircle = MEC.GetMec(posibleTargets.Select(h => h.Position).ToList());
if (mecCircle.Radius <= input.RealRadius - 10
&& Vector2.DistanceSquared(mecCircle.Center, input.RangeCheckFrom.To2D())
< input.Range * input.Range)
{
return new PredictionOutput
{
AoeTargetsHit = posibleTargets.Select(h => (Obj_AI_Hero)h.Unit).ToList(),
CastPosition = mecCircle.Center.To3D(),
UnitPosition = mainTargetPrediction.UnitPosition,
Hitchance = mainTargetPrediction.Hitchance, Input = input,
_aoeTargetsHitCount = posibleTargets.Count
};
}
float maxdist = -1;
var maxdistindex = 1;
for (var i = 1; i < posibleTargets.Count; i++)
{
var distance = Vector2.DistanceSquared(posibleTargets[i].Position, posibleTargets[0].Position);
if (distance > maxdist || maxdist.CompareTo(-1) == 0)
{
maxdistindex = i;
maxdist = distance;
}
}
posibleTargets.RemoveAt(maxdistindex);
}
return mainTargetPrediction;
}
#endregion
}
/// <summary>
/// Represents a conical skillshot.
/// </summary>
public static class Cone
{
#region Public Methods and Operators
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>PredictionOutput.</returns>
public static PredictionOutput GetPrediction(PredictionInput input)
{
var mainTargetPrediction = Prediction.GetPrediction(input, false, true);
var posibleTargets = new List<PossibleTarget>
{
new PossibleTarget
{
Position = mainTargetPrediction.UnitPosition.To2D(),
Unit = input.Unit
}
};
if (mainTargetPrediction.Hitchance >= HitChance.Medium)
{
//Add the posible targets in range:
posibleTargets.AddRange(GetPossibleTargets(input));
}
if (posibleTargets.Count > 1)
{
var candidates = new List<Vector2>();
foreach (var target in posibleTargets)
{
target.Position = target.Position - input.From.To2D();
}
for (var i = 0; i < posibleTargets.Count; i++)
{
for (var j = 0; j < posibleTargets.Count; j++)
{
if (i != j)
{
var p = (posibleTargets[i].Position + posibleTargets[j].Position) * 0.5f;
if (!candidates.Contains(p))
{
candidates.Add(p);
}
}
}
}
var bestCandidateHits = -1;
var bestCandidate = new Vector2();
var positionsList = posibleTargets.Select(t => t.Position).ToList();
foreach (var candidate in candidates)
{
var hits = GetHits(candidate, input.Range, input.Radius, positionsList);
if (hits > bestCandidateHits)
{
bestCandidate = candidate;
bestCandidateHits = hits;
}
}
if (bestCandidateHits > 1 && input.From.To2D().Distance(bestCandidate, true) > 50 * 50)
{
return new PredictionOutput
{
Hitchance = mainTargetPrediction.Hitchance, _aoeTargetsHitCount = bestCandidateHits,
UnitPosition = mainTargetPrediction.UnitPosition,
CastPosition = bestCandidate.To3D(), Input = input
};
}
}
return mainTargetPrediction;
}
#endregion
#region Methods
/// <summary>
/// Gets the hits.
/// </summary>