-
Notifications
You must be signed in to change notification settings - Fork 4
/
AuQW-Bot-Template-By-Bluu-Purple-Exelot.cs
604 lines (549 loc) · 19.7 KB
/
AuQW-Bot-Template-By-Bluu-Purple-Exelot.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
592
593
594
595
596
597
598
599
600
601
602
603
604
using System;
using RBot;
using System.Collections.Generic;
public class BluuPurpleTemplate
{
//-----------EDIT BELOW-------------//
public int MapNumber = 2142069;
public readonly int[] SkillOrder = { 3, 1, 2, 4 };
public int SaveStateLoops = 8700;
public int TurnInAttempts = 10;
public string[] RequiredItems = { };
public string[] EquippedItems = { };
//-----------EDIT ABOVE-------------//
public int FarmLoop;
public int SavedState;
public ScriptInterface bot => ScriptInterface.Instance;
public void ScriptMain(ScriptInterface bot)
{
if (bot.Player.Cell != "Wait") bot.Player.Jump("Wait", "Spawn");
ConfigureBotOptions();
ConfigureLiteSettings();
DeathHandler();
SkillList(SkillOrder);
EquipList(EquippedItems);
UnbankList(RequiredItems);
CheckSpace(RequiredItems);
GetDropList(RequiredItems);
while (!bot.ShouldExit())
{
while (!bot.Player.Loaded) { }
/*
* Enter Your Code Here
* Check the system functions for a list of functions you can use.
*/
}
StopBot();
}
/*------------------------------------------------------------------------------------------------------------
Invokable Functions
------------------------------------------------------------------------------------------------------------*/
/*
* These functions are used to perform a major action in AQW.
* All of them require at least one of the Auxiliary Functions listed below to be present in your script.
* Some of the functions require you to pre-declare certain integers under "public class Script"
* ItemFarm, MultiQuestFarm and HuntItemFarm will require some Background Functions to be present as well.
* All of this information can be found inside the functions. Make sure to read.
* ItemFarm("ItemName", ItemQuantity, Temporary, HuntFor, QuestID, "MonsterName", "MapName", "CellName", "PadName");
* MultiQuestFarm("MapName", "CellName", "PadName", QuestList[], "MonsterName");
* SafeEquip("ItemName");
* SafePurchase("ItemName", ItemQuantityNeeded, "MapName", "MapNumber", ShopID)
* SafeSell("ItemName", ItemQuantityNeeded)
* SafeQuestComplete(QuestID, ItemID)
* StopBot("Text", "MapName", "MapNumber", "CellName", "PadName", "Caption")
*/
/// <summary>
/// Farms you the specified quantity of the specified item with the specified quest accepted from specified monsters in the specified location. Saves States every ~5 minutes.
/// </summary>
public void ItemFarm(string ItemName, int ItemQuantity, bool Temporary = false, bool HuntFor = false, int QuestID = 0, string MonsterName = "*", string MapName = "Map", string CellName = "Enter", string PadName = "Spawn")
{
/*
* Must have the following functions in your script:
* SafeMapJoin
* SmartSaveState
* SkillList
* ExitCombat
* GetDropList OR ItemWhitelist
*
* Must have the following commands under public class Script:
* int FarmLoop = 0;
* int SavedState = 0;
*/
startFarmLoop:
if (FarmLoop > 0) goto maintainFarmLoop;
SavedState++;
FormatLog("Farm", $"Started Farming Loop {SavedState}");
goto maintainFarmLoop;
breakFarmLoop:
SmartSaveState();
FormatLog("Farm", $"Completed Farming Loop {SavedState}");
FarmLoop = 0;
goto startFarmLoop;
maintainFarmLoop:
if (Temporary)
{
if (HuntFor)
{
while (!bot.Inventory.ContainsTempItem(ItemName, ItemQuantity))
{
FarmLoop++;
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower());
if (QuestID > 0) bot.Quests.EnsureAccept(QuestID);
bot.Options.AggroMonsters = true;
AttackType("h", MonsterName);
if (FarmLoop > SaveStateLoops) goto breakFarmLoop;
}
}
else
{
while (!bot.Inventory.ContainsTempItem(ItemName, ItemQuantity))
{
FarmLoop++;
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower(), CellName, PadName);
if (bot.Player.Cell != CellName) bot.Player.Jump(CellName, PadName);
if (QuestID > 0) bot.Quests.EnsureAccept(QuestID);
bot.Options.AggroMonsters = true;
AttackType("a", MonsterName);
if (FarmLoop > SaveStateLoops) goto breakFarmLoop;
}
}
}
else
{
if (HuntFor)
{
while (!bot.Inventory.Contains(ItemName, ItemQuantity))
{
FarmLoop++;
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower());
if (QuestID > 0) bot.Quests.EnsureAccept(QuestID);
bot.Options.AggroMonsters = true;
AttackType("h", MonsterName);
if (FarmLoop > SaveStateLoops) goto breakFarmLoop;
}
}
else
{
while (!bot.Inventory.Contains(ItemName, ItemQuantity))
{
FarmLoop++;
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower(), CellName, PadName);
if (bot.Player.Cell != CellName) bot.Player.Jump(CellName, PadName);
if (QuestID > 0) bot.Quests.EnsureAccept(QuestID);
bot.Options.AggroMonsters = true;
AttackType("a", MonsterName);
if (FarmLoop > SaveStateLoops) goto breakFarmLoop;
}
}
}
}
/// <summary>
/// Farms all the quests in a given string, must all be farmable in the same room and cell.
/// </summary>
public void MultiQuestFarm(string MapName, string CellName, string PadName, int[] QuestList, string MonsterName = "*")
{
/*
* Must have the following functions in your script:
* SafeMapJoin
* SmartSaveState
* SkillList
* ExitCombat
* GetDropList OR ItemWhitelist
*
* Must have the following commands under public class Script:
* int FarmLoop = 0;
* int SavedState = 0;
*/
startFarmLoop:
if (FarmLoop > 0) goto maintainFarmLoop;
SavedState++;
FormatLog("Farm", $"Started Farming Loop {SavedState}");
goto maintainFarmLoop;
breakFarmLoop:
SmartSaveState();
FormatLog("Farm", $"Completed Farming Loop {SavedState}");
FarmLoop = 0;
goto startFarmLoop;
maintainFarmLoop:
FarmLoop++;
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower(), CellName, PadName);
if (bot.Player.Cell != CellName) bot.Player.Jump(CellName, PadName);
foreach (var Quest in QuestList)
{
if (!bot.Quests.IsInProgress(Quest)) bot.Quests.EnsureAccept(Quest);
if (bot.Quests.CanComplete(Quest)) SafeQuestComplete(Quest);
}
bot.Options.AggroMonsters = true;
AttackType("a", MonsterName);
if (FarmLoop > SaveStateLoops) goto breakFarmLoop;
}
/// <summary>
/// Equips an item.
/// </summary>
public void SafeEquip(string ItemName)
{
//Must have the following functions in your script:
//ExitCombat
while (bot.Inventory.Contains(ItemName) && !bot.Inventory.IsEquipped(ItemName))
{
ExitCombat();
bot.Player.EquipItem(ItemName);
}
}
/// <summary>
/// Sets attack type to Attack(Attack/A) or Hunt(Hunt/H)
/// </summary>
/// <param name="AttackType">Attack/A or Hunt/H</param>
/// <param name="MonsterName">Name of the monster</param>
public void AttackType(string AttackType, string MonsterName)
{
string attack_ = AttackType.ToLower();
if (attack_ == "a" || attack_ == "attack")
{
bot.Player.Attack(MonsterName);
}
else if (attack_ == "h" || attack_ == "hunt")
{
bot.Player.Hunt(MonsterName);
}
}
/// <summary>
/// Purchases the specified quantity of the specified item from the specified shop in the specified map.
/// </summary>
public void SafePurchase(string ItemName, int ItemQuantityNeeded, string MapName, int ShopID)
{
//Must have the following functions in your script:
//SafeMapJoin
//ExitCombat
while (!bot.Inventory.Contains(ItemName, ItemQuantityNeeded))
{
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower(), "Wait", "Spawn");
ExitCombat();
bot.Log($"[{DateTime.Now:HH:mm:ss}] Purchasing \t [{ItemName}]");
bot.Shops.Load(ShopID);
bot.Log($"[{DateTime.Now:HH:mm:ss}] Shop \t \t Loaded Shop {ShopID}.");
bot.Shops.BuyItem(ItemName);
bot.Log($"[{DateTime.Now:HH:mm:ss}] Shop \t \t Purchased {ItemName} from Shop {ShopID}.");
}
}
/// <summary>
/// Sells the specified item until you have the specified quantity.
/// </summary>
public void SafeSell(string ItemName, int ItemQuantityNeeded)
{
//Must have the following functions in your script:
//ExitCombat
int sellingPoint = ItemQuantityNeeded + 1;
while (bot.Inventory.Contains(ItemName, sellingPoint))
{
ExitCombat();
bot.Shops.SellItem(ItemName);
}
}
/// <summary>
/// Attempts to complete the quest with the set amount of {TurnInAttempts}. If it fails to complete, logs out. If it successfully completes, re-accepts the quest and checks if it can be completed again.
/// </summary>
public void SafeQuestComplete(int QuestID, int ItemID = -1)
{
//Must have the following functions in your script:
//ExitCombat
ExitCombat();
bot.Quests.EnsureAccept(QuestID);
bot.Quests.EnsureComplete(QuestID, ItemID, tries: TurnInAttempts);
if (bot.Quests.IsInProgress(QuestID))
{
FormatLog("Quest", $"Turning in Quest {QuestID} failed. Logging out");
bot.Player.Logout();
}
FormatLog("Quest", $"Turning in Quest {QuestID} successful.");
while (!bot.Quests.IsInProgress(QuestID)) bot.Quests.EnsureAccept(QuestID);
}
/// <summary>
/// Stops the bot at yulgar if no parameters are set, or your specified map if the parameters are set.
/// </summary>
public void StopBot(string Text = "Bot stopped successfully.", string MapName = "yulgar", string CellName = "Enter", string PadName = "Spawn", string Caption = "Stopped", string MessageType = "event")
{
//Must have the following functions in your script:
//SafeMapJoin
//ExitCombat
if (bot.Map.Name != MapName.ToLower()) SafeMapJoin(MapName.ToLower(), CellName, PadName);
if (bot.Player.Cell != CellName) bot.Player.Jump(CellName, PadName);
bot.Drops.RejectElse = false;
bot.Options.LagKiller = false;
bot.Options.AggroMonsters = false;
FormatLog(Title: true, Text: "Script Stopped");
Console.WriteLine(Text);
SendMSGPacket(Text, Caption, MessageType);
ScriptManager.StopScript();
}
/*------------------------------------------------------------------------------------------------------------
Auxiliary Functions
------------------------------------------------------------------------------------------------------------*/
/*
* These functions are used to perform small actions in AQW.
* They are usually called upon by the Invokable Functions, but can be used separately as well.
* Make sure to have them loaded if your Invokable Function states that they are required.
* ExitCombat()
* SmartSaveState()
* SafeMapJoin("MapName", "CellName", "PadName")
* FormatLog("Topic", "Text", Tabs, Title, Followup)
*/
/// <summary>
/// Exits Combat by jumping cells.
/// </summary>
public void ExitCombat()
{
bot.Options.AggroMonsters = false;
bot.Player.Jump("Wait", "Spawn");
while (bot.Player.State == 2) { }
}
/// <summary>
/// Creates a quick Save State by messaging yourself.
/// </summary>
public void SmartSaveState()
{
bot.SendPacket("%xt%zm%whisper%1%creating save state%" + bot.Player.Username + "%");
FormatLog("Saving", "Successfully Saved State");
}
/// <summary>
/// Joins the specified map.
/// </summary>
public void SafeMapJoin(string MapName, string CellName = "Enter", string PadName = "Spawn")
{
//Must have the following functions in your script:
//ExitCombat
string mapname = MapName.ToLower();
while (bot.Map.Name != mapname)
{
ExitCombat();
if (mapname == "tercessuinotlim") bot.Player.Jump("m22", "Center");
bot.Player.Join($"{mapname}-{MapNumber}", CellName, PadName);
bot.Wait.ForMapLoad(mapname);
bot.Sleep(500);
}
if (bot.Player.Cell != CellName) bot.Player.Jump(CellName, PadName);
FormatLog("Joined", $"[{mapname}-{MapNumber}, {CellName}, {PadName}]");
}
/// <summary>
/// Logs following a specific format. No more than 3 tabs allowed.
/// </summary>
public void FormatLog(string Topic = "FormatLog", string Text = "Missing Input", int Tabs = 2, bool Title = false, bool Followup = false)
{
if (Title)
bot.Log($"[{DateTime.Now:HH:mm:ss}] -----{Text}-----");
else
{
Tabs = Tabs > 3 ? 3 : Tabs;
string TabPlace = "";
for (int i = 0; i < Tabs; i++)
TabPlace += "\t";
if (Followup)
bot.Log($"[{DateTime.Now:HH:mm:ss}] ↑ {TabPlace}{Text}");
else
bot.Log($"[{DateTime.Now:HH:mm:ss}] {Topic} {TabPlace}{Text}");
}
}
/*------------------------------------------------------------------------------------------------------------
Background Functions
------------------------------------------------------------------------------------------------------------*/
/*
* These functions help you to either configure certain settings or run event handlers in the background.
* It is highly recommended to have all these functions present in your script as they are very useful.
* Some Invokable Functions may call or require the assistance of some Background Functions as well.
* These functions are to be run at the very beginning of the bot under public class Script.
* ConfigureBotOptions("PlayerName", "GuildName", LagKiller, SafeTimings, RestPackets, AutoRelogin, PrivateRooms, InfiniteRange, SkipCutscenes, ExitCombatBeforeQuest)
* ConfigureLiteSettings(UntargetSelf, UntargetDead, CustomDrops, ReacceptQuest, SmoothBackground, Debugger)
* SkillList(int[])
* GetDropList(string[])
* ItemWhiteList(string[])
* EquipList(string[])
* UnbankList(string[])
* CheckSpace(string[])
* SendMSGPacket("Message", "Name", "MessageType")
*/
/// <summary>
/// Change the player's name and guild for your bots specifications.
/// Recommended Default Bot Configurations.
/// </summary>
public void ConfigureBotOptions(string PlayerName = "Bot By AuQW", string GuildName = "https://auqw.tk/", bool LagKiller = true, bool SafeTimings = true, bool RestPackets = true, bool AutoRelogin = true, bool PrivateRooms = false, bool InfiniteRange = true, bool SkipCutscenes = true, bool ExitCombatBeforeQuest = true, bool HideMonster=true)
{
SendMSGPacket("Configuring bot.", "AuQW", "moderator");
bot.Options.CustomName = PlayerName;
bot.Options.CustomGuild = GuildName;
bot.Options.LagKiller = LagKiller;
bot.Options.SafeTimings = SafeTimings;
bot.Options.RestPackets = RestPackets;
bot.Options.AutoRelogin = AutoRelogin;
bot.Options.PrivateRooms = PrivateRooms;
bot.Options.InfiniteRange = InfiniteRange;
bot.Options.SkipCutscenes = SkipCutscenes;
bot.Options.ExitCombatBeforeQuest = ExitCombatBeforeQuest;
// bot.Events.PlayerDeath += PD => ScriptManager.RestartScript();
// bot.Events.PlayerAFK += PA => ScriptManager.RestartScript();
HideMonsters(HideMonster);
}
/// <summary>
/// Hides the monsters for performance
/// </summary>
/// <param name="Value"> true -> hides monsters. false -> reveals them </param>
public void HideMonsters(bool Value) {
switch(Value) {
case true:
if (!bot.GetGameObject<bool>("ui.monsterIcon.redX.visible")) {
bot.CallGameFunction("world.toggleMonsters");
}
return;
case false:
if (bot.GetGameObject<bool>("ui.monsterIcon.redX.visible")) {
bot.CallGameFunction("world.toggleMonsters");
}
return;
}
}
/// <summary>
/// Gets AQLite Functions
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="optionName"></param>
/// <returns></returns>
public T GetLite<T>(string optionName)
{
return bot.GetGameObject<T>($"litePreference.data.{optionName}");
}
/// <summary>
/// Sets AQLite Functions
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="optionName"></param>
/// <param name="value"></param>
public void SetLite<T>(string optionName, T value)
{
bot.SetGameObject($"litePreference.data.{optionName}", value);
}
/// <summary>
/// Allows you to turn on and off AQLite functions.
/// Recommended Default Bot Configurations.
/// </summary>
public void ConfigureLiteSettings(bool UntargetSelf = true, bool UntargetDead = true, bool CustomDrops = false, bool ReacceptQuest = false, bool SmoothBackground = true, bool Debugger = false)
{
SetLite("bUntargetSelf", UntargetSelf);
SetLite("bUntargetDead", UntargetDead);
SetLite("bCustomDrops", CustomDrops);
SetLite("bReaccept", ReacceptQuest);
SetLite("bSmoothBG", SmoothBackground);
SetLite("bDebugger", Debugger);
}
/// <summary>
/// Spams Skills when in combat. You can get in combat by going to a cell with monsters in it with bot.Options.AggroMonsters enabled or using an attack command against one.
/// </summary>
public void SkillList(params int[] Skillset)
{
bot.RegisterHandler(1, b => {
if (bot.Player.InCombat)
{
foreach (var Skill in Skillset)
{
bot.Player.UseSkill(Skill);
}
}
});
}
/// <summary>
/// Checks if items in an array have dropped every second and picks them up if so. GetDropList is recommended.
/// </summary>
public void GetDropList(params string[] GetDropList)
{
bot.RegisterHandler(4, b => {
foreach (string Item in GetDropList)
{
if (bot.Player.DropExists(Item)) bot.Player.Pickup(Item);
}
bot.Player.RejectExcept(GetDropList);
});
}
/// <summary>
/// Pick up items in an array when they dropped. May fail to pick up items that drop immediately after the same item is picked up. GetDropList is preferable instead.
/// </summary>
public void ItemWhiteList(params string[] WhiteList)
{
foreach (var Item in WhiteList)
{
bot.Drops.Add(Item);
}
bot.Drops.RejectElse = true;
bot.Drops.Start();
}
/// <summary>
/// Equips all items in an array.
/// </summary>
/// <param name="EquipList"></param>
public void EquipList(params string[] EquipList)
{
foreach (var Item in EquipList)
{
if (bot.Inventory.Contains(Item))
{
SafeEquip(Item);
}
}
}
/// <summary>
/// Unbanks all items in an array after banking every other AC-tagged Misc item in the inventory.
/// </summary>
/// <param name="UnbankList"></param>
public void UnbankList(params string[] UnbankList)
{
if (bot.Player.Cell != "Wait") bot.Player.Jump("Wait", "Spawn");
while (bot.Player.State == 2) { }
bot.Player.LoadBank();
List<string> Whitelisted = new List<string>() { "Note", "Item", "Resource", "QuestItem", "ServerUse" };
foreach (var item in bot.Inventory.Items)
{
if (!Whitelisted.Contains(item.Category.ToString())) continue;
if (item.Name != "Treasure Potion" && item.Coins && !Array.Exists(UnbankList, x => x == item.Name)) bot.Inventory.ToBank(item.Name);
}
foreach (var item in UnbankList)
{
if (bot.Bank.Contains(item)) bot.Bank.ToInventory(item);
}
}
/// <summary>
/// Checks the amount of space you need from an array's length/set amount.
/// </summary>
/// <param name="ItemList"></param>
public void CheckSpace(params string[] ItemList)
{
int MaxSpace = bot.GetGameObject<int>("world.myAvatar.objData.iBagSlots");
int FilledSpace = bot.GetGameObject<int>("world.myAvatar.items.length");
int EmptySpace = MaxSpace - FilledSpace;
int SpaceNeeded = 0;
foreach (var Item in ItemList)
{
if (!bot.Inventory.Contains(Item)) SpaceNeeded++;
}
if (EmptySpace < SpaceNeeded)
{
StopBot($"Need {SpaceNeeded} empty inventory slots, please make room for the quest.", bot.Map.Name, bot.Player.Cell, bot.Player.Pad, "Error", "moderator");
}
}
/// <summary>
/// Sends a message packet to client in chat.
/// </summary>
/// <param name="Message"></param>
/// <param name="Name"></param>
/// <param name="MessageType">moderator, warning, server, event, guild, zone, whisper</param>
public void SendMSGPacket(string Message = " ", string Name = "SERVER", string MessageType = "zone")
{
// bot.SendClientPacket($"%xt%{MessageType}%-1%{Name}: {Message}%");
bot.SendClientPacket($"%xt%chatm%0%{MessageType}~{Message}%{Name}%");
}
public void DeathHandler() {
bot.RegisterHandler(2, b => {
if (bot.Player.State==0) {
bot.Player.SetSpawnPoint();
ExitCombat();
bot.Sleep(12000);
}
});
}
}