Skip to content

Commit 9ca35a6

Browse files
committed
fix(DepositBox): read notes
- removed ESlots from DepositBox, didn't serve any purpose - renamed ISlots to Slots in DepositBox - Gave types to the `TRSSlotInterface` and `TRSItemInterface` functions - Inventory.Slots now has a "PreConditionFunction" - Made Hover and Open functions for TRSDepositBox
1 parent 10f1d9c commit 9ca35a6

11 files changed

Lines changed: 259 additions & 100 deletions

File tree

examples/script_template.simba

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ begin
5656

5757
Map.Setup([ERSChunk.VARROCK]);
5858

59-
Antiban.Zoom.Max := 0;
59+
Antiban.Zoom.Min := 0;
6060
Antiban.Zoom.Max := 50;
6161
Antiban.Skills := [ERSSkill.TOTAL];
6262

@@ -157,6 +157,7 @@ begin
157157
FormCheckbox.SetChecked(True);
158158

159159
Self.CreateAntibanTab();
160+
Self.CreateMiscTab();
160161
Self.Run();
161162
end;
162163

osrs/antiban/antibantasks.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ var
395395
begin
396396
if not DepositBox.IsOpen() then Exit;
397397
WriteLn GetDebugLn('Antiban', 'Hovering a random deposit box item');
398-
boxes := DepositBox.ISlots.Boxes();
398+
boxes := DepositBox.Slots.Boxes();
399399
if boxes = [] then Exit;
400400
Mouse.Move(boxes.Random());
401401
Biometrics.Sleep(500, 2000, ERandomDir.LEFT);

osrs/interfaces/gametabs/inventory.simba

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function TRSInventory.Open(): Boolean; forward;
5151

5252
procedure TRSInventory.SetupGameTab();
5353
begin
54-
Self.Slots.Setup('Inventory.Slots', TBoxArray.Create(GameTab.TopLeft.Offset(13,9), 4, 7, 31, 31, [11, 5]));
54+
Self.Slots.Setup('Inventory.Slots', TBoxArray.Create(GameTab.TopLeft.Offset(13,9), 4, 7, 31, 31, [11, 5]), nil, @Self.Open);
5555
Self.Items.Setup('Inventory.Items', @Self.Slots, [0, 0], @Self.Open);
5656
Self.ShiftEnabled := True;
5757
end;

osrs/interfaces/iteminterface.simba

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ unless specified otherwise.
4949
Name: String;
5050
Slots: ^TRSSlotInterface;
5151
DiscoverOffset: TPoint;
52-
CheckFunction: function (): Boolean of object;
52+
PreConditionFunction: TInterfacePreConditionFunction;
5353
end;
5454

5555
(*
@@ -82,12 +82,17 @@ Bank.Slots.Setup('Bank.Slots', Bank.SlotBoxes, @Bank.FindItemBoundaries);
8282
Bank.Items.Setup('Bank.Items', @Bank.Slots, [0, 1], @Bank.IsOpen);
8383
```
8484
*)
85-
procedure TRSItemInterface.Setup(name: String; slots: ^TRSSlotInterface; discoverOffset: TPoint; checkFunc: function (): Boolean of object = nil);
85+
procedure TRSItemInterface.Setup(
86+
name: String;
87+
slots: ^TRSSlotInterface;
88+
discoverOffset: TPoint;
89+
checkFunc: TInterfacePreConditionFunction = nil
90+
);
8691
begin
8792
Self.Name := name;
8893
Self.Slots := slots;
8994
Self.DiscoverOffset := discoverOffset;
90-
Self.CheckFunction := @checkFunc;
95+
Self.PreConditionFunction := @checkFunc;
9196
end;
9297

9398

@@ -110,7 +115,7 @@ function TRSItemInterface.IndexOf(items: TRSItemArray): Integer;
110115
var
111116
match: TImageMatch;
112117
begin
113-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
118+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
114119
Exit(-1);
115120
if ItemFinder.Find(items, Self.Slots^.Boxes(), match) then
116121
Exit(match.Index);
@@ -137,7 +142,7 @@ function TRSItemInterface.IndicesOf(items: TRSItemArray): TIntegerArray;
137142
var
138143
match: TImageMatch;
139144
begin
140-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
145+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
141146
Exit;
142147

143148
for match in ItemFinder.FindAll(items, Self.Slots^.Boxes()) do
@@ -170,7 +175,7 @@ function TRSItemInterface.FindAny(items: TRSItemArray; out slot: TBox): Boolean;
170175
var
171176
match: TImageMatch;
172177
begin
173-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
178+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
174179
Exit;
175180

176181
Result := ItemFinder.Find(items, Self.Slots^.Boxes(), match);
@@ -210,7 +215,7 @@ function TRSItemInterface.Find(items: TRSItemArray; out slot: Integer): Boolean;
210215
var
211216
match: TImageMatch;
212217
begin
213-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
218+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
214219
Exit;
215220

216221
Result := ItemFinder.Find(items, Self.Slots^.Boxes(), match);
@@ -254,7 +259,7 @@ function TRSItemInterface.FindAll(items: TRSItemArray): TBoxArray;
254259
var
255260
match: TImageMatch;
256261
begin
257-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
262+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
258263
Exit;
259264

260265
for match in ItemFinder.FindAll(items, Self.Slots^.Boxes()) do
@@ -267,7 +272,7 @@ var
267272
i: Integer;
268273
begin
269274
slots := [];
270-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
275+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
271276
Exit;
272277

273278
Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
@@ -282,7 +287,7 @@ var
282287
i: Integer;
283288
begin
284289
boxes := [];
285-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
290+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
286291
Exit;
287292

288293
Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
@@ -361,7 +366,7 @@ function TRSItemInterface.ContainsAll(items: TRSItemArray): Boolean;
361366
var
362367
matches: TImageMatchArray;
363368
begin
364-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
369+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
365370
Exit;
366371
Result := ItemFinder.FindAll(items, Self.Slots^.Boxes(), matches);
367372
end;
@@ -409,7 +414,7 @@ end;
409414

410415
function TRSItemInterface.Discover(slot: Integer): TRSItemArray;
411416
begin
412-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
417+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
413418
Exit;
414419

415420
Result := Self._Discover(slot);
@@ -419,7 +424,7 @@ function TRSItemInterface.DiscoverAllEx(): array of TRSItemArray;
419424
var
420425
slot: Integer;
421426
begin
422-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
427+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
423428
Exit;
424429

425430
for slot := Low(Self.Slots^.Boxes()) to High(Self.Slots^.Boxes()) do
@@ -431,7 +436,7 @@ var
431436
slot: Integer;
432437
items: TRSItemArray;
433438
begin
434-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
439+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
435440
Exit;
436441

437442
for slot := Low(Self.Slots^.Boxes()) to High(Self.Slots^.Boxes()) do
@@ -693,7 +698,7 @@ var
693698
center: TPoint;
694699
dist, closest: Double;
695700
begin
696-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
701+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
697702
Exit;
698703
slots := Self.Slots^.Boxes();
699704
if not ItemFinder.FindAll([item], slots, matches) then Exit;
@@ -753,7 +758,7 @@ function TRSItemInterface.Interact(slot: Integer; option: String = ''): Boolean;
753758
var
754759
box: TBox;
755760
begin
756-
if (@Self.CheckFunction <> nil) and not Self.CheckFunction() then
761+
if (@Self.PreConditionFunction <> nil) and not Self.PreConditionFunction() then
757762
Exit;
758763

759764
if not Self.Slots^.IsUsed(slot) then Exit;

osrs/interfaces/mainscreen/bank.simba

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,8 @@ end;
13941394
(*
13951395
## Bank.Hover
13961396
```pascal
1397-
function TRSBank.Hover(constref obj: TRSObject; walk: Boolean = True): Boolean;
1398-
function TRSBank.Hover(constref npc: TRSEntity; walk: Boolean = True): Boolean; overload;
1397+
function TRSBank.Hover(const obj: TRSObject; walk: Boolean = True): Boolean;
1398+
function TRSBank.Hover(const npc: TRSEntity; walk: Boolean = True): Boolean; overload;
13991399
function TRSBank.Hover(walk: Boolean = True): Boolean; overload;
14001400
```
14011401
Hovers the closest bank that WaspLib is aware of.
@@ -1409,14 +1409,14 @@ loaded map.
14091409

14101410
If you are too far, it will attempt to walk closer to it.
14111411
*)
1412-
function TRSBank.Hover(constref obj: TRSObject; walk: Boolean = True): Boolean;
1412+
function TRSBank.Hover(const obj: TRSObject; walk: Boolean = True): Boolean;
14131413
begin
14141414
if walk then
14151415
Exit(obj.WalkHover());
14161416
Result := obj.Hover();
14171417
end;
14181418

1419-
function TRSBank.Hover(constref npc: TRSEntity; walk: Boolean = True): Boolean; overload;
1419+
function TRSBank.Hover(const npc: TRSEntity; walk: Boolean = True): Boolean; overload;
14201420
begin
14211421
if walk then
14221422
Exit(npc.WalkHover());
@@ -1425,27 +1425,27 @@ end;
14251425

14261426
function TRSBank.Hover(walk: Boolean = True): Boolean; overload;
14271427
var
1428-
obj: TRSObject;
1429-
npc: TRSEntity;
1428+
obj: PRSObject;
1429+
npc: PRSEntity;
14301430
me: TPoint;
14311431
begin
14321432
if (Self.Banks = []) or (Self.Bankers = []) then
14331433
Self._SetupMapObjects();
14341434

14351435
me := Map.Position();
1436-
obj := Self.Banks[Self.Banks.ClosestIndex(me)];
1437-
npc := Self.Bankers[Self.Bankers.ClosestIndex(me)];
1436+
obj := @Self.Banks[Self.Banks.ClosestIndex(me)];
1437+
npc := @Self.Bankers[Self.Bankers.ClosestIndex(me)];
14381438

1439-
if obj.DistanceTo(me) < npc.DistanceTo(me) then
1440-
Exit(Self.Hover(obj, walk));
1441-
Result := Self.Hover(npc, walk);
1439+
if obj^.DistanceTo(me) < npc^.DistanceTo(me) then
1440+
Exit(Self.Hover(obj^, walk));
1441+
Result := Self.Hover(npc^, walk);
14421442
end;
14431443

14441444
(*
14451445
## Bank.Open
14461446
```pascal
1447-
function TRSBank.Open(constref obj: TRSObject; walk: Boolean = True): Boolean;
1448-
function TRSBank.Open(constref npc: TRSEntity; walk: Boolean = True): Boolean; overload;
1447+
function TRSBank.Open(const obj: TRSObject; walk: Boolean = True): Boolean;
1448+
function TRSBank.Open(const npc: TRSEntity; walk: Boolean = True): Boolean; overload;
14491449
function TRSBank.Open(walk: Boolean = True): Boolean; overload;
14501450
```
14511451
Opens the bank for you.
@@ -1471,7 +1471,7 @@ end.
14711471
```{figure} ../../images/bankopen.gif
14721472
```
14731473
*)
1474-
function TRSBank.Open(constref obj: TRSObject; walk: Boolean = True): Boolean;
1474+
function TRSBank.Open(const obj: TRSObject; walk: Boolean = True): Boolean;
14751475
begin
14761476
if walk then
14771477
Result := obj.WalkInteract(['Bank B', 'Bank E', 'Bank G', 'Use B'])
@@ -1486,7 +1486,7 @@ begin
14861486
Result := Self.WaitOpen(3000);
14871487
end;
14881488

1489-
function TRSBank.Open(constref npc: TRSEntity; walk: Boolean = True): Boolean; overload;
1489+
function TRSBank.Open(const npc: TRSEntity; walk: Boolean = True): Boolean; overload;
14901490
begin
14911491
if walk then
14921492
Result := npc.WalkInteract(['Bank B', 'Bank E'])
@@ -1502,8 +1502,8 @@ end;
15021502

15031503
function TRSBank.Open(walk: Boolean = True): Boolean; overload;
15041504
var
1505-
obj: TRSObject;
1506-
npc: TRSEntity;
1505+
obj: PRSObject;
1506+
npc: PRSEntity;
15071507
me: TPoint;
15081508
begin
15091509
if MSInterface.IsOpen() then
@@ -1517,12 +1517,12 @@ begin
15171517
Self._SetupMapObjects();
15181518

15191519
me := Map.Position();
1520-
obj := Self.Banks[Self.Banks.ClosestIndex(me)];
1521-
npc := Self.Bankers[Self.Bankers.ClosestIndex(me)];
1520+
obj := @Self.Banks[Self.Banks.ClosestIndex(me)];
1521+
npc := @Self.Bankers[Self.Bankers.ClosestIndex(me)];
15221522

1523-
if obj.DistanceTo(me) < npc.DistanceTo(me) then
1524-
Exit(Self.Open(obj, walk));
1525-
Result := Self.Open(npc, walk);
1523+
if obj^.DistanceTo(me) < npc^.DistanceTo(me) then
1524+
Exit(Self.Open(obj^, walk));
1525+
Result := Self.Open(npc^, walk);
15261526
end;
15271527

15281528
(*

osrs/interfaces/mainscreen/collectionbox.simba

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -272,31 +272,31 @@ end;
272272

273273
function TRSCollectionBox.Hover(walk: Boolean = True): Boolean;
274274
var
275-
obj: TRSObject;
276-
npc: TRSEntity;
275+
obj: PRSObject;
276+
npc: PRSEntity;
277277
me: TPoint;
278278
begin
279279
if (Bank.Banks = []) or (Bank.Bankers = []) then
280280
Bank._SetupMapObjects();
281281

282282
me := Map.Position();
283-
obj := Bank.Banks[Bank.Banks.ClosestIndex(me)];
284-
npc := Bank.Bankers[Bank.Bankers.ClosestIndex(me)];
283+
obj := @Bank.Banks[Bank.Banks.ClosestIndex(me)];
284+
npc := @Bank.Bankers[Bank.Bankers.ClosestIndex(me)];
285285

286-
if obj.DistanceTo(me) < npc.DistanceTo(me) then
286+
if obj^.DistanceTo(me) < npc^.DistanceTo(me) then
287287
begin
288-
if walk then Exit(obj.WalkHover());
289-
Exit(obj.Hover());
288+
if walk then Exit(obj^.WalkHover());
289+
Exit(obj^.Hover());
290290
end;
291291

292-
if walk then Exit(npc.WalkHover());
293-
Result := npc.Hover();
292+
if walk then Exit(npc^.WalkHover());
293+
Result := npc^.Hover();
294294
end;
295295

296296
function TRSCollectionBox.Open(walk: Boolean = True): Boolean;
297297
var
298-
obj: TRSObject;
299-
npc: TRSEntity;
298+
obj: PRSObject;
299+
npc: PRSEntity;
300300
me: TPoint;
301301
begin
302302
if MSInterface.IsOpen() then
@@ -309,35 +309,35 @@ begin
309309
Bank._SetupMapObjects();
310310

311311
me := Map.Position();
312-
obj := Bank.Banks[Bank.Banks.ClosestIndex(me)];
313-
npc := Bank.Bankers[Bank.Bankers.ClosestIndex(me)];
312+
obj := @Bank.Banks[Bank.Banks.ClosestIndex(me)];
313+
npc := @Bank.Bankers[Bank.Bankers.ClosestIndex(me)];
314314

315-
if obj.DistanceTo(me) < npc.DistanceTo(me) then
315+
if obj^.DistanceTo(me) < npc^.DistanceTo(me) then
316316
begin
317-
if walk then Result := obj.WalkInteract(['Collect'])
318-
else Result := obj.Interact(['Collect']);
317+
if walk then Result := obj^.WalkInteract(['Collect'])
318+
else Result := obj^.Interact(['Collect']);
319319

320320
if not Result then
321321
begin
322322
Result := MainScreen.IsUpText('Bank') and ChooseOption.Select(['Collect']);
323323
if not Result then Exit;
324324
end;
325325

326-
obj.Walker^.WaitMoving();
326+
obj^.Walker^.WaitMoving();
327327
Result := Self.WaitOpen(3000);
328328
Exit;
329329
end;
330330

331-
if walk then Result := npc.WalkInteract(['Collect'])
332-
else Result := npc.Interact(['Collect']);
331+
if walk then Result := npc^.WalkInteract(['Collect'])
332+
else Result := npc^.Interact(['Collect']);
333333

334334
if not Result then
335335
begin
336336
Result := MainScreen.IsUpText('Bank') and ChooseOption.Select(['Collect']);
337337
if not Result then Exit;
338338
end;
339339

340-
npc.Walker^.WaitMoving();
340+
npc^.Walker^.WaitMoving();
341341
Result := Self.WaitOpen(3000);
342342
end;
343343

0 commit comments

Comments
 (0)