Skip to content

Commit 50d39c3

Browse files
committed
feat: core of TAntiban
and a lot of docs
1 parent cb0fb61 commit 50d39c3

File tree

8 files changed

+782
-26
lines changed

8 files changed

+782
-26
lines changed

osrs/antiban.simba

Lines changed: 544 additions & 0 deletions
Large diffs are not rendered by default.

osrs/interfaces/mainscreen/bank.simba

Lines changed: 130 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ Bank enums used to interact with the bank interface.
3434
Slot: TBox;
3535
end;
3636

37-
TRSBankItem = record
38-
Item: TRSItem;
39-
Quantity: Integer;
40-
Noted: Boolean;
41-
end;
42-
43-
TRSBankItemArray = array of TRSBankItem;
44-
4537
(*
4638
(TRSBank)=
4739
## type TRSBank
@@ -127,7 +119,7 @@ procedure Bank.SetupInterface;
127119
Initializes Bank interface coordinates.
128120

129121
```{note}
130-
This is automatically called on the **Bank** variable.
122+
This is automatically called on the {ref}`Bank` variable.
131123
```
132124
*)
133125
procedure TRSBank.SetupInterface();
@@ -218,6 +210,19 @@ begin
218210
end;
219211
end;
220212

213+
(*
214+
## Bank.UpdateButtons
215+
```pascal
216+
procedure TRSBank.UpdateButtons(offset: Integer);
217+
```
218+
Internal helper method used to update the buttons coordinates.
219+
220+
All the bank's bottom buttons shift slightly on the X axis depending on how many dynamic buttons are visible.
221+
222+
```{note}
223+
This is automatically called for you with {ref}`Bank.IsOpen()`.
224+
```
225+
*)
221226
procedure TRSBank.UpdateButtons(offset: Integer);
222227
var
223228
i: Integer;
@@ -591,20 +596,61 @@ begin
591596
end;
592597

593598

599+
(*
600+
## Bank.HasIncinerator
601+
```pascal
602+
function TRSBank.HasIncinerator(): Boolean;
603+
```
604+
Returns true if the bank screen has the incenerator visible.
594605

606+
Example:
607+
```pascal
608+
if Bank.HasIncenerator() then
609+
ShowOnClient(Self.Incenerator);
610+
```
611+
*)
595612
function TRSBank.HasIncinerator(): Boolean;
596613
begin
597614
with Self.Incenerator do
598615
Result := Target.HasColor(ColorTolerance($517F9E, 2.132, EColorSpace.HSV, [2.437, 0.309, 0.256]), 1, [X1, Y1+55, X2, Y2]);
599616
end;
600617

618+
(*
619+
## Bank.InceneratorTooltipVisible
620+
```pascal
621+
function TRSBank.InceneratorTooltipVisible(): Boolean;
622+
```
623+
Returns true if the incenerator tooltip is visible.
624+
This is important to check when you want to interact with the bottom buttons of
625+
the bank as the tooltip will cover them.
626+
627+
Example:
628+
```pascal
629+
WriteLn Bank.InceneratorTooltipVisible();
630+
```
631+
*)
601632
function TRSBank.InceneratorTooltipVisible(): Boolean;
602633
begin
603634
with Self.Incenerator do
604635
Result := Target.HasColor($A0FFFF, 0, 1, [X1+6, Y1+76, X2, Y2+35]);
605636
end;
606637

607-
function TRSBank.UnHoverIncinerator(): Boolean;
638+
(*
639+
## Bank.CloseInceneratorTooltip
640+
```pascal
641+
function TRSBank.CloseInceneratorTooltip(): Boolean;
642+
```
643+
Attempts to close the incenerator tooltip.
644+
This is important to do when you want to interact with the bottom buttons of
645+
the bank as the tooltip will cover them.
646+
647+
Example:
648+
```pascal
649+
if Bank.InceneratorTooltipVisible() then
650+
WriteLn Bank.CloseInceneratorTooltip();
651+
```
652+
*)
653+
function TRSBank.CloseInceneratorTooltip(): Boolean;
608654
var
609655
boxes: TBoxArray;
610656
begin
@@ -618,17 +664,42 @@ begin
618664
end;
619665

620666

667+
(*
668+
## Bank.HasPotionStorage
669+
```pascal
670+
function TRSBank.HasPotionStorage(): Boolean;
671+
```
672+
Returns True/False if the bank has the potion storage menu available.
673+
674+
Example:
675+
```pascal
676+
WriteLn Bank.HasPotionStorage();
677+
```
678+
*)
621679
function TRSBank.HasPotionStorage(): Boolean;
622680
begin
623681
Result := Target.HasColor(ColorTolerance($517F9E, 2.132, EColorSpace.HSV, [2.437, 0.309, 0.256]), 1, Self.PotionStorage);
624682
end;
625683

684+
(*
685+
## Bank.PotionStorageIsOpen
686+
```pascal
687+
function TRSBank.PotionStorageIsOpen(): Boolean;
688+
```
689+
Returns True if the potion storage is currently open.
690+
691+
Example:
692+
```pascal
693+
WriteLn Bank.PotionStorageIsOpen();
694+
```
695+
*)
626696
function TRSBank.PotionStorageIsOpen(): Boolean;
627697
begin
628698
Result := Target.HasColor($1F98FF, 0, 3000, Self.SlotsArea);
629699
end;
630700

631701

702+
{%codetools off}
632703
(*
633704
## Bank._FindTabText
634705
```pascal
@@ -643,7 +714,6 @@ if Bank.Search('logs') then
643714
ShowOnClient(bounds);
644715
```
645716
*)
646-
{%codetools off}
647717
function TRSBank._FindTabText(const tpa: TPointArray; out bounds: TBox): Boolean;
648718
var
649719
atpa: T2DPointArray;
@@ -854,7 +924,20 @@ begin
854924
end;
855925

856926

857-
function TRSBank.Withdraw(const item: TRSBankItem;const useQuantityButton: Boolean = True; const useCache: Boolean = True): Boolean;
927+
(*
928+
## Bank.Withdraw
929+
```pascal
930+
function TRSBank.Withdraw(const item: TRSBankItem; const useQuantityButton: Boolean = True; const useCache: Boolean = True): Boolean;
931+
function TRSBank.Withdraw(const item: TRSItem; const useQuantityButton: Boolean = True; const useCache: Boolean = True): Boolean; overload;
932+
```
933+
Attempts to withdraw `item` from the bank.
934+
935+
Example:
936+
```pascal
937+
WriteLn Bank.Withdraw(item);
938+
```
939+
*)
940+
function TRSBank.Withdraw(const item: TRSBankItem; const useQuantityButton: Boolean = True; const useCache: Boolean = True): Boolean;
858941
var
859942
data: TBankPosition;
860943
begin
@@ -869,6 +952,41 @@ begin
869952
Result := Self._InteractionHelper(ERSBankInteraction.WITHDRAW, data.Slot, item.Quantity, useQuantityButton);
870953
end;
871954

955+
function TRSBank.Withdraw(const item: TRSItem; const useQuantityButton: Boolean = True; const useCache: Boolean = True): Boolean; overload;
956+
begin
957+
Result := Self.Withdraw(item.ToBankItem(), useQuantityButton, useCache);
958+
end;
959+
960+
(*
961+
## Bank.Deposit
962+
```pascal
963+
function TRSBank.Deposit(const item: TRSBankItem; const useQuantityButton: Boolean = True): Boolean;
964+
function TRSBank.Deposit(const item: TRSItem; const useQuantityButton: Boolean = True): Boolean; overload;
965+
```
966+
Attempts to deposit `item` into the bank.
967+
968+
Example:
969+
```pascal
970+
WriteLn Bank.Deposit(item);
971+
```
972+
*)
973+
function TRSBank.Deposit(const item: TRSBankItem; const useQuantityButton: Boolean = True): Boolean;
974+
var
975+
slot: TBox;
976+
begin
977+
if Inventory.Items.Find(item.ToItem(), slot) then
978+
Result := Self._InteractionHelper(ERSBankInteraction.DEPOSIT, slot, item.Quantity, useQuantityButton);
979+
end;
980+
981+
function TRSBank.Deposit(const item: TRSItem; const useQuantityButton: Boolean = True): Boolean; overload;
982+
var
983+
slot: TBox;
984+
begin
985+
if Inventory.Items.Find(item, slot) then
986+
Result := Self._InteractionHelper(ERSBankInteraction.DEPOSIT, slot, 1, useQuantityButton);
987+
end;
988+
989+
872990
procedure TRSBank.Draw(img: TImage);
873991
var
874992
i: Integer;

osrs/walker.simba

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,46 @@ iterations made by Olly.
1212

1313
type
1414
(*
15-
## PRSWalker
15+
(PRSWalker)=
16+
## type PRSWalker
1617
TRSWalker pointer.
1718
*)
1819
PRSWalker = ^TRSWalker;
1920

2021
(*
21-
## TRSWalker_OnWalkEvent
22+
(TRSWalkerEvent)=
23+
## type TRSWalkerEvent
2224
Callback object method to use while walking. This can be used to perform custom tasks while walking.
2325

2426
Example:
2527
```pascal
26-
procedure TRSWalker.WalkerTasks(Walker: PRSWalker; Position: TPoint; Destination: TPoint);
28+
procedure TRSWalker.WalkerTasks(walker: PRSWalker; position, destination: TPoint);
2729
begin
2830
Antiban.RandomTab();
2931
end;
3032

31-
var
32-
rsw: TRSWalker;
3333
begin
34-
rsw.Setup('world');
35-
rsw.OnWaitMoving := @rsw.WalkerTasks;
34+
//this assumes walker is already setup.
35+
walker.OnWaitMoving := @walker.WalkerTasks;
3636
end;
3737
```
3838
*)
39-
TRSWalkerEvent = procedure(walker: PRSWalker; position: TPoint; destination: TPoint) of object;
39+
TRSWalkerEvent = procedure(walker: PRSWalker; position, destination: TPoint) of object;
4040
TRSWalkerPositionFunction = function (): TPoint of object;
4141
TRSWalkerHeightFunction = function (pt: TPoint = [0,0]): Single of object;
4242
TRWalkerGetLocalFunction = function (pt: TPoint; offset: TPoint = [0,0]): TPoint of object;
4343

44+
(*
45+
(TRSWalker)=
46+
## type TRSWalker
47+
TRSWalker is the record responsible for walking.
48+
To work you need to set it up with something that gives it a position function
49+
as by itself it doesn't really do anything.
50+
51+
Once you have a function that gives you an accurate position, you can pass it to
52+
into a `TRSWalker` variable or into the {ref}`Walker` one, either directly or
53+
via the {ref}`Walker.Setup()` method.
54+
*)
4455
TRSWalker = record
4556
Name: String;
4657

@@ -108,18 +119,56 @@ function TRSWalker.DummyHeight(pt: TPoint = [0,0]): Single; begin Result := pt.X
108119
function TRSWalker.DummyGetLocal(pt: TPoint; offset: TPoint = [0,0]): TPoint; begin Result := pt+offset; end;
109120
{%codetools on}
110121

122+
(*
123+
## Walker.Setup
124+
```pascal
125+
procedure TRSWalker.Setup(position: TRSWalkerPositionFunction; height: TRSWalkerHeightFunction; getLocal: TRWalkerGetLocalFunction; graph: ^TWebGraph; mapImage: TImage);
126+
```
127+
Method responsible for setting up the {ref}`TRSWalker` variable.
128+
All parameters of this function can be `nil` except for `position`.
129+
Without a `position` callback you cannot use `TRSWalker`.
130+
131+
The following example is purely an example, you never have to do this since
132+
`Map.Setup` already does this for you anyway.
133+
134+
Example:
135+
```pascal
136+
Map.Setup(ERSChunk.CATACOMBS_OF_KOUREND);
137+
Walker.Setup(@Map.Position, @Map.Height, @Map.Loader.GetLocal, @Map.Loader.Graph, @Map.Loader.Map);
138+
```
139+
*)
111140
procedure TRSWalker.Setup(position: TRSWalkerPositionFunction; height: TRSWalkerHeightFunction; getLocal: TRWalkerGetLocalFunction; graph: ^TWebGraph; mapImage: TImage);
112141
begin
113142
Self.Position := @position;
114143
if @height <> nil then Self.Height := @height else Self.Height := @Self.DummyHeight;
115144
if @getLocal <> nil then Self.GetLocal := @getLocal else Self.GetLocal := @Self.DummyGetLocal;
116-
Self.WebGraph := graph;
145+
117146
Self.WalkUpText := ['Walk here', 'alk her'];
118147
Self.AdaptiveWalk := True;
148+
Self.WebGraph := graph;
119149
Self.MapImage := mapImage;
120150
end;
121151

122152

153+
(*
154+
## Walker Conversions
155+
```pascal
156+
function TRSWalker.Point2MM(const playerPoint, pt: TPoint; const radians: Double): TPoint;
157+
function TRSWalker.Point2MMVec(const playerPoint, pt: TPoint; const radians: Double): Vector2;
158+
function TRSWalker.Points2MM(const playerPoint: TPoint; const tpa: TPointArray; const radians: Double): TPointArray;
159+
function TRSWalker.GetLocalEx(const tpa: TPointArray; const offset: TPoint = [0,0]): TPointArray;
160+
function TRSWalker.GetQuadMS(const playerPoint, mapPoint: TPoint; const height: Double = 0; const offset: Vector3 = [0,0,0]; radians: Single = $FFFF): TQuad;
161+
function TRSWalker.MM2Map(const playerPoint, minimapPoint: TPoint; radians: Single = $FFFF): TPoint;
162+
```
163+
Used to convert coordinates from `TRSWalker` to the minimap or the mainscreen.
164+
165+
Example:
166+
```pascal
167+
//assuming walker is already setup...
168+
me := Walker.Position();
169+
ShowOnClient(Walker.GetQuadMS(me, me + [4,0])); //should show you the tile to your right.
170+
```
171+
*)
123172
function TRSWalker.Point2MM(const playerPoint, pt: TPoint; const radians: Double): TPoint;
124173
begin
125174
Result := pt - playerPoint + Minimap.Center;

tests/000.simba

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
//compile test
1+
(*
2+
# Tests
3+
Automated tests to ensure the library is working as expected.
4+
All the test files run whenever there's a commit to the library and only if
5+
they all pass without crashing a release is created.
6+
7+
There's limitations to what can be tested but anything that doesn't require direct
8+
interaction with the game can be tested through this process.
9+
*)
10+
11+
(*
12+
## Compile Test
13+
Simple compile test.
14+
*)
215
{$I SRLT/osrs.simba}
316

tests/001.simba

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//gametabs and inventory tests
1+
(*
2+
## Inventory Tests
3+
Tests the integrety of several inventory methods.
4+
*)
25
{$I SRLT/osrs.simba}
36
{$ASSERTIONS ON}
47

tests/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

utils/item.simba

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ type
77
TRSItem = String;
88
TRSItemArray = array of TRSItem;
99

10+
TRSBankItem = record
11+
Item: TRSItem;
12+
Quantity: Integer;
13+
Noted: Boolean;
14+
end;
15+
16+
TRSBankItemArray = array of TRSBankItem;
17+
1018
function TRSItem.HasAmount(): Boolean;
1119
begin
1220
Result := Self.EndsWith(')', True);
@@ -37,3 +45,19 @@ begin
3745
short := Min(0, long - Ceil(long/3));
3846
Result := Result.CopyRange(0, Random(short, long));
3947
end;
48+
49+
function TRSItem.ToBankItem(): TRSBankItem;
50+
begin
51+
Result.Quantity := 1;
52+
Result.Noted := Self.StartsWith('Noted ', False);
53+
if Result.Noted then Result.Item := Self.After('Noted ')
54+
else Result.Item := Self;
55+
end;
56+
57+
function TRSBankItem.ToItem(): TRSItem;
58+
begin
59+
Result := Self.Item;
60+
if Self.Noted then
61+
Result := 'Noted ' + Result.ToLower();
62+
end;
63+

0 commit comments

Comments
 (0)