forked from BrenoHenrike/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreBots.cs
More file actions
1179 lines (1098 loc) · 44.9 KB
/
Copy pathCoreBots.cs
File metadata and controls
1179 lines (1098 loc) · 44.9 KB
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Scripts v2.27
using RBot;
using RBot.Items;
using RBot.Monsters;
using RBot.Quests;
using RBot.Flash;
using RBot.Skills;
using RBot.Servers;
using RBot.Shops;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class CoreBots
{
// [Can Change] Delay between commom actions, 700 is the safe number
public int ActionDelay { get; set; } = 700;
// [Can Change] Delay used to get out of combat, 1600 is the safe number
public int ExitCombatDelay { get; set; } = 1600;
// [Can Change] Delay between jumping rooms after hunting a monster, increase if you think it is jumping too much
public int HuntDelay { get; set; } = 1000;
// [Can Change] How many tries to accept/complete the quest will be sent
public int AcceptandCompleteTries { get; set; } = 20;
// [Can Change] Whether the bots should also log in AQW's chat
public bool LoggerInChat { get; set; } = true;
// [Can Change] When enabled, no messagesboxes will be shown unless absolutely neccesary
public bool ForceOffMessageboxes { get; set; } = false;
// [Can Change] Whether the bots will use private rooms
public bool PrivateRooms { get; set; } = true;
// [Can Change] What privat roomnumber the bot should use, if > 99999 it will pick a random room
public int PrivateRoomNumber { get; set; } = 100000;
// [Can Change] Use public rooms if the enemy is tough
public bool PublicDifficult { get; set; } = true;
// [Can Change] Whether the player should rest after killing a monster
public bool ShouldRest { get; set; } = false;
// [Can Change] Whether the bot should attempt to clean your inventory by banking Misc. AC Items before starting the bot
public bool BankMiscAC { get; set; } = true;
// [Can Change] Whether you want anti lag features (lag killer, invisible monsters, set to 10 FPS)
public bool AntiLag { get; set; } = true;
// [Can Change] Name of your soloing class
public string SoloClass { get; set; } = "Generic";
// [Can Change] Mode of soloing class, if it has multiple.
public ClassUseMode SoloUseMode { get; set; } = ClassUseMode.Base;
// [Can Change] Names of your soloing equipment
public string[] SoloGear { get; set; } = { "Weapon", "Headpiece", "Cape" };
// [Can Change] Name of your farming class
public string FarmClass { get; set; } = "Generic";
// [Can Change] Mode of farminging class, if it has multiple.
public ClassUseMode FarmUseMode { get; set; } = ClassUseMode.Base;
// [Can Change] Names of your farming equipment
public string[] FarmGear { get; set; } = { "Weapon", "Headpiece", "Cape" };
// [Can Change] Some Sagas use the hero alignment to give extra reputation, change to your desired rep (Alignment.Evil or Alignment.Good).
public int HeroAlignment { get; set; } = (int)Alignment.Evil;
// Whether the player is Member
public bool IsMember => ScriptInterface.Instance.Player.IsMember;
private static CoreBots? _instance;
public static CoreBots Instance => _instance ??= new CoreBots();
public ScriptInterface Bot => ScriptInterface.Instance;
public List<ItemBase> CurrentRequirements = new();
public List<string> BankingBlackList = new();
public string[] EmptyArray = { "" };
public List<InventoryItem> EmptyList = new();
public string? GuildRestore = null;
public string? ExecutablePath = Path.GetDirectoryName(Application.ExecutablePath);
/// <summary>
/// Set commom bot options to desired value
/// </summary>
/// <param name="changeTo">Value the options will be changed to</param>
public void SetOptions(bool changeTo = true)
{
VersionChecker("4");
if (!Bot.Player.LoggedIn)
{
Logger("Auto Login triggered");
Bot.Player.Login(Bot.Player.Username, Bot.Player.Password);
Bot.Sleep(1000);
Bot.Player.Connect(ServerList.Servers[2]);
while (!Bot.Player.LoggedIn)
Bot.Sleep(500);
Bot.Sleep(5000);
}
// Common Options
Bot.Options.PrivateRooms = false;
Bot.Options.SafeTimings = changeTo;
Bot.Options.RestPackets = changeTo;
Bot.Options.AutoRelogin = changeTo;
Bot.Options.InfiniteRange = changeTo;
Bot.Options.ExitCombatBeforeQuest = changeTo;
Bot.Options.SkipCutscenes = changeTo;
Bot.Drops.RejectElse = changeTo;
Bot.Lite.UntargetDead = changeTo;
Bot.Lite.UntargetSelf = changeTo;
Bot.Lite.ReacceptQuest = false;
Bot.Lite.CharacterSelectScreen = false;
Bot.Lite.Set("dOptions[\"disRed\"]", true);
if (changeTo)
{
Logger("Bot Started");
Bot.Options.HuntDelay = HuntDelay;
Bot.Events.ScriptStopping += StopBotEvent;
Bot.SendPacket("%xt%zm%afk%1%false%");
Bot.Sleep(ActionDelay);
bool TimerRunning = false;
Bot.RegisterHandler(5000, b =>
{
if (b.Player.AFK && !TimerRunning)
{
TimerRunning = true;
Bot.Sleep(300000);
if (b.Player.AFK)
{
b.Options.AutoRelogin = true;
b.Player.Logout();
}
TimerRunning = false;
}
}, "AFK Handler");
Bot.Player.LoadBank();
Bot.Runtime.BankLoaded = true;
if (BankMiscAC)
{
List<string> Whitelisted = new() { "Note", "Item", "Resource", "QuestItem" };
List<string> WhitelistedSU = new() { "Note", "Item", "Resource", "QuestItem", "ServerUse" };
List<string> MiscForBank = new();
foreach (var item in Bot.Inventory.Items)
{
if (Bot.Boosts.Enabled ? !Whitelisted.Contains(item.Category.ToString()) : !WhitelistedSU.Contains(item.Category.ToString()))
continue;
if (item.Name != "Treasure Potion" && !BankingBlackList.Contains(item.Name) && item.Coins)
MiscForBank.Add(item.Name);
}
ToBank(MiscForBank.ToArray());
}
usingSoloGeneric = SoloClass.ToLower() == "generic";
usingFarmGeneric = FarmClass.ToLower() == "generic";
EquipClass(ClassType.Solo);
// Anti-lag option
if (AntiLag)
{
Bot.Options.LagKiller = true;
Bot.SetGameObject("stage.frameRate", 10);
if (!Bot.GetGameObject<bool>("ui.monsterIcon.redX.visible"))
Bot.CallGameFunction("world.toggleMonsters");
}
GuildRestore = Bot.GetGameObject<string>("world.myAvatar.pMC.pname.tg.text").Replace("< ", "< ").Replace(" >", " >");
Bot.Options.CustomName = "AUQW RBOT MASTER";
Bot.Options.CustomGuild = "HTTPS://AUQW.TK/";
Bot.Drops.Start();
Logger("Bot Configured");
}
}
private bool StopBotEvent(ScriptInterface bot) => StopBot();
#region Inventory, Bank and Shop
/// <summary>
/// Check the Bank, Inventory and Temp Inventory for the item
/// </summary>
/// <param name="item">Name of the item</param>
/// <param name="quant">Desired quantity</param>
/// <param name="toInv">Whether or not send the item to Inventory</param>
/// <returns>Returns whether the item exists in the desired quantity in the bank and inventory</returns>
public bool CheckInventory(string? item, int quant = 1, bool toInv = true)
{
if (Bot.Inventory.ContainsTempItem(item, quant))
return true;
if (Bot.Bank.Contains(item))
{
if (!toInv)
return true;
Unbank(item);
}
if (Bot.Inventory.Contains(item, quant))
return true;
return false;
}
/// <summary>
/// Checks the Bank and Inventory for the item with it's ID
/// </summary>
/// <param name="itemID">ID of the item to verify</param>
/// <param name="quant">Desired quantity</param>
/// <param name="toInv">Whether or not send the item to Inventory</param>
/// <returns>Returns whether the item exists in the desired quantity in the Bank and Inventory</returns>
public bool CheckInventory(int itemID, int quant = 1, bool toInv = true)
{
InventoryItem? itemBank = Bot.Bank.BankItems.Find(i => i.ID == itemID);
InventoryItem? itemInv = Bot.Inventory.Items.Find(i => i.ID == itemID);
ItemBase? itemTempInv = Bot.Inventory.TempItems.Find(i => i.ID == itemID);
if (itemBank == null && itemInv == null && itemTempInv == null)
return false;
if (itemTempInv != null && Bot.Inventory.ContainsTempItem(itemTempInv.Name, quant))
return true;
if (itemBank != null && Bot.Bank.Contains(itemBank.Name))
{
if (!toInv)
return true;
Unbank(itemBank.Name);
}
if (itemInv != null && Bot.Inventory.Contains(itemInv.Name, quant))
return true;
return false;
}
/// <summary>
/// Check if the Bank/Inventory has atleast 1 of all listed items
/// </summary>
/// <param name="itemNames">Array of names of the items to be check</param>
/// <param name="toInv">Whether or not send the item to Inventory</param>
/// <param name="any">If any of the items exist, returns true</param>
/// <returns>Returns whether all the items exist in the Bank or Inventory</returns>
public bool CheckInventory(string?[] itemNames, int quant = 1, bool any = false, bool toInv = true)
{
if (itemNames == null)
return true;
foreach (string? name in itemNames)
{
if (Bot.Bank.Contains(name, quant))
{
if (!toInv && !any)
continue;
if (!toInv && any)
return true;
Unbank(name);
}
if (Bot.Inventory.Contains(name, quant) && any)
return true;
else if (Bot.Inventory.Contains(name, quant) && !any)
continue;
else if (!any)
return false;
}
return !any;
}
/// <summary>
/// Move items from bank to inventory
/// </summary>
/// <param name="items">Items to move</param>
public void Unbank(params string?[] items)
{
if (items == null)
return;
JumpWait();
Bot.Player.OpenBank();
foreach (string? item in items)
{
if (Bot.Bank.Contains(item))
{
Bot.Sleep(ActionDelay);
while (!Bot.Inventory.Contains(item))
{
Bot.Bank.ToInventory(item);
Bot.Wait.ForBankToInventory(item);
Bot.Sleep(ActionDelay);
}
Logger($"{item} moved from bank");
}
}
}
/// <summary>
/// Move items from inventory to bank
/// </summary>
/// <param name="items">Items to move</param>
public void ToBank(params string[] items)
{
if (items == null)
return;
JumpWait();
Bot.Player.OpenBank();
foreach (string item in items)
{
if (Bot.Inventory.Contains(item))
{
Bot.Sleep(ActionDelay);
while (!Bot.Bank.Contains(item))
{
Bot.Inventory.ToBank(item);
Bot.Wait.ForInventoryToBank(item);
Bot.Sleep(ActionDelay);
}
Logger($"{item} moved to bank");
}
}
}
/// <summary>
/// Buys a item till you have the desired quantity
/// </summary>
/// <param name="map">Map of the shop</param>
/// <param name="shopID">ID of the shop</param>
/// <param name="itemName">Name of the item</param>
/// <param name="quant">Desired quantity</param>
/// <param name="shopQuant">How many items you get for 1 buy</param>
/// <param name="shopItemID">Use this for Merge shops that has 2 or more of the item with the same name and you need the second/third/etc., be aware that it will relog you after to prevent ghost buy. To get the ShopItemID use the built in loader of RBot</param>
public void BuyItem(string map, int shopID, string itemName, int quant = 1, int shopQuant = 1, int shopItemID = 0)
{
if (CheckInventory(itemName, quant))
return;
Join(map);
Bot.Shops.Load(shopID);
ShopItem item = Bot.Shops.ShopItems.First(shopitem => shopitem.Name == itemName);
quant = _CalcBuyQuantity(item, quant, shopQuant);
if (quant <= 0)
return;
if (item.Coins && item.Cost > 0)
if (MessageBox.Show(
$"The bot is about to buy \"{item.Name}\", which costs {item.Cost} AC, do you accept this?",
"Warning: Costs AC!",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
!= DialogResult.Yes)
Logger($"The bot cannot continue without buying \"{item.Name}\", stopping the bot.", messageBox: true, stopBot: true);
else if (Bot.GetGameObject<int>("world.myAvatar.objData.intCoins") < item.Cost)
Logger($"You dont have enough AC to buy \"{item.Name}\", the bot cannot continue.", messageBox: true, stopBot: true);
if (!item.Coins && item.Cost > Bot.Player.Gold)
Logger($"You dont have the {item.Cost} Gold to buy \"{item.Name}\", the bot cannot continue.", messageBox: true, stopBot: true);
_BuyItem(shopID, item, quant, shopQuant, shopItemID);
}
/// <summary>
/// Buys a item till it have the desired quantity
/// </summary>
/// <param name="map">Map of the shop</param>
/// <param name="shopID">ID of the shop</param>
/// <param name="itemID">ID of the item</param>
/// <param name="quant">Desired quantity</param>
/// <param name="shopQuant">How many items you get for 1 buy</param>
/// <param name="shopItemID">Use this for Merge shops that has 2 or more of the item with the same name and you need the second/third/etc., be aware that it will relog you after to prevent ghost buy. To get the ShopItemID use the built in loader of RBot</param>
public void BuyItem(string map, int shopID, int itemID, int quant = 1, int shopQuant = 1, int shopItemID = 0)
{
if (CheckInventory(itemID, quant))
return;
Join(map);
Bot.Shops.Load(shopID);
Bot.Sleep(ActionDelay);
ShopItem item = Bot.Shops.ShopItems.First(shopitem => shopitem.ID == itemID);
quant = _CalcBuyQuantity(item, quant, shopQuant);
if (quant <= 0)
return;
if (item.Coins && item.Cost > 0)
if (MessageBox.Show(
$"The bot is about to buy \"{item.Name}\", which costs {item.Cost} AC, do you accept this?",
"Warning: Costs AC!",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
!= DialogResult.Yes)
Logger($"The bot cannot continue without buying \"{item.Name}\", stopping the bot.", messageBox: true, stopBot: true);
else if (Bot.GetGameObject<int>("world.myAvatar.objData.intCoins") < item.Cost)
Logger($"You dont have the {item.Cost} AC needed to buy \"{item.Name}\", the bot cannot continue.", messageBox: true, stopBot: true);
if (!item.Coins && item.Cost > Bot.Player.Gold)
Logger($"You dont have the {item.Cost} Gold to buy \"{item.Name}\", the bot cannot continue.", messageBox: true, stopBot: true);
_BuyItem(shopID, item, quant, shopQuant, shopItemID);
}
private void _BuyItem(int shopID, ShopItem item, int quant, int shopQuant, int shopItemID)
{
if (shopItemID == 0)
for (int i = 0; i < quant; i++)
Bot.Shops.BuyItem(shopID, item.Name);
else
{
SendPackets($"%xt%zm%buyItem%{Bot.Map.RoomID}%{item.ID}%{shopID}%{shopItemID}%", quant);
Logger("Relogin to prevent ghost buy");
Relogin();
}
if (CheckInventory(item.Name, quant))
Logger($"Bought {quant}x{shopQuant} {item.Name}");
else Logger($"Failed at buying {quant}x{shopQuant} {item.Name}");
}
private int _CalcBuyQuantity(ShopItem item, int quant, int shopQuant)
{
if (Bot.Inventory.GetQuantity(item.Name) + shopQuant > item.MaxStack)
{
Logger("Can't buy merge item past its max stack, skipping");
return 0;
}
int quantB = quant - Bot.Inventory.GetQuantity(item.Name);
if (quantB < 0)
return 0;
decimal quantF = (decimal)quantB / (decimal)shopQuant;
return (int)Math.Ceiling(quantF);
}
/// <summary>
/// Sells a item till you have the desired quantity
/// </summary>
/// <param name="itemName">Name of the item</param>
/// <param name="quant">Desired quantity</param>
/// <param name="all">Set to true if you wish to sell all the items</param>
public void SellItem(string itemName, int quant = 0, bool all = false)
{
if (!CheckInventory(itemName))
return;
JumpWait();
if (!all)
for (int i = 0; i < quant; i++)
{
Bot.Shops.SellItem(itemName);
Bot.Sleep(ActionDelay);
}
else
while (Bot.Inventory.GetQuantity(itemName) != 0)
{
Bot.Shops.SellItem(itemName);
Bot.Sleep(ActionDelay);
}
Logger($"{(all ? "" : quant.ToString())} {itemName} sold");
}
#endregion
#region Drops
/// <summary>
/// Adds drops to the pickup list, unbank the items.
/// </summary>
/// <param name="items">Items to add</param>
public void AddDrop(params string[] items)
{
Unbank(items);
Bot.Drops.Add(items);
}
/// <summary>
/// Removes drops from the pickup list.
/// </summary>
/// <param name="items">Items to remove</param>
public void RemoveDrop(params string[] items)
{
Bot.Drops.Remove(items);
}
#endregion
#region Quest
/// <summary>
/// Ensures you are out of combat before accepting the quest
/// </summary>
/// <param name="questID">ID of the quest to accept</param>
public bool EnsureAccept(int questID)
{
if (Bot.Quests.IsInProgress(questID))
return true;
if (questID <= 0)
return false;
JumpWait();
Bot.Sleep(ActionDelay);
return Bot.Quests.EnsureAccept(questID, tries: AcceptandCompleteTries);
}
/// <summary>
/// Accepts all the quests given
/// </summary>
/// <param name="questIDs">IDs of the quests</param>
public void EnsureAccept(params int[] questIDs)
{
JumpWait();
foreach (int quest in questIDs)
{
if (Bot.Quests.IsInProgress(quest) || quest <= 0)
continue;
Bot.Sleep(ActionDelay);
Bot.Quests.EnsureAccept(quest, tries: AcceptandCompleteTries);
}
}
/// <summary>
/// Ensures you are out of combat before completing the quest
/// </summary>
/// <param name="questID">ID of the quest to complete</param>
/// <param name="itemID">ID of the choosable reward item</param>
public bool EnsureComplete(int questID, int itemID = -1)
{
if (questID <= 0)
return false;
JumpWait();
Bot.Sleep(ActionDelay);
return Bot.Quests.EnsureComplete(questID, itemID, tries: AcceptandCompleteTries);
}
/// <summary>
/// Completes a quest and choose any item from it that you don't have (automatically accepts the drop)
/// </summary>
/// <param name="questID">ID of the quest</param>
/// <param name="itemList">List of the items to get, if you want all just let it be null</param>
public bool EnsureCompleteChoose(int questID, string[]? itemList = null)
{
if (questID <= 0)
return false;
JumpWait();
Bot.Sleep(ActionDelay);
if (Bot.Quests.TryGetQuest(questID, out Quest quest))
foreach (ItemBase item in quest.Rewards)
{
if (!CheckInventory(item.Name, toInv: false)
&& (itemList == null || (itemList != null && itemList.Contains(item.Name))))
{
Logger($"Completed [{quest.Name}] for {item.Name}");
bool completed = Bot.Quests.EnsureComplete(questID, item.ID, tries: AcceptandCompleteTries);
Bot.Player.Pickup(item.Name);
return completed;
}
}
Logger($"Could not complete the quest {questID}. Maybe all items are already in your inv");
return false;
}
/// <summary>
/// Completes all the quests given but doesn't support quests with choosable rewards
/// </summary>
/// <param name="questIDs">IDs of the quests</param>
public void EnsureComplete(params int[] questIDs)
{
JumpWait();
foreach (int quest in questIDs)
{
if (quest <= 0)
continue;
Bot.Sleep(ActionDelay);
Bot.Quests.EnsureComplete(quest, tries: AcceptandCompleteTries);
}
}
public Quest EnsureLoad(int questID)
{
return Bot.Quests.QuestTree.Find(x => x.ID == questID) ?? _EnsureLoad(questID);
Quest _EnsureLoad(int questID)
{
JumpWait();
Bot.Sleep(ActionDelay);
return Bot.Quests.EnsureLoad(questID);
}
}
/// <summary>
/// Accepts and then completes the quest, used inside a loop
/// </summary>
/// <param name="questID">ID of the quest</param>
/// <param name="itemID">ID of the choosable reward item</param>
public void ChainComplete(int questID, int itemID = -1)
{
JumpWait();
Bot.Quests.EnsureAccept(questID, tries: AcceptandCompleteTries);
Bot.Sleep(ActionDelay);
Bot.Quests.EnsureComplete(questID, itemID, tries: AcceptandCompleteTries);
}
/// <param name="QuestID">ID of the quest</param>
public bool isCompletedBefore(int QuestID)
{
Quest QuestData = EnsureLoad(QuestID);
return QuestData.Slot < 0 || Bot.CallGameFunction<int>("world.getQuestValue", QuestData.Slot) >= QuestData.Value;
}
#endregion
#region Kill
/// <summary>
/// Kills the specified monsters in the map for the quest requirements
/// </summary>
/// <param name="questID">ID of the quest</param>
/// <param name="map">Map where the <paramref name="monsters"/> are</param>
/// <param name="monsters">Array of the monsters to kill</param>
/// <param name="iterations">How many times it should kill the monster until going to the next</param>
/// <param name="completeQuest">Whether complete the quest after killing all monsters</param>
public void SmartKillMonster(int questID, string map, string[] monsters, int iterations = 20, bool completeQuest = false, bool publicRoom = false)
{
EnsureAccept(questID);
_AddRequirement(questID);
Join(map, publicRoom: publicRoom);
foreach (string monster in monsters)
_SmartKill(monster, iterations);
if (completeQuest)
EnsureComplete(questID);
CurrentRequirements.Clear();
}
/// <summary>
/// Kills the specified monsters in the map for the quest requirements
/// </summary>
/// <param name="questID">ID of the quest</param>
/// <param name="map">Map where the <paramref name="monster"/> is</param>
/// <param name="monster">Monster to kill</param>
/// <param name="iterations">How many times it should kill the monster until exiting</param>
/// <param name="completeQuest">Whether complete the quest after killing all monsters</param>
public void SmartKillMonster(int questID, string map, string monster, int iterations = 20, bool completeQuest = false, bool publicRoom = false)
{
EnsureAccept(questID);
_AddRequirement(questID);
Join(map, publicRoom: publicRoom);
_SmartKill(monster, iterations);
if (completeQuest)
EnsureComplete(questID);
CurrentRequirements.Clear();
}
private void _SmartKill(string monster, int iterations = 20)
{
bool repeat = true;
for (int j = 0; j < iterations; j++)
{
if (CurrentRequirements.Count == 0)
break;
if (CurrentRequirements.Count == 1)
{
if (_RepeatCheck(ref repeat, 0))
break;
_MonsterHunt(ref repeat, monster, CurrentRequirements[0].Name, CurrentRequirements[0].Quantity, CurrentRequirements[0].Temp, 0);
break;
}
else
{
for (int i = CurrentRequirements.Count - 1; i >= 0; i--)
{
if (j == 0 && (CheckInventory(CurrentRequirements[i].Name, CurrentRequirements[i].Quantity)))
{
CurrentRequirements.RemoveAt(i);
continue;
}
if (j != 0 && CheckInventory(CurrentRequirements[i].Name))
{
if (_RepeatCheck(ref repeat, i))
break;
_MonsterHunt(ref repeat, monster, CurrentRequirements[i].Name, CurrentRequirements[i].Quantity, CurrentRequirements[i].Temp, i);
break;
}
}
}
if (!repeat)
break;
Bot.Player.Hunt(monster);
Bot.Player.Pickup(CurrentRequirements.Where(item => !item.Temp).Select(item => item.Name).ToArray());
Bot.Sleep(ActionDelay);
}
}
private void _MonsterHunt(ref bool shouldRepeat, string monster, string itemName, int quantity, bool isTemp, int index)
{
_HuntForItem(monster, itemName, quantity, isTemp);
CurrentRequirements.RemoveAt(index);
shouldRepeat = false;
}
private bool _RepeatCheck(ref bool shouldRepeat, int index)
{
if (CheckInventory(CurrentRequirements[index].Name, CurrentRequirements[index].Quantity))
{
CurrentRequirements.RemoveAt(index);
shouldRepeat = false;
return true;
}
return false;
}
/// <summary>
/// Joins a map, jump & set the spawn point and kills the specified monster
/// </summary>
/// <param name="map">Map to join</param>
/// <param name="cell">Cell to jump to</param>
/// <param name="pad">Pad to jump to</param>
/// <param name="monster">Name of the monster to kill</param>
/// <param name="item">Item to kill the monster for, if null will just kill the monster 1 time</param>
/// <param name="quant">Desired quantity of the item</param>
/// <param name="isTemp">Whether the item is temporary</param>
/// <param name="log">Whether it will log that it is killing the monster</param>
public void KillMonster(string map, string cell, string pad, string monster, string? item = null, int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != null && CheckInventory(item, quant))
return;
if (!isTemp && item != null)
AddDrop(item);
Join(map, publicRoom: publicRoom);
Jump(cell, pad);
if (item == null)
{
if (log)
Logger($"Killing {monster}");
Bot.Player.Kill(monster);
Rest();
}
else
_KillForItem(monster, item, quant, isTemp, log: log);
}
/// <summary>
/// Kills a monster using it's ID
/// </summary>
/// <param name="map">Map to join</param>
/// <param name="cell">Cell to jump to</param>
/// <param name="pad">Pad to jump to</param>
/// <param name="monsterID">ID of the monster</param>
/// <param name="item">Item to kill the monster for, if null will just kill the monster 1 time</param>
/// <param name="quant">Desired quantity of the item</param>
/// <param name="isTemp">Whether the item is temporary</param>
/// <param name="log">Whether it will log that it is killing the monster</param>
public void KillMonster(string map, string cell, string pad, int monsterID, string? item = null, int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != null && CheckInventory(item, quant))
return;
if (!isTemp && item != null)
AddDrop(item);
Join(map, publicRoom: publicRoom);
Jump(cell, pad);
Monster? monster = Bot.Monsters.CurrentMonsters.Find(m => m.ID == monsterID);
if (monster == null)
{
Logger($"Monster [{monsterID}] not found. Something is wrong. Stopping bot", messageBox: true, stopBot: true);
return;
}
if (item == null)
{
if (log)
Logger($"Killing {monster}");
Bot.Player.Kill(monster);
Rest();
}
else
_KillForItem(monster.Name, item, quant, isTemp, log: log);
}
/// <summary>
/// Joins a map and hunt for the monster
/// </summary>
/// <param name="map">Map to join</param>
/// <param name="monster">Name of the monster to kill</param>
/// <param name="item">Item to hunt the monster for, if null will just hunt & kill the monster 1 time</param>
/// <param name="quant">Desired quantity of the item</param>
/// <param name="isTemp">Whether the item is temporary</param>
public void HuntMonster(string map, string monster, string? item = null, int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != null && CheckInventory(item, quant))
return;
if (!isTemp && item != null)
AddDrop(item);
Join(map, publicRoom: publicRoom);
if (item == null)
{
if (log)
Logger($"Hunting {monster}");
Bot.Player.Hunt(monster);
Rest();
}
else
_HuntForItem(monster, item, quant, isTemp, log: log);
}
/// <summary>
/// Kill Escherion for the desired item
/// </summary>
/// <param name="item">Item name</param>
/// <param name="quant">Desired quantity</param>
/// <param name="isTemp">Whether the item is temporary</param>
public void KillEscherion(string? item = null, int quant = 1, bool isTemp = false, bool publicRoom = false)
{
if (item != null && CheckInventory(item, quant))
return;
if (!isTemp && item != null)
AddDrop(item);
Join("escherion", publicRoom: publicRoom);
Jump("Boss", "Left");
if (item == null)
{
Logger("Killing Escherion");
while (Bot.Monsters.MapMonsters.Find(m => m.Name == "Escherion").Alive)
{
if (Bot.Monsters.MapMonsters.Find(m => m.Name == "Staff of Inversion").Alive)
Bot.Player.Hunt("Staff of Inversion");
Bot.Player.Attack("Escherion");
Bot.Sleep(1000);
}
}
else
{
Logger($"Killing Escherion for {item} ({quant}) [Temp = {isTemp}]");
while (!CheckInventory(item, quant))
{
if (Bot.Monsters.MapMonsters.Find(m => m.Name == "Staff of Inversion").Alive)
Bot.Player.Hunt("Staff of Inversion");
Bot.Player.Attack("Escherion");
Bot.Sleep(1000);
}
}
}
#endregion
#region Utils
/// <summary>
/// Logs a line of text to the script log with time, method from where it's called and a message
/// </summary>
public void Logger(string message = "", [CallerMemberName] string caller = null, bool messageBox = false, bool stopBot = false)
{
Bot.Log($"[{DateTime.Now:HH:mm:ss}] ({caller}) {message}");
if (LoggerInChat)
Bot.SendMSGPacket(message.Replace('[', '(').Replace(']', ')'), caller, "moderator");
if (messageBox & !ForceOffMessageboxes)
Message(message, caller);
if (stopBot)
StopBot();
}
/// <summary>
/// Creates a Message Box with the desired text and caption
/// </summary>
/// <param name="message">Message to display</param>
/// <param name="caption">Title of the box</param>
public void Message(string message, string caption)
{
if (DialogResult.OK == MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000))
return;
}
/// <summary>
/// Send a packet to the server the desired amount of times
/// </summary>
/// <param name="packet">Packet to send</param>
/// <param name="times">How many times to send</param>
public void SendPackets(string packet, int times = 1, bool toClient = false)
{
for (int i = 0; i < times; i++)
{
if (toClient)
Bot.SendClientPacket(packet);
else
Bot.SendPacket(packet);
Bot.Sleep(ActionDelay * 2);
}
}
/// <summary>
/// Rest the player until full if ShouldRest = true
/// </summary>
public void Rest()
{
if (ShouldRest)
Bot.Player.Rest(true);
}
/// <summary>
/// Logs the player out and then in again to the same server. Disables Options.AutoRelogin temporarily
/// </summary>
public void Relogin()
{
bool autoRelogSwitch = Bot.Options.AutoRelogin;
Bot.Options.AutoRelogin = false;
Bot.Sleep(2000);
Logger("Relogin started");
Bot.Player.Logout();
Bot.Sleep(5000);
Server server = Bot.Options.AutoReloginAny
? ServerList.Servers.Find(x => x.IP != ServerList.LastServerIP)
: ServerList.Servers.Find(s => s.IP == ServerList.LastServerIP) ?? ServerList.Servers[0];
Bot.Player.Login(Bot.Player.Username, Bot.Player.Password);
Bot.Sleep(1000);
Bot.Player.Connect(server);
while (!Bot.Player.LoggedIn)
Bot.Sleep(500);
Bot.Sleep(5000);
Logger("Relogin finished");
Bot.Options.AutoRelogin = autoRelogSwitch;
}
/// <summary>
/// Checks, and promps for the latest Rbot Version
/// <param name="TargetVersion">Current RBot Version to Check against</param>
/// </summary>
public void VersionChecker(string TargetVersion)
{
List<int> TargetVArray = Array.ConvertAll(TargetVersion.Split('.'), int.Parse).ToList();
List<int> CurrentVArray = Array.ConvertAll(Forms.Main.Text.Replace("RBot ", "").Split('.'), int.Parse).ToList();
for (int i = 0; i < TargetVArray.Count; i++)
{
int Target = TargetVArray.Skip(i).First();
int Current = CurrentVArray.Skip(i).First();
if (Target < Current)
return;
else if (Target > Current)
{
DialogResult SendSite = MessageBox.Show($"This script requires RBot {TargetVersion} or above, click OK to open the download page of the latest release", "Outdated RBot detected", MessageBoxButtons.OKCancel);
if (SendSite == DialogResult.OK)
{
System.Diagnostics.Process.Start("https://github.com/BrenoHenrike/RBot/releases");
StopBot();
}
else
Logger($"This script requires RBot {TargetVersion} or above. Stopping the script", messageBox: true, stopBot: true);
}
}
}
ClassType currentClass = ClassType.None;
bool usingSoloGeneric = false;
bool usingFarmGeneric = false;
/// <summary>
/// Equips either the FarmClass or SoloClass from the CanChange section at the top of CoreBots
/// </summary>
/// <param name="classToUse">Type "ClassType." and then either Farm or Solo in order to select which type it should swap too</param>
public void EquipClass(ClassType classToUse)
{
if (currentClass == classToUse)
return;
switch (classToUse)
{
case ClassType.Farm:
Equip(FarmGear);
if (!usingFarmGeneric)
Bot.Skills.StartAdvanced(FarmClass, true, FarmUseMode);
else Bot.Skills.StartAdvanced(Bot.Inventory.CurrentClass.Name, false);
break;
default:
Equip(SoloGear);
if (!usingSoloGeneric)
Bot.Skills.StartAdvanced(SoloClass, true, SoloUseMode);
else Bot.Skills.StartAdvanced(Bot.Inventory.CurrentClass.Name, false);
break;
}
currentClass = classToUse;
}
public void Equip(params string?[] gear)
{
if (gear == null)
return;
foreach (string? Item in gear)
{
if ((Item != "Weapon" && Item != "Headpiece" && Item != "Cape") && CheckInventory(Item) && !Bot.Inventory.IsEquipped(Item))
{
JumpWait();
Bot.Player.EquipItem(Item);
Bot.Sleep(ActionDelay);
Logger($"{Item} equipped");
}
}
}
/// <summary>
/// Switches the player's Alignment to the input Alignment type
/// </summary>
/// <param name="Side">Type "Alignment." and then Good, Evil or Chaos in order to select which Alignment it should swap too</param>
public void ChangeAlignment(Alignment Side)
{
Bot.SendPacket($"%xt%zm%updateQuest%{Bot.Map.RoomID}%41%{(int)Side}%");
Bot.Sleep(ActionDelay * 2);
}
public bool HasAchievement(int ID, string ia = "ia0")
{
return Bot.CallGameFunction<bool>("world.getAchievement", ia, ID);
}
public void SetAchievement(int ID, string ia = "ia0")
{
if (!HasAchievement(ID, ia))
Bot.SendPacket($"%xt%zm%setAchievement%{Bot.Map.RoomID}%{ia}%{ID}%1%");
}
private void _KillForItem(string name, string item, int quantity, bool tempItem = false, bool rejectElse = false, bool log = true)
{
if (log)
{
int dynamicQuantity = tempItem ? Bot.Inventory.GetTempQuantity(item) : Bot.Inventory.GetQuantity(item);
Logger($"Killing {name} for {item}, ({dynamicQuantity}/{quantity}) [Temp = {tempItem}]");
}
while (!Bot.ShouldExit() && !CheckInventory(item, quantity))
{
Bot.Player.Attack(name);
Bot.Sleep(ActionDelay);
if (rejectElse)
Bot.Player.RejectExcept(item);
Rest();
}
}
private void _HuntForItem(string name, string item, int quantity, bool tempItem = false, bool rejectElse = false, bool log = true)