-
Notifications
You must be signed in to change notification settings - Fork 14
/
wasp_sawmill_runner.simba
351 lines (282 loc) · 8.56 KB
/
wasp_sawmill_runner.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
{$DEFINE SCRIPT_ID := 'b6feb67b-9949-45f4-a175-e92f219dfa46'}
{$DEFINE SCRIPT_REVISION := '17'}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
type
ERSPlankType = (
NORMAL, OAK, TEAK, MAHOGANY
);
var
CurrentTask: ERSPlankType := ERSPlankType.TEAK;
type
ESawmillRunnerState = (
WAIT_STATE,
OPEN_BANK,
WITHDRAW_ITEMS,
DEPOSIT_ITEMS,
DEPOSIT_RANDOM_ITEMS,
OPEN_COLLECT,
HANDLE_COLLECT,
CLOSE_INTERFACE,
TELEPORT_SAWMILL,
TELEPORT_GE,
BUY_PLANKS,
HANDLE_MAKE,
OUT_OF_SUPPLIES,
END_SCRIPT
);
TSawmillRunner = record(TBaseBankScript)
State: ESawmillRunnerState;
Coins, Plank, Ring: TRSItem;
Logs: TRSBankItem;
NeededItems: TRSItemArray;
RingPosition: (UNKOWN, INV, EQUIP);
TeleportCost: Int32;
ROECost: Int32;
end;
procedure TAntiban.Setup(); override;
begin
Self.Skills := [ERSSkill.TOTAL];
Self.MinZoom := 15;
Self.MaxZoom := 40;
inherited;
end;
procedure TSawmillRunner.Init(maxActions: UInt32; maxTime: UInt64); override;
var
lawCost, airCost, fireCost: Int32;
begin
inherited;
Self.RSW.SetupRegions([RSRegions.VARROCK]);
Self.Coins := 'Coins';
Self.Ring := 'Ring of the elements';
case CurrentTask of
ERSPlankType.NORMAL:
begin
Self.Logs := TRSBankItem.Setup('Logs', Bank.QUANTITY_ALL, False);
Self.Plank := 'Plank';
Self.ActionProfit := -100;
end;
ERSPlankType.OAK:
begin
Self.Logs := TRSBankItem.Setup('Oak logs', Bank.QUANTITY_ALL, False);
Self.Plank := 'Oak plank';
Self.ActionProfit := -250;
end;
ERSPlankType.TEAK:
begin
Self.Logs := TRSBankItem.Setup('Teak logs', Bank.QUANTITY_ALL, False);
Self.Plank := 'Teak plank';
Self.ActionProfit := -500;
end;
ERSPlankType.MAHOGANY:
begin
Self.Logs := TRSBankItem.Setup('Mahogany logs', Bank.QUANTITY_ALL, False);
Self.Plank := 'Mahogany plank';
Self.ActionProfit := -1500;
end;
end;
Self.ActionProfit += ItemData.GetAverage(Self.Plank) - ItemData.GetAverage(Self.Logs.Item);
//teleport from spell and ring of the elements prices
lawCost := ItemData.GetAverage('Law rune');
airCost := ItemData.GetAverage('Air rune');
fireCost := ItemData.GetAverage('Fire rune');
Self.TeleportCost := lawCost + fireCost + airCost * 3;
Self.ROECost := lawCost + fireCost + airCost +
ItemData.GetAverage('Water rune') +
ItemData.GetAverage('Earth rune');
Self.NeededItems := [
Self.Coins, Self.Logs.Item, Self.Ring, 'Law rune', 'Air rune', 'Fire rune', 'Rune pouch', 'Divine rune pouch'
];
end;
function TSawmillRunner.Deposit(): Boolean;
var
count: Int32;
begin
count := Inventory.CountItem(Self.Plank);
if Bank.DepositItem(Self.Plank, True) then
Result := WaitUntil(not Inventory.ContainsItem(Self.Plank), 200, 4000);
if Result then
begin
Self.TotalActions += count;
Self.TotalProfit += count * Self.ActionProfit;
WL.Activity.Restart();
end;
end;
function TSawmillRunner.InGE(p: TPoint): Boolean;
begin
Result := p.AnyInRange(RSObjects.GEBank.Coordinates, 200);
end;
function TSawmillRunner.VarrockTeleport(): Boolean;
begin
if not Magic.CastSpell(ERSSpell.VARROCK_TELEPORT) then
Exit;
Self.TotalProfit -= Self.TeleportCost;
Result := WaitUntil(Self.InGE(Self.RSW.GetMyPos()), 300, 5000);
end;
function TSawmillRunner.SawmillTeleport(): Boolean;
var
option: String;
begin
if Self.RingPosition = UNKOWN then
begin
if Inventory.ContainsItem(Self.Ring) then
Self.RingPosition := INV
else if Equipment.ContainsItem(Self.Ring) then
Self.RingPosition := EQUIP
else
TerminateScript('Can''t find the ring of the elements.');
end;
case Self.RingPosition of
INV:
begin
if (Self.TotalActions = 0) then
begin
if not Inventory.ClickItem(Self.Ring, 'Rub') then Exit;
if not WaitUntil(Chat.FindOption('Earth'), 300, 4000) then Exit;
Result := Chat.ClickOption('Earth');
end
else
Result := Inventory.ClickItem(Self.Ring, 'Last');
end;
EQUIP:
begin
if (Self.TotalActions = 0) or Antiban.BioDice() then
option := 'Earth'
else
option := 'Last';
Result := Equipment.ClickItem(Self.Ring, option);
end;
end;
if Result then
begin
Self.TotalProfit -= Self.ROECost;
Result := WaitUntil(not Self.InGE(Self.RSW.GetMyPos()), 300, 5000);
end;
end;
function TSawmillRunner.BuyPlanks(): Boolean;
begin
if RSNPCs.SawmillOperator.WalkSelectOption(['Buy']) then
begin
Minimap.WaitMoving();
Result := Make.IsOpen(3000);
end;
end;
function TSawmillRunner.HandleSawmill(): Boolean;
begin
if Make.Select(Ord(CurrentTask), Make.QUANTITY_ALL) then
Result := WaitUntil(Inventory.ContainsItem(Self.Plank), 200, 3000);
end;
function TSawmillRunner.GetState(): ESawmillRunnerState;
begin
if WL.Activity.IsFinished() then
Exit(ESawmillRunnerState.END_SCRIPT);
if RSInterface.IsOpen() then
begin
if not Self.BankEmpty and Bank.IsOpen() then
begin
if Inventory.ContainsItem(Self.Plank) then
Exit(ESawmillRunnerState.DEPOSIT_ITEMS);
if Inventory.ContainsRandomItems(Self.NeededItems) then
Exit(ESawmillRunnerState.DEPOSIT_RANDOM_ITEMS);
if not Inventory.IsFull() then
Exit(ESawmillRunnerState.WITHDRAW_ITEMS);
end;
if not Self.CollectEmpty and CollectBox.IsOpen() then
Exit(ESawmillRunnerState.HANDLE_COLLECT);
Exit(ESawmillRunnerState.CLOSE_INTERFACE);
end;
if Inventory.ContainsItem(Self.Plank) or not Inventory.ContainsItem(Self.Logs.Item) then
begin
if Self.InGE(Self.RSW.GetMyPos()) then
begin
if Self.BankEmpty then
begin
if Self.CollectEmpty then
Exit(ESawmillRunnerState.OUT_OF_SUPPLIES);
Exit(ESawmillRunnerState.OPEN_COLLECT);
end;
Exit(ESawmillRunnerState.OPEN_BANK);
end;
Exit(ESawmillRunnerState.TELEPORT_GE);
end;
if Make.IsOpen() then
Exit(ESawmillRunnerState.HANDLE_MAKE);
if Inventory.ContainsItem(Self.Logs.Item) then
begin
if Self.InGE(Self.RSW.GetMyPos()) then
Exit(ESawmillRunnerState.TELEPORT_SAWMILL);
Exit(ESawmillRunnerState.BUY_PLANKS);
end;
Exit(ESawmillRunnerState.WAIT_STATE);
end;
procedure TSawmillRunner.Run(maxActions: UInt32; maxTime: UInt64);
begin
Self.Init(maxActions, maxTime);
repeat
Self.State := Self.GetState();
Self.SetAction(ToStr(Self.State));
case Self.State of
ESawmillRunnerState.WAIT_STATE: Wait(500, 800);
ESawmillRunnerState.OPEN_BANK: Bank.WalkOpen();
ESawmillRunnerState.WITHDRAW_ITEMS: Self.Withdraw(Self.Logs);
ESawmillRunnerState.DEPOSIT_ITEMS: Self.Deposit();
ESawmillRunnerState.DEPOSIT_RANDOM_ITEMS: Bank.DepositRandomItems(Self.NeededItems);
ESawmillRunnerState.OPEN_COLLECT: CollectBox.WalkOpen();
ESawmillRunnerState.HANDLE_COLLECT: Self.HandleCollectBox([]);
ESawmillRunnerState.CLOSE_INTERFACE: RSInterface.Close();
ESawmillRunnerState.TELEPORT_SAWMILL: Self.SawmillTeleport();
ESawmillRunnerState.TELEPORT_GE: Self.VarrockTeleport();
ESawmillRunnerState.BUY_PLANKS: Self.BuyPlanks();
ESawmillRunnerState.HANDLE_MAKE: Self.HandleSawmill();
ESawmillRunnerState.OUT_OF_SUPPLIES, ESawmillRunnerState.END_SCRIPT: Break;
end;
Self.DoAntiban();
until Self.ShouldStop();
end;
var
SawmillRunner: TSawmillRunner;
{$IFDEF SCRIPT_GUI}
type
TSawmillRunnerConfig = record(TScriptForm)
PlankSelector: TLabeledCombobox;
end;
procedure TSawmillRunnerConfig.StartScript(sender: TObject); override;
begin
CurrentTask := ERSPlankType(Self.PlankSelector.GetItemIndex());
inherited;
end;
procedure TSawmillRunnerConfig.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('Sawmill runner');
Self.Start.setOnClick(@Self.StartScript);
Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];
Self.CreateAccountManager(tab);
with Self.PlankSelector do
begin
Create(tab);
SetCaption('Plank type:');
SetLeft(TControl.AdjustToDPI(40));
SetTop(TControl.AdjustToDPI(170));
SetStyle(csDropDownList);
AddItemArray(['Plank', 'Oak planks', 'Teak planks', 'Mahogany planks']);
SetItemIndex(2);
end;
Self.CreateAntibanManager();
Self.CreateBankSettings();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();
inherited;
end;
var
SawmillRunnerConfig: TSawmillRunnerConfig;
{$ENDIF}
begin
{$IFDEF SCRIPT_GUI}
SawmillRunnerConfig.Run();
{$ENDIF}
SawmillRunner.Run(WLSettings.MaxActions, WLSettings.MaxTime);
end.