-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathTargetSelector.cs
591 lines (498 loc) · 21.5 KB
/
TargetSelector.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
#region LICENSE
/*
Copyright 2014 - 2014 LeagueSharp
TargetSelector.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;
using Color = System.Drawing.Color;
#endregion
namespace LeagueSharp.Common
{
public class TargetSelector
{
#region Enum
public enum DamageType
{
Magical,
Physical,
True
}
public enum TargetingMode
{
AutoPriority,
LowHP,
MostAD,
MostAP,
Closest,
NearMouse,
LessAttack,
LessCast,
MostStack
}
#endregion
#region Vars
public static TargetingMode Mode = TargetingMode.AutoPriority;
private static Menu _configMenu;
private static Obj_AI_Hero _selectedTargetObjAiHero;
private static bool UsingCustom;
public static bool CustomTS
{
get { return UsingCustom; }
set
{
UsingCustom = value;
if (value)
{
Game.OnWndProc -= GameOnOnWndProc;
Drawing.OnDraw -= DrawingOnOnDraw;
}
else
{
Game.OnWndProc += GameOnOnWndProc;
Drawing.OnDraw += DrawingOnOnDraw;
}
}
}
#endregion
#region EventArgs
private static void DrawingOnOnDraw(EventArgs args)
{
if (_selectedTargetObjAiHero.IsValidTarget() && _configMenu != null &&
_configMenu.Item("FocusSelected").GetValue<bool>() &&
_configMenu.Item("SelTColor").GetValue<Circle>().Active)
{
Render.Circle.DrawCircle(
_selectedTargetObjAiHero.Position, 150, _configMenu.Item("SelTColor").GetValue<Circle>().Color, 7,
true);
}
var a = (_configMenu.Item("ForceFocusSelectedK").GetValue<KeyBind>().Active ||
_configMenu.Item("ForceFocusSelectedK2").GetValue<KeyBind>().Active) &&
_configMenu.Item("ForceFocusSelectedKeys").GetValue<bool>();
_configMenu.Item("ForceFocusSelectedKeys").Permashow(SelectedTarget != null && a);
_configMenu.Item("ForceFocusSelected").Permashow(_configMenu.Item("ForceFocusSelected").GetValue<bool>());
_configMenu.Item("stack.count").Show(_configMenu.Item("TargetingMode").GetValue<StringList>().SelectedIndex == 8);
}
private static void GameOnOnWndProc(WndEventArgs args)
{
if (args.Msg != (uint) WindowsMessages.WM_LBUTTONDOWN)
{
return;
}
_selectedTargetObjAiHero =
HeroManager.Enemies
.FindAll(hero => hero.IsValidTarget() && hero.Distance(Game.CursorPos, true) < 40000) // 200 * 200
.OrderBy(h => h.Distance(Game.CursorPos, true)).FirstOrDefault();
}
#endregion
#region Functions
public static Obj_AI_Hero SelectedTarget
{
get
{
return (_configMenu != null && _configMenu.Item("FocusSelected").GetValue<bool>()
? _selectedTargetObjAiHero
: null);
}
}
/// <summary>
/// Sets the priority of the hero
/// </summary>
public static void SetPriority(Obj_AI_Hero hero, int newPriority)
{
if (_configMenu == null || _configMenu.Item("TargetSelector" + hero.ChampionName + "Priority") == null)
{
return;
}
var p = _configMenu.Item("TargetSelector" + hero.ChampionName + "Priority").GetValue<Slider>();
p.Value = Math.Max(1, Math.Min(5, newPriority));
_configMenu.Item("TargetSelector" + hero.ChampionName + "Priority").SetValue(p);
}
/// <summary>
/// Returns the priority of the hero
/// </summary>
public static float GetPriority(Obj_AI_Hero hero)
{
var p = 1;
if (_configMenu != null && _configMenu.Item("TargetSelector" + hero.ChampionName + "Priority") != null)
{
p = _configMenu.Item("TargetSelector" + hero.ChampionName + "Priority").GetValue<Slider>().Value;
}
switch (p)
{
case 2:
return 1.5f;
case 3:
return 1.75f;
case 4:
return 2f;
case 5:
return 2.5f;
default:
return 1f;
}
}
private static int GetPriorityFromDb(string championName)
{
string[] p1 =
{
"Alistar", "Amumu", "Bard", "Blitzcrank", "Braum", "Cho'Gath", "Dr. Mundo", "Garen", "Gnar",
"Hecarim", "Janna", "Jarvan IV", "Leona", "Lulu", "Malphite", "Nami", "Nasus", "Nautilus", "Nunu",
"Olaf", "Rammus", "Renekton", "Sejuani", "Shen", "Shyvana", "Singed", "Sion", "Skarner", "Sona",
"Soraka", "Taric", "TahmKench", "Thresh", "Volibear", "Warwick", "MonkeyKing", "Yorick", "Zac", "Zyra"
};
string[] p2 =
{
"Aatrox", "Darius", "Elise", "Evelynn", "Galio", "Gangplank", "Gragas", "Irelia", "Jax",
"Lee Sin", "Maokai", "Morgana", "Nocturne", "Pantheon", "Poppy", "Rengar", "Rumble", "Ryze", "Swain",
"Trundle", "Tryndamere", "Udyr", "Urgot", "Vi", "XinZhao", "RekSai"
};
string[] p3 =
{
"Akali", "Diana", "Ekko", "Fiddlesticks", "Fiora", "Fizz", "Heimerdinger", "Jayce", "Kassadin",
"Kayle", "Kha'Zix", "Lissandra", "Mordekaiser", "Nidalee", "Riven", "Shaco", "Vladimir", "Yasuo",
"Zilean"
};
string[] p4 =
{
"Ahri", "Anivia", "Annie", "Ashe", "Azir", "Brand", "Caitlyn", "Cassiopeia", "Corki", "Draven",
"Ezreal", "Graves", "Jinx", "Kalista", "Karma", "Karthus", "Katarina", "Kennen", "KogMaw", "Kindred",
"Leblanc", "Lucian", "Lux", "Malzahar", "MasterYi", "MissFortune", "Orianna", "Quinn", "Sivir", "Syndra",
"Talon", "Teemo", "Tristana", "TwistedFate", "Twitch", "Varus", "Vayne", "Veigar", "Velkoz", "Viktor",
"Xerath", "Zed", "Ziggs"
};
if (p1.Contains(championName))
{
return 1;
}
if (p2.Contains(championName))
{
return 2;
}
if (p3.Contains(championName))
{
return 3;
}
return p4.Contains(championName) ? 4 : 1;
}
internal static void Initialize()
{
CustomEvents.Game.OnGameLoad += args =>
{
Menu config = new Menu("Target Selector", "TargetSelector");
_configMenu = config;
Menu focusMenu = new Menu("Focus Target Settings", "FocusTargetSettings");
focusMenu.AddItem(new MenuItem("FocusSelected", "Focus selected target").SetShared().SetValue(true));
focusMenu.AddItem(
new MenuItem("SelTColor", "Focus selected target color").SetShared().SetValue(new Circle(true, Color.Red)));
focusMenu.AddItem(
new MenuItem("ForceFocusSelected", "Only attack selected target").SetShared().SetValue(false));
focusMenu.AddItem(new MenuItem("sep", ""));
focusMenu.AddItem(
new MenuItem("ForceFocusSelectedKeys", "Enable only attack selected Keys").SetShared().SetValue(false));
focusMenu.AddItem(
new MenuItem("ForceFocusSelectedK", "Only attack selected Key"))
.SetValue(new KeyBind(32, KeyBindType.Press));
focusMenu.AddItem(
new MenuItem("ForceFocusSelectedK2", "Only attack selected Key 2"))
.SetValue(new KeyBind(32, KeyBindType.Press));
config.AddSubMenu(focusMenu);
var autoPriorityItem =
new MenuItem("AutoPriority", "Auto arrange priorities").SetShared().SetValue(false).SetTooltip("5 = Highest Priority");
autoPriorityItem.ValueChanged += autoPriorityItem_ValueChanged;
foreach (var enemy in HeroManager.Enemies)
{
config.AddItem(
new MenuItem("TargetSelector" + enemy.ChampionName + "Priority", enemy.ChampionName).SetShared()
.SetValue(
new Slider(
autoPriorityItem.GetValue<bool>() ? GetPriorityFromDb(enemy.ChampionName) : 1, 5, 1)));
if (autoPriorityItem.GetValue<bool>())
{
config.Item("TargetSelector" + enemy.ChampionName + "Priority")
.SetValue(
new Slider(
autoPriorityItem.GetValue<bool>() ? GetPriorityFromDb(enemy.ChampionName) : 1, 5, 1));
}
}
config.AddItem(autoPriorityItem);
config.AddItem(
new MenuItem("stack.count", "Stack Count").SetValue(new Slider(2, 1, 20)))
.SetTooltip("Only for Stack Mode");
config.AddItem(
new MenuItem("TargetingMode", "Target Mode").SetShared()
.SetValue(new StringList(Enum.GetNames(typeof (TargetingMode)))));
CommonMenu.Config.AddSubMenu(config);
Game.OnWndProc += GameOnOnWndProc;
Drawing.OnDraw += DrawingOnOnDraw;
};
}
public static void AddToMenu(Menu config)
{
config.AddItem(new MenuItem("Alert", "----Use TS in Common Menu----"));
}
private static void autoPriorityItem_ValueChanged(object sender, OnValueChangeEventArgs e)
{
if (!e.GetNewValue<bool>())
{
return;
}
foreach (var enemy in HeroManager.Enemies)
{
_configMenu.Item("TargetSelector" + enemy.ChampionName + "Priority")
.SetValue(new Slider(GetPriorityFromDb(enemy.ChampionName), 5, 1));
}
}
public static bool IsInvulnerable(Obj_AI_Base target, DamageType damageType, bool ignoreShields = true)
{
//Kindred's Lamb's Respite(R)
if (target.HasBuff("kindredrnodeathbuff") && target.HealthPercent <= 10)
{
return true;
}
// Tryndamere's Undying Rage (R)
if (target.HasBuff("Undying Rage") && target.Health <= target.MaxHealth * 0.10f)
{
return true;
}
// Kayle's Intervention (R)
if (target.HasBuff("JudicatorIntervention"))
{
return true;
}
// Poppy's Diplomatic Immunity (R)
if (target.HasBuff("DiplomaticImmunity") && !ObjectManager.Player.HasBuff("poppyulttargetmark"))
{
//TODO: Get the actual target mark buff name
return true;
}
if (ignoreShields)
{
return false;
}
// Morgana's Black Shield (E)
if (damageType.Equals(DamageType.Magical) && target.HasBuff("BlackShield"))
{
return true;
}
// Banshee's Veil (PASSIVE)
if (damageType.Equals(DamageType.Magical) && target.HasBuff("BansheesVeil"))
{
// TODO: Get exact Banshee's Veil buff name.
return true;
}
// Sivir's Spell Shield (E)
if (damageType.Equals(DamageType.Magical) && target.HasBuff("SivirShield"))
{
// TODO: Get exact Sivir's Spell Shield buff name
return true;
}
// Nocturne's Shroud of Darkness (W)
if (damageType.Equals(DamageType.Magical) && target.HasBuff("ShroudofDarkness"))
{
// TODO: Get exact Nocturne's Shourd of Darkness buff name
return true;
}
return false;
}
public static void SetTarget(Obj_AI_Hero hero)
{
if (hero.IsValidTarget())
{
_selectedTargetObjAiHero = hero;
}
}
public static Obj_AI_Hero GetSelectedTarget()
{
return SelectedTarget;
}
public static Obj_AI_Hero GetTarget(float range,
DamageType damageType,
bool ignoreShield = true,
IEnumerable<Obj_AI_Hero> ignoredChamps = null,
Vector3? rangeCheckFrom = null)
{
return GetTarget(ObjectManager.Player, range, damageType, ignoreShield, ignoredChamps, rangeCheckFrom);
}
public static Obj_AI_Hero GetTargetNoCollision(Spell spell,
bool ignoreShield = true,
IEnumerable<Obj_AI_Hero> ignoredChamps = null,
Vector3? rangeCheckFrom = null)
{
var t = GetTarget(ObjectManager.Player, spell.Range,
spell.DamageType, ignoreShield, ignoredChamps, rangeCheckFrom);
if (spell.Collision && spell.GetPrediction(t).Hitchance != HitChance.Collision)
{
return t;
}
return null;
}
private static bool IsValidTarget(Obj_AI_Base target,
float range,
DamageType damageType,
bool ignoreShieldSpells = true,
Vector3? rangeCheckFrom = null)
{
return target.IsValidTarget() &&
target.Distance(rangeCheckFrom ?? ObjectManager.Player.ServerPosition, true) <
Math.Pow(range <= 0 ? Orbwalking.GetRealAutoAttackRange(target) : range, 2) &&
!IsInvulnerable(target, damageType, ignoreShieldSpells);
}
private static string[] StackNames =
{
"KalistaExpungeMarker",
"vaynesilvereddebuff",
"twitchdeadlyvenom",
"EkkoStacks",
"dariushemo",
"gnarwproc",
"TahmKenchPDebuffCounter",
"varuswdebuff",
};
public static Obj_AI_Hero GetTarget(Obj_AI_Base champion,
float range,
DamageType type,
bool ignoreShieldSpells = true,
IEnumerable<Obj_AI_Hero> ignoredChamps = null,
Vector3? rangeCheckFrom = null)
{
try
{
if (ignoredChamps == null)
{
ignoredChamps = new List<Obj_AI_Hero>();
}
var damageType = (Damage.DamageType) Enum.Parse(typeof(Damage.DamageType), type.ToString());
if (_configMenu != null && IsValidTarget(
SelectedTarget, _configMenu.Item("ForceFocusSelected").GetValue<bool>() ? float.MaxValue : range,
type, ignoreShieldSpells, rangeCheckFrom))
{
return SelectedTarget;
}
if (_configMenu != null && IsValidTarget(
SelectedTarget, _configMenu.Item("ForceFocusSelectedKeys").GetValue<bool>() ? float.MaxValue : range,
type, ignoreShieldSpells, rangeCheckFrom))
{
if (_configMenu.Item("ForceFocusSelectedK").GetValue<KeyBind>().Active ||
_configMenu.Item("ForceFocusSelectedK2").GetValue<KeyBind>().Active)
{
return SelectedTarget;
}
}
if (_configMenu != null && _configMenu.Item("TargetingMode") != null &&
Mode == TargetingMode.AutoPriority)
{
var menuItem = _configMenu.Item("TargetingMode").GetValue<StringList>();
Enum.TryParse(menuItem.SList[menuItem.SelectedIndex], out Mode);
}
var targets =
HeroManager.Enemies
.FindAll(
hero =>
ignoredChamps.All(ignored => ignored.NetworkId != hero.NetworkId) &&
IsValidTarget(hero, range, type, ignoreShieldSpells, rangeCheckFrom));
switch (Mode)
{
case TargetingMode.LowHP:
return targets.MinOrDefault(hero => hero.Health);
case TargetingMode.MostAD:
return targets.MaxOrDefault(hero => hero.BaseAttackDamage + hero.FlatPhysicalDamageMod);
case TargetingMode.MostAP:
return targets.MaxOrDefault(hero => hero.BaseAbilityDamage + hero.FlatMagicDamageMod);
case TargetingMode.Closest:
return
targets.MinOrDefault(
hero =>
(rangeCheckFrom.HasValue ? rangeCheckFrom.Value : champion.ServerPosition).Distance(
hero.ServerPosition, true));
case TargetingMode.NearMouse:
return targets.MinOrDefault(hero => hero.Distance(Game.CursorPos, true));
case TargetingMode.AutoPriority:
return
targets.MaxOrDefault(
hero =>
champion.CalcDamage(hero, damageType, 100) / (1 + hero.Health) * GetPriority(hero));
case TargetingMode.LessAttack:
return
targets.MaxOrDefault(
hero =>
champion.CalcDamage(hero, Damage.DamageType.Physical, 100) / (1 + hero.Health) *
GetPriority(hero));
case TargetingMode.LessCast:
return
targets.MaxOrDefault(
hero =>
champion.CalcDamage(hero, Damage.DamageType.Magical, 100) / (1 + hero.Health) *
GetPriority(hero));
case TargetingMode.MostStack:
return targets.MaxOrDefault(hero =>
hero.Buffs.Where(x => StackNames.Contains(x.Name.ToLower()) &&
x.Count >= _configMenu.Item("stack.count").GetValue<Slider>().Value)
.Sum(buff => buff.Count));
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
return null;
}
#endregion
}
/// <summary>
/// This TS attempts to always lock the same target, useful for people getting targets for each spell, or for champions
/// that have to burst 1 target.
/// </summary>
public class LockedTargetSelector
{
public static Obj_AI_Hero _lastTarget;
private static TargetSelector.DamageType _lastDamageType;
public static Obj_AI_Hero GetTarget(float range,
TargetSelector.DamageType damageType,
bool ignoreShield = true,
IEnumerable<Obj_AI_Hero> ignoredChamps = null,
Vector3? rangeCheckFrom = null)
{
if (_lastTarget == null || !_lastTarget.IsValidTarget() || _lastDamageType != damageType)
{
var newTarget = TargetSelector.GetTarget(range, damageType, ignoreShield, ignoredChamps, rangeCheckFrom);
_lastTarget = newTarget;
_lastDamageType = damageType;
return newTarget;
}
if (_lastTarget.IsValidTarget(range) && damageType == _lastDamageType)
{
return _lastTarget;
}
var newTarget2 = TargetSelector.GetTarget(range, damageType, ignoreShield, ignoredChamps, rangeCheckFrom);
_lastTarget = newTarget2;
_lastDamageType = damageType;
return newTarget2;
}
/// <summary>
/// Unlocks the currently locked target.
/// </summary>
public static void UnlockTarget()
{
_lastTarget = null;
}
public static void AddToMenu(Menu menu)
{
TargetSelector.AddToMenu(menu);
}
}
}