forked from LeagueSharp/LeagueSharp.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterrupter2.cs
354 lines (315 loc) · 14.2 KB
/
Interrupter2.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
#region LICENSE
/*
Copyright 2014 - 2015 LeagueSharp
Interrupter2.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;
#endregion
namespace LeagueSharp.Common
{
/// <summary>
/// Provides information an API regarding interruptable spells.
/// </summary>
public static class Interrupter2
{
/// <summary>
/// The delegate for <see cref="Interrupter2.OnInterruptableTarget"/>.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="InterruptableTargetEventArgs"/> instance containing the event data.</param>
public delegate void InterruptableTargetHandler(Obj_AI_Hero sender, InterruptableTargetEventArgs args);
/// <summary>
/// The danger level of the interruptable spell.
/// </summary>
public enum DangerLevel
{
/// <summary>
/// The low
/// </summary>
Low,
/// <summary>
/// The medium
/// </summary>
Medium,
/// <summary>
/// The high
/// </summary>
High
}
/// <summary>
/// Initializes static members of the <see cref="Interrupter2"/> class.
/// </summary>
static Interrupter2()
{
// Initialize Properties
InterruptableSpells = new Dictionary<string, List<InterruptableSpell>>();
CastingInterruptableSpell = new Dictionary<int, InterruptableSpell>();
InitializeSpells();
// Trigger LastCastedSpell
ObjectManager.Player.LastCastedspell();
// Listen to required events
Game.OnUpdate += Game_OnGameUpdate;
Obj_AI_Base.OnProcessSpellCast += Obj_AI_Base_OnProcessSpellCast;
Spellbook.OnStopCast += Spellbook_OnStopCast;
}
/// <summary>
/// Gets or sets the interruptable spells.
/// </summary>
/// <value>
/// The interruptable spells.
/// </value>
private static Dictionary<string, List<InterruptableSpell>> InterruptableSpells { get; set; }
/// <summary>
/// Gets or sets the casting interruptable spell.
/// </summary>
/// <value>
/// The casting interruptable spell.
/// </value>
private static Dictionary<int, InterruptableSpell> CastingInterruptableSpell { get; set; }
/// <summary>
/// Occurs on an interruptable target.
/// </summary>
public static event InterruptableTargetHandler OnInterruptableTarget;
/// <summary>
/// Initializes the spells.
/// </summary>
private static void InitializeSpells()
{
#region Spells
RegisterSpell("Caitlyn", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("FiddleSticks", new InterruptableSpell(SpellSlot.W, DangerLevel.Medium));
RegisterSpell("FiddleSticks", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Galio", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Janna", new InterruptableSpell(SpellSlot.R, DangerLevel.Low));
RegisterSpell("Karthus", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Katarina", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Lucian", new InterruptableSpell(SpellSlot.R, DangerLevel.High, false));
RegisterSpell("Malzahar", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("MasterYi", new InterruptableSpell(SpellSlot.W, DangerLevel.Low));
RegisterSpell("MissFortune", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Nunu", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Pantheon", new InterruptableSpell(SpellSlot.E, DangerLevel.Low));
RegisterSpell("Pantheon", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Quinn", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("RekSai", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Sion", new InterruptableSpell(SpellSlot.R, DangerLevel.Low));
RegisterSpell("Shen", new InterruptableSpell(SpellSlot.R, DangerLevel.Low));
RegisterSpell("TahmKench", new InterruptableSpell(SpellSlot.R, DangerLevel.Medium));
RegisterSpell("TwistedFate", new InterruptableSpell(SpellSlot.R, DangerLevel.Medium));
RegisterSpell("Urgot", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Velkoz", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Warwick", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Xerath", new InterruptableSpell(SpellSlot.R, DangerLevel.High));
RegisterSpell("Varus", new InterruptableSpell(SpellSlot.Q, DangerLevel.Low, false));
#endregion
}
/// <summary>
/// Registers the spell.
/// </summary>
/// <param name="champName">Name of the champ.</param>
/// <param name="spell">The spell.</param>
private static void RegisterSpell(string champName, InterruptableSpell spell)
{
if (!InterruptableSpells.ContainsKey(champName))
{
InterruptableSpells.Add(champName, new List<InterruptableSpell>());
}
InterruptableSpells[champName].Add(spell);
}
/// <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)
{
// Remove heros that have finished casting their interruptable spell
HeroManager.AllHeroes.ForEach(
hero =>
{
if (CastingInterruptableSpell.ContainsKey(hero.NetworkId) &&
!hero.Spellbook.IsCastingSpell &&
!hero.Spellbook.IsChanneling &&
!hero.Spellbook.IsCharging)
{
CastingInterruptableSpell.Remove(hero.NetworkId);
}
});
// Trigger OnInterruptableTarget event if needed
if (OnInterruptableTarget != null)
{
HeroManager.Enemies.ForEach(
enemy =>
{
var newArgs = GetInterruptableTargetData(enemy);
if (newArgs != null)
{
OnInterruptableTarget(enemy, newArgs);
}
});
}
}
/// <summary>
/// Fired when the game processes spell casts.
/// </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)
{
var target = sender as Obj_AI_Hero;
if (target != null && !CastingInterruptableSpell.ContainsKey(target.NetworkId))
{
// Check if the target is known to have interruptable spells
if (InterruptableSpells.ContainsKey(target.ChampionName))
{
// Get the interruptable spell
var spell =
InterruptableSpells[target.ChampionName].Find(
s => s.Slot == target.GetSpellSlot(args.SData.Name));
if (spell != null)
{
// Mark champ as casting interruptable spell
CastingInterruptableSpell.Add(target.NetworkId, spell);
}
}
}
}
/// <summary>
/// Fired when the spellbook stops a cast.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="args">The <see cref="SpellbookStopCastEventArgs"/> instance containing the event data.</param>
private static void Spellbook_OnStopCast(Spellbook sender, SpellbookStopCastEventArgs args)
{
var target = sender.Owner as Obj_AI_Hero;
if (target != null)
{
// Check if the spell itself stopped casting (interrupted)
if (!target.Spellbook.IsCastingSpell && !target.Spellbook.IsChanneling && !target.Spellbook.IsCharging)
{
CastingInterruptableSpell.Remove(target.NetworkId);
}
}
}
/// <summary>
/// Determines whether the target is casting an interruptable spell.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="checkMovementInterruption">if set to <c>true</c> checks if movement interrupts.</param>
/// <returns></returns>
public static bool IsCastingInterruptableSpell(this Obj_AI_Hero target, bool checkMovementInterruption = false)
{
var data = GetInterruptableTargetData(target);
return data != null && (!checkMovementInterruption || data.MovementInterrupts);
}
/// <summary>
/// Gets the interruptable target data.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public static InterruptableTargetEventArgs GetInterruptableTargetData(Obj_AI_Hero target)
{
if (target.IsValid<Obj_AI_Hero>())
{
if (CastingInterruptableSpell.ContainsKey(target.NetworkId))
{
// Return the args with spell end time
return new InterruptableTargetEventArgs(
CastingInterruptableSpell[target.NetworkId].DangerLevel, target.Spellbook.CastEndTime, CastingInterruptableSpell[target.NetworkId].MovementInterrupts);
}
}
return null;
}
/// <summary>
/// Prevents event arguments for the <see cref="Interrupter2.OnInterruptableTarget"/>
/// </summary>
public class InterruptableTargetEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="InterruptableTargetEventArgs"/> class.
/// </summary>
/// <param name="dangerLevel">The danger level.</param>
/// <param name="endTime">The end time.</param>
/// <param name="movementInterrupts">if set to <c>true</c> [movement interrupts].</param>
public InterruptableTargetEventArgs(DangerLevel dangerLevel, float endTime, bool movementInterrupts)
{
DangerLevel = dangerLevel;
EndTime = endTime;
MovementInterrupts = movementInterrupts;
}
/// <summary>
/// Gets the danger level.
/// </summary>
/// <value>
/// The danger level.
/// </value>
public DangerLevel DangerLevel { get; private set; }
/// <summary>
/// Gets the end time.
/// </summary>
/// <value>
/// The end time.
/// </value>
public float EndTime { get; private set; }
/// <summary>
/// Gets a value indicating whether movement interrupts the channel.
/// </summary>
/// <value>
/// <c>true</c> if movement interrupts the channel; otherwise, <c>false</c>.
/// </value>
public bool MovementInterrupts { get; private set; }
}
/// <summary>
/// Represents an interruptable spell.
/// </summary>
private class InterruptableSpell
{
/// <summary>
/// Initializes a new instance of the <see cref="InterruptableSpell"/> class.
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="dangerLevel">The danger level.</param>
/// <param name="movementInterrupts">if set to <c>true</c> [movement interrupts].</param>
public InterruptableSpell(SpellSlot slot, DangerLevel dangerLevel, bool movementInterrupts = true)
{
Slot = slot;
DangerLevel = dangerLevel;
MovementInterrupts = movementInterrupts;
}
/// <summary>
/// Gets or sets the slot.
/// </summary>
/// <value>
/// The slot.
/// </value>
public SpellSlot Slot { get; private set; }
/// <summary>
/// Gets or sets the danger level.
/// </summary>
/// <value>
/// The danger level.
/// </value>
public DangerLevel DangerLevel { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether movement interrupts the channel.
/// </summary>
/// <value>
/// <c>true</c> if movement interrupts the channel; otherwise, <c>false</c>.
/// </value>
public bool MovementInterrupts { get; private set; }
}
}
}