-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathMinionManager.cs
286 lines (248 loc) · 9.75 KB
/
MinionManager.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
#region LICENSE
/*
Copyright 2014 - 2014 LeagueSharp
MinionManager.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.Collections.Generic;
using System.Linq;
using SharpDX;
#endregion
namespace LeagueSharp.Common
{
public enum MinionOrderTypes
{
None,
Health,
MaxHealth
}
public enum MinionTeam
{
Neutral,
Ally,
Enemy,
NotAlly,
NotAllyForEnemy,
All
}
public enum MinionTypes
{
Ranged,
Melee,
All,
Wards //TODO
}
public static class MinionManager
{
/// <summary>
/// Returns the minions in range from From.
/// </summary>
public static List<Obj_AI_Base> GetMinions(Vector3 from,
float range,
MinionTypes type = MinionTypes.All,
MinionTeam team = MinionTeam.Enemy,
MinionOrderTypes order = MinionOrderTypes.Health)
{
var result = (from minion in ObjectManager.Get<Obj_AI_Minion>()
where minion.IsValidTarget(range, false, @from)
let minionTeam = minion.Team
where
team == MinionTeam.Neutral && minionTeam == GameObjectTeam.Neutral ||
team == MinionTeam.Ally &&
minionTeam ==
(ObjectManager.Player.Team == GameObjectTeam.Chaos ? GameObjectTeam.Chaos : GameObjectTeam.Order) ||
team == MinionTeam.Enemy &&
minionTeam ==
(ObjectManager.Player.Team == GameObjectTeam.Chaos ? GameObjectTeam.Order : GameObjectTeam.Chaos) ||
team == MinionTeam.NotAlly && minionTeam != ObjectManager.Player.Team ||
team == MinionTeam.NotAllyForEnemy &&
(minionTeam == ObjectManager.Player.Team || minionTeam == GameObjectTeam.Neutral) ||
team == MinionTeam.All
where
minion.IsMelee() && type == MinionTypes.Melee || !minion.IsMelee() && type == MinionTypes.Ranged ||
type == MinionTypes.All
where IsMinion(minion) || minionTeam == GameObjectTeam.Neutral
select minion).Cast<Obj_AI_Base>().ToList();
switch (order)
{
case MinionOrderTypes.Health:
result = result.OrderBy(o => o.Health).ToList();
break;
case MinionOrderTypes.MaxHealth:
result = result.OrderBy(o => o.MaxHealth).Reverse().ToList();
break;
}
return result;
}
public static List<Obj_AI_Base> GetMinions(float range,
MinionTypes type = MinionTypes.All,
MinionTeam team = MinionTeam.Enemy,
MinionOrderTypes order = MinionOrderTypes.Health)
{
return GetMinions(ObjectManager.Player.ServerPosition, range, type, team, order);
}
public static bool IsMinion(Obj_AI_Minion minion, bool includeWards = false)
{
var name = minion.CharData.BaseSkinName.ToLower();
return name.Contains("minion") || includeWards && IsWard(name);
}
public static bool IsWard(string baseSkinName)
{
return baseSkinName.Contains("ward") || baseSkinName.Contains("trinket");
}
/// <summary>
/// Returns the point where, when casted, the circular spell with hit the maximum amount of minions.
/// </summary>
public static FarmLocation GetBestCircularFarmLocation(List<Vector2> minionPositions,
float width,
float range,
int useMECMax = 9)
{
var result = new Vector2();
var minionCount = 0;
var startPos = ObjectManager.Player.ServerPosition.To2D();
range = range * range;
if (minionPositions.Count == 0)
{
return new FarmLocation(result, minionCount);
}
/* Use MEC to get the best positions only when there are less than 9 positions because it causes lag with more. */
if (minionPositions.Count <= useMECMax)
{
var subGroups = GetCombinations(minionPositions);
foreach (var subGroup in subGroups)
{
if (subGroup.Count > 0)
{
var circle = MEC.GetMec(subGroup);
if (circle.Radius <= width && circle.Center.Distance(startPos, true) <= range)
{
minionCount = subGroup.Count;
return new FarmLocation(circle.Center, minionCount);
}
}
}
}
else
{
foreach (var pos in minionPositions)
{
if (pos.Distance(startPos, true) <= range)
{
var count = minionPositions.Count(pos2 => pos.Distance(pos2, true) <= width * width);
if (count >= minionCount)
{
result = pos;
minionCount = count;
}
}
}
}
return new FarmLocation(result, minionCount);
}
/// <summary>
/// Returns the point where, when casted, the lineal spell with hit the maximum amount of minions.
/// </summary>
public static FarmLocation GetBestLineFarmLocation(List<Vector2> minionPositions, float width, float range)
{
var result = new Vector2();
var minionCount = 0;
var startPos = ObjectManager.Player.ServerPosition.To2D();
var posiblePositions = new List<Vector2>();
posiblePositions.AddRange(minionPositions);
var max = minionPositions.Count;
for (var i = 0; i < max; i++)
{
for (var j = 0; j < max; j++)
{
if (minionPositions[j] != minionPositions[i])
{
posiblePositions.Add((minionPositions[j] + minionPositions[i]) / 2);
}
}
}
foreach (var pos in posiblePositions)
{
if (pos.Distance(startPos, true) <= range * range)
{
var endPos = startPos + range * (pos - startPos).Normalized();
var count =
minionPositions.Count(pos2 => pos2.Distance(startPos, endPos, true, true) <= width * width);
if (count >= minionCount)
{
result = endPos;
minionCount = count;
}
}
}
return new FarmLocation(result, minionCount);
}
public static List<Vector2> GetMinionsPredictedPositions(List<Obj_AI_Base> minions,
float delay,
float width,
float speed,
Vector3 from,
float range,
bool collision,
SkillshotType stype,
Vector3 rangeCheckFrom = new Vector3())
{
from = from.To2D().IsValid() ? from : ObjectManager.Player.ServerPosition;
return (from minion in minions
select
Prediction.GetPrediction(
new PredictionInput
{
Unit = minion,
Delay = delay,
Radius = width,
Speed = speed,
From = @from,
Range = range,
Collision = collision,
Type = stype,
RangeCheckFrom = rangeCheckFrom
})
into pos
where pos.Hitchance >= HitChance.High
select pos.UnitPosition.To2D()).ToList();
}
/*
from: https://stackoverflow.com/questions/10515449/generate-all-combinations-for-a-list-of-strings :^)
*/
/// <summary>
/// Returns all the subgroup combinations that can be made from a group
/// </summary>
private static List<List<Vector2>> GetCombinations(List<Vector2> allValues)
{
var collection = new List<List<Vector2>>();
for (var counter = 0; counter < (1 << allValues.Count); ++counter)
{
var combination = allValues.Where((t, i) => (counter & (1 << i)) == 0).ToList();
collection.Add(combination);
}
return collection;
}
public struct FarmLocation
{
public int MinionsHit;
public Vector2 Position;
public FarmLocation(Vector2 position, int minionsHit)
{
Position = position;
MinionsHit = minionsHit;
}
}
}
}