Skip to content

Commit bca98f5

Browse files
committed
feat: bank interface
Unfinished. Fixed a ton of bugs on itemfinder
1 parent 1ced367 commit bca98f5

File tree

5 files changed

+171
-5
lines changed

5 files changed

+171
-5
lines changed

osrs.simba

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
{$IFNDEF SRLT_MAPLOADER_INCLUDED} {$I osrs/map/maploader.simba}
4747
{$IFNDEF SRLT_MAP_INCLUDED} {$I osrs/map/map.simba}
4848
{$IFNDEF SRLT_MAPDEBUGGER_INCLUDED} {$I osrs/map/mapdebugger.simba}
49+
{$IFNDEF SRLT_BANK_INCLUDED} {$I osrs/interfaces/mainscreen/bank.simba}
4950

5051

5152

@@ -86,3 +87,4 @@
8687
{$ELSE}{$ENDIF}
8788
{$ELSE}{$ENDIF}
8889
{$ELSE}{$ENDIF}
90+
{$ELSE}{$ENDIF}

osrs/finders/items/itemfinder.simba

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,31 @@ type
2424
end;
2525

2626

27-
procedure TRSItemFinder.Align(image, template: TImage);
27+
function TRSItemFinder.Align(image, template: TImage): Boolean;
2828
var
2929
borderA, borderB: TPointArray;
30+
bounds: TBox;
31+
align, p: TPoint;
3032
begin
3133
borderA := image.FindColor(RSColors.ITEM_BORDER, 0);
3234
borderB := template.FindColor(RSColors.ITEM_BORDER, 0) + template.FindColor(RSColors.ITEM_BORDER_WHITE, 0);
3335

34-
image.Crop(borderA.Bounds());
35-
template.Crop(borderB.Bounds());
36+
align := borderA[High(borderA)] - borderB[High(borderB)];
37+
38+
borderB := borderB.Offset(align);
39+
for p in borderB do
40+
begin
41+
if p.Y <= 8 then Continue;//stack number... Don't compare.
42+
43+
//borders don't match.
44+
if not image.InImage(p.X, p.Y) then Exit;
45+
if image.Pixel[p.X, p.Y] <> RSColors.ITEM_BORDER then Exit;
46+
end;
47+
48+
bounds := borderA.Bounds();
49+
image.Crop(bounds);
50+
template.Crop(bounds.Offset([-align.X, -align.Y]));
51+
Result := True;
3652
end;
3753

3854
procedure TRSItemFinder.Clean(image, template: TImage);
@@ -49,6 +65,7 @@ begin
4965
for color in RSColors.STACK_COLORS do
5066
tpa += template.FindColor(color, 0);
5167

68+
tpa += template.FindColor(RSColors.ITEM_BORDER, 0);
5269
image.DrawTPA(tpa);
5370
template.DrawTPA(tpa);
5471
end;
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
(*
2+
# Bank
3+
Methods to interact with the bank interface
4+
*)
5+
6+
{$DEFINE SRLT_BANK_INCLUDED}
7+
{$IFNDEF SRLT_OSR}
8+
{$I SRLT/osrs.simba}
9+
{$ENDIF}
10+
11+
type
12+
ERSBankButtons = (WORN, MENU);
13+
ERSBankArrangement = enum(SWAP, INSERT);
14+
ERSBankWithdraw = enum(ITEM, NOTE);
15+
ERSBankQuantity = enum(QUANTITY_1, QUANTITY_5, QUANTITY_10, QUANTITY_CUSTOM, QUANTITY_ALL);
16+
ERSBankDynamicButtons = enum(PLACEHOLDERS, SEARCH, DEPOSIT_INVENTORY, DEPOSIT_WORN);
17+
18+
TRSItemBankPosition = record
19+
Tab: Integer;
20+
Scroll: Integer;
21+
Box: TBox;
22+
end;
23+
24+
TRSBankItem = record
25+
Item: TRSItem;
26+
Quantity: Integer;
27+
Noted: Boolean;
28+
end;
29+
30+
TRSBankItemArray = array of TRSBankItem;
31+
32+
TRSBank = record
33+
Bounds: TBox;
34+
Slots: TRSSlotInterface;
35+
Items: TRSItemInterface;
36+
37+
CachedQuantity: Int32;
38+
39+
Incenerator, PotionStorage, SlotsArea: TBox;
40+
41+
Tabs, SlotBoxes: TBoxArray;
42+
43+
Cache: record
44+
Quantity: Integer;
45+
Items: TStringMap<TRSItemBankPosition>;
46+
end;
47+
const QUANTITY_ALL: Integer = -1;
48+
const QUANTITY_ALL_BUT_ONE: Integer = -2;
49+
end;
50+
51+
(*
52+
## Bank.FindItemBoundaries
53+
```pascal
54+
function TRSBank.FindItemBoundaries(): TBoxArray;
55+
```
56+
Finds item boundaries. This is an internal function used to retrieve the boxes we
57+
search for items in.
58+
59+
Example:
60+
```pascal
61+
ShowOnClient(Self.FindItemBoundaries());
62+
```
63+
*)
64+
function TRSBank.FindItemBoundaries(): TBoxArray;
65+
var
66+
tpa, final: TPointArray;
67+
atpa: T2DPointArray;
68+
b: TBox;
69+
color: Int32;
70+
begin
71+
final := Target.FindColor(RSColors.ITEM_BORDER, 0, Self.SlotsArea);
72+
if final = [] then Exit;
73+
74+
for color in RSColors.STACK_COLORS do
75+
begin
76+
tpa := Target.FindColor(color, 0, Self.SlotsArea);
77+
if tpa <> [] then final += tpa;
78+
end;
79+
80+
atpa := final.Cluster(200, 3);
81+
82+
for tpa in atpa do
83+
begin
84+
b := tpa.Bounds();
85+
if b.Height <= 5 then Continue;
86+
Result += TBoxArray.Create([Self.SlotsArea.X1, b.Y1 - 1], 8, 1, 32, 32, [16, 0]);
87+
end;
88+
end;
89+
90+
(*
91+
## Bank.SetupInterface
92+
```pascal
93+
procedure Bank.SetupInterface;
94+
```
95+
Initializes Bank interface coordinates.
96+
97+
```{note}
98+
This is automatically called on the **Bank** variable.
99+
```
100+
*)
101+
procedure TRSBank.SetupInterface();
102+
begin
103+
with InterfaceArea do
104+
begin
105+
Self.Bounds.X1 := Max(Floor(Center.X-(Width-1)/2), Floor(Center.X-487/2));
106+
Self.Bounds.X2 := Min(Floor(Center.X+(Width-1)/2), Floor(Center.X +487/2));
107+
Self.Bounds.Y1 := Max(Floor(Center.Y-(Height-3)/2), Floor(Center.Y-799/2));
108+
Self.Bounds.Y2 := Min(Floor(Center.Y+(Height-3)/2), Floor(Center.Y+799/2));
109+
end;
110+
111+
Self.Tabs := TBoxArray.Create(Self.Bounds.TopLeft.Offset(47, 42), 10, 1, 35, 28, [5, 0]);
112+
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]);
113+
114+
Self.SlotsArea.X1 := Self.Bounds.X1 + 57;
115+
Self.SlotsArea.Y1 := Self.Bounds.Y1 + 77;
116+
Self.SlotsArea.X2 := Self.Bounds.X2 - 63;
117+
Self.SlotsArea.Y2 := Self.Bounds.Y2 - 44;
118+
119+
Self.Incenerator.X1 := Self.Bounds.X1 + 5;
120+
Self.Incenerator.Y1 := Self.Bounds.Y2 - 113;
121+
Self.Incenerator.X2 := Self.Bounds.X1 + 51;
122+
Self.Incenerator.Y2 := Self.Bounds.Y2 - 44;
123+
124+
Self.PotionStorage.X1 := Self.Bounds.X1 + 8;
125+
Self.PotionStorage.Y1 := Self.Bounds.Y2 - 156;
126+
Self.PotionStorage.X2 := Self.Bounds.X1 + 51;
127+
Self.PotionStorage.Y2 := Self.Bounds.Y2 - 118;
128+
129+
(*
130+
Self.ScrollArea.X1 := Self.Bounds.X1 + 5;
131+
Self.ScrollArea.Y1 := Self.Bounds.Y1 + 77;
132+
Self.ScrollArea.X2 := Self.Bounds.X2 - 24;
133+
Self.ScrollArea.Y2 := Self.Bounds.Y2 - 44;
134+
*)
135+
136+
137+
Self.Slots.Setup('Bank.Slots', Self.SlotBoxes, @Self.FindItemBoundaries);
138+
Self.Items.Setup('Bank.Items', @Self.Slots, [0, 10, 3, 0]);
139+
end;
140+
141+
142+
143+
var
144+
Bank: TRSBank;
145+

osrs/interfaces/setup.simba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ begin
2020
RSInterface.SetupInterface();
2121
XPBar.SetupInterface();
2222
Prayer.SetupInterface();
23+
Bank.SetupInterface();
2324
end;
2425

2526
function TRSClient.IsLoggedIn(): Boolean; override;

utils/imagecompare.simba

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ type
1616

1717
TImageCompareUtils = record
1818
Clean: procedure (image, template: TImage) of object;
19-
Align: procedure (image, template: TImage) of object;
19+
Align: function (image, template: TImage): Boolean of object;
2020
Filter: TImageCompareFilter;
2121
end;
2222

2323
function TImageCompareUtils.Compare(image, template: TImage; var similarity: Single): Boolean;
2424
var
2525
match: Single;
2626
begin
27-
if @Self.Align <> nil then Self.Align(image, template);
27+
if @Self.Align <> nil then
28+
if not Self.Align(image, template) then Exit;
2829

2930
if (template.Width < image.Width) or (template.Height < image.Height) then
3031
begin

0 commit comments

Comments
 (0)