forked from BrenoHenrike/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoreAdvanced.cs
2855 lines (2554 loc) · 112 KB
/
CoreAdvanced.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
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.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.DependencyInjection;
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 CoreFarms Farm = new();
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="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 re-log you after to prevent ghost buy. To get the ShopItemID use the built in loader of Skua</param>
public void BuyItem(string map, int shopID, string itemName, int quant = 1, int shopItemID = 0)
{
if (Core.CheckInventory(itemName, quant))
return;
Core.Join(map);
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);
}
/// <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>
public void BuyItem(string map, int shopID, int itemID, int quant = 1, int shopQuant = 1, int shopItemID = 0)
{
if (Core.CheckInventory(itemID, quant))
return;
Core.Join(map);
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);
}
private void _BuyItem(string map, int shopID, ShopItem item, int quant = 1)
{
if (item.Requirements != null)
{
foreach (ItemBase req in item.Requirements)
{
if (Core.CheckInventory(req.ID, req.Quantity))
continue;
if (Core.GetShopItems(map, shopID).Any(x => req.ID == x.ID))
BuyItem(map, shopID, req.ID, req.Quantity * quant);
}
}
GetItemReq(item, quant);
Core._BuyItem(map, shopID, item, quant);
}
/// <summary>
/// Will make sure you have every requierment (XP, Rep and Gold) to buy the item.
/// </summary>
/// <param name="item">The ShopItem object containing all the information</param>
public void GetItemReq(ShopItem item, int quant = 1)
{
if (!String.IsNullOrEmpty(item.Faction) && item.Faction != "None" && item.RequiredReputation > 0)
runRep(item.Faction, Core.PointsToLevel(item.RequiredReputation));
Farm.Experience(item.Level);
if (!item.Coins)
Farm.Gold(item.Cost * quant);
}
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 all merge from a shop based on the script options selected setting. Will read where to get the ingredients from from the findIngredients param
/// </summary>
/// <param name="map">The map where the shop can be loaded from</param>
/// <param name="shopID">The shop ID to load the shopdata</param>
/// <param name="findIngredients">A switch nested in a void that will explain this function where to get items</param>
public void StartBuyAllMerge(string map, int shopID, Action findIngredients, string? buyOnlyThis = null, string[]? itemBlackList = null, mergeOptionsEnum? buyMode = null)
{
if (buyOnlyThis == null && buyMode == null)
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;
List<ShopItem> shopItems = Core.GetShopItems(map, shopID);
List<ShopItem> items = new();
bool memSkipped = false;
shopItems = shopItems.GroupBy(item => item.ID)
.Select(group => group.First())
.ToList();
foreach (ShopItem item in shopItems)
{
if (Core.CheckInventory(item.ID, toInv: false) ||
miscCatagories.Contains(item.Category) ||
(!String.IsNullOrEmpty(buyOnlyThis) && buyOnlyThis != item.Name) ||
(itemBlackList != null && itemBlackList.Any(b => b.ToLower() == item.Name.ToLower())))
continue;
if (Core.IsMember || !item.Upgrade)
{
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 member.");
memSkipped = true;
}
}
if (items.Count == 0)
{
if (buyOnlyThis != null)
return;
switch (mode)
{
case 0: // all
case 2: // mergeMats
Core.Logger("The bot fetched 0 items to farm. Something must have gone wrong.");
return;
case 1: // acOnly
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.");
return;
case 3: // select
if (memSkipped)
Core.Logger("The bot fetched 0 items to farm. This is because you aren't member.");
else Core.Logger("The bot fetched 0 items to farm. Something must have gone wrong.");
return;
}
}
int t = 1;
for (int i = 0; i < 2; i++)
{
foreach (ShopItem item in items)
{
if (!matsOnly)
Core.Logger($"Farming to buy {item.Name} (#{t}/{items.Count})");
getIngredients(item, 1);
if (!matsOnly && !Core.CheckInventory(item.ID, toInv: false))
{
Core.Logger($"Buying {item.Name} (#{t++}/{items.Count})");
BuyItem(map, shopID, item.ID);
if (item.Coins)
Core.ToBank(item.Name);
else Core.Logger($"{item} could not be banked");
}
}
if (!matsOnly)
i++;
}
void getIngredients(ShopItem item, int craftingQ)
{
if (Core.CheckInventory(item.ID, craftingQ) || item.Requirements == null)
return;
Core.FarmingLogger(item.Name, craftingQ);
foreach (ItemBase req in item.Requirements)
{
if (matsOnly)
{
if (Bot.Inventory.IsMaxStack(req.Name))
externalQuant = req.MaxStack;
else
{
if (req.Temp)
externalQuant = Bot.TempInv.GetQuantity(req.Name) + req.Quantity;
else externalQuant = Bot.Inventory.GetQuantity(req.Name) + req.Quantity;
}
}
else if (MaxStackOneItems.Contains(req.Name))
externalQuant = 1;
else
externalQuant = req.Quantity * (craftingQ - Bot.Inventory.GetQuantity(item.ID));
if (Core.CheckInventory(req.Name, externalQuant) && (!matsOnly || req.MaxStack == 1))
continue;
if (shopItems.Select(x => x.ID).Contains(req.ID) && !AltFarmItems.Contains(req.Name))
{
ShopItem selectedItem = shopItems.First(x => x.ID == req.ID);
if (selectedItem.Requirements.Any(r => MaxStackOneItems.Contains(r.Name)))
{
while (!Core.CheckInventory(selectedItem.ID, req.Quantity))
{
getIngredients(selectedItem, req.Quantity);
Core.Sleep();
if (!matsOnly)
BuyItem(map, shopID, selectedItem.ID, (Bot.Inventory.GetQuantity(selectedItem.ID) + selectedItem.Quantity));
else break;
}
}
else
{
getIngredients(selectedItem, req.Quantity);
Core.Sleep();
if (!matsOnly)
BuyItem(map, shopID, selectedItem.ID, req.Quantity);
}
}
else
{
Core.AddDrop(req.Name);
externalItem = req;
findIngredients();
}
}
}
}
public List<ItemCategory> miscCatagories = new() { ItemCategory.Note, ItemCategory.Item, ItemCategory.Resource, 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()
{
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, jump & set the spawn point and kills the specified monster with 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="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 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>
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 and hunt for the monster and kills the specified monster with the best available race gear
/// </summary>
/// </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 BoostHuntMonster(string map, 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, publicRoom: publicRoom);
// _RaceGear(monster);
Core.HuntMonster(map, monster, item, quant, isTemp, log, publicRoom);
GearStore(true);
}
/// <summary>
/// Joins a map, jump & set the spawn point and kills the specified monster with the best available race gear. But also listens for Counter Attacks
/// </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 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);
if (item == null)
{
if (log)
Core.Logger($"Killing Ultra-Boss {monster}");
bool ded = false;
Bot.Events.MonsterKilled += b => ded = true;
while (!Bot.ShouldExit && !ded)
if (!Bot.Combat.StopAttacking)
Bot.Combat.Attack(monster);
Core.Rest();
return;
}
if (log)
Core.Logger($"Killing Ultra-Boss {monster} for {item} ({quant}) [Temp = {isTemp}]");
Bot.Hunt.ForItem(monster, item, quant, isTemp);
if (!forAuto)
GearStore(true);
}
#endregion
#region Gear
/// <summary>
/// Ranks up your class
/// </summary>
/// <param name="ClassName">Name of the class you want it to rank up</param>
public void RankUpClass(string className, bool gearRestore = true)
{
Bot.Wait.ForPickup(className, 20);
InventoryItem? itemInv = Bot.Inventory.Items.Find(i => i.Name.Equals(className, StringComparison.Ordinal) && i.Category == ItemCategory.Class);
if (itemInv == null)
{
Core.Logger($"Can't level up \"{className}\" because you do not own it.");
return;
}
if (itemInv.Quantity == 302500)
{
Core.Logger($"\"{className}\" is already Rank 10");
}
else if (itemInv.Name.Equals("Hobo Highlord") || itemInv.Name.Equals("No Class") || itemInv.Name.Equals("Obsidian No Class"))
{
Core.Logger($"\"{itemInv.Name}\" cannot be leveled past Rank 1");
}
else
{
if (gearRestore)
GearStore();
SmartEnhance(itemInv.Name);
var classItem = Bot.Inventory.Items.Find(i => i.Name.Equals(itemInv.Name, StringComparison.Ordinal) && i.Category == ItemCategory.Class);
if (classItem?.EnhancementLevel == 0)
{
Core.Logger($"Can't level up \"{itemInv.Name}\" because it's not enhanced, and AutoEnhance is turned off");
}
else
{
string cpBoost = BestGear(GenericGearBoost.cp, false);
EnhanceItem(cpBoost, CurrentClassEnh(), CurrentCapeSpecial(), CurrentHelmSpecial(), CurrentWeaponSpecial());
Core.Equip(cpBoost);
Farm.ToggleBoost(BoostType.Class);
Farm.IcestormArena(Bot.Player.Level, true);
Core.Logger($"\"{itemInv.Name}\" is now Rank 10");
Farm.ToggleBoost(BoostType.Class, false);
if (gearRestore)
GearStore(true);
}
}
}
// Temp here cuz name change is fucky on auto update for some reason
public void rankUpClass(string ClassName, bool GearRestore = true) => RankUpClass(ClassName, GearRestore);
/// <summary>
/// Do not use this variant
/// </summary>
private void BestGear()
{
// Just here so I can read the other things I had planned
//foreach (string Item in ArrayOutput)
//{
// InventoryItem invItem = BankInvData.First(x => x.Name == Item);
// if (!invItem.Equipped)
// continue;
// if (invItem.ItemGroup == "Weapon")
// {
// List<InventoryItem> theList = new();
// theList.AddRange(Bot.Inventory.Items.Where(x => x.Name != Item && x.ItemGroup == "Weapon" && x.EnhancementLevel > 0 && Core.IsMember ? true : !x.Upgrade));
// if (theList.Count == 0)
// theList.AddRange(Bot.Bank.Items.Where(x => x.Name != Item && x.ItemGroup == "Weapon" && x.EnhancementLevel > 0 && Core.IsMember ? true : !x.Upgrade));
// if (theList.Count != 0)
// Core.Equip(theList.First().Name);
// else
// {
// Core.BuyItem(Bot.Map.Name, 299, "Battle Oracle Battlestaff");
// Core.Equip("Battle Oracle Battlestaff");
// }
// }
// else
// {
// Core.JumpWait();
// Bot.Send.Packet($"%xt%zm%unequipItem%{Bot.Map.RoomID}%{invItem.ID}%");
// }
//}
//List<BestGearData> BestBestGearData = BestGearData.Where(x => x.BoostValue == TotalBoostValue).ToList();
//if (BestBestGearData.Count() > 1)
//{
// if (BestBestGearData.Any(x => BankInvData.Where(i => i.Equipped).Select(x => x.Name).Contains(x.iRace)
// || BestBestGearData.Any(x => BankInvData.Where(i => i.Equipped).Select(x => x.Name).Contains(x.iDMGall))))
// ArrayOutput = new[] { BestBestGearData.First(x => BankInvData.Where(i => i.Equipped).Select(x => x.Name).Contains(x.Key)).Key };
// foreach (BestGearData Gear in BestGearData.Where(x => x.BoostValue == TotalBoostValue))
// {
// InventoryItem Item = BankInvData.First(x => x.Name == Gear.iRace || x.Name == Gear.iDMGall);
// InventoryItem equippedWeapon = BankInvData.First(x => x.Equipped == true && x.ItemGroup == "Weapon");
// if (Item != null && equippedWeapon != null
// && Bot.Flash.GetGameObject<int>($"world.invTree.{Item.ID}.EnhID") == Bot.Flash.GetGameObject<int>($"world.invTree.{equippedWeapon.ID}.EnhID"))
// {
// ArrayOutput = new[] { Item.Name };
// break;
// }
// }
//}
//foreach (string Item in ArrayOutput)
//{
// InventoryItem invItem = BankInvData.First(x => x.Name == Item);
// if (!invItem.Equipped)
// continue;
// if (invItem.ItemGroup == "Weapon")
// {
// List<InventoryItem> theList = new();
// theList.AddRange(Bot.Inventory.Items.Where(x => x.Name != Item && x.ItemGroup == "Weapon" && x.EnhancementLevel > 0 && Core.IsMember ? true : !x.Upgrade));
// if (theList.Count == 0)
// theList.AddRange(Bot.Bank.Items.Where(x => x.Name != Item && x.ItemGroup == "Weapon" && x.EnhancementLevel > 0 && Core.IsMember ? true : !x.Upgrade));
// if (theList.Count != 0)
// Core.Equip(theList.First().Name);
// else
// {
// Core.BuyItem(Bot.Map.Name, 299, "Battle Oracle Battlestaff");
// Core.Equip("Battle Oracle Battlestaff");
// }
// }
// else
// {
// Core.JumpWait();
// Bot.Send.Packet($"%xt%zm%unequipItem%{Bot.Map.RoomID}%{invItem.ID}%");
// }
//}
}
/// <summary>
/// Equips the best gear available in a player's inventory/bank by checking what item has the highest boost value of the given type. Also works with damage stacking for monsters with a Race
/// </summary>
/// <param name="BoostType">Type "GenericGearBoost." and then the boost of your choice in order to determine and equip the best available boosting gear</param>
/// <param name="EquipItem">To Equip the found item(s) or not</param>
public string BestGear(GenericGearBoost boostType, bool equipItem = true)
{
try
{
// If CBO settings disable bestgear, dont do anything
if (Core.CBOBool("DisableBestGear", out bool _DisableBestGear) && _DisableBestGear)
return String.Empty;
// If this bestgear prompt is the same as the last, return the previous value
if (LastGenericBoostType == boostType)
return LastGenericBestGear ?? String.Empty;
string boostString = boostType.ToString();
Core.Logger($"Searching for the best available gear for {boostString}");
IEnumerable<InventoryItem> GearWithChosenBoost =
Bot.Inventory.Items
.Concat(Bot.Bank.Items)
.Where(item => !String.IsNullOrEmpty(item.Meta) && item.Meta.Contains(boostString));
InventoryItem? toReturn = null;
// Cant find anything if the list is empty
if (!GearWithChosenBoost.Any())
{
Core.Logger($"Best gear for {boostString} wasn't found!");
return String.Empty;
}
IEnumerable<(InventoryItem, float)> bestGearData = GearWithChosenBoost.Select(item => (item, _getBoostFloat(item, boostString)));
//bestGearData.ForEach(b => Core.DebugLogger(this, $"{b.Item1.Name} = {b.Item2}"));
float BestBoostValue = bestGearData.Select(x => x.Item2).Max();
IEnumerable<InventoryItem> bestItems = bestGearData.Where(x => x.Item2 == BestBoostValue).Select(x => x.Item1);
// Prioritize an item that is already equipped
IEnumerable<InventoryItem> filter = bestItems.Where(x => x.Equipped);
if (filter != null && filter.Any(x => x != null))
setToReturn(filter);
else
{
// Prioritize an item that has the same EnhID
// The int (Item2) is EnhID
List<(InventoryItem, int)> equippedItems =
Bot.Inventory.Items
.Where(x => x.Equipped)
.Select(x => (x, getEnhID(x)))
.ToList();
IEnumerable<(InventoryItem, int)> bestItemsEnh =
bestItems
.Select(x => (x, getEnhID(x)));
filter =
bestItemsEnh
.Where(x =>
x.Item2 == equippedItems.Find(e => e.Item1.ItemGroup == x.Item1.ItemGroup).Item2)
.Select(b => b.Item1);
// Should always return true if its two pets or armors or ground runes
if (filter != null && filter.Any(x => x != null && x.ID > 0))
setToReturn(filter);
else
{
// If none of the enhancement IDs match, prioritize items that are enhanced in general
filter = bestItemsEnh.Where(x => x.Item2 != 0).Select(b => b.Item1);
if (filter != null && filter.Any(x => x != null))
setToReturn(filter);
// If no items are enhanced, just pick the item (based on category ofc)
else setToReturn(bestItems);
}
}
if (toReturn == null)
{
// This should be impossible to reach, but is a good savety precaughtion
Core.Logger($"Best gear for {boostString} wasn't found!");
return String.Empty;
}
else Core.Logger($"Best gear for {boostString} found: {toReturn.Name} ({(BestBoostValue - 1).ToString("+0.##%")})");
LastGenericBestGear = toReturn.Name;
if (equipItem)
{
// If the item is not enhanced and it can be and should be done so before it's equipped
if (toReturn.EnhancementLevel == 0 && EnhanceableCatagories.Contains(toReturn.Category))
{
if (!Core.CBOBool("DisableAutoEnhance", out bool _disableAutoEnhance) || !_disableAutoEnhance)
{
InventoryItem? equippedItem = Bot.Inventory.Items.Find(x => x.Equipped && x.ItemGroup == toReturn.ItemGroup);
EnhancementType type = EnhancementType.Lucky;
CapeSpecial cape = CapeSpecial.None;
HelmSpecial helm = HelmSpecial.None;
WeaponSpecial weapon = WeaponSpecial.None;
if (equippedItem != null)
{
switch (toReturn.Category)
{
case ItemCategory.Cape:
if (equippedItem.EnhancementPatternID <= 10 && !IsEnhancedWithBaseForge(equippedItem)) // If its not a forge enhancement
type = (EnhancementType)equippedItem.EnhancementPatternID;
else cape = (CapeSpecial)equippedItem.EnhancementPatternID;
break;
case ItemCategory.Helm:
if (equippedItem.EnhancementPatternID <= 25 && !IsEnhancedWithBaseForge(equippedItem)) // If its not a forge enhancement
type = (EnhancementType)equippedItem.EnhancementPatternID;
else helm = (HelmSpecial)equippedItem.EnhancementPatternID;
break;
case ItemCategory.Class:
type = (EnhancementType)equippedItem.EnhancementPatternID;
break;
default: // Weapon
if (equippedItem.EnhancementPatternID <= 6 && !IsEnhancedWithBaseForge(equippedItem)) // If its not a forge enhancement
type = (EnhancementType)equippedItem.EnhancementPatternID;
weapon = (WeaponSpecial)getProcID(equippedItem);
break;
}
}
EnhanceItem(toReturn.Name, type, cape, helm, weapon);
}
else
{
Core.Logger("Equipping Failed: BestGear tried to equip an unenhanced item and AutoEnhance is disabled.");
}
}
else Core.Equip(LastGenericBestGear);
}
LastGenericBoostType = boostType;
return LastGenericBestGear;
void setToReturn(IEnumerable<InventoryItem> combos)
{
toReturn =
combos.OrderBy(c => getPriority(bestGearData.First(r => r.Item1.ID == c.ID).Item1))
.First();
}
}
catch (Exception e)
{
AdvCrash(e);
return String.Empty;
}
}
/// <summary>
/// Equips the best gear available in a player's inventory/bank by checking what item has the highest boost value of the given type. Also works with damage stacking for monsters with a Race
/// </summary>
/// <param name="BoostType">Type "RacialGearBoost." and then the boost of your choice in order to determine and equip the best available boosting gear</param>
/// <param name="EquipItem">To Equip the found item(s) or not</param>
public string[] BestGear(RacialGearBoost boostType, bool equipItem = true)
{
try
{
// If CBO settings disable bestgear, dont do anything
if (Core.CBOBool("DisableBestGear", out bool _DisableBestGear) && _DisableBestGear)
return Array.Empty<string>();
// If this bestgear prompt is the same as the last, return the previous value
if (LastRacialBoostType == boostType)
return LastRacialBestGear ?? Array.Empty<string>();
// If the enemy has no race, focus dmgAll
string boostString = boostType == RacialGearBoost.None ? "Untagged" : boostType.ToString();
Core.Logger($"Searching for the best available gear against {boostString}");
IEnumerable<InventoryItem> GearWithMeta = Bot.Inventory.Items.Concat(Bot.Bank.Items).Where(item => !String.IsNullOrEmpty(item.Meta));
IEnumerable<InventoryItem> GearWithChosenBoost = GearWithMeta.Where(item => item.Meta.Contains(boostString));
List<InventoryItem> toReturn = new();
// Fetch all dmg all items
IEnumerable<(InventoryItem, float)> damageAllItems =
GearWithMeta
.Where(item => item.Meta.Contains("dmgAll"))
.Select(item => (item, _getBoostFloat(item, "dmgAll")));
IEnumerable<InventoryItem> relevantItems = GearWithChosenBoost.Concat(damageAllItems.Select(x => x.Item1));
List<RacialBestGearData> bestGearData = new();
// If the player has damage all items (should also work if empty)
bestGearData.AddRange(
damageAllItems.Select(dmgTulpe =>
new RacialBestGearData(dmgTulpe.Item1, dmgTulpe.Item2)));
// If the player has racial boosting items
if (GearWithChosenBoost.Any())
{
foreach (InventoryItem racialItem in GearWithChosenBoost)
{
float racialBoost = _getBoostFloat(racialItem, boostString);
// Add the racial item standalone
bestGearData.Add(new(racialItem, racialBoost));
// Add the racial items in combination with the
bestGearData.AddRange(
damageAllItems
.Where(dmgTulpe => dmgTulpe.Item1.ItemGroup != racialItem.ItemGroup)
.Select(dmgTulpe =>
new RacialBestGearData(racialItem, dmgTulpe.Item1, dmgTulpe.Item2 * racialBoost)));
}
}
// This triggers if there are no racial boost items, but also no damage all items
if (!bestGearData.Any())
{
Core.Logger($"Best gear against {boostString} wasn't found!");
return Array.Empty<string>();
}
//bestGearData.ForEach(b => Core.DebugLogger(this, $"{b.Item1.Name} + {b.Item2?.Name ?? "NULL"} = {b.BoostValue}"));
float BestBoostValue = bestGearData.Select(x => x.BoostValue).Max();
IEnumerable<RacialBestGearData> bestCombos = bestGearData.Where(x => x.BoostValue == BestBoostValue);
// Prioritize a combination where both items of any of the optimal set are already equipped
IEnumerable<RacialBestGearData> filter = bestCombos.Where(x => x.Item1.Equipped && (x.Item2 == null || x.Item2.Equipped));
if (filter != null && filter.Any(x => x != null))
setToReturn(filter);
else
{
// Prioritize a combination where one items in the optimal sets is equipped
filter = bestCombos.Where(x => x.Item1.Equipped || (x.Item2 != null && x.Item2.Equipped));
if (filter != null && filter.Any(x => x != null))
setToReturn(filter);
// If it gets here, that means none of the optimal items are equipped
// Supporting enhancement consideration for racial items is overly complex and unneccessary
else setToReturn(bestCombos);
}
switch (toReturn.Count)
{
// This might already be handled and could be unneccessary
//case 0:
// Core.Logger($"Best gear against {boostString} wasn't found!");
// return Array.Empty<string>();
case 1:
Core.Logger($"Best gear against {boostString} found: {toReturn[0].Name} ({(BestBoostValue - 1).ToString("+0.##%")})");
break;
case 2:
Core.Logger($"Best gear against {boostString} found: {toReturn[0].Name} + {toReturn[1].Name} ({(BestBoostValue - 1).ToString("+0.##%")})");
break;
default:
Core.Logger($"How the fuck did toReturn.Count get {toReturn.Count}. Please report");
break;
}
LastRacialBestGear = toReturn.Select(i => i.Name).ToArray();
if (equipItem)
Core.Equip(LastRacialBestGear);
LastRacialBoostType = boostType;
return LastRacialBestGear;
void setToReturn(IEnumerable<RacialBestGearData> combos)
{
RacialBestGearData combo =
combos.OrderBy(c =>
c.Item2 == null ?
getPriority(
relevantItems.First(r => r.ID == c.Item1.ID)) :
getPriority(
relevantItems.First(r => r.ID == c.Item1.ID),
relevantItems.First(r => r.ID == c.Item2.ID)))
.First();
if (combo.Item2 == null)
toReturn = new() { combo.Item1 };
else toReturn = new() { combo.Item1, combo.Item2 };
}
}
catch (Exception e)
{
AdvCrash(e);
return Array.Empty<string>();
}
}
int getPriority(params InventoryItem[] items)
{
int toReturn = 0;
foreach (ItemCategory c in items.Select(i => i.Category))
{
switch (c)
{
case ItemCategory.Misc: // Ground runes
break; // Value is 0
case ItemCategory.Helm:
toReturn += 1;
break;
case ItemCategory.Pet:
toReturn += 2;
break;
case ItemCategory.Cape:
toReturn += 4;
break;
case ItemCategory.Armor:
toReturn += 8;
break;
default: // Weapons
toReturn += 16;
break;
}
}
return toReturn;
}
private GenericGearBoost? LastGenericBoostType = null;
private RacialGearBoost? LastRacialBoostType = null;
private string? LastGenericBestGear = null;
private string[]? LastRacialBestGear = null;
private class RacialBestGearData
{
public InventoryItem Item1 { get; set; }
public InventoryItem? Item2 { get; set; }
public float BoostValue { get; set; }
public RacialBestGearData(InventoryItem item1, InventoryItem item2, float boostValue)
{
Item1 = item1;
Item2 = item2;
BoostValue = boostValue;
}
public RacialBestGearData(InventoryItem item1, float boostValue)
{
Item1 = item1;
BoostValue = boostValue;
}
}
/// <summary>
/// Stores the gear a player has so that it can later restore these
/// </summary>
/// <param name="Restore">Set true to restore previously stored gear</param>
public void GearStore(bool Restore = false, bool EnhAfter = false)
{
if (!Restore)
{
foreach (InventoryItem Item in Bot.Inventory.Items.FindAll(i => i.Equipped == true))
ReEquippedItems.Add(Item.Name);
ReEnhanceAfter = CurrentClassEnh();
if (Bot.Inventory.Items.Any(x => x.Category == ItemCategory.Cape && x.Equipped))
ReCEnhanceAfter = CurrentCapeSpecial();
if (Bot.Inventory.Items.Any(x => x.Category == ItemCategory.Helm && x.Equipped))
ReHEnhanceAfter = CurrentHelmSpecial();
ReWEnhanceAfter = CurrentWeaponSpecial();
}
else if (ReEquippedItems.Count > 0)
{
Core.Equip(ReEquippedItems.ToArray());
if (EnhAfter)
EnhanceEquipped(ReEnhanceAfter, ReCEnhanceAfter, ReHEnhanceAfter, ReWEnhanceAfter);
}
}
private List<string> ReEquippedItems = new();
private EnhancementType ReEnhanceAfter = EnhancementType.Lucky;
private CapeSpecial ReCEnhanceAfter = CapeSpecial.None;
private HelmSpecial ReHEnhanceAfter = HelmSpecial.None;
private WeaponSpecial ReWEnhanceAfter = WeaponSpecial.None;
/// <summary>
/// Find out if an item is a weapon or not
/// </summary>
/// <param name="Item">The ItemBase object of the item</param>
/// <returns>Returns if its a weapon or not</returns>
public bool isWeapon(ItemBase Item) => Item.ItemGroup == "Weapon";
/// <summary>
/// Will do GearStore() and then figure out the race of the monster paramater and equip bestGear on it
/// </summary>
/// <param name="Monster">The Monster object of the monster</param>
public void _RaceGear(string Monster)
{
if (!Bot.Monsters.MapMonsters.Any(x => x.Name.ToLower() == Monster.ToLower()))
{
Core.Logger("Could not find any monster with the name " + Monster);
return;
}
GearStore();
string Map = Bot.Map.LastMap;
string MonsterRace = "";
if (Monster != "*")
MonsterRace = Bot.Monsters.MapMonsters.First(x => x.Name.ToLower() == Monster.ToLower())?.Race ?? "";
else
{
if (Bot.Monsters.CurrentMonsters.Count == 0)
{
Core.Logger($"No monsters are present in cell \"{Bot.Player.Cell}\" in /{Bot.Map.Name}");
return;
}
MonsterRace = Bot.Monsters.CurrentMonsters.First().Race ?? "";
}
if (MonsterRace == null || MonsterRace == "")
return;
string[] _BestGear = BestGear((RacialGearBoost)Enum.Parse(typeof(RacialGearBoost), MonsterRace), false);
if (_BestGear.Length == 0)
return;
EnhanceItem(_BestGear, CurrentClassEnh(), CurrentCapeSpecial(), CurrentHelmSpecial(), CurrentWeaponSpecial());
Core.Equip(_BestGear);
//EnhanceEquipped(CurrentClassEnh(), CurrentCapeSpecial(), CurrentHelmSpecial(), CurrentWeaponSpecial());
Core.Join(Map);
}