-
Notifications
You must be signed in to change notification settings - Fork 11
/
AutoLevler.cs
273 lines (248 loc) · 9.51 KB
/
AutoLevler.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using LeagueSharp;
using LeagueSharp.Common;
namespace SAwareness
{
internal class AutoLevler
{
private int[] _priority = {0, 0, 0, 0};
private int[] _sequence;
private int _useMode;
public AutoLevler()
{
//LoadLevelFile();
Game.OnGameUpdate += Game_OnGameUpdate;
}
~AutoLevler()
{
Game.OnGameUpdate -= Game_OnGameUpdate;
}
public bool IsActive()
{
return Menu.Misc.GetActive() && Menu.AutoLevler.GetActive();
}
private void Game_OnGameUpdate(EventArgs args)
{
if (!IsActive())
return;
var stringList = Menu.AutoLevler.GetMenuItem("SAwarenessAutoLevlerSMode").GetValue<StringList>();
if (stringList.SelectedIndex == 0)
{
_useMode = 0;
_priority = new[]
{
Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPrioritySliderQ").GetValue<Slider>().Value,
Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPrioritySliderW").GetValue<Slider>().Value,
Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPrioritySliderE").GetValue<Slider>().Value,
Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPrioritySliderR").GetValue<Slider>().Value
};
}
else if (stringList.SelectedIndex == 1)
{
_useMode = 1;
}
else
{
_useMode = 2;
}
Obj_AI_Hero player = ObjectManager.Player;
SpellSlot[] spellSlotst = GetSortedPriotitySlots();
if (player.SpellTrainingPoints > 0)
{
//TODO: Add level logic// try levelup spell, if fails level another up etc.
if (_useMode == 0 && Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPriorityActive").GetValue<bool>())
{
if (Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPriorityFirstSpellsActive").GetValue<bool>())
{
player.Spellbook.LevelUpSpell(GetCurrentSpell());
return;
}
SpellSlot[] spellSlots = GetSortedPriotitySlots();
for (int slotId = 0; slotId <= 3; slotId++)
{
int spellLevel = player.Spellbook.GetSpell(spellSlots[slotId]).Level;
player.Spellbook.LevelUpSpell(spellSlots[slotId]);
if (player.Spellbook.GetSpell(spellSlots[slotId]).Level != spellLevel)
break;
}
}
else if (_useMode == 1)
{
if (Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerSequence")
.GetMenuItem("SAwarenessAutoLevlerSequenceActive").GetValue<bool>())
{
SpellSlot spellSlot = GetSpellSlot(_sequence[player.Level - 1]);
player.Spellbook.LevelUpSpell(spellSlot);
}
}
else
{
if (Menu.AutoLevler.GetMenuItem("SAwarenessAutoLevlerSMode").GetValue<StringList>().SelectedIndex == 2)
{
if (ObjectManager.Player.Level == 6 ||
ObjectManager.Player.Level == 11 ||
ObjectManager.Player.Level == 16)
{
player.Spellbook.LevelUpSpell(SpellSlot.R);
}
}
}
}
}
public void SetPriorities(int priorityQ, int priorityW, int priorityE, int priorityR)
{
_sequence[0] = priorityQ;
_sequence[1] = priorityW;
_sequence[2] = priorityE;
_sequence[3] = priorityR;
}
private void LoadLevelFile()
{
//TODO: Read Level File for sequence leveling.
string loc = Assembly.GetExecutingAssembly().Location;
loc = loc.Remove(loc.LastIndexOf("\\", StringComparison.Ordinal));
loc = loc + "\\Config\\SAwareness\\autolevel.conf";
if (!File.Exists(loc))
{
//Download.DownloadFile("127.0.0.1", loc);
}
try
{
StreamReader sr = File.OpenText(loc);
ReadLevelFile(sr);
}
catch (Exception)
{
Console.WriteLine("Couldn't load autolevel.conf. Using priority mode.");
_useMode = 0;
}
}
private void ReadLevelFile(StreamReader streamReader)
{
var sequence = new int[18];
while (!streamReader.EndOfStream)
{
String line = streamReader.ReadLine();
String champion = "";
if (line != null && line.Length > line.IndexOf("="))
champion = line.Remove(line.IndexOf("="));
if (!champion.Contains(ObjectManager.Player.ChampionName))
continue;
if (line != null)
{
string temp = line.Remove(0, line.IndexOf("=") + 2);
for (int i = 0; i < 18; i++)
{
sequence[i] = Int32.Parse(temp.Remove(1));
temp = temp.Remove(0, 1);
}
}
break;
}
_sequence = sequence;
}
private SpellSlot GetSpellSlot(int id)
{
var spellSlot = SpellSlot.Unknown;
switch (id)
{
case 0:
spellSlot = SpellSlot.Q;
break;
case 1:
spellSlot = SpellSlot.W;
break;
case 2:
spellSlot = SpellSlot.E;
break;
case 3:
spellSlot = SpellSlot.R;
break;
}
return spellSlot;
}
private SpellSlot[] GetSortedPriotitySlots()
{
int[] listOld = _priority;
var listNew = new SpellSlot[4];
listNew = ToSpellSlot(listOld, listNew);
//listNew = listNew.OrderByDescending(c => c).ToList();
return listNew;
}
private SpellSlot[] ToSpellSlot(int[] listOld, SpellSlot[] listNew)
{
for (int i = 0; i <= 3; i++)
{
switch (listOld[i])
{
case 0:
listNew[0] = GetSpellSlot(i);
break;
case 1:
listNew[1] = GetSpellSlot(i);
break;
case 2:
listNew[2] = GetSpellSlot(i);
break;
case 3:
listNew[3] = GetSpellSlot(i);
break;
}
}
return listNew;
}
private SpellSlot GetCurrentSpell()
{
SpellSlot[] spellSlot = null;
switch (Menu.AutoLevler.GetMenuSettings("SAwarenessAutoLevlerPriority")
.GetMenuItem("SAwarenessAutoLevlerPriorityFirstSpells").GetValue<StringList>().SelectedIndex)
{
case 0:
spellSlot = new[] {SpellSlot.Q, SpellSlot.W, SpellSlot.E};
break;
case 1:
spellSlot = new[] { SpellSlot.Q, SpellSlot.E, SpellSlot.W };
break;
case 2:
spellSlot = new[] { SpellSlot.W, SpellSlot.Q, SpellSlot.E };
break;
case 3:
spellSlot = new[] { SpellSlot.W, SpellSlot.E, SpellSlot.Q };
break;
case 4:
spellSlot = new[] { SpellSlot.E, SpellSlot.Q, SpellSlot.W };
break;
case 5:
spellSlot = new[] { SpellSlot.E, SpellSlot.W, SpellSlot.Q };
break;
}
return spellSlot[ObjectManager.Player.Level - 1];
}
//private List<SpellSlot> SortAlgo(List<int> listOld, List<SpellSlot> listNew)
//{
// int highestPriority = -1;
// for (int i = 0; i < listOld.Count; i++)
// {
// int prio = _priority[i];
// if (highestPriority < prio)
// {
// highestPriority = prio;
// listNew.Add(GetSpellSlot(i));
// listOld.Remove(_priority[i]);
// }
// }
// if (listOld.Count > 1)
// listNew = SortAlgo(listOld, listNew);
// return listNew;
//}
}
}