-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwasp_jewelry_smelter.simba
559 lines (454 loc) · 15.3 KB
/
wasp_jewelry_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
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
{$DEFINE SCRIPT_ID := '96576fb4-1fa5-48c2-97d4-4d5344c3f2b0'}
{$DEFINE SCRIPT_REVISION := '13'}
{$IFNDEF SCRIPT_CHAIN}
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/osr.simba}
{$ENDIF}
{$I WaspLib/optional/interfaces/mainscreen/craftscreen.simba}
{$I WaspLib/optional/interfaces/mainscreen/silverscreen.simba}
type
ERSMetalType = (SILVER, GOLD);
ERSStoneType = (
NONE, OPAL, JADE, RED_TOPAZ, SAPPHIRE, EMERALD,
RUBY, DIAMOND, DRAGONSTONE, ONYX, ZENYTE
);
ERSJewelType = (
TIARA, HOLY_SYMBOL, UNHOLY_SYMBOL, BOLTS, RING,
NECKLACE, BRACELET, AMULET
);
ERSFurnace = (EDGEVILLE, FALADOR, PRIFDDINAS);
var
CurrentMetal = ERSMetalType.GOLD;
CurrentStone = ERSStoneType.EMERALD;
CurrentJewel = ERSJewelType.RING;
CurrentFurnace = ERSFurnace.EDGEVILLE;
type
EJewelCrafterState = (
HOVER_BANK, OPEN_BANK,
WITHDRAW_MOULD, WITHDRAW_BARS, WITHDRAW_GEMS,
DEPOSIT_JEWELS, DEPOSIT_RANDOM_ITEM,
OPEN_COLLECT, HANDLE_COLLECT,
OPEN_FURNACE, CRAFT_JEWEL, WAIT_CRAFT,
CLOSE_INTERFACE,
LEVEL_UP, CLOSE_CONTEXT,
END_SCRIPT, OUT_OF_SUPPLIES
);
TJewelryCrafter = record(TBaseBankScript)
State: EJewelCrafterState;
Furnace: TRSObjectV2;
Mould, Bar, Gem, Jewel: TRSBankItem;
Materials: TRSItemArray;
NoGem, IsCrafting: Boolean;
CraftItem: ERSCraftItem;
end;
procedure TAntiban.Setup(); override;
begin
Self.Skills := [ERSSkill.CRAFTING, ERSSkill.TOTAL];
Self.MinZoom := 0;
Self.MaxZoom := 30;
inherited;
end;
procedure TJewelryCrafter.SetupItems();
begin
case CurrentMetal of
ERSMetalType.SILVER: Self.Bar := TRSBankItem.Setup('Silver bar', 13);
ERSMetalType.GOLD: Self.Bar := TRSBankItem.Setup('Gold bar', 13);
end;
case CurrentStone of
ERSStoneType.NONE:
begin
Self.Bar.Quantity := -1;
Self.NoGem := True;
end;
ERSStoneType.OPAL: Self.Gem := TRSBankItem.Setup('Opal', 13);
ERSStoneType.JADE: Self.Gem := TRSBankItem.Setup('Jade', 13);
ERSStoneType.RED_TOPAZ: Self.Gem := TRSBankItem.Setup('Red topaz', 13);
ERSStoneType.SAPPHIRE: Self.Gem := TRSBankItem.Setup('Sapphire', 13);
ERSStoneType.EMERALD: Self.Gem := TRSBankItem.Setup('Emerald', 13);
ERSStoneType.RUBY: Self.Gem := TRSBankItem.Setup('Ruby', 13);
ERSStoneType.DIAMOND: Self.Gem := TRSBankItem.Setup('Diamond', 13);
ERSStoneType.DRAGONSTONE: Self.Gem := TRSBankItem.Setup('Dragonstone', 13);
ERSStoneType.ONYX: Self.Gem := TRSBankItem.Setup('Onyx', 13);
ERSStoneType.ZENYTE: Self.Gem := TRSBankItem.Setup('Zenyte', 13);
end;
case CurrentJewel of
ERSJewelType.TIARA:
begin
Self.Mould := TRSBankItem.Setup('Tiara mould', 1);
CurrentStone := ERSStoneType.NONE;
Self.NoGem := True;
Self.Bar.Quantity := -1;
if CurrentMetal = ERSMetalType.GOLD then
Self.Jewel := TRSBankItem.Setup('Gold tiara', -1)
else
Self.Jewel := TRSBankItem.Setup('Tiara', -1);
end;
ERSJewelType.HOLY_SYMBOL:
begin
Self.Mould := TRSBankItem.Setup('Holy mould', 1);
CurrentMetal := ERSMetalType.SILVER;
CurrentStone := ERSStoneType.NONE;
Self.NoGem := True;
Self.Jewel := TRSBankItem.Setup('Unstrung symbol', -1);
end;
ERSJewelType.UNHOLY_SYMBOL:
begin
Self.Mould := TRSBankItem.Setup('Unholy mould', 1);
CurrentMetal := ERSMetalType.SILVER;
CurrentStone := ERSStoneType.NONE;
Self.NoGem := True;
Self.Jewel := TRSBankItem.Setup('Unstrung emblem', -1);
end;
ERSJewelType.BOLTS:
begin
Self.Mould := TRSBankItem.Setup('Bolt mould', 1);
CurrentMetal := ERSMetalType.SILVER;
CurrentStone := ERSStoneType.NONE;
Self.NoGem := True;
Self.Jewel := TRSBankItem.Setup('Silver bolts (unf)', -1);
end;
ERSJewelType.RING:
begin
Self.Mould := TRSBankItem.Setup('Ring mould', 1);
if Self.NoGem then
Self.Jewel := TRSBankItem.Setup('Gold ring', -1)
else
Self.Jewel := TRSBankItem.Setup(ToStr(Self.Gem.Item).Replace('Red t', 'T') + ' ring', -1);
end;
ERSJewelType.NECKLACE:
begin
Self.Mould := TRSBankItem.Setup('Necklace mould', 1);
if Self.NoGem then
Self.Jewel := TRSBankItem.Setup('Gold necklace', -1)
else
Self.Jewel := TRSBankItem.Setup(ToStr(Self.Gem.Item).Replace('Red t', 'T') + ' necklace', -1);
end;
ERSJewelType.BRACELET:
begin
Self.Mould := TRSBankItem.Setup('Bracelet mould', 1);
if Self.NoGem then
Self.Jewel := TRSBankItem.Setup('Gold bracelet', -1)
else
Self.Jewel := TRSBankItem.Setup(ToStr(Self.Gem.Item).Replace('Red t', 'T') + ' bracelet', -1);
end;
ERSJewelType.AMULET:
begin
Self.Mould := TRSBankItem.Setup('Amulet mould', 1);
if Self.NoGem then
Self.Jewel := TRSBankItem.Setup('Gold amulet (u)', -1)
else
Self.Jewel := TRSBankItem.Setup(ToStr(Self.Gem.Item).Replace('Red t', 'T') + ' amulet (u)', -1);
end;
end;
if (CurrentMetal = ERSMetalType.GOLD) and (CurrentJewel <> ERSJewelType.TIARA) then
Self.CraftItem.SetCraftItem(Self.Jewel.Item);
Self.ActionProfit := ItemData.GetAverage(Self.Jewel.Item) -
ItemData.GetAverage(Self.Bar.Item);
if not Self.NoGem then
Self.ActionProfit -= ItemData.GetAverage(Self.Gem.Item);
Self.Materials := [Self.Bar.Item, Self.Jewel.Item, Self.Mould.Item];
if not Self.NoGem then
Self.Materials += Self.Gem.Item;
end;
procedure TJewelryCrafter.Init(maxActions: UInt32; maxTime: UInt64); override;
begin
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);
Self.Furnace := Objects.Get('Furnace');
Self.SetupItems();
end;
function TJewelryCrafter.OpenFurnace(): Boolean;
begin
if Furnace.WalkSelectOption(['Smelt']) then
begin
Minimap.WaitMoving();
Result := WaitUntil(CraftScreen.IsOpen() or SilverScreen.IsOpen() or Make.IsOpen(), 300, 5000);
end;
end;
function TJewelryCrafter.WaitCraft(waitTime: Int32 = 6000): Boolean;
var
count: Int32;
begin
count := Inventory.CountItem(Self.Bar.Item);
if count = 0 then
begin
Self.IsCrafting := False;
Exit;
end;
Result := WaitUntil((Inventory.CountItem(Self.Bar.Item) < count) or XPBar.EarnedXP(), 300, waitTime);
Self.IsCrafting := Result;
if Result then
WL.Activity.Restart();
end;
function TJewelryCrafter._CraftSilverJewel(): Boolean;
begin
if SilverScreen.CraftItem(Self.Jewel.Item, -1, Antiban.BioDice(EBioBehavior.KEYBOARD_CHAT_CHANCE)) then
Result := Self.WaitCraft();
end;
function TJewelryCrafter._CraftGoldJewel(): Boolean;
begin
if CurrentJewel = ERSJewelType.TIARA then
begin
if Make.Select(0, Make.QUANTITY_ALL) then
Exit(Self.WaitCraft());
Exit;
end;
if CraftScreen.CraftItem(Self.CraftItem, -1, Antiban.BioDice(EBioBehavior.KEYBOARD_CHAT_CHANCE)) then
Result := Self.WaitCraft();
end;
function TJewelryCrafter.CraftJewel(): Boolean;
begin
if not Inventory.ContainsItem(Self.Bar.Item) then
Exit;
if CurrentMetal = ERSMetalType.SILVER then
Exit(Self._CraftSilverJewel());
Result := Self._CraftGoldJewel();
end;
function TJewelryCrafter.GetState(): EJewelCrafterState;
begin
if WL.Activity.IsFinished() then
Exit(EJewelCrafterState.END_SCRIPT);
if Chat.LeveledUp() then
begin
Self.IsCrafting := False;
Exit(EJewelCrafterState.LEVEL_UP);
end;
if RSInterface.IsOpen() then
begin
Self.IsCrafting := False;
Self.HoveringBank := False;
if Bank.IsOpen() then
begin
if Inventory.ContainsItem(Self.Jewel.Item) then
Exit(EJewelCrafterState.DEPOSIT_JEWELS);
if Inventory.ContainsRandomItems(Self.Materials) then
Exit(EJewelCrafterState.DEPOSIT_RANDOM_ITEM);
if not Self.BankEmpty then
begin
if not Inventory.ContainsItem(Self.Mould.Item) then
Exit(EJewelCrafterState.WITHDRAW_MOULD);
if not Inventory.ContainsItem(Self.Bar.Item) then
Exit(EJewelCrafterState.WITHDRAW_BARS);
if not Self.NoGem and not Inventory.ContainsItem(Self.Gem.Item) then
Exit(EJewelCrafterState.WITHDRAW_GEMS);
end;
end;
if CraftScreen.IsOpen() or SilverScreen.IsOpen() then
Exit(EJewelCrafterState.CRAFT_JEWEL);
if not Self.CollectEmpty and CollectBox.IsOpen() then
Exit(EJewelCrafterState.HANDLE_COLLECT);
Exit(EJewelCrafterState.CLOSE_INTERFACE);
end;
if Make.IsOpen() then
Exit(EJewelCrafterState.CRAFT_JEWEL);
if (Self.NoGem and Inventory.ContainsAll([Self.Mould.Item, Self.Bar.Item])) or
(not Self.NoGem and Inventory.ContainsAll([Self.Mould.Item, Self.Bar.Item, Self.Gem.Item])) then
begin
if Self.IsCrafting then
begin
if not Self.HoveringBank then
begin
Self.CountItemsLeft(Self.Bar.Item);
if Self.ShouldHoverBank() then
Exit(EJewelCrafterState.HOVER_BANK);
end;
Exit(EJewelCrafterState.WAIT_CRAFT);
end;
if Make.IsOpen() then
Exit(EJewelCrafterState.CRAFT_JEWEL);
Exit(EJewelCrafterState.OPEN_FURNACE);
end;
if Self.BankEmpty then
begin
if Self.CollectEmpty then
Exit(EJewelCrafterState.OUT_OF_SUPPLIES);
Exit(EJewelCrafterState.OPEN_COLLECT);
end;
if Self.BankEmpty then
Exit(EJewelCrafterState.OPEN_COLLECT);
Exit(EJewelCrafterState.OPEN_BANK);
end;
function TJewelryCrafter.Terminate(): Boolean; override;
begin
Result := inherited;
end;
procedure TJewelryCrafter.Run(maxActions: UInt32; maxTime: UInt64);
begin
Self.Init(maxActions, maxTime);
repeat
Self.State := Self.GetState();
Self.SetAction(ToStr(Self.State));
case Self.State of
EJewelCrafterState.HOVER_BANK: Self.HoverBank();
EJewelCrafterState.OPEN_BANK: Banks.WalkOpen();
EJewelCrafterState.WITHDRAW_MOULD: Self.Withdraw(Self.Mould);
EJewelCrafterState.WITHDRAW_BARS: Self.Withdraw(Self.Bar);
EJewelCrafterState.WITHDRAW_GEMS: Self.Withdraw(Self.Gem);
EJewelCrafterState.DEPOSIT_JEWELS: Bank.DepositItem(Self.Jewel, True);
EJewelCrafterState.DEPOSIT_RANDOM_ITEM: Bank.DepositRandomItems(Self.Materials);
EJewelCrafterState.OPEN_COLLECT: CollectBoxes.WalkOpen();
EJewelCrafterState.HANDLE_COLLECT: Self.HandleCollectBox(Self.Materials);
EJewelCrafterState.OPEN_FURNACE: Self.OpenFurnace();
EJewelCrafterState.CRAFT_JEWEL: Self.CraftJewel();
EJewelCrafterState.WAIT_CRAFT: Self.WaitCraft();
EJewelCrafterState.CLOSE_INTERFACE: RSInterface.Close();
EJewelCrafterState.CLOSE_CONTEXT: ChooseOption.Close();
EJewelCrafterState.LEVEL_UP: Chat.HandleLevelUp();
EJewelCrafterState.END_SCRIPT, EJewelCrafterState.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
JewelryCrafter: TJewelryCrafter;
{$IFNDEF SCRIPT_CHAIN}
{$IFDEF SCRIPT_GUI}
type
TJewelryCrafterConfig = record(TScriptForm)
BarTypeSelector: TLabeledCombobox;
StoneTypeSelector: TLabeledCombobox;
JewelTypeSelector: TLabeledCombobox;
FurnaceSelector: TLabeledCombobox;
Config: TConfigJSON;
end;
procedure TJewelryCrafterConfig.StartScript(sender: TObject); override;
begin
CurrentMetal := ERSMetalType(Self.BarTypeSelector.GetItemIndex());
CurrentStone := ERSStoneType(Self.StoneTypeSelector.GetItemIndex());
CurrentJewel := ERSJewelType(Self.JewelTypeSelector.GetItemIndex());
CurrentFurnace := ERSFurnace(Self.FurnaceSelector.GetItemIndex());
inherited;
end;
procedure TJewelryCrafterConfig.StoneSelectorOnChange(sender: TObject);
var
combobox: TComboBox;
i, j: Int32;
begin
combobox := sender;
i := combobox.getItemIndex();
j := Self.JewelTypeSelector.GetItemIndex();
Self.BarTypeSelector.SetEnabled((i = 0) and (j = 0));
case i of
1..3: Self.BarTypeSelector.SetItemIndex(0);
else
begin
if j < 4 then
Self.BarTypeSelector.SetItemIndex(0)
else
Self.BarTypeSelector.SetItemIndex(1);
end;
end;
end;
procedure TJewelryCrafterConfig.JewelSelectorOnChange(sender: TObject);
var
combobox: TComboBox;
i: Int32;
begin
combobox := sender;
i := combobox.getItemIndex();
Self.StoneTypeSelector.SetEnabled(i > 3);
if i < 4 then
Self.StoneTypeSelector.SetItemIndex(0);
Self.StoneSelectorOnChange(Self.StoneTypeSelector.ComboBox);
end;
procedure TJewelryCrafterConfig.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('Wasp Jewelry Crafter');
Self.Config.Setup('wasp-jewelry-crafter');
Self.Start.SetOnClick(@Self.StartScript);
Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];
Self.CreateAccountManager(tab);
with Self.FurnaceSelector do
begin
Create(tab);
SetCaption('Furnace:');
SetLeft(TControl.AdjustToDPI(50));
SetTop(TControl.AdjustToDPI(200));
SetStyle(csDropDownList);
AddItemArray([
//'Al Kharid',
'Edgeville', 'Falador', 'Prifddinnas'
]);
if Self.Config.Has('furnace') then
SetItemIndex(Self.Config.GetInt('furnace'))
else
SetItemIndex(Ord(CurrentFurnace));
end;
with Self.JewelTypeSelector do
begin
Create(tab);
SetCaption('Jewel type:');
SetLeft(Self.FurnaceSelector.GetLeft());
SetTop(Self.FurnaceSelector.GetBottom() + TControl.AdjustToDPI(20));
SetStyle(csDropDownList);
AddItemArray([
'Tiara', 'Holy symbol', 'Unholy symbol', 'Bolts', 'Ring',
'Necklace', 'Bracelet', 'Amulet'
]);
if Self.Config.Has('jewel') then
SetItemIndex(Self.Config.GetInt('jewel'))
else
SetItemIndex(Ord(CurrentJewel));
ComboBox.SetOnChange(@Self.JewelSelectorOnChange);
end;
with Self.StoneTypeSelector do
begin
Create(tab);
SetCaption('Stone type:');
SetLeft(Self.JewelTypeSelector.GetRight() + TControl.AdjustToDPI(15));
SetTop(Self.JewelTypeSelector.GetTop());
SetStyle(csDropDownList);
AddItemArray([
'None', 'Opal', 'Jade', 'Red topaz', 'Sapphire', 'Emerald',
'Ruby', 'Diamond', 'Dragonstone', 'Onyx', 'Zenyte'
]);
if Self.Config.Has('stone') then
SetItemIndex(Self.Config.GetInt('stone'))
else
SetItemIndex(Ord(CurrentStone));
ComboBox.SetOnChange(@Self.StoneSelectorOnChange);
end;
with Self.BarTypeSelector do
begin
Create(tab);
SetCaption('Bar type:');
SetLeft(Self.StoneTypeSelector.GetRight() + TControl.AdjustToDPI(15));
SetTop(Self.StoneTypeSelector.GetTop());
SetStyle(csDropDownList);
AddItemArray(['Silver', 'Gold']);
if Self.Config.Has('bar') then
SetItemIndex(Self.Config.GetInt('bar'))
else
SetItemIndex(Ord(CurrentMetal));
SetEnabled(False);
end;
Self.CreateAntibanManager();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();
Self.JewelSelectorOnChange(Self.JewelTypeSelector.ComboBox);
inherited;
end;
var
JewelryCrafterConfig: TJewelryCrafterConfig;
{$ENDIF}
{$ENDIF}
{$IFNDEF SCRIPT_CHAIN}
begin
{$IFDEF SCRIPT_GUI}
JewelryCrafterConfig.Run();
{$ENDIF}
JewelryCrafter.Run(WLSettings.MaxActions, WLSettings.MaxTime);
end.
{$ENDIF}