forked from LeagueSharp/LeagueSharp.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spell.cs
1437 lines (1276 loc) · 51 KB
/
Spell.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 LeagueSharp.Common.Data;
using LeagueSharp.Data.Enumerations;
using SharpDX;
/// <summary>
/// This class allows you to handle the spells easily.
/// </summary>
public class Spell
{
#region Fields
/// <summary>
/// check if the spell is being channeled
/// </summary>
public bool IsChanneling = false;
/// <summary>
/// Diffrenet object names
/// </summary>
private readonly string[] _deleteObject =
{
"Fiddlesticks_Base_Drain.troy", "katarina_deathLotus_tar.troy",
"Galio_Base_R_explo.troy", "Malzahar_Base_R_Beam.troy",
"ReapTheWhirlwind_green_cas.troy",
};
/// <summary>
/// Diffrenet spell process names
/// </summary>
private readonly string[] _processName =
{
"DrainChannel", "KatarinaR", "Crowstorm", "GalioIdolOfDurand",
"AlZaharNetherGrasp", "ReapTheWhirlwind"
};
/// <summary>
/// Last time casting has been issued
/// </summary>
private int _cancelSpellIssue;
/// <summary>
/// The tick the charged spell was casted at.
/// </summary>
private int _chargedCastedT;
/// <summary>
/// The tick the charged request was sent at.
/// </summary>
private int _chargedReqSentT;
/// <summary>
/// The from position.
/// </summary>
private Vector3 _from;
/// <summary>
/// The range of the spell
/// </summary>
private float _range;
/// <summary>
/// The position to check the range from.
/// </summary>
private Vector3 _rangeCheckFrom;
/// <summary>
/// The width
/// </summary>
private float _width;
#endregion
#region Constructors and Destructors
public Spell()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Spell" /> class.
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="range">The range.</param>
/// <param name="damageType">Type of the damage.</param>
public Spell(
SpellSlot slot,
float range = float.MaxValue,
TargetSelector.DamageType damageType = TargetSelector.DamageType.Physical)
{
this.Slot = slot;
this.Range = range;
this.DamageType = damageType;
// Default values
this.MinHitChance = HitChance.VeryHigh;
}
/// <summary>
/// Initializes a spell using SpellDb defined values
/// </summary>
/// <param name="slot">The SpellSlot</param>
/// <param name="useSpellDbValues">
/// Doesn't matter if it's true or false, using this override will automatically use SpellDb
/// Values.
/// </param>
public Spell(SpellSlot slot, bool useSpellDbValues)
{
this.Slot = slot;
var spellData = SpellDatabase.GetBySpellSlot(slot, ObjectManager.Player.CharData.BaseSkinName);
// Charged Spell:
if (spellData.ChargedSpellName != "")
{
this.ChargedBuffName = spellData.ChargedBuffName;
this.ChargedMaxRange = spellData.ChargedMaxRange;
this.ChargedMinRange = spellData.ChargedMinRange;
this.ChargedSpellName = spellData.ChargedSpellName;
this.ChargeDuration = spellData.ChargeDuration;
this.Delay = spellData.Delay;
this.Range = spellData.Range;
this.Width = spellData.Radius > 0 && spellData.Radius < 30000
? spellData.Radius
: ((spellData.Width > 0 && spellData.Width < 30000) ? spellData.Width : 30000);
this.Collision = (spellData.CollisionObjects != null
&& spellData.CollisionObjects.Any(
obj => obj == LeagueSharp.Data.Enumerations.CollisionableObjects.Minions));
this.Speed = spellData.MissileSpeed;
this.IsChargedSpell = true;
this.Type = SpellDatabase.GetSkillshotTypeFromSpellType(spellData.SpellType);
return;
}
// Skillshot:
if (spellData.CastType.Any(type => type == CastType.Position || type == CastType.Direction))
{
this.Delay = spellData.Delay;
this.Range = spellData.Range;
this.Width = spellData.Radius > 0 && spellData.Radius < 30000
? spellData.Radius
: ((spellData.Width > 0 && spellData.Width < 30000) ? spellData.Width : 30000);
this.Collision = (spellData.CollisionObjects != null
&& spellData.CollisionObjects.Any(
obj => obj == LeagueSharp.Data.Enumerations.CollisionableObjects.Minions));
this.Speed = spellData.MissileSpeed;
this.IsSkillshot = true;
this.Type = SpellDatabase.GetSkillshotTypeFromSpellType(spellData.SpellType);
return;
}
// Targeted:
this.Range = spellData.Range;
this.Delay = spellData.Delay;
this.Speed = spellData.MissileSpeed;
this.IsSkillshot = false;
}
#endregion
#region Enums
/// <summary>
/// The state of the spell after being cases.
/// </summary>
public enum CastStates
{
/// <summary>
/// The spell was successfully casted
/// </summary>
SuccessfullyCasted,
/// <summary>
/// The spell was not ready
/// </summary>
NotReady,
/// <summary>
/// The spell was not casted
/// </summary>
NotCasted,
/// <summary>
/// The spell was out of range
/// </summary>
OutOfRange,
/// <summary>
/// There is a collision.
/// </summary>
Collision,
/// <summary>
/// There is not enough targets
/// </summary>
NotEnoughTargets,
/// <summary>
/// The spell has a low hit chance
/// </summary>
LowHitChance,
}
#endregion
#region Public Properties
/// <summary>
/// Adds the Enemies hitbox to the range value
/// </summary>
public bool AddEnemyHitboxToRange { get; set; }
/// <summary>
/// Adds the Players hitbox to the range value
/// </summary>
public bool AddSelfHitboxToRange { get; set; }
/// <summary>
/// Allow user to cancel channeling
/// </summary>
public bool CanBeCanceledByUser { get; set; }
/// <summary>
/// Gets or sets the name of the charged buff.
/// </summary>
/// <value>The name of the charged buff.</value>
public string ChargedBuffName { get; set; }
/// <summary>
/// Gets or sets the charged maximum range.
/// </summary>
/// <value>The charged maximum range.</value>
public int ChargedMaxRange { get; set; }
/// <summary>
/// Gets or sets the charged minimum range.
/// </summary>
/// <value>The charged minimum range.</value>
public int ChargedMinRange { get; set; }
/// <summary>
/// Gets or sets the name of the charged spell.
/// </summary>
/// <value>The name of the charged spell.</value>
public string ChargedSpellName { get; set; }
/// <summary>
/// Gets or sets the duration of the charge.
/// </summary>
/// <value>The duration of the charge.</value>
public int ChargeDuration { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Spell" /> has collision.
/// </summary>
/// <value><c>true</c> if the spell has collision; otherwise, <c>false</c>.</value>
public bool Collision { get; set; }
/// <summary>
/// Returns the cooldown of the spell.
/// </summary>
/// <value>The cooldown.</value>
public float Cooldown
{
get
{
var coolDown = ObjectManager.Player.Spellbook.GetSpell(this.Slot).CooldownExpires;
return Game.Time < coolDown ? coolDown - Game.Time : 0;
}
}
/// <summary>
/// Gets or sets the type of the damage.
/// </summary>
/// <value>The type of the damage.</value>
public TargetSelector.DamageType DamageType { get; set; }
/// <summary>
/// Gets or sets the delay.
/// </summary>
/// <value>The delay.</value>
public float Delay { get; set; }
/// <summary>
/// Gets or sets from position.
/// </summary>
/// <value>From position.</value>
public Vector3 From
{
get
{
return !this._from.To2D().IsValid() ? ObjectManager.Player.ServerPosition : this._from;
}
set
{
this._from = value;
}
}
/// <summary>
/// Gets the spell data instance.
/// </summary>
/// <value>The spell data instance.</value>
public SpellDataInst Instance
{
get
{
return ObjectManager.Player.Spellbook.GetSpell(this.Slot);
}
}
/// <summary>
/// Is spell type channel
/// </summary>
public bool IsChannelTypeSpell { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is charged spell.
/// </summary>
/// <value><c>true</c> if this instance is charged spell; otherwise, <c>false</c>.</value>
public bool IsChargedSpell { get; set; }
/// <summary>
/// Gets a value indicating whether this instance is charging a charged spell.
/// </summary>
/// <value><c>true</c> if this instance is charging a charged spell; otherwise, <c>false</c>.</value>
public bool IsCharging
{
get
{
if (!this.Slot.IsReady()) return false;
return ObjectManager.Player.HasBuff(this.ChargedBuffName)
|| Utils.TickCount - this._chargedCastedT < 300 + Game.Ping;
}
}
/// <summary>
/// Gets or sets a value indicating whether this instance is skillshot.
/// </summary>
/// <value><c>true</c> if this instance is skillshot; otherwise, <c>false</c>.</value>
public bool IsSkillshot { get; set; }
/// <summary>
/// Gets or sets the last cast attempt tick.
/// </summary>
/// <value>The last cast attempt tick.</value>
public int LastCastAttemptT { get; set; }
/// <summary>
/// Should the spell be interuptable by casting other spells
/// </summary>
public bool LetSpellcancel { get; set; }
/// <summary>
/// Gets the level of the spell.
/// </summary>
/// <value>The level of the spell.</value>
public int Level
{
get
{
return ObjectManager.Player.Spellbook.GetSpell(this.Slot).Level;
}
}
/// <summary>
/// Returns the amount of mana the spell costs to cast
/// </summary>
/// <value>The mana cost.</value>
public float ManaCost
{
get
{
return ObjectManager.Player.Spellbook.GetSpell(this.Slot).ManaCost;
}
}
/// <summary>
/// Gets or sets the minimum hit chance.
/// </summary>
/// <value>The minimum hit chance.</value>
public HitChance MinHitChance { get; set; }
/// <summary>
/// Gets or sets the range.
/// </summary>
/// <value>The range.</value>
public float Range
{
get
{
var baseRange = this._range;
if (this.AddSelfHitboxToRange)
{
baseRange += ObjectManager.Player.BoundingRadius;
}
if (!this.IsChargedSpell)
{
return baseRange;
}
if (this.IsCharging)
{
return this.ChargedMinRange
+ Math.Min(
this.ChargedMaxRange - this.ChargedMinRange,
(Utils.TickCount - this._chargedCastedT) * (this.ChargedMaxRange - this.ChargedMinRange)
/ this.ChargeDuration - 150);
}
return this.ChargedMaxRange;
}
set
{
this._range = value;
}
}
/// <summary>
/// Gets or sets the position to check the range from.
/// </summary>
/// <value>Yhe position to check the range from.</value>
public Vector3 RangeCheckFrom
{
get
{
return !this._rangeCheckFrom.To2D().IsValid()
? ObjectManager.Player.ServerPosition
: this._rangeCheckFrom;
}
set
{
this._rangeCheckFrom = value;
}
}
/// <summary>
/// Gets the range squared.
/// </summary>
/// <value>The range squared.</value>
public float RangeSqr
{
get
{
return this.Range * this.Range;
}
}
/// <summary>
/// Gets or sets the spell slot.
/// </summary>
/// <value>The slot.</value>
public SpellSlot Slot { get; set; }
/// <summary>
/// Gets or sets the speed.
/// </summary>
/// <value>The speed.</value>
public float Speed { get; set; }
/// <summary>
/// Is spell targettable
/// </summary>
public bool TargetSpellCancel { get; set; }
/// <summary>
/// Gets or sets the type of skillshot.
/// </summary>
/// <value>The type of skillshot.</value>
public SkillshotType Type { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
public float Width
{
get
{
return this._width;
}
set
{
this._width = value;
this.WidthSqr = value * value;
}
}
/// <summary>
/// Gets the width squared.
/// </summary>
/// <value>The width squared.</value>
public float WidthSqr { get; private set; }
#endregion
#region Public Methods and Operators
/// <summary>
/// Returns if a spell can be cast and the target is in range.
/// </summary>
/// <param name="unit">The unit.</param>
/// <returns><c>true</c> if this instance can cast on the specified unit; otherwise, <c>false</c>.</returns>
public bool CanCast(Obj_AI_Base unit)
{
return this.Slot.IsReady() && unit.IsValidTarget(this.Range);
}
/// <summary>
/// Casts the spell to the unit using the prediction if its an skillshot.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="packetCast">if set to <c>true</c>, uses packets to cast the spell.</param>
/// <param name="aoe">if set to <c>true</c>, the prediction will try to hit as many enemies as possible.</param>
/// <returns>CastStates.</returns>
public CastStates Cast(Obj_AI_Base unit, bool packetCast = false, bool aoe = false)
{
return this._cast(unit, packetCast, aoe);
}
/// <summary>
/// Casts the spell on the player.
/// </summary>
/// <param name="packetCast">if set to <c>true</c> uses packets to cast the spell.</param>
/// <returns><c>true</c> if the spell was casted sucessfully, <c>false</c> otherwise.</returns>
public bool Cast(bool packetCast = false)
{
return this.CastOnUnit(ObjectManager.Player, packetCast);
}
/// <summary>
/// Casts the spell from a position to a position.
/// </summary>
/// <param name="fromPosition">From position.</param>
/// <param name="toPosition">To position.</param>
/// <returns><c>true</c> if the spell was sucessfully casted, <c>false</c> otherwise.</returns>
public bool Cast(Vector2 fromPosition, Vector2 toPosition)
{
return this.Cast(fromPosition.To3D(), toPosition.To3D());
}
/// <summary>
/// Casts the spell from a position to a position.
/// </summary>
/// <param name="fromPosition">From position.</param>
/// <param name="toPosition">To position.</param>
/// <returns><c>true</c> if the spell was sucessfully casted, <c>false</c> otherwise.</returns>
public bool Cast(Vector3 fromPosition, Vector3 toPosition)
{
if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return false;
}
return this.Slot.IsReady() && ObjectManager.Player.Spellbook.CastSpell(this.Slot, fromPosition, toPosition);
}
/// <summary>
/// Casts the spell to the position.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="packetCast">if set to <c>true</c> uses packets to cast the spell</param>
/// <returns><c>true</c> if the spell was casted successfully, <c>false</c> otherwise.</returns>
public bool Cast(Vector2 position, bool packetCast = false)
{
if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return false;
}
return this.Cast(position.To3D(), packetCast);
}
/// <summary>
/// Casts the spell to the position.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="packetCast">if set to <c>true</c> uses packets to cast the spell.</param>
/// <returns><c>true</c> if the spell was casted sucessfully, <c>false</c> otherwise.</returns>
public bool Cast(Vector3 position, bool packetCast = false)
{
if (!this.Slot.IsReady())
{
return false;
}
this.LastCastAttemptT = Utils.TickCount;
if (this.IsChargedSpell)
{
if (this.IsCharging)
{
ShootChargedSpell(this.Slot, position);
}
else
{
this.StartCharging();
}
}
else if (this.IsChannelTypeSpell)
{
if (this.TargetSpellCancel)
{
this.CastCancelSpell(position);
}
else
{
this.CastCancelSpell();
}
}
else if (packetCast)
{
return ObjectManager.Player.Spellbook.CastSpell(this.Slot, position, false);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(this.Slot, position);
}
return false;
}
public void CastCancelSpell()
{
if (!this.IsChanneling && Utils.TickCount - this._cancelSpellIssue > 400 + Game.Ping)
{
ObjectManager.Player.Spellbook.CastSpell(this.Slot);
this._cancelSpellIssue = Utils.TickCount;
}
}
public void CastCancelSpell(Vector3 position)
{
if (!this.IsChanneling && Utils.TickCount - this._cancelSpellIssue > 400 + Game.Ping)
{
ObjectManager.Player.Spellbook.CastSpell(this.Slot, position);
this._cancelSpellIssue = Utils.TickCount;
}
}
/// <summary>
/// Casts the spell if the hitchance equals the set hitchance.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="hitChance">The hit chance.</param>
/// <param name="packetCast">if set to <c>true</c> [packet cast].</param>
/// <returns><c>true</c> if the spell was successfully casted, <c>false</c> otherwise.</returns>
public bool CastIfHitchanceEquals(Obj_AI_Base unit, HitChance hitChance, bool packetCast = false)
{
var currentHitchance = this.MinHitChance;
this.MinHitChance = hitChance;
var castResult = this._cast(unit, packetCast, false, false);
this.MinHitChance = currentHitchance;
return castResult == CastStates.SuccessfullyCasted;
}
/// <summary>
/// Casts the spell if it will hit the set targets.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="minTargets">The minimum targets.</param>
/// <param name="packetCast">if set to <c>true</c> [packet cast].</param>
/// <returns><c>true</c> if the spell was successfully casted, <c>false</c> otherwise.</returns>
public bool CastIfWillHit(Obj_AI_Base unit, int minTargets = 5, bool packetCast = false)
{
var castResult = this._cast(unit, packetCast, true, false, minTargets);
return castResult == CastStates.SuccessfullyCasted;
}
/// <summary>
/// Spell will be casted on the best target found with the Spell.GetTarget method.
/// </summary>
/// <param name="extraRange">The extra range.</param>
/// <param name="packetCast">if set to <c>true</c>, casts the spell with packets..</param>
/// <param name="aoe">if set to <c>true</c>, the prediction will try to hit as many enemies as possible.</param>
/// <returns>CastStates.</returns>
public CastStates CastOnBestTarget(float extraRange = 0, bool packetCast = false, bool aoe = false)
{
if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return CastStates.NotCasted;
}
var target = this.GetTarget(extraRange);
return target != null ? this.Cast(target, packetCast, aoe) : CastStates.NotCasted;
}
/// <summary>
/// Casts the targetted spell on the unit.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="packetCast">if set to <c>true</c> [packet cast].</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool CastOnUnit(Obj_AI_Base unit, bool packetCast = false)
{
if (!this.Slot.IsReady() || this.From.Distance(unit.ServerPosition, true) > this.GetRangeSqr(unit))
{
return false;
}
if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return false;
}
this.LastCastAttemptT = Utils.TickCount;
if (packetCast)
{
return ObjectManager.Player.Spellbook.CastSpell(this.Slot, unit, false);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(this.Slot, unit);
}
}
/// <summary>
/// Counts the hits.
/// </summary>
/// <param name="units">The units.</param>
/// <param name="castPosition">The cast position.</param>
/// <returns>System.Int32.</returns>
public int CountHits(List<Obj_AI_Base> units, Vector3 castPosition)
{
var points = units.Select(unit => this.GetPrediction(unit).UnitPosition).ToList();
return this.CountHits(points, castPosition);
}
/// <summary>
/// Counts the hits.
/// </summary>
/// <param name="points">The points.</param>
/// <param name="castPosition">The cast position.</param>
/// <returns>System.Int32.</returns>
public int CountHits(List<Vector3> points, Vector3 castPosition)
{
return points.Count(point => this.WillHit(point, castPosition));
}
/// <summary>
/// Gets the circular farm location.
/// </summary>
/// <param name="minionPositions">The minion positions.</param>
/// <param name="overrideWidth">Width of the override.</param>
/// <returns>MinionManager.FarmLocation.</returns>
public MinionManager.FarmLocation GetCircularFarmLocation(
List<Obj_AI_Base> minionPositions,
float overrideWidth = -1)
{
var positions = MinionManager.GetMinionsPredictedPositions(
minionPositions,
this.Delay,
this.Width,
this.Speed,
this.From,
this.Range,
false,
SkillshotType.SkillshotCircle);
return this.GetCircularFarmLocation(positions, overrideWidth);
}
/// <summary>
/// Gets the circular farm location.
/// </summary>
/// <param name="minionPositions">The minion positions.</param>
/// <param name="overrideWidth">Width of the override.</param>
/// <returns>MinionManager.FarmLocation.</returns>
public MinionManager.FarmLocation GetCircularFarmLocation(
List<Vector2> minionPositions,
float overrideWidth = -1)
{
return MinionManager.GetBestCircularFarmLocation(
minionPositions,
overrideWidth >= 0 ? overrideWidth : this.Width,
this.Range);
}
/// <summary>
/// Gets the collision.
/// </summary>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <param name="delayOverride">The delay override.</param>
/// <returns>List<Obj_AI_Base>.</returns>
public List<Obj_AI_Base> GetCollision(Vector2 from, List<Vector2> to, float delayOverride = -1)
{
return Common.Collision.GetCollision(
to.Select(h => h.To3D()).ToList(),
new PredictionInput
{
From = from.To3D(), Type = this.Type, Radius = this.Width,
Delay = delayOverride > 0 ? delayOverride : this.Delay, Speed = this.Speed
});
}
/// <summary>
/// Gets the damage that the skillshot will deal to the target using the damage library.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="stage">The stage.</param>
/// <returns>System.Single.</returns>
public float GetDamage(Obj_AI_Base target, int stage = 0)
{
return (float)ObjectManager.Player.GetSpellDamage(target, this.Slot, stage);
}
/// <summary>
/// Returns the unit health when the spell hits the unit.
/// </summary>
/// <param name="unit">The unit.</param>
/// <returns>System.Single.</returns>
public float GetHealthPrediction(Obj_AI_Base unit)
{
var time = (int)(this.Delay * 1000 + this.From.Distance(unit.ServerPosition) / this.Speed - 100);
return HealthPrediction.GetHealthPrediction(unit, time);
}
/// <summary>
/// Gets the hit count.
/// </summary>
/// <param name="hitChance">The hit chance.</param>
/// <returns>System.Single.</returns>
public float GetHitCount(HitChance hitChance = HitChance.High)
{
return HeroManager.Enemies.Select(e => this.GetPrediction(e)).Count(p => p.Hitchance >= hitChance);
}
/// <summary>
/// Gets the line farm location.
/// </summary>
/// <param name="minionPositions">The minion positions.</param>
/// <param name="overrideWidth">Width of the override.</param>
/// <returns>MinionManager.FarmLocation.</returns>
public MinionManager.FarmLocation GetLineFarmLocation(
List<Obj_AI_Base> minionPositions,
float overrideWidth = -1)
{
var positions = MinionManager.GetMinionsPredictedPositions(
minionPositions,
this.Delay,
this.Width,
this.Speed,
this.From,
this.Range,
false,
SkillshotType.SkillshotLine);
return this.GetLineFarmLocation(positions, overrideWidth >= 0 ? overrideWidth : this.Width);
}
/// <summary>
/// Gets the line farm location.
/// </summary>
/// <param name="minionPositions">The minion positions.</param>
/// <param name="overrideWidth">Width of the override.</param>
/// <returns>MinionManager.FarmLocation.</returns>
public MinionManager.FarmLocation GetLineFarmLocation(List<Vector2> minionPositions, float overrideWidth = -1)
{
return MinionManager.GetBestLineFarmLocation(
minionPositions,
overrideWidth >= 0 ? overrideWidth : this.Width,
this.Range);
}
/// <summary>
/// Gets the prediction.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="aoe">if set to <c>true</c>, the prediction will try to hit as many enemies.</param>
/// <param name="overrideRange">The override range.</param>
/// <param name="collisionable">The collisionable.</param>
/// <returns>PredictionOutput.</returns>
public PredictionOutput GetPrediction(
Obj_AI_Base unit,
bool aoe = false,
float overrideRange = -1,
CollisionableObjects[] collisionable = null)
{
return
Prediction.GetPrediction(
new PredictionInput
{
Unit = unit, Delay = this.Delay, Radius = this.Width, Speed = this.Speed, From = this.From,
Range = (overrideRange > 0) ? overrideRange : this.Range, Collision = this.Collision,
Type = this.Type, RangeCheckFrom = this.RangeCheckFrom, Aoe = aoe,
CollisionObjects =
collisionable ?? new[] { CollisionableObjects.Heroes, CollisionableObjects.Minions }
});
}
/// <summary>
/// Gets the range the spell has when casted to target
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public float GetRange(Obj_AI_Base target)
{
var result = this.Range;
if (this.AddEnemyHitboxToRange && target != null)
{
result += target.BoundingRadius;
}
return result;
}
/// <summary>
/// Gets the range sqared the spell has when casted to target
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public float GetRangeSqr(Obj_AI_Base target)
{
var result = this.GetRange(target);
return result * result;
}
/// <summary>
/// Returns the best target found using the current TargetSelector mode.
/// Please make sure to set the Spell.DamageType Property to the type of damage this spell does (if not done on
/// initialization).
/// </summary>
/// <param name="extraRange">The extra range.</param>
/// <param name="champsToIgnore">The champs to ignore.</param>
/// <returns>Obj_AI_Hero.</returns>
public Obj_AI_Hero GetTarget(float extraRange = 0, IEnumerable<Obj_AI_Hero> champsToIgnore = null)
{
return TargetSelector.GetTarget(this.Range + extraRange, this.DamageType, true, champsToIgnore, this.From);
}
/// <summary>
/// Returns if the GameObject is in range of the spell.
/// </summary>
/// <param name="obj">The object.</param>
/// <param name="range">The range.</param>
/// <returns><c>true</c> if the spell is in range of the unit; otherwise, <c>false</c>.</returns>
public bool IsInRange(GameObject obj, float range = -1)
{
return this.IsInRange(
obj is Obj_AI_Base ? (obj as Obj_AI_Base).ServerPosition.To2D() : obj.Position.To2D(),
range);
}
/// <summary>
/// Returns if the position is in range of the spell.
/// </summary>
/// <param name="point">The point.</param>
/// <param name="range">The range.</param>
/// <returns><c>true</c> if the specified location is in range of the spell; otherwise, <c>false</c>.</returns>
public bool IsInRange(Vector3 point, float range = -1)
{
return this.IsInRange(point.To2D(), range);
}
/// <summary>
/// Returns if the Vector2 is in range of the spell.
/// </summary>
/// <param name="point">The point.</param>
/// <param name="range">The range.</param>
/// <returns><c>true</c> if the specified location is in range of the spell; otherwise, <c>false</c>.</returns>
public bool IsInRange(Vector2 point, float range = -1)
{
return this.RangeCheckFrom.To2D().Distance(point, true) < (range < 0 ? this.RangeSqr : range * range);
}
/// <summary>
/// Gets the damage that the skillshot will deal to the target using the damage lib and returns if the target is
/// killable or not.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="stage">The stage.</param>
/// <returns><c>true</c> if the specified target is killable; otherwise, <c>false</c>.</returns>
public bool IsKillable(Obj_AI_Base target, int stage = 0)
{
return ObjectManager.Player.GetSpellDamage(target, this.Slot, stage) > target.Health;
}
/// <summary>
/// Sets the spell to be a charged spell.
/// </summary>
/// <param name="spellName">Name of the spell.</param>
/// <param name="buffName">Name of the buff.</param>
/// <param name="minRange">The minimum range.</param>
/// <param name="maxRange">The maximum range.</param>
/// <param name="deltaT">The delta time.</param>
public void SetCharged(string spellName, string buffName, int minRange, int maxRange, float deltaT)
{
this.IsChargedSpell = true;
this.ChargedSpellName = spellName;
this.ChargedBuffName = buffName;
this.ChargedMinRange = minRange;
this.ChargedMaxRange = maxRange;