-
Notifications
You must be signed in to change notification settings - Fork 14
/
wasp_smelter.simba
465 lines (370 loc) · 11.7 KB
/
wasp_smelter.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
{$DEFINE SCRIPT_ID := 'e8df872a-afaf-44b8-9fc5-eef079ada50b'}
{$DEFINE SCRIPT_REVISION := '40'}
{$IFNDEF SCRIPT_CHAIN}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
{$ENDIF}
type
ERSBarType = (
BRONZE, IRON, SILVER, STEEL, GOLD, MITHRIL, ADAMANT, RUNITE, MOLTEN_GLASS
);
ERSFurnace = (AL_KHARID, EDGEVILLE, FALADOR, PRIFDDINAS);
var
CurrentBar = ERSBarType.GOLD;
CurrentFurnace = ERSFurnace.EDGEVILLE;
type
ESmelterState = (
HOVER_BANK,
OPEN_BANK,
WITHDRAW_MATERIALS,
DEPOSIT_BAR,
DEPOSIT_RANDOM_ITEM,
OPEN_COLLECT,
HANDLE_COLLECT,
OPEN_FURNACE,
SMELT_BAR,
WAIT_SMELT,
CLOSE_INTERFACE,
LEVEL_UP,
CLOSE_CONTEXT,
END_SCRIPT,
OUT_OF_SUPPLIES
);
TSmelter = record(TBaseBankScript)
State: ESmelterState;
Furnace: TRSObjectV2;
Ore1, Ore2, Bar: TRSBankItem;
Materials: TRSItemArray;
Smelting: Boolean;
BarAmount, Multiplier: Int32;
end;
procedure TSmelter.SetupItems();
begin
case CurrentBar of
ERSBarType.BRONZE:
begin
Self.Bar := TRSBankItem.Setup('Bronze bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Copper ore', 14, False);
Self.Ore2 := TRSBankItem.Setup('Tin ore', 14, False);
end;
ERSBarType.IRON:
begin
Self.Bar := TRSBankItem.Setup('Iron bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Iron ore', Bank.QUANTITY_ALL, False);
end;
ERSBarType.SILVER:
begin
Self.Bar := TRSBankItem.Setup('Silver bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Silver ore', Bank.QUANTITY_ALL, False);
end;
ERSBarType.STEEL:
begin
Self.Bar := TRSBankItem.Setup('Steel bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Iron ore', 9, False);
Self.Ore2 := TRSBankItem.Setup('Coal', 18, False);
end;
ERSBarType.GOLD:
begin
Self.Bar := TRSBankItem.Setup('Gold bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Gold ore', Bank.QUANTITY_ALL, False);
end;
ERSBarType.MITHRIL:
begin
Self.Bar := TRSBankItem.Setup('Mithril bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Mithril ore', 5, False);
Self.Ore2 := TRSBankItem.Setup('Coal', 20, False);
end;
ERSBarType.ADAMANT:
begin
Self.Bar := TRSBankItem.Setup('Adamantite bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Adamantite ore', 4, False);
Self.Ore2 := TRSBankItem.Setup('Coal', 24, False);
end;
ERSBarType.RUNITE:
begin
Self.Bar := TRSBankItem.Setup('Runite bar', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Runite ore', 4, False);
Self.Ore2 := TRSBankItem.Setup('Coal', 24, False);
end;
ERSBarType.MOLTEN_GLASS:
begin
Self.Bar := TRSBankItem.Setup('Molten glass', Bank.QUANTITY_ALL, False);
Self.Ore1 := TRSBankItem.Setup('Soda ash', 14, False);
Self.Ore2 := TRSBankItem.Setup('Bucket of sand', 14, False);
Antiban.Skills := [ERSSkill.CRAFTING, ERSSkill.TOTAL];
end;
end;
Self.Materials += Self.Ore1.Item;
Self.ActionProfit := (ItemData.GetAverage(Self.Bar.Item)) -
(ItemData.GetAverage(Self.Ore1.Item) * Self.Ore1.Quantity);
if Self.Ore2 <> [] then
begin
Self.ActionProfit -= (ItemData.GetAverage(Self.Ore2.Item) * Round(Self.Ore2.Quantity / Self.Ore1.Quantity));
Materials += Self.Ore2.Item;
end;
end;
procedure TSmelter.Init(maxActions: UInt32; maxTime: UInt64); override;
begin
Antiban.Skills := [ERSSkill.Smithing, ERSSkill.TOTAL];
Antiban.MinZoom := 0;
Antiban.MaxZoom := 40;
inherited;
case CurrentFurnace of
ERSFurnace.AL_KHARID: Map.SetupChunk(ERSChunk.AL_KHARID);
ERSFurnace.EDGEVILLE: Map.SetupChunk(ERSChunk.EDGEVILLE);
ERSFurnace.FALADOR: Map.SetupChunk(ERSChunk.FALADOR);
ERSFurnace.PRIFDDINAS: Map.SetupChunk(ERSChunk.PRIFDDINAS);
end;
Objects.Setup(Map.Objects(), @Map.Walker);
NPCs.Setup(Map.NPCs(), @Map.Walker);
Self.Furnace := Objects.Get('Furnace');
Self.SetupItems();
end;
function TSmelter.Withdraw(): Boolean; overload;
var
invCount: Int32;
item: TRSBankItem;
find1, find2: Boolean;
begin
find1 := Inventory.ContainsItem(Self.Ore1.Item);
find2 := (Self.Ore2 = []) or Inventory.ContainsItem(Self.Ore2.Item);
if find1 then
begin
if find2 then
Exit;
item := Self.Ore2;
item.Quantity := Self.Ore1.Quantity;
end
else if find2 or (Self.Ore1.Quantity > Self.Ore2.Quantity) or
((Self.Ore1.Quantity = Self.Ore2.Quantity) and Antiban.BioDice()) then
begin
item := Self.Ore1;
if Self.Ore2 <> [] then
item.Quantity := Self.Ore2.Quantity;
end
else
item := Self.Ore2;
invCount := Inventory.Count();
if Bank.WithdrawItem(item, True) then
Result := WaitUntil(Inventory.Count() > invCount, 100, 3000);
if not Result then
begin
Bank.UnHoverIncinerator();
Self.BankEmpty := not Bank.IsSearchOpen() and
not WaitUntil(Bank.ContainsItem(item), 300, 3000);
if Bank.IsSearchOpen() then
Bank.CloseSearch();
end;
Self.BankEmpty := Self.BankEmpty and Bank.IsOpen();
if Self.BankEmpty then
SaveScreenshot('bankempty' + DIRECTORYSEPARATOR + 'bankempty', MainScreen.Bounds());
if Self.CollectEmpty and Self.CollectTimer.IsFinished() then
Self.CollectEmpty := False;
end;
function TSmelter.Deposit(): Boolean;
var
itemCount: Int32;
begin
itemCount := Inventory.Count();
if Bank.DepositAll() then
Result := WaitUntil(Inventory.Count() = 0, 100, 3000);
if Result then
begin
Self.TotalActions += itemCount;
Self.TotalProfit := Self.TotalActions * Self.ActionProfit;
end;
end;
function TSmelter.OpenFurnace(): Boolean;
begin
if Self.Furnace.WalkSelectOption(['Smelt']) then
begin
Minimap.WaitPlayerMoving(300, 10000);
Result := Make.IsOpen(8000);
end;
end;
function TSmelter.SmeltBar(): Boolean;
begin
if not Inventory.ContainsAll(Materials) then
Exit;
if Result := Make.Select(ToStr(Self.Bar.Item), Make.QUANTITY_ALL, Antiban.BioDice(EBioBehavior.KEYBOARD_CHAT_CHANCE)) then
Smelting := XPBar.WaitXP(4000);
end;
function TSmelter.IsMakingItem(waitTime: Int32 = 6000): Boolean;
var
itemCount: Int32 := Inventory.CountItem(Self.Bar.Item);
begin
if Result := WaitUntil((itemCount < Inventory.CountItem(Self.Bar.Item)) or not Inventory.ContainsAll(Materials), 100, waitTime) then
WL.Activity.Restart();
end;
function TSmelter.WaitSmelt(): Boolean;
begin
if Smelting then
Result := Smelting := (Inventory.ContainsAll(Materials) and Self.IsMakingItem())
else
Result := Smelting := Self.IsMakingItem();
if Result then
WL.Activity.Restart();
end;
function TSmelter.GetState(): ESmelterState;
begin
if WL.Activity.IsFinished() then
Exit(ESmelterState.END_SCRIPT);
if Chat.LeveledUp() then
begin
Self.Smelting := False;
Exit(ESmelterState.LEVEL_UP);
end;
if RSInterface.IsOpen() then
begin
Self.Smelting := False;
Self.HoveringBank := False;
if Bank.IsOpen() then
begin
if Inventory.ContainsItem(Self.Bar.Item) then
Exit(ESmelterState.DEPOSIT_BAR);
if Inventory.ContainsRandomItems(Materials) then
Exit(ESmelterState.DEPOSIT_RANDOM_ITEM);
if not Self.BankEmpty and not Inventory.ContainsAll(Materials) then
Exit(ESmelterState.WITHDRAW_MATERIALS);
end;
if not Self.CollectEmpty and CollectBox.IsOpen() then
Exit(ESmelterState.HANDLE_COLLECT);
Exit(ESmelterState.CLOSE_INTERFACE);
end;
if Inventory.ContainsAll(Materials) then
begin
if Self.Smelting then
begin
if not Self.HoveringBank then
begin
Self.CountItemsLeft(Self.Ore1.Item);
if Self.ShouldHoverBank() then
Exit(ESmelterState.HOVER_BANK);
end;
Exit(ESmelterState.WAIT_SMELT);
end;
if Make.IsOpen() then
Exit(ESmelterState.SMELT_BAR);
Exit(ESmelterState.OPEN_FURNACE);
end;
if Self.BankEmpty then
begin
if Self.CollectEmpty then
Exit(ESmelterState.OUT_OF_SUPPLIES);
Exit(ESmelterState.OPEN_COLLECT);
end;
if Self.BankEmpty then
Exit(ESmelterState.OPEN_COLLECT);
Exit(ESmelterState.OPEN_BANK);
end;
function TSmelter.Terminate(): Boolean; override;
begin
Result := inherited;
Self.Bar.Noted := True;
if Result then
for 0 to 5 do
if Result := Bank.WithdrawItem(Self.Bar, True) then
Break;
end;
procedure TSmelter.Run(maxActions: UInt32; maxTime: UInt64);
begin
Self.Init(maxActions, maxTime);
repeat
State := Self.GetState();
Self.SetAction(ToStr(State));
case Self.State of
ESmelterState.HOVER_BANK: Self.HoverBank();
ESmelterState.OPEN_BANK: Banks.WalkOpen();
ESmelterState.WITHDRAW_MATERIALS: Self.Withdraw();
ESmelterState.DEPOSIT_BAR: Self.Deposit();
ESmelterState.DEPOSIT_RANDOM_ITEM: Bank.DepositRandomItems(Self.Materials);
ESmelterState.OPEN_COLLECT: CollectBoxes.WalkOpen();
ESmelterState.HANDLE_COLLECT: Self.HandleCollectBox(Self.Materials);
ESmelterState.OPEN_FURNACE: Self.OpenFurnace();
ESmelterState.SMELT_BAR: Self.SmeltBar();
ESmelterState.WAIT_SMELT: Self.WaitSmelt();
ESmelterState.CLOSE_INTERFACE: RSInterface.Close();
ESmelterState.CLOSE_CONTEXT: ChooseOption.Close();
ESmelterState.LEVEL_UP: Chat.HandleLevelUp();
ESmelterState.END_SCRIPT, ESmelterState.OUT_OF_SUPPLIES: Break;
end;
Self.DoAntiban();
until Self.ShouldStop();
if not Self.Terminate() then
TerminateScript(Self.Name + ' didn''t terminate properly. Stopping execution.');
end;
var
Smelter: TSmelter;
{$IFNDEF SCRIPT_CHAIN}
{$IFDEF SCRIPT_GUI}
type
TSmelterConfig = record(TScriptForm)
BarTypeSelector: TLabeledCombobox;
FurnaceSelector: TLabeledCombobox;
Config: TConfigJSON;
end;
procedure TSmelterConfig.StartScript(sender: TObject); override;
begin
CurrentBar := ERSBarType(Self.BarTypeSelector.GetItemIndex());
CurrentFurnace := ERSFurnace(Self.FurnaceSelector.GetItemIndex());
Self.Config.Put('bar', Ord(CurrentBar));
Self.Config.Put('furnace', Ord(CurrentFurnace));
inherited;
end;
procedure TSmelterConfig.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('Wasp Smelter');
Self.Config.Setup('wasp-smelter');
Self.Start.SetOnClick(@Self.StartScript);
Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];
Self.CreateAccountManager(tab);
with Self.BarTypeSelector do
begin
Create(tab);
SetCaption('Self.Bar type:');
SetLeft(TControl.AdjustToDPI(50));
SetTop(TControl.AdjustToDPI(200));
SetStyle(csDropDownList);
AddItemArray(['Bronze', 'Iron', 'Silver', 'Steel', 'Gold', 'Mithril', 'Adamantite', 'Runite', 'Molten glass']);
if Self.Config.Has('bar') then
SetItemIndex(Self.Config.GetInt('bar'))
else
SetItemIndex(Ord(CurrentBar));
end;
with Self.FurnaceSelector do
begin
Create(tab);
SetCaption('Furnace:');
SetLeft(Self.BarTypeSelector.GetRight() + TControl.AdjustToDPI(15));
SetTop(Self.BarTypeSelector.GetTop());
SetStyle(csDropDownList);
AddItemArray([
'Al Kharid',
'Edgeville', 'Falador', 'Prifddinnas'
]);
if Self.Config.Has('furnace') then
SetItemIndex(Self.Config.GetInt('furnace'))
else
SetItemIndex(Ord(CurrentFurnace));
end;
Self.CreateAntibanManager();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();
inherited;
end;
var
SmelterConfig: TSmelterConfig;
{$ENDIF}
{$ENDIF}
{$IFNDEF SCRIPT_CHAIN}
begin
{$IFDEF SCRIPT_GUI}
SmelterConfig.Run();
{$ENDIF}
Smelter.Run(WLSettings.MaxActions, WLSettings.MaxTime);
end.
{$ENDIF}