-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathCoreAdvanced.cs
More file actions
3426 lines (3016 loc) · 134 KB
/
CoreAdvanced.cs
File metadata and controls
3426 lines (3016 loc) · 134 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
/*
name: null
description: null
tags: null
*/
//cs_include Scripts/CoreBots.cs
//cs_include Scripts/CoreFarms.cs
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.DependencyInjection;
using Newtonsoft.Json;
using Skua.Core.Interfaces;
using Skua.Core.Models;
using Skua.Core.Models.Items;
using Skua.Core.Models.Monsters;
using Skua.Core.Models.Quests;
using Skua.Core.Models.Shops;
using Skua.Core.Options;
using Skua.Core.Utils;
public class CoreAdvanced
{
private IScriptInterface Bot => IScriptInterface.Instance;
private CoreBots Core => CoreBots.Instance;
private static CoreFarms Farm { get => _Farm ??= new CoreFarms(); set => _Farm = value; }
private static CoreFarms _Farm;
// Thousand-level Constants
const int OneK = 1000; // 1k
const int TenK = 10000; // 10k
const int OneHundredK = 100000; // 100k
const int FiveHundredK = 500000; // 500k
// Million-level Constants
const int OneMillion = 1000000; // 1m
const int FiveMillion = 5000000; // 5m
const int TenMillion = 10000000; // 10m
const int FiftyMillion = 50000000; // 50m
const int OneHundredMillion = 100000000; // 100m
//Max integer
const int maxint = Int32.MaxValue;
public void ScriptMain(IScriptInterface Bot)
{
Core.RunCore();
}
#region Shop
/// <summary>
/// Buys a item from a shop, but also try to obtain stuff like XP, Rep, Gold, and merge items (where possible)
/// </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="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 re-log you after to prevent ghost buy. To get the ShopItemID use the built in loader of Skua</param>
/// <param name="index"></param>
/// <param name="Log"></param>
public void BuyItem(string map, int shopID, string itemName, int quant = 1, int shopItemID = 0, int index = 0, bool Log = true)
{
if (Core.CheckInventory(itemName, quant))
return;
Core.Join(map);
Bot.Wait.ForMapLoad(map);
Core.JumpWait();
if (Bot.Player.InCombat || Bot.Player.HasTarget)
{
Core.JumpWait();
Bot.Wait.ForCombatExit();
}
ShopItem? item = Core.parseShopItem(Core.GetShopItems(map, shopID).Where(x => shopItemID == 0 ? x.Name.ToLower() == itemName.ToLower() : x.ShopItemID == shopItemID).ToList(), shopID, itemName);
if (item == null)
return;
_BuyItem(map, shopID, item, quant, item.Quantity, shopItemID, index, Log);
}
/// <summary>
/// Buys a item from a shop, but also try to obtain stuff like XP, Rep, Gold, and merge items (where possible)
/// </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 Skua</param>
/// <param name="index"></param>
/// <param name="Log"></param>
public void BuyItem(string map, int shopID, int itemID, int quant = 1, int shopQuant = 1, int shopItemID = 0, int index = 0, bool Log = true)
{
if (Core.CheckInventory(itemID, quant))
return;
Core.Join(map);
Bot.Wait.ForMapLoad(map);
Core.JumpWait();
if (Bot.Player.InCombat || Bot.Player.HasTarget)
{
Core.JumpWait();
Bot.Wait.ForCombatExit();
}
ShopItem? item = Core.parseShopItem(Core.GetShopItems(map, shopID).Where(x => shopItemID == 0 ? x.ID == itemID : x.ShopItemID == shopItemID).ToList(), shopID, itemID.ToString());
if (item == null)
return;
_BuyItem(map, shopID, item, quant, shopQuant, shopItemID, index, Log);
}
private void _BuyItem(string map, int shopID, ShopItem item, int quant = 1, int shopquant = 1, int shopItemID = 1, int index = 0, bool Log = true)
{
int shopQuant = item.Quantity; // Quantity per purchase from the shop
string shopName = Bot.Shops.Name; // Store the currently loaded shop name
if (item.Requirements != null)
{
foreach (ItemBase req in item.Requirements)
{
// Determine how many total items are needed
int totalBundlesNeeded = (int)Math.Ceiling((double)req.Quantity * quant / shopQuant);
if (Core.CheckInventory(req.ID, totalBundlesNeeded))
{
continue;
}
if (req.Name.Contains("Gold Voucher"))
{
Farm.Voucher(req.Name, totalBundlesNeeded); // Will buy from shop if available
continue;
}
if (req.Name == "Dragon Runestone")
{
Farm.DragonRunestone(totalBundlesNeeded);
continue;
}
while (!Bot.ShouldExit && !Core.CheckInventory(req.ID, totalBundlesNeeded))
{
if (Bot.Map.Name != map)
{
Core.Join(map);
Bot.Wait.ForMapLoad(map);
}
// Load shop data
while (!Bot.ShouldExit && Bot.Shops.ID != shopID)
{
Bot.Shops.Load(shopID);
Bot.Wait.ForActionCooldown(GameActions.LoadShop);
Bot.Wait.ForTrue(() => Bot.Shops.IsLoaded && Bot.Shops.ID == shopID, 20);
Core.Sleep(1000);
if (Bot.Shops.ID == shopID)
break;
}
// int bundlesToBuy = totalBundlesNeeded - (QuantOwned / req.Quantity);
// Ensure we Reload the proper shop:
// Load shop data
while (!Bot.ShouldExit && Bot.Shops.ID != shopID)
{
Bot.Shops.Load(shopID);
Bot.Wait.ForActionCooldown(GameActions.LoadShop);
Bot.Wait.ForTrue(() => Bot.Shops.IsLoaded && Bot.Shops.ID == shopID, 20);
Core.Sleep(1000);
if (Bot.Shops.ID == shopID)
break;
}
ShopItem? shopItem = Bot.Shops.Items.FirstOrDefault(x => x.ID == req.ID);
if (shopItem != null)
{
BuyItem(map, shopID, req.ID, totalBundlesNeeded, shopItemID, Log: Log);
Bot.Wait.ForPickup(req.ID);
}
// Else return and hope it hits the `findingredients` area. when the req.name isnt in the shop.
else
{
Core.Logger($"Failed to find shop item: \"{req.Name} [{req.ID}]\" in ({Bot.Shops.Name} [{Bot.Shops.ID}].)\n"
+ $"Its either a `mob drop` or a `daily`.\n"
+ $"Check the Wiki: http://aqwwiki.wikidot.com/search:main/fullname/{req.Name.Replace(" ", "-")}.\n"
+ $"Maybe the bot will just farm in a moment once it returns to the previous code..? if not then its probably from a daily or an mob we cannot kill with skua.");
return;
}
}
}
// Ensure required items are available before purchasing the main item
GetItemReq(item, quant);
// Rejoin the map here incase getitemreq takes you elsewhere, to ensure that the shopitem is found (hopefully)
if (Bot.Map.Name != map)
Core.Join(map);
// Load shop data
while (!Bot.ShouldExit && Bot.Shops.ID != shopID)
{
Bot.Shops.Load(shopID);
Bot.Wait.ForActionCooldown(GameActions.LoadShop);
Bot.Wait.ForTrue(() => Bot.Shops.IsLoaded && Bot.Shops.ID == shopID, 20);
Core.Sleep(1000);
if (Bot.Shops.ID == shopID)
break;
}
// Try to find the exact item match based on ID and ShopItemID
List<ShopItem> matchingItems = Bot.Shops.Items
.Where(x => x.ID == item.ID &&
x.ShopItemID == (item.ShopItemID != 1 ? item.ShopItemID : shopItemID) &&
!(x.Coins && x.Cost > 0) && // Exclude AC/paid items
item.Requirements.All(r => Core.CheckInventory(r.ID, r.Quantity)))
.ToList(); // Convert to list to allow index selection
// If no exact match is found, fall back to matching only by ID
if (!matchingItems.Any())
{
matchingItems = Bot.Shops.Items
.Where(x => x.ID == item.ID &&
!(x.Coins && x.Cost > 0) && // Exclude AC/paid items
item.Requirements.All(r => Core.CheckInventory(r.ID, r.Quantity)))
.ToList();
}
// Select the item by index if possible, otherwise default to the first available match
ShopItem? mainItem = matchingItems.Count > index ? matchingItems[index] : matchingItems.FirstOrDefault();
if (mainItem != null)
{
// Attempt to buy the item using the correct ShopItemID if applicable
Core.BuyItem(map, shopID, mainItem.ID, quant, mainItem.ShopItemID != 1 ? mainItem.ShopItemID : shopItemID, Log: Log);
Core.Sleep();
// Verify if the item was successfully purchased
if (!Core.CheckInventory(mainItem.ID, quant))
{
Core.Logger($"❌ Failed to buy {mainItem.Name} ({quant}x)");
// Log any missing requirements for debugging
foreach (ItemBase req in mainItem.Requirements.Where(r => r != null && !Core.CheckInventory(r.ID, r.Quantity)))
{
Core.Logger($"⚠️ Missing: {req.Name} x{req.Quantity}");
}
}
}
else
{
Core.Logger($"❌ Failed to find the item: {item.Name} in shop {shopID} on map {map}");
}
}
}
/// <summary>
/// Ensures that all necessary requirements (Experience, Reputation, Gold, and specific items)
/// are met in order to purchase an item. This includes verifying player level, farming or purchasing
/// required reputation, acquiring specific items such as Gold Vouchers and Dragon Runestones,
/// and ensuring enough gold is available for the transaction.
/// </summary>
/// <param name="item">
/// The <see cref="ShopItem"/> object that contains all the details about the item,
/// including its requirements like reputation, level, gold cost, and additional items needed.
/// </param>
/// <param name="quant">
/// The quantity of the item needed for purchase. The default value is 1, but can be adjusted
/// to handle cases where multiple units of the item are required.
/// </param>
public void GetItemReq(ShopItem item, int quant = 1)
{
if (item?.Requirements == null)
{
Core.Logger("Invalid item or missing requirements.");
return;
}
// Ensure required reputation for faction-based items
if (!string.IsNullOrEmpty(item.Faction) && item.Faction != "None" && item.RequiredReputation > 0)
{
Core.Logger($"Farming reputation for {item.Faction} (Required: {item.RequiredReputation})");
runRep(item.Faction, Core.PointsToLevel(item.RequiredReputation));
}
// Level up if the item requires a higher player level
if (item.Level > Bot.Player.Level)
{
Core.Logger($"Farming experience to reach level {item.Level}");
Farm.Experience(Math.Min(item.Level, 100));
}
// Farm gold if the item costs gold and isn't a premium currency purchase
if (!item.Coins && item.Cost > 0)
{
int GoldtoFarm = Math.Min(item.Cost * quant, 100000000); // 100m gold cap
Farm.Gold(GoldtoFarm);
}
// Handle Gold Vouchers (multiple types possible)
if (item.Requirements.Any(x => x != null && x.Name.StartsWith("Gold Voucher")))
{
foreach (ItemBase req in item.Requirements.Where(x => x != null && x.Name.StartsWith("Gold Voucher")))
{
Farm.Voucher(req.Name, req.Quantity);
}
}
// Handle Dragon Runestone farming if required
if (item.Requirements.Any(x => x != null && x.Name.StartsWith("Dragon Runestone")))
{
Farm.DragonRunestone(item.Requirements.FirstOrDefault(x => x != null && x.Name == "Dragon Runestone").Quantity);
}
// Warn if a temp item is missing
foreach (ItemBase req in item.Requirements.Where(x => x != null && x.Temp && x.Quantity > Bot.TempInv.GetQuantity(x.ID)))
Core.Logger($"Temp item: {req.Name}, quant needed: {req.Quantity}... did the bot not farm them?");
}
private void runRep(string faction, int rank)
{
faction = faction.Replace(" ", "");
Type farmClass = Farm.GetType();
MethodInfo? theMethod = farmClass.GetMethod(faction + "REP");
if (theMethod == null)
{
Core.Logger("Failed to find " + faction + "REP. Make sure you have the correct name and capitalization.");
return;
}
try
{
switch (faction.ToLower())
{
case "alchemy":
case "blacksmith":
theMethod.Invoke(Farm, new object[] { rank, true });
break;
case "bladeofawe":
theMethod.Invoke(Farm, new object[] { rank, false });
break;
default:
theMethod.Invoke(Farm, new object[] { rank });
break;
}
}
catch
{
Core.Logger($"Faction {faction} has invalid paramaters, please report", messageBox: true, stopBot: true);
}
}
/// <summary>
/// Buys merge items from a shop based on specified options. Filters ShopItems to ensure uniqueness by ID and ShopItemID,
/// selecting items based on Upgrade requirements and excluding those ending with "insignia".
/// </summary>
/// <param name="map">The map from which the shop is loaded.</param>
/// <param name="shopID">The shop ID to load shop data.</param>
/// <param name="findIngredients">Action determining where to retrieve items.</param>
/// <param name="buyOnlyThis">Optional. Limits purchases to a specific item.</param>
/// <param name="itemBlackList">Optional. List of excluded items.</param>
/// <param name="buyMode">Optional. Specifies buying mode.</param>
/// <param name="Group">Optional. Specifies group selection method.</param>
/// <param name="ShopItemID">Optional. Specifies ShopItem ID.</param>
/// <param name="Log">Optional. Enables logging.</param>
// We'll use this later
public void StartBuyAllMerge(string map, int shopID, Action findIngredients, string? buyOnlyThis = null, string[]? itemBlackList = null, mergeOptionsEnum? buyMode = null, string Group = "First", int ShopItemID = 0, bool Log = true)
{
#region Setup and Initialization
if (buyOnlyThis == null && buyMode == null && Bot.Config != null && !Bot.Config.Get<bool>(CoreBots.Instance.SkipOptions))
Bot.Config!.Configure();
int mode = 0;
if (buyOnlyThis != null)
mode = (int)mergeOptionsEnum.all;
else if (buyMode != null)
mode = (int)buyMode;
else if (Bot.Config != null && Bot.Config.MultipleOptions.Any(o => o.Value.Any(x => x.Category == "Generic" && x.Name == "mode")))
mode = (int)Bot.Config.Get<mergeOptionsEnum>("Generic", "mode");
else Core.Logger("Invalid setup detected for StartBuyAllMerge. Please report", messageBox: true, stopBot: true);
matsOnly = mode == 2;
// HashSet for tracking unique item IDs to prevent redundant operations
HashSet<int> uniqueItemIds = new(
new[] {
Bot.Bank.Items.Select(item => item.ID),
Bot.TempInv.Items.Select(item => item.ID),
Bot.House.Items.Select(item => item.ID),
Bot.Inventory.Items.Select(item => item.ID)
}.SelectMany(id => id)
);
// Filter shop items based on various conditions
List<ShopItem> shopItems = Core.GetShopItems(map, shopID)
.GroupBy(item => new { item.Name, item.ID, item.ShopItemID })
.Select(group =>
{
IOrderedEnumerable<ShopItem> orderedGroup = group.OrderBy(item => item.ShopItemID != group.First().ShopItemID);
return Group == "First" ? orderedGroup.First() : orderedGroup.Last();
})
.Where(x => !x.Name.ToLower().EndsWith("insignia"))
.Where(x => !uniqueItemIds.Contains(x.ID))
.ToList();
uniqueItemIds = new HashSet<int>(); // Reset for re-use
List<ShopItem> items = new();
bool memSkipped = false;
// Process shop items based on various conditions
foreach (ShopItem item in shopItems)
{
if (miscCatagories.Contains(item.Category) ||
(!string.IsNullOrEmpty(buyOnlyThis) && buyOnlyThis != item.Name) ||
(itemBlackList != null && itemBlackList.Any(x => x.ToLower() == item.Name.ToLower())))
continue;
if (Core.IsMember || !item.Upgrade
|| item.Requirements.Any(x => x != null && Bot.Shops.Items.Any(x => x != null && x.Upgrade && !Core.IsMember)))
{
if (mode == 3)
{
if (Bot.Config!.Get<bool>("Select", $"{item.ID}"))
items.Add(item);
}
else if (mode != 1)
items.Add(item);
else if (item.Coins)
items.Add(item);
}
else if (mode == 3 && Bot.Config!.Get<bool>("Select", $"{item.ID}"))
{
Core.Logger($"\"{item.Name}\" will be skipped, as you aren't a member.");
memSkipped = true;
}
}
if (items.Count == 0)
{
Core.Logger($"Found {items.Count} items to purchase from shop [{shopID}] on map [{map}].");
HandleNoItemsFound(mode, memSkipped);
return;
}
#endregion
int t = 0;
// Why did we need the `for ( int i = 0; i < 2; i++)`?
foreach (ShopItem item in items)
{
if (Core.CheckInventory(item.ID, toInv: false))
continue;
if (item.Upgrade && !Core.IsMember)
{
Core.Logger($"Skipping {item.Name} [{item.ID}] as it is member-only.");
continue;
}
if (!matsOnly)
{
Core.Logger($"Farming to buy {item.Name} (#{t++}/{items.Count})");
}
foreach (ItemBase req in item.Requirements)
{
EnsureShopLoaded(map, shopID);
HandleItemRequirements(req, req.Quantity, findIngredients);
}
if (item.Requirements.All(x => x != null && Core.CheckInventory(x.ID, x.Quantity)))
{
if (!matsOnly)
Core.Logger($"Buying {item.Name} (#{t++}/{items.Count})");
// Attempt to purchase the required quantity of the shop item
BuyItem(map, shopID, item.ID, shopItemID: item.ShopItemID, Log: Log);
Bot.Wait.ForPickup(item.ID);
if (Core.CheckInventory(item.ID, item.Quantity))
{
continue;
}
else
{
IEnumerable<string> missing = item.Requirements
.Where(x => !Core.CheckInventory(x.ID, x.Quantity))
.Select(x => $"\"{x.Name} x{x.Quantity}\"");
Core.Logger($"Failed to meet requirements for {item.Name} [{item.ID}] due to missing: {string.Join(", ", missing)}.");
continue;
}
}
}
// Helper methods
bool EnsureShopLoaded(string? map, int shopID)
{
if (map == null)
{
Core.Logger("Map is null, unable to load shop.");
return false;
}
Core.Join(map);
Bot.Wait.ForMapLoad(map);
while (!Bot.ShouldExit && Bot.Shops.ID != shopID)
{
Bot.Shops.Load(shopID);
Bot.Wait.ForActionCooldown(GameActions.LoadShop);
Bot.Wait.ForTrue(() => Bot.Shops.IsLoaded && Bot.Shops.ID == shopID, 20);
Core.Sleep(1000);
if (Bot.Shops.ID == shopID)
return true;
}
return true;
}
void HandleItemRequirements(ItemBase Req, int ReqQuant, Action findIngredients)
{
if (Core.CheckInventory(Req.ID, ReqQuant))
return;
EnsureShopLoaded(map, shopID);
ShopItem? wasinshop = Bot.Shops.Items.FirstOrDefault(x => x.ID == Req.ID);
if (wasinshop != null && !wasinshop.Name.Contains("Gold Voucher"))
{
Core.Logger($"Item: \"{Req.Name} [{Req.ID}\"] is in the shop!");
while (!Bot.ShouldExit && !Core.CheckInventory(Req.ID, ReqQuant))
{
// for requirements that are in the shop, but are just buyable with gold. (excludes ac buyable items)
if (wasinshop.Requirements.Count <= 0 && (wasinshop.Coins && wasinshop.Cost <= 0 || !wasinshop.Coins)) //|| wasinshop.Name.Contains("Gold Voucher") || wasinshop.Name.Contains("Dragon Runestone"))
{
// // Handle special cases for Gold Vouchers and Dragon Runestones
// if (wasinshop.Name.Contains("Gold Voucher"))
// {
// Farm.Voucher(wasinshop.Name, ReqQuant);
// return;
// }
// if (wasinshop.Name.Contains("Dragon Runestone"))
// {
// Farm.DragonRunestone(ReqQuant);
// return;
// }
// Otherwise buy the item directly
BuyItem(map, shopID, Req.ID, ReqQuant, shopItemID: wasinshop.ShopItemID, Log: Log);
Bot.Wait.ForPickup(Req.ID);
}
else IngredientWasintheShop(wasinshop, ReqQuant);
if (Core.CheckInventory(Req.ID, ReqQuant))
break;
else
Core.Logger($"Failed to meet requirements for \"{Req.Name}\" [{Req.ID}] x{ReqQuant}, Retrying the farm (items may have been used).");
}
}
else if (wasinshop == null)
{
// Items not in the shop, so we have to get it externally
externalItem = Req;
externalQuant = Req.Quantity;
Core.AddDrop(externalItem.ID);
Core.Logger($"{externalItem.Name} [{externalItem.ID}] is an external item (not from this shop), attempting to farm it from The ingredient list.");
// These are here inacse ae forgot to put vouchers in the original merge... like idiots (more of a fail safe)
if (Req.Name.Contains("Dragon Runestone"))
{
Farm.DragonRunestone(ReqQuant);
return;
}
if (Req.Name.StartsWith("Gold Voucher"))
{
Farm.Voucher(Req.Name, ReqQuant);
return;
}
findIngredients();
Bot.Wait.ForPickup(externalItem.ID);
}
Bot.Wait.ForPickup(Req.ID);
}
void IngredientWasintheShop(ShopItem item, int craftingQ)
{
// Ensure we are checking for items in the shop and inventory properly
if (item == null)
{
Core.Logger($"Item not found in the shop.");
return;
}
// If item is already in inventory, no need to continue
if (Core.CheckInventory(item.ID, item.Quantity))
return;
// Ensure shop is loaded before proceeding
EnsureShopLoaded(map, shopID);
foreach (ItemBase req in item.Requirements)
{
if (Core.CheckInventory(req.ID, req.Quantity))
continue;
EnsureShopLoaded(map, shopID);
int ReqQuant = req.Quantity * craftingQ;
ShopItem? wasinshop = Bot.Shops.Items.FirstOrDefault(x => x.ID == req.ID);
if (wasinshop != null && !wasinshop.Name.Contains("Gold Voucher"))
{
Core.Logger($"Item: \"{wasinshop.Name} [{wasinshop.ID}\"] is in the shop.");
ReqQuant = Math.Min(ReqQuant, wasinshop.MaxStack);
// for requirements that are in the shop, but are just buyable with gold. (excludes ac buyable items)
if (wasinshop.Requirements.Count <= 0 && wasinshop.Cost <= 0)
{
BuyItem(map, shopID, wasinshop.ID, ReqQuant, shopItemID: wasinshop.ShopItemID, Log: Log);
Bot.Wait.ForPickup(wasinshop.ID);
}
else IngredientWasintheShop(wasinshop, ReqQuant);
continue;
}
else if (wasinshop == null)
{
// Items not in the shop, so we have to get it externally
if (req.Name.Contains("Dragon Runestone"))
{
Farm.DragonRunestone(ReqQuant);
continue;
}
if (req.Name.StartsWith("Gold Voucher"))
{
Farm.Voucher(req.Name, ReqQuant);
continue;
}
externalItem = req;
externalQuant = ReqQuant;
Core.AddDrop(externalItem.ID);
Core.Logger($"{externalItem.Name} [{externalItem.ID}] is an external item (not a shop item), attempting to farm it from The ingredient list.");
findIngredients();
}
}
EnsureShopLoaded(map, shopID);
if (item.Requirements.All(x => x != null && Core.CheckInventory(x.ID, x.Quantity)))
{
// If all requirements are met, attempt to buy the item
if (!matsOnly)
Core.Logger($"Buying {item.Name} [{item.ID}] from the shop.");
// Attempt to purchase the Requirement of Main / Sub-Main item
BuyItem(map, shopID, item.ID, craftingQ, shopItemID: item.ShopItemID, Log: Log);
Bot.Wait.ForPickup(item.ID);
}
else
// If the purchase was unsuccessful, log the failure
Core.Logger($"Failed to meet requirements for {item.Name} [{item.ID}].");
}
void HandleNoItemsFound(int mode, bool memSkipped)
{
if (buyOnlyThis != null)
return;
switch (mode)
{
case 0:
case 2:
Core.Logger("The bot fetched 0 items to farm. Something must have gone wrong.");
break;
case 1:
if (shopItems.All(x => !x.Coins))
Core.Logger("The bot fetched 0 items to farm. This is because none of the items in this shop are AC tagged.");
else
Core.Logger("The bot fetched 0 items to farm. Something must have gone wrong.");
break;
case 3:
if (memSkipped)
Core.Logger("The bot fetched 0 items to farm. This is because you aren't a member.");
else
Core.Logger("The bot fetched 0 items to farm. Something must have gone wrong.");
break;
}
}
}
public List<ItemCategory> miscCatagories = new() { ItemCategory.Note, ItemCategory.Item, ItemCategory.QuestItem, ItemCategory.ServerUse };
public ItemBase externalItem = new();
public int externalQuant = 0;
public bool matsOnly = false;
public List<string> MaxStackOneItems = new();
public List<string> AltFarmItems = new();
/// <summary>
/// The list of ScriptOptions for any merge script.
/// </summary>
public List<IOption> MergeOptions = new()
{
CoreBots.Instance.SkipOptions,
new Option<mergeOptionsEnum>("mode", "Select the mode to use", "Regardless of the mode you pick, the bot wont (attempt to) buy Legend-only items if you're not a Legend.\n" +
"Select the Mode Explanation item to get more information", mergeOptionsEnum.all),
new Option<string>(" ", "Mode Explanation [all]", "Mode [all]: \t\tYou get all the items from shop, even if non-AC ones if any.", "click here"),
new Option<string>(" ", "Mode Explanation [acOnly]", "Mode [acOnly]: \tYou get all the AC tagged items from the shop.", "click here"),
new Option<string>(" ", "Mode Explanation [mergeMats]", "Mode [mergeMats]: \tYou dont buy any items but instead get the materials to buy them yourself, this way you can choose.", "click here"),
new Option<string>(" ", "Mode Explanation [select]", "Mode [select]: \tYou are able to select what items you get and which ones you dont in the Select Category below.", "click here"),
};
/// <summary>
/// The name of ScriptOptions for any merge script.
/// </summary>
public string OptionsStorage = "MergeOptionStorage";
#endregion
#region Kill
#nullable enable
/// <summary>
/// Joins a map, jumps to a specified cell and pad, sets the spawn point, and kills the specified monster using the best available race gear.
/// </summary>
/// <param name="map">The map to join.</param>
/// <param name="cell">The cell to jump to.</param>
/// <param name="pad">The pad to jump to.</param>
/// <param name="monster">The name of the monster to kill.</param>
/// <param name="item">The item to kill the monster for. If null or empty, will just kill the monster once.</param>
/// <param name="quant">The desired quantity of the item to collect.</param>
/// <param name="isTemp">Whether the item is temporary.</param>
/// <param name="log">Whether to log the killing of the monster.</param>
/// <param name="publicRoom">Whether the action should take place in a public room.</param>
public void BoostKillMonster(string map, string cell, string pad, string monster, string item = "", int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != "" && Core.CheckInventory(item, quant))
return;
Core.Join(map, cell, pad, publicRoom: publicRoom);
// _RaceGear(monster);
Core.KillMonster(map, cell, pad, monster, item, quant, isTemp, log, publicRoom);
GearStore(true);
}
/// <summary>
/// Kills a monster using it's ID, with the specified monsters the best available race gear
/// </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>
/// <param name="publicRoom"></param>
public void BoostKillMonster(string map, string cell, string pad, int monsterID, string item = "", int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != "" && Core.CheckInventory(item, quant))
return;
Core.Join(map, cell, pad, publicRoom: publicRoom);
// _RaceGear(monsterID);
Core.KillMonster(map, cell, pad, monsterID, item, quant, isTemp, log, publicRoom);
GearStore(true);
}
/// <summary>
/// Joins a map, hunts for the monster, and kills the specified monster using the best available race gear.
/// </summary>
/// <param name="map">The map to join.</param>
/// <param name="monster">The name of the monster to hunt and kill.</param>
/// <param name="item">The item to hunt the monster for. If null, it will just hunt and kill the monster once.</param>
/// <param name="quant">The desired quantity of the item to collect.</param>
/// <param name="isTemp">Whether the item is temporary.</param>
/// <param name="log">Whether to log the hunting and killing of the monster.</param>
/// <param name="publicRoom">Whether the action should take place in a public room.</param>
public void BoostHuntMonster(string map, string monster, string? item = null, int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = false)
{
if (item != null && Core.CheckInventory(item, quant))
return;
Core.Join(map, publicRoom: publicRoom);
// _RaceGear(monster);
Core.HuntMonster(map, monster, item, quant, isTemp, log, publicRoom);
GearStore(true);
}
/// <summary>
/// Joins a map, jumps to a specified cell and pad, sets the spawn point, and kills the specified monster using the best available race gear. Additionally, it listens for counter-attacks.
/// </summary>
/// <param name="map">The map to join.</param>
/// <param name="cell">The cell to jump to.</param>
/// <param name="pad">The pad to jump to.</param>
/// <param name="monster">The name of the monster to kill.</param>
/// <param name="item">The item to kill the monster for. If null, it will just kill the monster once.</param>
/// <param name="quant">The desired quantity of the item to collect.</param>
/// <param name="isTemp">Whether the item is temporary.</param>
/// <param name="log">Whether to log the killing of the monster.</param>
/// <param name="publicRoom">Whether the action should take place in a public room.</param>
/// <param name="forAuto">Whether the method is used for an automated process.</param>
public void KillUltra(string map, string cell, string pad, string monster, string? item = null, int quant = 1, bool isTemp = true, bool log = true, bool publicRoom = true, bool forAuto = false)
{
if (item != null && Core.CheckInventory(item, quant))
return;
if (item != null && !isTemp)
Core.AddDrop(item);
Core.Join(map, cell, pad, publicRoom: publicRoom);
// if (!forAuto)
// _RaceGear(monster);
Core.Jump(cell, pad);
bool ded = false;
Bot.Events.MonsterKilled += b => ded = true;
if (item == null)
{
if (log)
Core.Logger($"Killing Ultra-Boss {monster}");
while (!Bot.ShouldExit && !ded)
{
ded = false;
Core.Jump(cell, pad);
if (!Bot.Combat.StopAttacking)
Bot.Combat.Attack(monster);
Core.Sleep();
}
Core.Rest();
return;
}
Bot.Events.MonsterKilled -= b => ded = true;
if (log)
Core.Logger($"Killing Ultra-Boss {monster} for {item} ({quant}) [Temp = {isTemp}]");
Bot.Hunt.ForItem(monster, item, quant, isTemp);
if (!forAuto)
GearStore(true);
}
#region WIP/Proof of Concept Methods(W.I.P)
/// <summary>
/// Kills a monster while monitoring for a specific aura.
/// </summary>
public void KillWithAura(
string map, string cell, string pad, string monster,
string[] auraNames,
Dictionary<string, Action>? auraReactions = null,
string? item = null, int quant = 1, bool isTemp = false, bool log = true,
int ItemToUse = 0, int SafeItem = 0,
CancellationToken cancellationToken = default)
{
if (item != null && (isTemp ? Bot.TempInv.Contains(item, quant) : Core.CheckInventory(item, quant)))
return;
DateTime lastAuraTrigger = DateTime.MinValue;
TimeSpan auraCooldown = TimeSpan.FromSeconds(0);
monster = monster.Trim().FormatForCompare();
Bot.Events.ExtensionPacketReceived += AuraListener;
#region Setup Item Equip (optional)
if (ItemToUse > 0)
{
int fallbackPotion = 1749;
int equipSafe = SafeItem > 0 ? SafeItem : fallbackPotion;
if (!Core.CheckInventory(equipSafe))
BuyItem("embersea", 1100, fallbackPotion, 10, 1, 17966);
EquipRetry(equipSafe);
Core.Equip(ItemToUse);
}
#endregion
if (item == null)
{
if (log)
Core.Logger($"Killing {monster}");
Bot.Kill.Monster(monster);
}
else
{
if (!isTemp)
Core.AddDrop(item);
if (log)
Core.FarmingLogger(item, quant);
while (!Bot.ShouldExit && !Core.CheckInventory(item, quant) && !cancellationToken.IsCancellationRequested)
{
while (!Bot.ShouldExit && !Bot.Player.Alive && !cancellationToken.IsCancellationRequested) { }
if (Bot.Map.Name != map)
Core.Join(map, cell, pad);
if (Bot.Player.Cell != cell)
Core.Jump(cell, pad);
Bot.Combat.Attack(monster);
Bot.Sleep(500);
if (isTemp ? Bot.TempInv.Contains(item, quant) : (Bot.Inventory.Contains(item, quant) || Bot.Bank.Contains(item, quant)))
break;
}
}
Bot.Events.ExtensionPacketReceived -= AuraListener;
void AuraListener(dynamic packet)
{
if (cancellationToken.IsCancellationRequested)
return;
if ((string?)packet["params"]?.type != "json")
return;
dynamic? data = packet["params"]?.dataObj;
if (data?.cmd?.ToString() != "ct" || data?.a is null)
return;
if (data == null)
return;
foreach (dynamic a in data.a)
{
string? auraName = a?.aura?["nam"]?.ToString();
if (string.IsNullOrEmpty(auraName) || !auraNames.Contains(auraName))
continue;
// Throttle cooldown
if (DateTime.Now - lastAuraTrigger < auraCooldown)
continue;
lastAuraTrigger = DateTime.Now;
if (auraReactions != null && auraReactions.TryGetValue(auraName, out Action? reaction))
{
Bot.Log($"Invoking reaction for aura: {auraName}");
try
{
reaction?.Invoke();
}
catch (Exception ex)
{
Core.Logger($"Exception during aura reaction '{auraName}': {ex}");
}
}
else
{
// fallback switch logic if no reaction found
switch (auraName)
{
case "Shapeshifted":
Bot.Log($"Detected aura (switch fallback): {auraName}");
break;
default:
Core.Logger($"Unhandled aura (switch fallback): {auraName}");
break;
}
}
break; // react to only one aura per packet
}
}
void EquipRetry(int id)
{
Core.Equip(id);
Bot.Wait.ForTrue(() => Bot.Inventory.IsEquipped(id), 20);
Bot.Sleep(2000);
Core.Equip(id); // Flash refresh workaround
Bot.Sleep(2000);
}
}
/* Example:
Adv.KillWithAura(
map: "kitsune",
cell: "Boss",
pad: "Left",
monster: "kitsune",
auraNames: new[] { "Shapeshifted" },
auraReactions: new Dictionary<string, Action>
{
["Shapeshifted"] = () => Core.Logger("Aura: Shapeshifted", "Example"),
},
item: "Fox Tail",
quant: 3,
log: true,
ItemToUse: 0,