-
Notifications
You must be signed in to change notification settings - Fork 244
/
Items.cs
360 lines (318 loc) · 11.1 KB
/
Items.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
namespace LeagueSharp.Common
{
using System.Collections.Generic;
using System.Linq;
using SharpDX;
/// <summary>
/// Provides methods regarding items.
/// </summary>
public static class Items
{
#region Public Methods and Operators
/// <summary>
/// Returns true if the player has the item and its not on cooldown.
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
public static bool CanUseItem(string name)
{
foreach (var slot in ObjectManager.Player.InventoryItems.Where(slot => slot.Name == name))
{
return ObjectManager.Player.Spellbook.CanUseSpell((SpellSlot)(slot.Slot + (int)SpellSlot.Item1))
== SpellState.Ready;
}
return false;
}
/// <summary>
/// Returns true if the player has the item and its not on cooldown.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns></returns>
public static bool CanUseItem(int id)
{
foreach (var slot in ObjectManager.Player.InventoryItems.Where(slot => slot.Id == (ItemId)id))
{
return ObjectManager.Player.Spellbook.CanUseSpell((SpellSlot)(slot.Slot + (int)SpellSlot.Item1))
== SpellState.Ready;
}
return false;
}
/// <summary>
/// Returns the ward slot.
/// </summary>
/// <returns></returns>
public static InventorySlot GetWardSlot()
{
var wardIds = new[]
{
2045, 2049, 2050, 2301, 2302, 2303, 3340, 3361, 3362, 3711, 1408, 1409, 1410, 1411, 2043, 2055
};
return (from wardId in wardIds
where CanUseItem(wardId)
select ObjectManager.Player.InventoryItems.FirstOrDefault(slot => slot.Id == (ItemId)wardId))
.FirstOrDefault();
}
/// <summary>
/// Returns true if the hero has the item.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="hero">The hero.</param>
/// <returns></returns>
public static bool HasItem(string name, Obj_AI_Hero hero = null)
{
return (hero ?? ObjectManager.Player).InventoryItems.Any(slot => slot.Name == name);
}
/// <summary>
/// Returns true if the hero has the item.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="hero">The hero.</param>
/// <returns></returns>
public static bool HasItem(int id, Obj_AI_Hero hero = null)
{
return (hero ?? ObjectManager.Player).InventoryItems.Any(slot => slot.Id == (ItemId)id);
}
/// <summary>
/// Casts the item on the target.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static bool UseItem(string name, Obj_AI_Base target = null)
{
foreach (var slot in ObjectManager.Player.InventoryItems.Where(slot => slot.Name == name))
{
if (target != null)
{
return ObjectManager.Player.Spellbook.CastSpell(slot.SpellSlot, target);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(slot.SpellSlot);
}
}
return false;
}
/// <summary>
/// Casts the item on the target.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static bool UseItem(int id, Obj_AI_Base target = null)
{
foreach (var slot in ObjectManager.Player.InventoryItems.Where(slot => slot.Id == (ItemId)id))
{
if (target != null)
{
return ObjectManager.Player.Spellbook.CastSpell(slot.SpellSlot, target);
}
else
{
return ObjectManager.Player.Spellbook.CastSpell(slot.SpellSlot);
}
}
return false;
}
/// <summary>
/// Casts the item on a Vector2 position.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="position">The position.</param>
/// <returns></returns>
public static bool UseItem(int id, Vector2 position)
{
return UseItem(id, position.To3D());
}
/// <summary>
/// Casts the item on a Vector3 position.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="position">The position.</param>
/// <returns></returns>
public static bool UseItem(int id, Vector3 position)
{
if (position != Vector3.Zero)
{
foreach (var slot in ObjectManager.Player.InventoryItems.Where(slot => slot.Id == (ItemId)id))
{
return ObjectManager.Player.Spellbook.CastSpell(slot.SpellSlot, position);
}
}
return false;
}
#endregion
/// <summary>
/// Represents an item.
/// </summary>
public class Item
{
#region Fields
/// <summary>
/// The range
/// </summary>
private float _range;
/// <summary>
/// The range squared
/// </summary>
private float _rangeSqr;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="Item" /> class.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="range">The range.</param>
public Item(int id, float range = 0)
{
this.Id = id;
this.Range = range;
}
#endregion
#region Public Properties
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public int Id { get; private set; }
/// <summary>
/// Gets or sets the range.
/// </summary>
/// <value>
/// The range.
/// </value>
public float Range
{
get
{
return this._range;
}
set
{
this._range = value;
this._rangeSqr = value * value;
}
}
/// <summary>
/// Gets the range squared.
/// </summary>
/// <value>
/// The range squared.
/// </value>
public float RangeSqr
{
get
{
return this._rangeSqr;
}
}
/// <summary>
/// Gets the slots.
/// </summary>
/// <value>
/// The slots.
/// </value>
public List<SpellSlot> Slots
{
get
{
return
ObjectManager.Player.InventoryItems.Where(slot => slot.Id == (ItemId)this.Id)
.Select(slot => slot.SpellSlot)
.ToList();
}
}
#endregion
#region Public Methods and Operators
/// <summary>
/// Buys the item.
/// </summary>
public void Buy()
{
ObjectManager.Player.BuyItem((ItemId)this.Id);
}
/// <summary>
/// Casts this instance.
/// </summary>
/// <returns></returns>
public bool Cast()
{
return UseItem(this.Id);
}
/// <summary>
/// Casts on the specified target.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public bool Cast(Obj_AI_Base target)
{
return UseItem(this.Id, target);
}
/// <summary>
/// Casts at the specified position.
/// </summary>
/// <param name="position">The position.</param>
/// <returns></returns>
public bool Cast(Vector2 position)
{
return UseItem(this.Id, position);
}
/// <summary>
/// Casts at the specified position.
/// </summary>
/// <param name="position">The position.</param>
/// <returns></returns>
public bool Cast(Vector3 position)
{
return UseItem(this.Id, position);
}
/// <summary>
/// Determines whether the specified target is in range of the item.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public bool IsInRange(Obj_AI_Base target)
{
return this.IsInRange(target.ServerPosition);
}
/// <summary>
/// Determines whether the specified vector is in range of the item.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public bool IsInRange(Vector2 target)
{
return this.IsInRange(target.To3D());
}
/// <summary>
/// Determines whether the specified vector is in range of the item.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public bool IsInRange(Vector3 target)
{
return ObjectManager.Player.ServerPosition.Distance(target, true) < this.RangeSqr;
}
/// <summary>
/// Determines whether the specified target owns this item.
/// </summary>
/// <param name="target">The target.</param>
/// <returns></returns>
public bool IsOwned(Obj_AI_Hero target = null)
{
return HasItem(this.Id, target);
}
/// <summary>
/// Determines whether this instance is ready.
/// </summary>
/// <returns></returns>
public bool IsReady()
{
return CanUseItem(this.Id);
}
#endregion
}
}
}