forked from LeagueSharp/LeagueSharp.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpell.cs
1287 lines (1135 loc) · 45 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
#region LICENSE
/*
Copyright 2014 - 2014 LeagueSharp
Spell.cs is part of LeagueSharp.Common.
LeagueSharp.Common is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LeagueSharp.Common is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LeagueSharp.Common. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
#region
using System;
using System.Collections.Generic;
using System.Linq;
using SharpDX;
#endregion
namespace LeagueSharp.Common
{
/// <summary>
/// This class allows you to handle the spells easily.
/// </summary>
public class Spell
{
/// <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,
}
/// <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;
/// <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)
{
Slot = slot;
Range = range;
DamageType = damageType;
// Default values
MinHitChance = HitChance.VeryHigh;
}
/// <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>
/// Gets or sets the delay.
/// </summary>
/// <value>The delay.</value>
public float Delay { 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 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>
/// Gets or sets the minimum hit chance.
/// </summary>
/// <value>The minimum hit chance.</value>
public HitChance MinHitChance { get; set; }
/// <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>
/// Gets or sets the type of skillshot.
/// </summary>
/// <value>The type of skillshot.</value>
public SkillshotType Type { get; set; }
/// <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 width.
/// </summary>
/// <value>The width.</value>
public float Width
{
get { return _width; }
set
{
_width = value;
WidthSqr = value*value;
}
}
/// <summary>
/// Gets the width squared.
/// </summary>
/// <value>The width squared.</value>
public float WidthSqr { get; private set; }
/// <summary>
/// Gets the spell data instance.
/// </summary>
/// <value>The spell data instance.</value>
public SpellDataInst Instance
{
get { return ObjectManager.Player.Spellbook.GetSpell(Slot); }
}
/// <summary>
/// Gets or sets the range.
/// </summary>
/// <value>The range.</value>
public float Range
{
get
{
if (!IsChargedSpell)
{
return _range;
}
if (IsCharging)
{
return ChargedMinRange +
Math.Min(
ChargedMaxRange - ChargedMinRange,
(Utils.TickCount - _chargedCastedT)*(ChargedMaxRange - ChargedMinRange)/
ChargeDuration - 150);
}
return ChargedMaxRange;
}
set { _range = value; }
}
/// <summary>
/// Gets the range squared.
/// </summary>
/// <value>The range squared.</value>
public float RangeSqr
{
get { return Range*Range; }
}
/// <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 (!Slot.IsReady())
return false;
return ObjectManager.Player.HasBuff(ChargedBuffName) ||
Utils.TickCount - _chargedCastedT < 300 + Game.Ping;
}
}
/// <summary>
/// Gets the level of the spell.
/// </summary>
/// <value>The level of the spell.</value>
public int Level
{
get { return ObjectManager.Player.Spellbook.GetSpell(Slot).Level; }
}
/// <summary>
/// Gets or sets from position.
/// </summary>
/// <value>From position.</value>
public Vector3 From
{
get { return !_from.To2D().IsValid() ? ObjectManager.Player.ServerPosition : _from; }
set { _from = 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 !_rangeCheckFrom.To2D().IsValid() ? ObjectManager.Player.ServerPosition : _rangeCheckFrom; }
set { _rangeCheckFrom = value; }
}
/// <summary>
/// Sets spell the be a targetted spell.
/// </summary>
/// <param name="delay">The delay.</param>
/// <param name="speed">The speed.</param>
/// <param name="from">The from position.</param>
/// <param name="rangeCheckFrom">The position to check the range from.</param>
public void SetTargetted(float delay,
float speed,
Vector3 from = new Vector3(),
Vector3 rangeCheckFrom = new Vector3())
{
Delay = delay;
Speed = speed;
From = from;
RangeCheckFrom = rangeCheckFrom;
IsSkillshot = false;
}
/// <summary>
/// Sets the spell to be a skillshot.
/// </summary>
/// <param name="delay">The delay.</param>
/// <param name="width">The width.</param>
/// <param name="speed">The speed.</param>
/// <param name="collision">if set to <c>true</c>, the spell has collision.</param>
/// <param name="type">The type.</param>
/// <param name="from">From.</param>
/// <param name="rangeCheckFrom">The range check from.</param>
public void SetSkillshot(float delay,
float width,
float speed,
bool collision,
SkillshotType type,
Vector3 from = new Vector3(),
Vector3 rangeCheckFrom = new Vector3())
{
Delay = delay;
Width = width;
Speed = speed;
From = from;
Collision = collision;
Type = type;
RangeCheckFrom = rangeCheckFrom;
IsSkillshot = true;
}
/// <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)
{
IsChargedSpell = true;
ChargedSpellName = spellName;
ChargedBuffName = buffName;
ChargedMinRange = minRange;
ChargedMaxRange = maxRange;
ChargeDuration = (int) (deltaT*1000);
_chargedCastedT = 0;
Obj_AI_Base.OnProcessSpellCast += Obj_AI_Hero_OnProcessSpellCast;
Spellbook.OnUpdateChargedSpell += Spellbook_OnUpdateChargedSpell;
Spellbook.OnCastSpell += SpellbookOnCastSpell;
}
/// <summary>
/// Start charging the spell if its not charging.
/// </summary>
public void StartCharging()
{
if (!IsCharging && Utils.TickCount - _chargedReqSentT > 400 + Game.Ping)
{
ObjectManager.Player.Spellbook.CastSpell(Slot);
_chargedReqSentT = Utils.TickCount;
}
}
/// <summary>
/// Start charging the spell if its not charging.
/// </summary>
/// <param name="position">The position.</param>
public void StartCharging(Vector3 position)
{
if (!IsCharging && Utils.TickCount - _chargedReqSentT > 400 + Game.Ping)
{
ObjectManager.Player.Spellbook.CastSpell(Slot, position);
_chargedReqSentT = Utils.TickCount;
}
}
/// <summary>
/// Fired when the charged spell is updated.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="SpellbookUpdateChargedSpellEventArgs"/> instance containing the event data.</param>
void Spellbook_OnUpdateChargedSpell(Spellbook sender, SpellbookUpdateChargedSpellEventArgs args)
{
if (sender.Owner.IsMe && Utils.TickCount - _chargedReqSentT < 3000 && args.ReleaseCast)
{
args.Process = false;
}
}
/// <summary>
/// Fired when the spellbook casts a spell.
/// </summary>
/// <param name="spellbook">The spellbook.</param>
/// <param name="args">The <see cref="SpellbookCastSpellEventArgs"/> instance containing the event data.</param>
private void SpellbookOnCastSpell(Spellbook spellbook, SpellbookCastSpellEventArgs args)
{
if (args.Slot != Slot)
{
return;
}
if ((Utils.TickCount - _chargedReqSentT > 500))
{
if (IsCharging)
{
Cast(args.StartPosition.To2D());
}
}
}
/// <summary>
/// Fired when the game processes a spell cast.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="GameObjectProcessSpellCastEventArgs"/> instance containing the event data.</param>
private void Obj_AI_Hero_OnProcessSpellCast(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs args)
{
if (sender.IsMe && args.SData.Name == ChargedSpellName)
{
_chargedCastedT = Utils.TickCount;
}
}
/// <summary>
/// Updates the source position.
/// </summary>
/// <param name="from">From.</param>
/// <param name="rangeCheckFrom">The range check from.</param>
public void UpdateSourcePosition(Vector3 from = new Vector3(), Vector3 rangeCheckFrom = new Vector3())
{
From = from;
RangeCheckFrom = rangeCheckFrom;
}
/// <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 = Delay,
Radius = Width,
Speed = Speed,
From = From,
Range = (overrideRange > 0) ? overrideRange : Range,
Collision = Collision,
Type = Type,
RangeCheckFrom = RangeCheckFrom,
Aoe = aoe,
CollisionObjects =
collisionable ?? new[] {CollisionableObjects.Heroes, CollisionableObjects.Minions}
});
}
/// <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 = Type,
Radius = Width,
Delay = delayOverride > 0 ? delayOverride : Delay,
Speed = Speed
});
}
/// <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 => GetPrediction(e)).Count(p => p.Hitchance >= hitChance);
}
/// <summary>
/// Casts the spell at the specified unit.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="packetCast">if set to <c>true</c> [packet cast].</param>
/// <param name="aoe">if set to <c>true</c> [aoe].</param>
/// <param name="exactHitChance">if set to <c>true</c> [exact hit chance].</param>
/// <param name="minTargets">The minimum targets.</param>
/// <returns>CastStates.</returns>
private CastStates _cast(Obj_AI_Base unit,
bool packetCast = false,
bool aoe = false,
bool exactHitChance = false,
int minTargets = -1)
{
if (unit == null || MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return CastStates.NotCasted;
}
//Spell not ready.
if (!Slot.IsReady())
{
return CastStates.NotReady;
}
if (minTargets != -1)
{
aoe = true;
}
//Targetted spell.
if (!IsSkillshot)
{
//Target out of range
if (RangeCheckFrom.Distance(unit.ServerPosition, true) > RangeSqr)
{
return CastStates.OutOfRange;
}
LastCastAttemptT = Utils.TickCount;
if (packetCast)
{
if (!ObjectManager.Player.Spellbook.CastSpell(Slot, unit, false))
{
return CastStates.NotCasted;
}
}
else
{
//Cant cast the Spell.
if (!ObjectManager.Player.Spellbook.CastSpell(Slot, unit))
{
return CastStates.NotCasted;
}
}
return CastStates.SuccessfullyCasted;
}
//Get the best position to cast the spell.
var prediction = GetPrediction(unit, aoe);
if (minTargets != -1 && prediction.AoeTargetsHitCount < minTargets)
{
return CastStates.NotEnoughTargets;
}
//Skillshot collides.
if (prediction.CollisionObjects.Count > 0)
{
return CastStates.Collision;
}
//Target out of range.
if (RangeCheckFrom.Distance(prediction.CastPosition, true) > RangeSqr)
{
return CastStates.OutOfRange;
}
//The hitchance is too low.
if (prediction.Hitchance < MinHitChance || (exactHitChance && prediction.Hitchance != MinHitChance))
{
return CastStates.LowHitChance;
}
LastCastAttemptT = Utils.TickCount;
if (IsChargedSpell)
{
if (IsCharging)
{
ShootChargedSpell(Slot, prediction.CastPosition);
}
else
{
StartCharging();
}
}
else if (packetCast)
{
ObjectManager.Player.Spellbook.CastSpell(Slot, prediction.CastPosition, false);
}
else
{
//Cant cast the spell (actually should not happen).
if (!ObjectManager.Player.Spellbook.CastSpell(Slot, prediction.CastPosition))
{
return CastStates.NotCasted;
}
}
return CastStates.SuccessfullyCasted;
}
/// <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 (!Slot.IsReady() || From.Distance(unit.ServerPosition, true) > RangeSqr)
{
return false;
}
if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen)
{
return false;
}
LastCastAttemptT = Utils.TickCount;
if (packetCast)
{
return ObjectManager.Player.Spellbook.CastSpell(Slot, unit, false);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(Slot, unit);
}
}
/// <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 _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 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 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 Slot.IsReady() && ObjectManager.Player.Spellbook.CastSpell(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 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 (!Slot.IsReady())
{
return false;
}
LastCastAttemptT = Utils.TickCount;
if (IsChargedSpell)
{
if (IsCharging)
{
ShootChargedSpell(Slot, position);
}
else
{
StartCharging();
}
}
else if (IsChannelTypeSpell)
{
if (TargetSpellCancel)
{
CastCancelSpell(position);
}
else
{
CastCancelSpell();
}
}
else if (packetCast)
{
return ObjectManager.Player.Spellbook.CastSpell(Slot, position, false);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(Slot, position);
}
return false;
}
/// <summary>
/// Shoots the charged spell.
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="position">The position.</param>
/// <param name="releaseCast">if set to <c>true</c> [release cast].</param>
private static void ShootChargedSpell(SpellSlot slot, Vector3 position, bool releaseCast = true)
{
position.Z = NavMesh.GetHeightForPosition(position.X, position.Y);
ObjectManager.Player.Spellbook.UpdateChargedSpell(slot, position, releaseCast, false);
ObjectManager.Player.Spellbook.CastSpell(slot, position, false);
}
/// <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 = MinHitChance;
MinHitChance = hitChance;
var castResult = _cast(unit, packetCast, false, false);
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 = _cast(unit, packetCast, true, false, minTargets);
return castResult == CastStates.SuccessfullyCasted;
}
/// <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)(Delay * 1000 + From.Distance(unit.ServerPosition) / Speed - 100);
return HealthPrediction.GetHealthPrediction(unit, time);
}
/// <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, Delay, Width, Speed, From, Range, false, SkillshotType.SkillshotCircle);
return 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 : Width, Range);
}
/// <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, Delay, Width, Speed, From, Range, false, SkillshotType.SkillshotLine);
return GetLineFarmLocation(positions, overrideWidth >= 0 ? overrideWidth : 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 : Width, Range);
}
/// <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 => GetPrediction(unit).UnitPosition).ToList();
return 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 => WillHit(point, castPosition));
}
/// <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, Slot, stage);
}
/// <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(Slot).ManaCost; }
}
/// <summary>
/// Returns the cooldown of the spell.
/// </summary>
/// <value>The cooldown.</value>
public float Cooldown
{
get
{
var coolDown = ObjectManager.Player.Spellbook.GetSpell(Slot).CooldownExpires;
return Game.Time < coolDown ? coolDown - Game.Time : 0;
}
}
/// <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, Slot, stage) > target.Health;
}
/// <summary>
/// Returns if the spell will hit the unit when casted on castPosition.
/// </summary>
/// <param name="unit">The unit.</param>
/// <param name="castPosition">The cast position.</param>
/// <param name="extraWidth">Added width to the spell.</param>
/// <param name="minHitChance">The minimum hit chance.</param>
/// <returns><c>true</c> if the spell will hit the unit, <c>false</c> otherwise.</returns>
public bool WillHit(Obj_AI_Base unit,
Vector3 castPosition,
int extraWidth = 0,
HitChance minHitChance = HitChance.High)
{
var unitPosition = GetPrediction(unit);
return unitPosition.Hitchance >= minHitChance &&
WillHit(unitPosition.UnitPosition, castPosition, extraWidth);
}
/// <summary>
/// Returns if the spell will hit the point when casted on castPosition.
/// </summary>
/// <param name="point">The point.</param>