forked from BrenoHenrike/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreStory.cs
More file actions
606 lines (538 loc) · 26.1 KB
/
CoreStory.cs
File metadata and controls
606 lines (538 loc) · 26.1 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
//cs_include Scripts/CoreBots.cs
using Skua.Core.Interfaces;
using Skua.Core.Models.Items;
using Skua.Core.Models.Quests;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Dynamic;
public class CoreStory
{
// [Can Change]
// True = Bot only does its smart checks on quests with Once: True
// False = Bot does it's smart checks on all quest
// Recommended: false
// Used for testing bots, dont toggle this as a user
public bool TestBot { get; set; } = false;
public IScriptInterface Bot => IScriptInterface.Instance;
public CoreBots Core => CoreBots.Instance;
public void ScriptMain(IScriptInterface bot)
{
Core.RunCore();
}
/// <summary>
/// Kills a monster for a Quest, and turns in the quest if possible. Automatically checks if the next quest is unlocked. If it is, it will skip this one.
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="MapName">Map where the <paramref name="MonsterName"/> are</param>
/// <param name="MonsterName">Monster to kill</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void KillQuest(int QuestID, string MapName, string MonsterName, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
SmartKillMonster(QuestID, MapName, MonsterName);
if (AutoCompleteQuest)
foreach (ItemBase item in QuestData.Requirements)
Bot.Wait.ForPickup(item.ID);
TryComplete(QuestData, AutoCompleteQuest);
void SmartKillMonster(int questID, string map, string monster)
{
Core.EnsureAccept(questID);
_AddRequirement(questID);
Core.Join(map);
_SmartKill(monster, 20);
CurrentRequirements.Clear();
}
}
/// <summary>
/// Kills an array of monsters for a Quest, and turns in the quest if possible. Automatically checks if the next quest is unlocked. If it is, it will skip this one.
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="MapName">Map where the <paramref name="MonsterName"/> are</param>
/// <param name="MonsterName">Monster to kill</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void KillQuest(int QuestID, string MapName, string[] MonsterNames, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
SmartKillMonster(QuestID, MapName, MonsterNames);
if (AutoCompleteQuest)
foreach (ItemBase item in QuestData.Requirements)
Bot.Wait.ForPickup(item.ID);
TryComplete(QuestData, AutoCompleteQuest);
void SmartKillMonster(int questID, string map, string[] monsters)
{
Core.EnsureAccept(questID);
_AddRequirement(questID);
Core.Join(map);
foreach (string monster in monsters)
_SmartKill(monster, 20);
CurrentRequirements.Clear();
}
}
/// <summary>
/// Gets a MapItem X times for a Quest, and turns in the quest if possible. Automatically checks if the next quest is unlocked. If it is, it will skip this one.
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="MapName">Map where the <paramref name="MonsterName"/> are</param>
/// <param name="MapItemID">ID of the item</param>
/// <param name="Amount">The amount of <paramref name="MapItemID"/> it grabs</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void MapItemQuest(int QuestID, string MapName, int MapItemID, int Amount = 1, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
Core.EnsureAccept(QuestID);
Core.GetMapItem(MapItemID, Amount, MapName);
TryComplete(QuestData, AutoCompleteQuest);
}
/// <summary>
/// Gets a MapItem X times for a Quest, and turns in the quest if possible. Automatically checks if the next quest is unlocked. If it is, it will skip this one.
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="MapName">Map where the <paramref name="MonsterName"/> are</param>
/// <param name="MapItemIDs">ID of the item</param>
/// <param name="Amount">The amount of <paramref name="MapItemID"/> it grabs</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void MapItemQuest(int QuestID, string MapName, int[] MapItemIDs, int Amount = 1, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
Core.EnsureAccept(QuestID);
foreach (int MapItemID in MapItemIDs)
Core.GetMapItem(MapItemID, Amount, MapName);
TryComplete(QuestData, AutoCompleteQuest);
}
/// <summary>
/// Gets a MapItem X times for a Quest, and turns in the quest if possible. Automatically checks if the next quest is unlocked. If it is, it will skip this one.
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="MapName">Map where the <paramref name="MonsterName"/> are</param>
/// <param name="ItemName">Name of the item</param>
/// <param name="Amount">The amount of <paramref name="ItemName"/> to buy</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void BuyQuest(int QuestID, string MapName, int ShopID, string ItemName, int Amount = 1, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
Core.EnsureAccept(QuestID);
Core.BuyItem(MapName, ShopID, ItemName, Amount);
TryComplete(QuestData, AutoCompleteQuest);
}
/// <summary>
/// Accepts a quest and then turns it in again
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
/// <param name="AutoCompleteQuest">If the method should turn in the quest for you when the quest can be completed</param>
public void ChainQuest(int QuestID, bool GetReward = true, string Reward = "All", bool AutoCompleteQuest = true)
{
Quest QuestData = Core.EnsureLoad(QuestID);
if (QuestProgression(QuestID, GetReward, Reward))
return;
Bot.Sleep(Core.ActionDelay);
if (AutoCompleteQuest)
Core.ChainComplete(QuestID);
else
{
Core.EnsureAccept(QuestID);
}
Bot.Wait.ForQuestComplete(QuestID);
Core.Logger($"Completed \"{QuestData.Name}\" [{QuestID}]");
Bot.Sleep(Core.ActionDelay);
}
private void TryComplete(Quest QuestData, bool AutoCompleteQuest)
{
if (!Bot.Quests.CanComplete(QuestData.ID))
return;
Bot.Sleep(Core.ActionDelay);
if (AutoCompleteQuest)
Core.EnsureComplete(QuestData.ID);
Bot.Wait.ForQuestComplete(QuestData.ID);
Core.Logger($"Completed Quest: [{QuestData.ID}] - \"{QuestData.Name}\"", "QuestProgression");
Bot.Sleep(1500);
}
/// <summary>
/// Skeleton of KillQuest, MapItemQuest, BuyQuest and ChainQuest. Only needs to be used inside a script if the quest spans across multiple maps
/// </summary>
/// <param name="QuestID">ID of the quest</param>
/// <param name="GetReward">Whether or not the <paramref name="Reward"/> should be added with AddDrop</param>
/// <param name="Reward">What item should be added with AddDrop</param>
public bool QuestProgression(int QuestID, bool GetReward = true, string Reward = "All")
{
if (QuestID != 0 && PreviousQuestID == QuestID)
return PreviousQuestState;
PreviousQuestID = QuestID;
if (!CBO_Checked)
{
if (Core.CBOBool("BCO_Story_TestBot", out bool _TestBot))
TestBot = _TestBot;
CBO_Checked = true;
}
Quest QuestData = Core.EnsureLoad(QuestID);
ItemBase[] Rewards = QuestData.Rewards.ToArray();
int timeout = 0;
while (!Bot.Quests.IsUnlocked(QuestID))
{
Bot.Sleep(1000);
timeout++;
if (timeout > 15)
{
int currentValue = Bot.Flash.CallGameFunction<int>("world.getQuestValue", QuestData.Slot);
if (lastFailedQuestID != QuestData.ID)
{
if (QuestData.Value - currentValue <= 2)
{
Core.Logger("A server/client desync happened (common) for your quest progress, the bot will now restart");
lastFailedQuestID = QuestData.ID;
timeout = 0;
Core.Relogin();
}
}
else
{
string message2 = $"Quest \"{QuestData.Name}\" [{QuestID}] is not unlocked.|" +
$"Expected value = [{QuestData.Value - 1}/{QuestData.Slot}], recieved = [{currentValue}/{QuestData.Slot}]|" +
"Please fill in the Skua Scripts Form to report this.|" +
"Do you wish to be brought to the form?";
Core.Logger(message2.Replace("|", " "));
if (Bot.ShowMessageBox(message2.Replace("|", "\n"), "Quest not unlocked", true) == true)
{
string path = Bot.Manager.LoadedScript.Replace(Core.AppPath, "").Replace("\\Scripts\\", "").Replace(".cs", "");
Process.Start("explorer", $"\"https://docs.google.com/forms/d/e/1FAIpQLSeI_S99Q7BSKoUCY2O6o04KXF1Yh2uZtLp0ykVKsFD1bwAXUg/viewform?usp=pp_url&" +
"entry.2118425091=Bug+Report&" +
$"entry.290078150={path}&" +
"entry.1803231651=I+got+a+popup+saying+a+quest+was+not+unlocked&" +
$"entry.1918245848={QuestData.ID}&" +
$"entry.1809007115={QuestData.Value - 1}/{QuestData.Slot}&" +
$"entry.493943632={currentValue}/{QuestData.Slot}&" +
$"entry.148016785={QuestData.Name}\"");
}
Bot.Stop(true);
}
}
}
if (Core.isCompletedBefore(QuestID) && (TestBot ? QuestData.Once : true))
{
if (TestBot)
Core.Logger($"Skipped (Once = true): [{QuestID}] - \"{QuestData.Name}\"");
else Core.Logger($"Already Completed: [{QuestID}] - \"{QuestData.Name}\"");
PreviousQuestState = true;
return true;
}
if (GetReward)
{
if (Reward != "All")
{
if (Core.CheckInventory(Reward))
{
Core.Logger($"You already have {Reward}, skipping quest");
PreviousQuestState = true;
return true;
}
Core.AddDrop(Reward);
}
else
foreach (ItemBase Item in Rewards)
Core.AddDrop(Item.Name);
}
Core.Logger($"Doing Quest: [{QuestID}] - \"{QuestData.Name}\"");
Core.EquipClass(ClassType.Solo);
PreviousQuestState = false;
return false;
}
private bool CBO_Checked = false;
private int lastFailedQuestID = 0;
public void LegacyQuestManager(Action questLogic, params int[] questIDs)
{
List<Quest> questData = Core.EnsureLoad(questIDs);
List<LegacyQuestObject> whereToGet = new List<LegacyQuestObject>();
//Core.DL_Enable();
Core.DebugLogger(this, "-------------\t");
foreach (Quest quest in questData)
{
List<ItemBase> desiredQuestReward = quest.Rewards.Where(r => questData.Any(q => q.AcceptRequirements.Any(a => a.ID == r.ID || a.Name == r.Name))).ToList();
int requiredQuestID = questData.Find((q => q.Rewards.Any(r => quest.AcceptRequirements.Any(a => a.ID == r.ID || a.Name == r.Name))))?.ID ?? 0;
List<ItemBase> requiredQuestReward = quest.AcceptRequirements?.Where(r => questData.Any(q => q.Rewards.Any(a => a.ID == r.ID || a.Name == r.Name)))?.ToList();
Core.DebugLogger(this, $"{quest.ID}\t\t");
Core.DebugLogger(this, $"{desiredQuestReward.FirstOrDefault()?.Name}\t");
Core.DebugLogger(this, $"{requiredQuestID}\t\t");
Core.DebugLogger(this, $"{requiredQuestReward.FirstOrDefault()?.Name}\t");
Core.DebugLogger(this, "-------------\t");
if (requiredQuestReward.Count() == 0 && quest.AcceptRequirements.Count() > 0)
{
Core.Logger("The managed failed to find the location of \"" +
String.Join("\" + \"", quest.AcceptRequirements.Select(a => a.Name)) +
$"\" for Quest ID {quest.ID}, is the function missing a Quest ID?",
messageBox: true);
return;
}
whereToGet.Add(new(quest.ID, desiredQuestReward, requiredQuestID, requiredQuestReward));
}
if (whereToGet.All(x => x.desiredQuestReward.Count == 0) || whereToGet.All(x => x.requiredQuestReward.Count == 0))
{
Core.Logger("None of Quest IDs filled in are supposed to be used in the LegacyQuestManager, " +
"please report to the bot makers that they must make this story line in the normal way.",
messageBox: true);
return;
}
int finalItemQuestID = whereToGet.Find(x => x.desiredQuestReward.Count == 0).desiredQuestID;
if (finalItemQuestID <= 0)
{
Core.Logger("Could not find the Quest ID of the last quest in the item chain");
return;
}
Core.Logger($"Final quest in Legacy Quest Chain: [{finalItemQuestID}] \"{Core.EnsureLoad(finalItemQuestID).Name}\"");
runQuest(finalItemQuestID);
foreach (LegacyQuestObject l in whereToGet)
Core.ToBank(l.requiredQuestReward.Select(i => i.ID).ToArray());
void runQuest(int questID)
{
LegacyQuestObject runQuestData = whereToGet.Find(d => d.desiredQuestID == questID);
Quest questData = Core.EnsureLoad(questID);
Core.DebugLogger(this);
if (runQuestData == null)
{
Core.Logger("runQuestData is NULL");
return;
}
Core.DebugLogger(this);
int[] requiredReward = runQuestData.requiredQuestReward.Select(i => i.ID).ToArray();
Core.DebugLogger(this);
if (runQuestData.desiredQuestReward.Count == 0 && questID != finalItemQuestID)
{
if (!Core.CheckInventory(requiredReward))
runQuest(runQuestData.requiredQuestID);
return;
}
Core.DebugLogger(this);
int[] desiredReward = runQuestData.desiredQuestReward.Select(i => i.ID).ToArray();
if (questID != finalItemQuestID ? Core.CheckInventory(desiredReward) : Core.CheckInventory(Core.EnsureLoad(finalItemQuestID).Rewards.Select(x => x.ID).ToArray()))
{
Core.Logger($"Already Completed: [{questID}] - \"{questData.Name}\"", "QuestProgression");
return;
}
Core.DebugLogger(this);
if (!Core.CheckInventory(requiredReward))
runQuest(runQuestData.requiredQuestID);
if (_LegacyQuestStop)
return;
Core.DebugLogger(this);
Core.Logger($"Doing Quest: [{questID}] - \"{questData.Name}\"", "QuestProgression");
Core.EnsureAccept(questID);
Core.AddDrop(desiredReward);
Core.DebugLogger(this);
LegacyQuestID = questID;
questLogic();
Core.DebugLogger(this);
TryComplete(questData, LegacyQuestAutoComplete);
Core.DebugLogger(this);
foreach (int i in desiredReward)
Bot.Wait.ForPickup(i);
Core.DebugLogger(this);
if (questID == finalItemQuestID)
Bot.Drops.Pickup(Core.EnsureLoad(finalItemQuestID).Rewards.Select(x => x.ID).ToArray());
Core.DebugLogger(this);
LegacyQuestAutoComplete = true;
}
}
private class LegacyQuestObject
{
public int desiredQuestID { get; set; } // In order to do ....
public List<ItemBase> desiredQuestReward { get; set; } // And obtain ...
public int requiredQuestID { get; set; } // You must do ...
public List<ItemBase> requiredQuestReward { get; set; } // And obtain ...
public LegacyQuestObject(int desiredQuestID, List<ItemBase> desiredQuestReward, int requiredQuestID, List<ItemBase> requiredQuestReward)
{
this.desiredQuestID = desiredQuestID;
this.desiredQuestReward = desiredQuestReward;
this.requiredQuestID = requiredQuestID;
this.requiredQuestReward = requiredQuestReward;
}
}
public int LegacyQuestID = -1;
public bool LegacyQuestAutoComplete = true;
private bool _LegacyQuestStop = false;
public void LegacyQuestStop() => _LegacyQuestStop = true;
/// <summary>
/// Put this at the start of your story script so that the bot will load all quests that are used in the bot. This will speed up any progression checks tremendiously.
/// </summary>
public void PreLoad(Object _this, [CallerMemberName] string caller = "")
{
List<int> QuestIDs = new();
string[] ScriptSlice = Core.CompiledScript();
if (ScriptSlice.Count() == 0)
{
Core.Logger("PreLoad failed, cannot read Compiled Script. You might not be on the latest version of Skua");
return;
}
int classStartIndex = Array.IndexOf(ScriptSlice, $"public class {_this}");
int classEndIndex = Array.IndexOf(ScriptSlice[(classStartIndex)..], "}") + classStartIndex + 1;
ScriptSlice = ScriptSlice[(classStartIndex)..classEndIndex];
int methodStartIndex = -1;
foreach (string p in new string[] { "public", "private" })
{
foreach (string s in new string[] { "void", "bool", "string", "int" })
{
methodStartIndex = Array.FindIndex(ScriptSlice, l => l.Contains($"{p} {s} {caller}"));
if (methodStartIndex > -1)
break;
}
if (methodStartIndex > -1)
break;
}
if (methodStartIndex == -1)
{
Core.Logger("Failed to parse methodStartIndex, no quests will be pre-loaded");
return;
}
int methodIndentCount = ScriptSlice[methodStartIndex + 1].IndexOf('{');
string indent = "";
for (int i = 0; i < methodIndentCount; i++)
indent += " ";
int methodEndIndex = Array.FindIndex(ScriptSlice, methodStartIndex, l => l == indent + "}") + 1;
ScriptSlice = ScriptSlice[methodStartIndex..methodEndIndex];
string[] SearchParam = {
"Story.KillQuest",
"Story.MapItemQuest",
"Story.BuyQuest",
"Story.ChainQuest",
"Story.QuestProgression",
"Core.EnsureAccept",
"Core.EnsureComplete",
"Core.EnsureCompleteChoose",
"Core.ChainComplete"
};
foreach (string Line in ScriptSlice)
{
if (!Line.Any(char.IsDigit))
continue;
string EdittedLine = Line
.Replace(" ", "")
.Replace("!", "")
.Replace("(", "")
.Replace("if", "")
.Replace("else", "");
if (!SearchParam.Any(x => EdittedLine.StartsWith(x)))
continue;
char[] digits = Line.SkipWhile(c => !Char.IsDigit(c)).TakeWhile(Char.IsDigit).ToArray();
string sQuestID = new string(digits);
int QuestID = int.Parse(sQuestID);
if (!QuestIDs.Contains(QuestID) && !Bot.Quests.Tree.Exists(x => x.ID == QuestID))
QuestIDs.Add(QuestID);
}
if (QuestIDs.Count() + Bot.Quests.Tree.Count() > Core.LoadedQuestLimit
&& QuestIDs.Count < Core.LoadedQuestLimit)
{
Bot.Flash.SetGameObject("world.questTree", new ExpandoObject());
}
else if (QuestIDs.Count > (Core.LoadedQuestLimit - Bot.Quests.Tree.Count()))
{
Core.Logger($"Found {QuestIDs.Count} Quests, this exceeds the max amount of loaded quests ({Core.LoadedQuestLimit}). No quests will be loaded.");
return;
}
Core.Logger($"Loading {QuestIDs.Count} Quests.");
if (QuestIDs.Count > 30)
Core.Logger($"Estimated Loading Time: {Convert.ToInt32(QuestIDs.Count / 30 * 1.6)}s");
for (int i = 0; i < QuestIDs.Count; i = i + 30)
{
Bot.Quests.Load(QuestIDs.ToArray()[i..(QuestIDs.Count > i ? QuestIDs.Count : i + 30)]);
Bot.Sleep(1500);
}
}
private int PreviousQuestID = 0;
private bool PreviousQuestState = false;
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 && (Core.CheckInventory(CurrentRequirements[i].Name, CurrentRequirements[i].Quantity)))
{
CurrentRequirements.RemoveAt(i);
continue;
}
if (j != 0 && Core.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.Hunt.Monster(monster);
Bot.Drops.Pickup(CurrentRequirements.Where(item => !item.Temp).Select(item => item.Name).ToArray());
Bot.Sleep(Core.ActionDelay);
}
}
private List<ItemBase> CurrentRequirements = new();
private void _MonsterHunt(ref bool shouldRepeat, string monster, string itemName, int quantity, bool isTemp, int index)
{
Bot.Hunt.ForItem(monster, itemName, quantity, isTemp);
CurrentRequirements.RemoveAt(index);
shouldRepeat = false;
}
private bool _RepeatCheck(ref bool shouldRepeat, int index)
{
if (Core.CheckInventory(CurrentRequirements[index].Name, CurrentRequirements[index].Quantity))
{
CurrentRequirements.RemoveAt(index);
shouldRepeat = false;
return true;
}
return false;
}
private int lastQuestID;
private void _AddRequirement(int questID)
{
if (questID > 0 && questID != lastQuestID)
{
lastQuestID = questID;
Quest quest = Core.EnsureLoad(questID);
List<string> reqItems = new();
quest.AcceptRequirements.ForEach(item => reqItems.Add(item.Name));
quest.Requirements.ForEach(item =>
{
if (!CurrentRequirements.Where(i => i.Name == item.Name).Any())
{
if (!item.Temp)
reqItems.Add(item.Name);
CurrentRequirements.Add(item);
}
});
Core.AddDrop(reqItems.ToArray());
}
}
}