-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwasp_glassblower.simba
419 lines (329 loc) · 10 KB
/
wasp_glassblower.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
{$DEFINE SCRIPT_ID := '6f619d33-4564-4650-95fe-db2f7e0925cd'}
{$DEFINE SCRIPT_REVISION := '32'}
{$IFNDEF SCRIPT_CHAIN}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
{$ENDIF}
type
ERSGlassItem = (BEER, LANTERN, LAMP, VIAL, FISHBOWL, ORB, LENS, BULB, BEST);
var
CurrentGlass: ERSGlassItem = ERSGlassItem.BEST;
type
EBlowerState = (
HOVER_BANK,
OPEN_BANK,
WITHDRAW_TOOL,
WITHDRAW_MATERIAL,
DEPOSIT_PRODUCT,
DEPOSIT_RANDOM_ITEM,
OPEN_COLLECT,
HANDLE_COLLECT,
CLOSE_INTERFACE,
DO_GLASS,
HANDLE_MAKE,
WAIT_GLASS,
LEVEL_UP,
CLOSE_CONTEXT,
OUT_OF_ITEMS,
END_SCRIPT
);
TBlower = record(TBaseBankScript)
State: EBlowerState;
Tool, Material, Product: TRSBankItem;
Blowing: Boolean;
CurrentLevel: Int32;
UseBestItem: Boolean;
ItemChanged: Boolean;
end;
procedure TBlower.SetupProduct();
var
CurrentLevelItem: ERSGlassItem;
begin
case CurrentLevel of
1..3: CurrentLevelItem := ERSGlassItem.BEER;
4..11: CurrentLevelItem := ERSGlassItem.LANTERN;
12..32: CurrentLevelItem := ERSGlassItem.LAMP;
33..41: CurrentLevelItem := ERSGlassItem.VIAL;
42..45: CurrentLevelItem := ERSGlassItem.FISHBOWL;
46..48: CurrentLevelItem := ERSGlassItem.ORB;
49..86: CurrentLevelItem := ERSGlassItem.LENS;
else CurrentLevelItem := ERSGlassItem.BULB;
end;
if CurrentLevelItem <> CurrentGlass then
begin
CurrentGlass := CurrentLevelItem;
ItemChanged := True;
end;
end;
procedure TBlower.SetupItems();
var
ProductCost: Int32;
X_Number: Int32;
begin
if not ItemChanged then
Exit;
Self.Tool := TRSBankItem.Setup('Glassblowing pipe', 1);
if SRL.Dice(70) then
X_Number := Bank.QUANTITY_ALL
else
X_Number := Random(27, 9999);
Self.Material := TRSBankItem.Setup('Molten glass', X_Number);
case CurrentGlass of
ERSGlassItem.BEER: Self.Product := TRSBankItem.Setup('Beer glass', X_Number);
ERSGlassItem.LANTERN: Self.Product := TRSBankItem.Setup('Empty candle lantern', X_Number);
ERSGlassItem.LAMP: Self.Product := TRSBankItem.Setup('Empty oil lamp', X_Number);
ERSGlassItem.VIAL: Self.Product := TRSBankItem.Setup('Vial', X_Number);
ERSGlassItem.FISHBOWL: Self.Product := TRSBankItem.Setup('Empty fishbowl', X_Number);
ERSGlassItem.ORB: Self.Product := TRSBankItem.Setup('Unpowered orb', X_Number);
ERSGlassItem.LENS: Self.Product := TRSBankItem.Setup('Lantern lens', X_Number);
ERSGlassItem.BULB: Self.Product := TRSBankItem.Setup('Empty light orb', X_Number);
end;
ProductCost := ItemData.GetAverage(Self.Material.Item);
Self.ActionProfit := ItemData.GetAverage(Self.Product.Item) - ProductCost;
Self.ItemChanged := False;
end;
procedure TBlower.Init(maxActions: UInt32; maxTime: UInt64); override;
begin
Antiban.Skills := [ERSSkill.CRAFTING, ERSSkill.TOTAL];
Antiban.MinZoom := 15;
Antiban.MaxZoom := 85;
inherited;
Self.RSW.SetupNamedRegion();
Self.UseBestItem := CurrentGlass = ERSGlassItem.Best;
Self.ItemChanged := True;
Self.CurrentLevel := Stats.GetLevel(ERSSkill.CRAFTING);
end;
function TBlower.CountItem(): Int32;
begin
if (Result := Inventory.CountItemStack(Product.Item)) = 0 then
Result := Inventory.CountItem(Product.Item);
end;
function TBlower.DepositExtraItems(): Boolean;
var
slots, DepositSlots: TIntegerArray;
i: Int32;
begin
if Tool.Quantity = 1 then
Inventory.FindItem(Tool.Item, Slots);
DepositSlots := Slots.Difference(Inventory.GetUsedSlots);
repeat
if Result := Bank.DepositSlot([DepositSlots[i], Bank.QUANTITY_ALL], True) then
WaitUntil(not Inventory.IsSlotUsed(DepositSlots[i]), 100, 2000);
DepositSlots := Slots.Difference(Inventory.GetUsedSlots);
until Result := (DepositSlots = []);
end;
function TBlower.Deposit(): Boolean;
var
ItemCount: Int32 := Self.CountItem;
begin
if Result := Bank.DepositItem(Self.Product, True) then
if WaitUntil(Self.CountItem() = 0, 100, 3000) then
TotalActions += ItemCount;
end;
function TBlower.DoGlass(): Boolean;
begin
if SRL.Dice(50) then
Result := Inventory.Use(Tool.Item, Material.Item)
else
Result := Inventory.Use(Material.Item, Tool.Item);
if Result then Make.IsOpen(2000);
end;
function TRSMake.SetQuantity(Amount: Int32): Boolean; override;
const
ENABLED_COLOR = $FFFFFF;
var
Button: TRSButton;
Buttons: TRSButtonArray;
begin
if Amount <> Make.QUANTITY_ALL then
begin
Result := inherited;
Exit;
end;
Buttons := GetQuantityButtons;
if Buttons = [] then
Exit;
Button := Buttons[High(Buttons)];
if SRL.CountColor(ENABLED_COLOR, Button.Bounds) > 0 then
Exit(True)
else
Exit(Button.Click);
end;
function TBlower.HandleMake(): Boolean;
var
MakeStringArray: TStringArray;
ItemIndex: Int32;
i: Int32;
begin
MakeStringArray := [
'Beer glass', 'Candle lantern', 'Oil lamp', 'Vial', 'Fishbowl',
'Unpowered staff orb', 'Lantern lens', 'Light orb'
];
for i := Ord(Low(ERSGlassItem)) to Ord(High(ERSGlassItem)) do
if CurrentGlass = ERSGlassItem(i) then
begin
ItemIndex := i;
Break;
end;
Blowing := Result := Make.Select(ItemIndex, Make.QUANTITY_ALL, SRL.Dice(98.5));
if Result then WaitUntil(not Make.IsOpen, 50, 2000);
end;
function TBlower.WaitBlowing(): Boolean;
begin
if Blowing then
Result := Blowing := Inventory.ContainsItem(Material.Item) and XPBar.WaitXP(2000)
else
Result := Blowing := XPBar.WaitXP(2000);
end;
function TBlower.GetState(): EBlowerState;
begin
if WL.Activity.IsFinished() then
Exit(EBlowerState.END_SCRIPT);
if XPBar.EarnedXP() then
Exit(EBlowerState.WAIT_GLASS);
if Chat.LeveledUp() then
begin
Self.Blowing := False;
Exit(EBlowerState.LEVEL_UP);
end;
if Make.IsOpen() then
Exit(EBlowerState.HANDLE_MAKE);
if RSInterface.IsOpen() then
begin
Self.Blowing := False;
Self.HoveringBank := False;
if Bank.IsOpen() then
begin
if Inventory.ContainsItem(Product.Item) then
Exit(EBlowerState.DEPOSIT_PRODUCT);
if Inventory.ContainsRandomItems([Tool.Item, Material.Item]) then
Exit(EBlowerState.DEPOSIT_RANDOM_ITEM);
if Self.BankEmpty or Inventory.ContainsAll([Tool.Item, Material.Item]) then
Exit(EBlowerState.CLOSE_INTERFACE);
if not Inventory.ContainsItem(Tool.Item) then
Exit(EBlowerState.WITHDRAW_TOOL);
if not Inventory.ContainsItem(Material.Item) then
Exit(EBlowerState.WITHDRAW_MATERIAL);
end;
if CollectBox.IsOpen() then
begin
if Self.CollectEmpty then
Exit(EBlowerState.CLOSE_INTERFACE);
Exit(EBlowerState.HANDLE_COLLECT);
end;
Exit(EBlowerState.CLOSE_INTERFACE);
end;
if Inventory.ContainsAll([Tool.Item, Material.Item]) then
begin
if Self.Blowing then
Exit(EBlowerState.WAIT_GLASS);
Exit(EBlowerState.DO_GLASS);
end;
if Self.BankEmpty and Self.CollectEmpty then
Exit(EBlowerState.OUT_OF_ITEMS);
if Self.BankEmpty then
Exit(EBlowerState.OPEN_COLLECT);
Exit(EBlowerState.OPEN_BANK);
end;
function TBlower.Terminate(): Boolean; override;
var
i: Int32;
begin
Self.Product.Quantity := Bank.QUANTITY_ALL;
Self.Product.Noted := True;
Result := inherited;
if Result then
for i := 0 to 3 do
if Result := Bank.WithdrawItem(Self.Product, True) then
Break;
end;
procedure TBlower.Run(maxActions: UInt32; maxTime: UInt64);
begin
Self.Init(maxActions, maxTime);
repeat
if Self.UseBestItem then
Self.SetupProduct();
Self.SetupItems();
Self.State := Self.GetState();
Self.SetAction(ToStr(Self.State));
case Self.State of
EBlowerState.OPEN_BANK: Bank.WalkOpen();
EBlowerState.WITHDRAW_TOOL: Self.Withdraw(Self.Tool);
EBlowerState.WITHDRAW_MATERIAL: Self.Withdraw(Self.Material);
EBlowerState.DEPOSIT_PRODUCT: Self.Deposit();
EBlowerState.DEPOSIT_RANDOM_ITEM: Self.DepositExtraItems();
EBlowerState.OPEN_COLLECT: CollectBox.WalkOpen();
EBlowerState.HANDLE_COLLECT: Self.HandleCollectBox([Tool.Item, Material.Item]);
EBlowerState.CLOSE_INTERFACE: RSInterface.Close();
EBlowerState.DO_GLASS: Self.DoGlass();
EBlowerState.HANDLE_MAKE: Self.HandleMake();
EBlowerState.WAIT_GLASS: Self.WaitBlowing();
EBlowerState.LEVEL_UP: Chat.HandleLevelUp();
EBlowerState.CLOSE_CONTEXT: ChooseOption.Close();
EBlowerState.OUT_OF_ITEMS,
EBlowerState.END_SCRIPT: Break;
end;
Self.DoAntiban();
until Self.ShouldStop();
if not Self.Terminate then
TerminateScript(Name + ' didn''t terminate properly. Stopping execution.');
end;
var
Blower: TBlower;
function TRSChat.HandleLevelUp(Chance: Double = BioHash): Boolean; override;
begin
Result := inherited(Chance);
Blower.CurrentLevel += 1;
end;
{$IFNDEF SCRIPT_CHAIN}
{$IFDEF SCRIPT_GUI}
type
TBlowerConfig = record(TScriptForm)
GlassSelector: TLabeledCombobox;
end;
procedure TBlowerConfig.StartScript(sender: TObject); override;
begin
CurrentGlass := ERSGlassItem(Self.GlassSelector.GetItemIndex());
inherited;
end;
procedure TBlowerConfig.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('Wasp Glassblower');
Self.Start.setOnClick(@Self.StartScript);
Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];
Self.CreateAccountManager(tab);
with Self.GlassSelector do
begin
Create(tab);
SetCaption('Glass item:');
SetLeft(TControl.AdjustToDPI(30));
SetTop(TControl.AdjustToDPI(200));
SetWidth(TControl.AdjustToDPI(200));
SetStyle(csDropDownList);
AddItemArray(['Beer glass', 'Candle lantern', 'Oil lamp', 'Vial',
'Fishbowl', 'Unpowered orb', 'Lantern lens',
'Light orb', 'Best available']);
SetItemIndex(Ord(CurrentGlass));
end;
Self.CreateAntibanManager();
Self.CreateBankSettings();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();
inherited;
end;
var
BlowerConfig: TBlowerConfig;
{$ENDIF}
{$ENDIF}
{$IFNDEF SCRIPT_CHAIN}
begin
{$IFDEF SCRIPT_GUI}
Sync(@BlowerConfig.Run);
{$ENDIF}
Blower.Run(WLSettings.MaxActions, WLSettings.MaxTime);
end.
{$ENDIF}