-
Notifications
You must be signed in to change notification settings - Fork 244
/
AntiGapcloser.cs
237 lines (196 loc) · 6.84 KB
/
AntiGapcloser.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
namespace LeagueSharp.Common
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using LeagueSharp.Data.DataTypes;
using SharpDX;
/// <summary>
/// The delegate for the <see cref="AntiGapcloser.OnEnemyGapcloser" /> event.
/// </summary>
/// <param name="gapcloser">The gapcloser.</param>
public delegate void OnGapcloseH(ActiveGapcloser gapcloser);
/// <summary>
/// The type of gapcloser.
/// </summary>
public enum GapcloserType
{
/// <summary>
/// The gapcloser used a skillshot ability.
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly",
Justification = "Reviewed. Suppression is OK here.")]
Skillshot,
/// <summary>
/// The gapcloser used a targeted ability.
/// </summary>
Targeted
}
/// <summary>
/// Represents a gapcloser.
/// </summary>
public struct Gapcloser
{
#region Fields
/// <summary>
/// The champion name
/// </summary>
public string ChampionName;
/// <summary>
/// The skill type
/// </summary>
public GapcloserType SkillType;
/// <summary>
/// The slot
/// </summary>
public SpellSlot Slot;
/// <summary>
/// The spell name
/// </summary>
public string SpellName;
#endregion
}
/// <summary>
/// Represents an active gapcloser.
/// </summary>
public struct ActiveGapcloser
{
#region Fields
/// <summary>
/// The end
/// </summary>
public Vector3 End;
/// <summary>
/// The sender
/// </summary>
public Obj_AI_Hero Sender;
/// <summary>
/// The skill type
/// </summary>
public GapcloserType SkillType;
/// <summary>
/// The slot
/// </summary>
public SpellSlot Slot;
/// <summary>
/// The start
/// </summary>
public Vector3 Start;
/// <summary>
/// The tick count
/// </summary>
public int TickCount;
#endregion
}
/// <summary>
/// Provides events and information about gapclosers.
/// </summary>
public static class AntiGapcloser
{
#region Static Fields
/// <summary>
/// The active gapclosers
/// </summary>
public static List<ActiveGapcloser> ActiveGapclosers = new List<ActiveGapcloser>();
/// <summary>
/// The gapcloser spells
/// </summary>
public static List<Gapcloser> Spells;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes static members of the <see cref="AntiGapcloser" /> class.
/// </summary>
static AntiGapcloser()
{
Spells =
LeagueSharp.Data.Data.Get<GapcloserData>()
.SpellsList.Select(
x =>
new Gapcloser
{
ChampionName = x.Key,
SkillType =
x.Value.SkillType == LeagueSharp.Data.Enumerations.GapcloserType.Skillshot
? GapcloserType.Skillshot
: GapcloserType.Targeted,
Slot = x.Value.Slot, SpellName = x.Value.SpellName
})
.ToList();
Initialize();
}
#endregion
#region Public Events
/// <summary>
/// Occurs on an incoming enemy gapcloser.
/// </summary>
public static event OnGapcloseH OnEnemyGapcloser;
#endregion
#region Public Methods and Operators
public static void Initialize()
{
Game.OnUpdate += Game_OnGameUpdate;
Obj_AI_Base.OnProcessSpellCast += Obj_AI_Base_OnProcessSpellCast;
}
public static void Shutdown()
{
Game.OnUpdate -= Game_OnGameUpdate;
Obj_AI_Base.OnProcessSpellCast -= Obj_AI_Base_OnProcessSpellCast;
}
#endregion
#region Methods
/// <summary>
/// Fired when the game updates.
/// </summary>
/// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void Game_OnGameUpdate(EventArgs args)
{
ActiveGapclosers.RemoveAll(entry => Utils.TickCount > entry.TickCount + 900);
if (OnEnemyGapcloser == null)
{
return;
}
foreach (var gapcloser in
ActiveGapclosers.Where(gapcloser => gapcloser.Sender.IsValidTarget())
.Where(
gapcloser =>
gapcloser.SkillType == GapcloserType.Targeted
|| (gapcloser.SkillType == GapcloserType.Skillshot
&& ObjectManager.Player.Distance(gapcloser.Sender, true) < 250000))) // 500 * 500
{
OnEnemyGapcloser(gapcloser);
}
}
/// <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 static void Obj_AI_Base_OnProcessSpellCast(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs args)
{
if (!SpellIsGapcloser(args))
{
return;
}
ActiveGapclosers.Add(
new ActiveGapcloser
{
Start = args.Start, End = args.End, Sender = (Obj_AI_Hero)sender, TickCount = Utils.TickCount,
SkillType =
(args.Target != null && args.Target.IsMe) ? GapcloserType.Targeted : GapcloserType.Skillshot,
Slot = ((Obj_AI_Hero)sender).GetSpellSlot(args.SData.Name)
});
}
/// <summary>
/// Checks if a spell is a gapcloser.
/// </summary>
/// <param name="args">The <see cref="GameObjectProcessSpellCastEventArgs" /> instance containing the event data.</param>
/// <returns></returns>
private static bool SpellIsGapcloser(GameObjectProcessSpellCastEventArgs args)
{
return Spells.Any(spell => spell.SpellName == args.SData.Name.ToLower());
}
#endregion
}
}