-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwasp_cooker.simba
515 lines (428 loc) · 12.7 KB
/
wasp_cooker.simba
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
{$DEFINE SCRIPT_ID := 'de957f22-8a37-4660-a7a3-9bef52cadd70'}
{$DEFINE SCRIPT_REVISION := '45'}
{$IFNDEF SCRIPT_CHAIN}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
{$ENDIF}
type
ERSLocation = (HOSIDIUS, ROGUES_DEN, MYTHS_GUILD);
const
RAW_FOOD: TRSItemArray = [
'Custom',
'Meat',
'Shrimps',
'Chicken',
'Rabbit',
'Anchovies',
'Sardine',
'Herring',
'Mackerel',
'Trout',
'Cod',
'Pike',
'Salmon',
'Tuna',
'Karambwan',
'Rainbow fish',
'Lobster',
'Bass',
'Swordfish',
'Monkfish',
'Shark',
'Sea turtle',
'Anglerfish',
'Dark crab',
'Manta ray'
];
var
CurrentFood: TRSItem := 'Anglerfish';
CurrentLocation := ERSLocation.HOSIDIUS;
type
ECookerState = (
OPEN_BANK,
WITHDRAW_ITEMS,
DEPOSIT_ITEMS,
OPEN_COLLECT,
HANDLE_COLLECT,
CLOSE_INTERFACE,
DO_COOKING,
HANDLE_MAKE,
WAIT_COOKING,
LEVEL_UP,
CLOSE_CONTEXT,
END_SCRIPT
);
TCooker = record(TBaseBankScript)
State: ECookerState;
Food: TRSItem;
Ingredient: TRSBankItem;
Products: array of TRSBankItem;
CookingObj: TRSObjectV2;
Cooking: Boolean;
UsingFire: Boolean;
end;
procedure TCooker.SetupItems();
var
cookedPrefix: TStringArray;
burntFish: TStringArray;
begin
Self.Food := CurrentFood;
ItemFinder.Similarity := 0.99999;
cookedPrefix := ['chicken', 'rabbit', 'meat', 'crab meat',
'karambwan', 'chompy', 'fishcake', 'jubbly', 'sweetcorn'];
burntFish := ['herring', 'mackerel', 'sardine', 'anchovies',
'giant carp', 'trout', 'cod', 'pike', 'salmon', 'tuna', 'bass'];
Self.Ingredient := TRSBankItem.Setup('Raw ' + ToString(Self.Food).Lower());
if cookedPrefix.Contains(LowerCase(Self.Food)) then
Self.Products := [
TRSBankItem.Setup('Cooked ' + ToString(Self.Food).Lower()),
TRSBankItem.Setup('Burnt ' + ToString(Self.Food).Lower())
]
else if burntFish.Contains(LowerCase(Self.Food)) then
Self.Products := [
TRSBankItem.Setup(Self.Food),
TRSBankItem.Setup('Burnt fish')
]
else if 'shrimps' in LowerCase(Self.Food) then
Self.Products := [
TRSBankItem.Setup(Self.Food),
TRSBankItem.Setup('Burnt shrimp')
]
else
Self.Products := [
TRSBankItem.Setup(Self.Food),
TRSBankItem.Setup('Burnt ' + ToString(Self.Food).Lower())
];
Self.ActionProfit := (
ItemData.GetAverage(Self.Products[0].Item) -
ItemData.GetAverage(Self.Ingredient.Item)
);
end;
procedure TCooker.SetupLocation();
var
tmp: TRSObjectV2;
begin
case CurrentLocation of
ERSLocation.HOSIDIUS:
begin
GENERATED_GRAPH.NodeRadius := 30;
Map.SetupChunk(ERSChunk.HOSIDIUS_KITCHEN);
Objects.Setup(Map.Objects(), @Map.Walker);
Self.CookingObj := Objects.Get('Clay oven');
Delete(Self.CookingObj.Coordinates, 0, 1);
Delete(Self.CookingObj.Coordinates, 1, 1);
Delete(Self.CookingObj.Rotations, 0, 2);
end;
ERSLocation.ROGUES_DEN:
begin
Map.SetupChunk(ERSChunk.ROGUES_DEN);
tmp := TRSObjectV2.Setup(0.7, 5, [[21128, 30542]]);
tmp.SetupUpText(['Emerald', 'Benedict']);
tmp.Walker := @Map.Walker;
tmp.Finder.Colors += CTS2(3430243, 19, 0.15, 0.81);
tmp.Finder.Colors += CTS2(6523832, 17, 0.03, 0.89);
Banks._AddObject(tmp);
Self.CookingObj := TRSObjectV2.Setup(0.8,1, [[21132,30538]]);
Self.CookingObj.SetupUpText('Fire');
Self.CookingObj.Finder.Colors += CTS2(3317724, 14, 0.23, 1.65);
Self.CookingObj.Walker := @Map.Walker;
end;
ERSLocation.MYTHS_GUILD:
begin
Map.SetupChunk([[38,44,38,44], [1]]);
Objects.Setup(Map.Objects(), @Map.Walker);
Self.CookingObj := Objects.Get('Range');
end;
end;
end;
procedure TCooker.Init(maxActions: UInt32; maxTime: UInt64); override;
begin
Antiban.Skills := [ERSSkill.COOKING, ERSSkill.TOTAL];
Antiban.MinZoom := 15;
Antiban.MaxZoom := 60;
inherited;
Self.SetupItems();
Self.SetupLocation();
end;
function TCooker.HasProducts(): Boolean;
begin
Result := Inventory.ContainsAny([Self.Products[0].Item, Self.Products[1].Item]);
end;
function TCooker.Deposit(): Boolean;
var
invCount: Int32;
begin
invCount := Inventory.Count();
Result := Self.DepositItem(Self.Products[0]);
Self.DepositItem(Self.Products[1]);
if Result then
begin
Self.TotalActions += invCount - Inventory.Count();
Self.TotalProfit := Self.TotalActions * Self.ActionProfit;
end;
end;
function TCooker.DoCooking(): Boolean;
var
fire, tpa: TPointArray;
playerBox: TBox;
begin
case CurrentLocation of
ERSLocation.ROGUES_DEN:
begin
playerBox := Box(Mainscreen.Center, 100, 100);
if SRL.FindColors(tpa, CTS2(2730450, 13, 0.09, 1.45), playerBox) > 0 then
fire += tpa;
if SRL.FindColors(tpa, CTS2(15432, 1, 0.15, 0.01), playerBox) > 0 then
fire += tpa;
Mouse.Move(fire.Cluster(1).Biggest());
if Mainscreen.IsUpText(['Cook', 'Fire']) then
begin
Mouse.Click(MOUSE_LEFT);
Minimap.WaitPlayerMoving(300, 3000);
Exit(Make.IsOpen(4000));
end;
end;
end;
if CookingObj.WalkSelectOption(['Cook', 'Fire']) then
begin
Minimap.WaitPlayerMoving(300, 3000);
Result := Make.IsOpen(4000);
end;
end;
function TCooker.HandleMake(): Boolean;
var
i: Int32 := 0;
begin
if not Make.IsOpen() then //not sure if I can remove this.
Exit; //it's probably not needed.
Result := Make.Select(i, Make.QUANTITY_ALL, Antiban.BioDice());
Self.Cooking := Result;
if Result then
WaitUntil(not Make.IsOpen(), 100, 4000);
end;
function TCooker.IsCooking(waitTime: Int32 = 2500): Boolean;
var
count: Int32;
begin
count := Inventory.CountItem(Self.Ingredient.Item);
if count = 0 then
Exit;
Result := WaitUntil(count > Inventory.CountItem(Self.Ingredient.Item), 300, waitTime);
if Result then
WL.Activity.Restart();
end;
function TCooker.WaitCooking(): Boolean;
begin
Result := Self.IsCooking();
Self.Cooking := Result;
end;
function TCooker.GetState(): ECookerState;
begin
if WL.Activity.IsFinished() then
Exit(ECookerState.END_SCRIPT);
if ChooseOption.IsOpen() then
Exit(ECookerState.CLOSE_CONTEXT);
if XPBar.EarnedXP() then
Exit(ECookerState.WAIT_COOKING);
if Chat.LeveledUp() then
begin
Self.Cooking := False;
Exit(ECookerState.LEVEL_UP);
end;
if Make.IsOpen() then
Exit(ECookerState.HANDLE_MAKE);
if RSInterface.IsOpen() then
begin
Self.Cooking := False;
Self.HoveringBank := False;
if not Self.BankEmpty and Bank.IsOpen() then
begin
if Self.HasProducts() then
Exit(ECookerState.DEPOSIT_ITEMS);
if not Inventory.ContainsItem(Self.Ingredient.Item) then
Exit(ECookerState.WITHDRAW_ITEMS);
end;
if not Self.CollectEmpty and CollectBox.IsOpen() then
begin
if not CollectBox.ContainsItem(Self.Ingredient.Item) then
Exit(ECookerState.HANDLE_COLLECT);
end;
Exit(ECookerState.CLOSE_INTERFACE);
end;
if Inventory.ContainsItem(Self.Ingredient.Item) then
begin
if Self.Cooking then
Exit(ECookerState.WAIT_COOKING);
Exit(ECookerState.DO_COOKING);
end;
if Self.BankEmpty and Self.CollectEmpty then
Exit(ECookerState.END_SCRIPT);
if Self.BankEmpty then
Exit(ECookerState.OPEN_COLLECT);
Exit(ECookerState.OPEN_BANK);
end;
function TCooker.Terminate(): Boolean; override;
begin
Result := inherited();
if Result then
for 0 to 5 do
if Result := Bank.WithdrawItem(Self.Products[0], True) then
Break;
end;
procedure TCooker.Run(maxActions: UInt32; maxTime: UInt64);
begin
Self.Init(maxActions, maxTime);
repeat
Self.State := Self.GetState();
Self.SetAction(ToString(Self.State));
case Self.State of
ECookerState.OPEN_BANK: Banks.WalkOpen();
ECookerState.WITHDRAW_ITEMS: Self.Withdraw(Self.Ingredient);
ECookerState.DEPOSIT_ITEMS: Self.Deposit();
ECookerState.OPEN_COLLECT: CollectBoxes.WalkOpen();
ECookerState.HANDLE_COLLECT: Self.HandleCollectBox([Self.Ingredient.Item]);
ECookerState.CLOSE_INTERFACE: RSInterface.Close();
ECookerState.LEVEL_UP: Chat.HandleLevelUp();
ECookerState.DO_COOKING: Self.DoCooking();
ECookerState.HANDLE_MAKE: Self.HandleMake();
ECookerState.WAIT_COOKING: Self.WaitCooking();
ECookerState.CLOSE_CONTEXT: ChooseOption.Close();
ECookerState.END_SCRIPT: Break;
end;
Self.DoAntiban();
until Self.ShouldStop();
if not Self.Terminate then
TerminateScript('aio_cooker didn''t terminate properly. Stopping execution.');
end;
var
Cooker: TCooker;
function TRSMake.Select(Index: Int32; Quantity: Int32; UseKeyboard: Boolean = True): Boolean; override;
var
Buttons: TRSButtonArray;
begin
Buttons := Self.GetItemButtons();
if Index <= High(Buttons) then
Result := Self.SelectHelper(Buttons[Index], Quantity, UseKeyboard);
end;
function TRSBanks.WalkOpen(mapObj: PRSMapObject = nil): Boolean; override;
begin
if RSInterface.IsOpen() then
begin
if Bank.IsOpen() or BankPin.IsOpen() then
Exit(True);
RSInterface.Close(True);
end;
if mapObj = nil then mapObj := Self.GetClosest();
case mapObj^.MapObjectType of
ERSMapObjectType.OBJ:
case CurrentLocation of
ERSLocation.ROGUES_DEN: Result := mapObj^.WalkSelectOption(['Bank']) or (MainScreen.IsUpText('Emerald') and ChooseOption.Select(['Bank B', 'Bank E']));
else Result := mapObj^.WalkClick() or (MainScreen.IsUpText('Banker') and ChooseOption.Select(['Bank B', 'Bank E']));
end;
ERSMapObjectType.NPC: Result := mapObj^.WalkSelectOption(['Bank B', 'Bank E']) or (MainScreen.IsUpText('Bank') and ChooseOption.Select(['Bank B', 'Bank E']));
end;
if not Result then
Exit;
Minimap.WaitMoving();
Result := WaitUntil(RSInterface.IsOpen(), 300, 3000) and (Bank.IsOpen() or BankPin.IsOpen());
end;
{$IFNDEF SCRIPT_CHAIN}
{$IFDEF SCRIPT_GUI}
type
TCookerConfig = record(TScriptForm)
LocSelector: TLabeledCombobox;
CustomFoodName: TLabeledEdit;
FoodSelector: TLabeledCombobox;
Config: TConfigJSON;
end;
procedure TCookerConfig.StartScript(sender: TObject); override;
begin
CurrentLocation := ERSLocation(Self.LocSelector.GetItemIndex());
Self.Config.Put('location', Ord(CurrentLocation));
Self.Config.Put('food_selector', Self.FoodSelector.GetItemIndex());
if Self.FoodSelector.GetItemIndex() = 0 then
begin
CurrentFood := Self.CustomFoodName.GetText();
Self.Config.Put('custom', ToStr(CurrentFood));
end
else
CurrentFood := Self.FoodSelector.GetText();
inherited;
end;
procedure TCookerConfig.FoodSelectorOnChange(sender: TObject);
var
combobox: TComboBox;
begin
combobox := sender;
Self.CustomFoodName.SetVisible(combobox.getText() = 'Custom');
end;
procedure TCookerConfig.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('Wasp Cooker');
Self.Config.Setup('wasp-cooker');
Self.Start.setOnClick(@Self.StartScript);
Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];
Self.CreateAccountManager(tab);
with Self.LocSelector do
begin
Create(tab);
SetCaption('Location:');
SetLeft(TControl.AdjustToDPI(20));
SetTop(TControl.AdjustToDPI(200));
SetWidth(TControl.AdjustToDPI(200));
SetStyle(csDropDownList);
AddItemArray(['Hosidius kitchen', 'Rogues den', 'Myth''s guild']);
if Self.Config.Has('location') then
SetItemIndex(Self.Config.GetInt('location'))
else
SetItemIndex(Ord(CurrentLocation));
end;
with Self.FoodSelector do
begin
Create(tab);
SetCaption('Food type:');
SetLeft(Self.LocSelector.GetRight() + TControl.AdjustToDPI(20));
SetTop(Self.LocSelector.GetTop());
SetWidth(TControl.AdjustToDPI(200));
SetStyle(csDropDownList);
AddItemArray(RAW_FOOD);
Combobox.setOnChange(@Self.FoodSelectorOnChange);
if Self.Config.Has('food_selector') then
SetItemIndex(Self.Config.GetInt('food_selector'))
else
SetItemIndex(0);
end;
with Self.CustomFoodName do
begin
Create(tab);
SetCaption('Food name (must be the exact name):');
SetLeft(Self.FoodSelector.GetRight() + TControl.AdjustToDPI(20));
SetTop(Self.LocSelector.GetTop());
SetWidth(TControl.AdjustToDPI(200));
SetVisible(Self.FoodSelector.GetText() = 'Custom');
if Self.Config.Has('custom') then
SetText(Self.Config.GetString('custom'))
else
SetText(CurrentFood);
end;
Self.CreateAntibanManager();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();
inherited;
end;
var
CookerConfig: TCookerConfig;
{$ENDIF}
{$ENDIF}
{$IFNDEF SCRIPT_CHAIN}
begin
{$IFDEF SCRIPT_GUI}
CookerConfig.Run();
{$ENDIF}
Cooker.Run(WLSettings.MaxActions, WLSettings.MaxTime);
end.
{$ENDIF}