Skip to content

Commit 33647ad

Browse files
committed
feat: hitsplats
not tested, probably working fine
1 parent 225787d commit 33647ad

File tree

4 files changed

+224
-23
lines changed

4 files changed

+224
-23
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
This is a library for [Simba 2.0](https://github.com/Villavu/Simba) and it's a tribute to the original [SRL-Development](https://github.com/Villavu/SRL-Development).
33
The library layout is heavily inspired in [SRL-T](https://github.com/Torwent/SRL-T) and [WaspLib](https://github.com/Torwent/WaspLib).
44

5+
Documentation can be found here: <https://torwent.github.io/SRLT/>
6+
57
Credits to certain code might be temporarily missing, refer to the original libraries above for proper credits, if a piece of code exists in both this and one of the libraries above,
6-
the credits to the original author will probably be there.
8+
the credits to the original author will probably be there.
9+
10+
For more information about WaspScripts and more about OldSchool Runescape Color botting visit [waspscripts.com](https://waspscripts.com).
11+
12+

osrs.simba

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
{$IFNDEF SRLT_MAP_INCLUDED} {$INCLUDE_ONCE osrs/map/map.simba}
4949
{$IFNDEF SRLT_MAPDEBUGGER_INCLUDED} {$INCLUDE_ONCE osrs/map/mapdebugger.simba}
5050
{$IFNDEF SRLT_BANK_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/mainscreen/bank.simba}
51+
{$IFNDEF SRLT_COLORFINDER_INCLUDED} {$INCLUDE_ONCE osrs/mainscreen/colorfinder.simba}
52+
{$IFNDEF SRLT_HITSPLATS_INCLUDED} {$INCLUDE_ONCE osrs/mainscreen/hitsplats.simba}
5153

5254

5355
{$IFNDEF SRLT_ANTIBAN_TASKS_INCLUDED} {$INCLUDE_ONCE osrs/antiban/antibantasks.simba}
@@ -95,3 +97,5 @@
9597
{$ENDIF}
9698
{$ENDIF}
9799
{$ENDIF}
100+
{$ENDIF}
101+
{$ENDIF}
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,14 @@ Main record used to find and interact with complex color objects.
273273
## TColorFinder.Find
274274
```pascal
275275
function TColorFinder.Find(out atpa: T2DPointArray; areas: TBoxArray): Boolean;
276-
function TColorFinder.Find(out atpa: T2DPointArray; area: TBox): Boolean; overload;
277276
function TColorFinder.Find(out atpa: T2DPointArray; areas: TPolygonArray): Boolean; overload;
278-
function TColorFinder.Find(out atpa: T2DPointArray; area: TPolygon): Boolean; overload;
279277
function TColorFinder.Find(out atpa: T2DPointArray; areas: TCuboidArray): Boolean; overload;
280-
function TColorFinder.Find(out atpa: T2DPointArray; area: TCuboid): Boolean; overload;
278+
function TColorFinder.Find(out atpa: T2DPointArray): Boolean; overload;
281279
```
282280
Attempts to find on the given `area` a {ref}`TColorFinder`.
283281
If `area` is not specified, {ref}`MainScreen` Bounds are used.
284282
The function returns true if we find anything and the coordinates containing
285283
what was found are returned through `atpa`.
286-
287284
*)
288285
function TColorFinder.Find(out atpa: T2DPointArray; areas: TBoxArray): Boolean;
289286
var
@@ -320,12 +317,6 @@ begin
320317
Result := atpa <> [];
321318
end;
322319

323-
function TColorFinder.Find(out atpa: T2DPointArray; area: TBox): Boolean; overload;
324-
begin
325-
Result := Self.Find(atpa, [area]);
326-
end;
327-
328-
329320
function TColorFinder.Find(out atpa: T2DPointArray; areas: TPolygonArray): Boolean; overload;
330321
var
331322
transformer: TColorFinderTransformer;
@@ -366,12 +357,6 @@ begin
366357
Result := atpa <> [];
367358
end;
368359

369-
function TColorFinder.Find(out atpa: T2DPointArray; area: TPolygon): Boolean; overload;
370-
begin
371-
Result := Self.Find(atpa, [area]);
372-
end;
373-
374-
375360
function TColorFinder.Find(out atpa: T2DPointArray; areas: TCuboidArray): Boolean; overload;
376361
var
377362
transformer: TColorFinderTransformer;
@@ -412,12 +397,6 @@ begin
412397
Result := atpa <> [];
413398
end;
414399

415-
function TColorFinder.Find(out atpa: T2DPointArray; area: TCuboid): Boolean; overload;
416-
begin
417-
Result := Self.Find(atpa, [area]);
418-
end;
419-
420-
421400
function TColorFinder.Find(out atpa: T2DPointArray): Boolean; overload;
422401
begin
423402
Result := Self.Find(atpa, [MainScreen.Bounds]);

osrs/mainscreen/hitsplats.simba

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
(*
2+
# HitSplats
3+
*)
4+
{$DEFINE SRLT_HITSPLATS_INCLUDED}
5+
{$INCLUDE_ONCE SRLT/osrs.simba}
6+
7+
type
8+
(*
9+
(ERSHitSplat)=
10+
## type ERSHitSplat
11+
```pascal
12+
ERSHitSplat = enum(BLUE, RED, MAX);
13+
```
14+
Enum representing the main hitsplat colors.
15+
*)
16+
ERSHitSplat = enum(BLUE, RED, MAX);
17+
18+
(*
19+
(TRSHitsplat)=
20+
## type TRSHitSplat
21+
Hitsplat record that holds the methods used to find hitsplats.
22+
*)
23+
TRSHitsplat = record
24+
Position: TPoint;
25+
Value: Integer;
26+
Color: ERSHitSplat;
27+
const TEXT_WHITE: TColor = $E3E3E3;
28+
const TEXT_TOLERANCE: Double = 10.981;
29+
end;
30+
31+
TRSHitSplatArray = array of TRSHitsplat;
32+
33+
34+
function TRSHitSplat._Find(area: TBox): TRSHitSplat; static;
35+
var
36+
blue, red, maxhit: TPointArray;
37+
begin
38+
blue := Target.FindColor(ColorTolerance($E03E33, 0.600, EColorSpace.HSV, [1.435, 1.435, 0.131]), area);
39+
if blue <> [] then
40+
begin
41+
Result.Position := area.TopLeft;
42+
Result.Value := OCR.RecognizeNumber(area, RSFonts.PLAIN_11, [Self.TEXT_WHITE], Self.TEXT_TOLERANCE);
43+
Result.Color := ERSHitSplat.BLUE;
44+
Exit;
45+
end;
46+
47+
red := Target.FindColor(ColorTolerance($0000A5, 0.498, EColorSpace.HSV, [1.413, 1.413, 0.176]), area);
48+
if red <> [] then
49+
begin
50+
Result.Position := area.TopLeft;
51+
Result.Value := OCR.RecognizeNumber(area, RSFonts.PLAIN_11, [Self.TEXT_WHITE], Self.TEXT_TOLERANCE);
52+
Result.Color := ERSHitSplat.RED;
53+
Exit;
54+
end;
55+
56+
maxhit := Target.FindColor(ColorTolerance($0000D8, 0.488, EColorSpace.HSV, [1.433, 1.433, 0.136]), area);
57+
if maxhit <> [] then
58+
begin
59+
Result.Position := area.TopLeft;
60+
Result.Value := OCR.RecognizeNumber(area, RSFonts.PLAIN_11, [Self.TEXT_WHITE], Self.TEXT_TOLERANCE);
61+
Result.Color := ERSHitSplat.MAX;
62+
Exit;
63+
end;
64+
end;
65+
66+
(*
67+
## TRSHitSplat.Find
68+
```pascal
69+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TBoxArray): Boolean; static;
70+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TPolygonArray): Boolean; static; overload;
71+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TCuboidArray): Boolean; static; overload;
72+
function TRSHitSplat.Find(out splats: TRSHitSplatArray): Boolean; static; overload;
73+
```
74+
Attempts to find hitsplats on the given `area` a {ref}`TColorFinder`.
75+
If `area` is not specified, {ref}`MainScreen` Bounds are used.
76+
The function returns true if we find at least one hitsplat and found splats are
77+
returned via `splats`.
78+
*)
79+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TBoxArray): Boolean; static;
80+
var
81+
area, b: TBox;
82+
white, black, tpa: TPointArray;
83+
clusters: T2DPointArray;
84+
hit: TRSHitSplat;
85+
begin
86+
splats := [];
87+
for area in areas do
88+
begin
89+
white := Target.FindColor($E3E3E3, 10.981, area);
90+
black := Target.FindColor($0, 0, area);
91+
clusters := white.PointsNearby(black, 1,3).Cluster(4);
92+
93+
if clusters = [] then Exit;
94+
95+
for tpa in clusters do
96+
begin
97+
with tpa.Bounds() do b := [X1-1, Y1-1, X2+2, Y2+3];
98+
99+
hit := TRSHitsplat._Find(b);
100+
if hit.Position <> Default(TPoint) then
101+
splats += hit;
102+
end;
103+
end;
104+
Result := splats <> [];
105+
end;
106+
107+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TPolygonArray): Boolean; static; overload;
108+
var
109+
poly: TPolygon;
110+
area, b: TBox;
111+
white, black, tpa: TPointArray;
112+
clusters: T2DPointArray;
113+
hit: TRSHitSplat;
114+
begin
115+
splats := [];
116+
for poly in areas do
117+
begin
118+
area := poly.Bounds();
119+
white := Target.FindColor($E3E3E3, 10.981, area);
120+
black := Target.FindColor($0, 0, area);
121+
clusters := white.PointsNearby(black, 1,3).Cluster(4);
122+
123+
if clusters = [] then Exit;
124+
125+
for tpa in clusters do
126+
begin
127+
with tpa.Bounds() do
128+
begin
129+
if not poly.Contains(Center) then Continue;
130+
b := [X1-1, Y1-1, X2+2, Y2+3];
131+
end;
132+
133+
hit := TRSHitsplat._Find(b);
134+
if hit.Position <> Default(TPoint) then
135+
splats += hit;
136+
end;
137+
end;
138+
Result := splats <> [];
139+
end;
140+
141+
function TRSHitSplat.Find(out splats: TRSHitSplatArray; areas: TCuboidArray): Boolean; static; overload;
142+
var
143+
poly: TPolygon;
144+
area: TCuboid;
145+
bounds, b: TBox;
146+
white, black, tpa: TPointArray;
147+
clusters: T2DPointArray;
148+
hit: TRSHitSplat;
149+
begin
150+
splats := [];
151+
for area in areas do
152+
begin
153+
bounds := area.Bounds();
154+
white := Target.FindColor($E3E3E3, 10.981, bounds);
155+
black := Target.FindColor($0, 0, bounds);
156+
clusters := white.PointsNearby(black, 1,3).Cluster(4);
157+
158+
if clusters = [] then Exit;
159+
160+
poly := area.Polygon();
161+
162+
for tpa in clusters do
163+
begin
164+
with tpa.Bounds() do
165+
begin
166+
if not poly.Contains(Center) then Continue;
167+
b := [X1-1, Y1-1, X2+2, Y2+3];
168+
end;
169+
170+
hit := TRSHitsplat._Find(b);
171+
if hit.Position <> Default(TPoint) then
172+
splats += hit;
173+
end;
174+
end;
175+
Result := splats <> [];
176+
end;
177+
178+
function TRSHitSplat.Find(out splats: TRSHitSplatArray): Boolean; static; overload;
179+
begin
180+
Result := TRSHitSplat.Find(splats, [MainScreen.Bounds]);
181+
end;
182+
183+
184+
185+
procedure TRSHitsplat.Draw(img: TImage);
186+
begin
187+
case Self.Color of
188+
ERSHitSplat.BLUE: img.DrawColor := $FF0000;
189+
ERSHitSplat.RED: img.DrawColor := $0000FF;
190+
ERSHitSplat.MAX: img.DrawColor := $00FFFF;
191+
end;
192+
img.DrawCircle(Self.Position, 10);
193+
end;
194+
195+
procedure TRSHitSplatArray.Draw(img: TImage);
196+
var
197+
splat: TRSHitSplat;
198+
begin
199+
for splat in Self do splat.Draw(img);
200+
end;
201+
202+
procedure ShowOnClient(splats: TRSHitSplatArray); overload;
203+
var
204+
img: TImage;
205+
begin
206+
img := TImage.CreateFromTarget();
207+
208+
splats.Draw(img);
209+
210+
img.Show();
211+
img.Free();
212+
end;

0 commit comments

Comments
 (0)