Skip to content

Commit 89e0366

Browse files
committed
feat: TRSObject and TRSNPC can use TModel now
- fixed a bug where TWebGraphGenerator.Hash was being calculated without taking into account the whole record data - Tweaks to TModel
1 parent db799a1 commit 89e0366

File tree

9 files changed

+288
-218
lines changed

9 files changed

+288
-218
lines changed

.github/workflows/version-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ jobs:
117117
run: |
118118
BODY=$(jq -nc \
119119
--arg title "WaspLib Version $TAG_NAME" \
120-
--arg desc "${{ github.event.workflow_run.head_commit.message }}\n\nDownload: https://github.com/WaspScripts/WaspLib/releases/tag/$TAG_NAME" \
120+
--arg desc "${{ github.event.workflow_run.head_commit.message }}
121+
122+
Download: https://github.com/WaspScripts/WaspLib/releases/tag/$TAG_NAME" \
121123
--arg url "https://github.com/WaspScripts/WaspLib/commit/${{ github.event.workflow_run.head_commit.id }}" \
122124
--arg foot "Author: ${{ github.event.workflow_run.head_commit.author.name }}" \
123125
--argjson color 16742912 \

osrs/interfaces/mainscreen/anvil.simba

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ begin
213213
Exit(btns[i].Enable());
214214
end;
215215

216+
217+
(*
218+
## Anvil.CanSmith
219+
```pascal
220+
function TRSAnvil.CanSmith(item: TRSItem): Boolean;
221+
```
222+
Checks if the specified `item` is currently available to smith.
223+
224+
## Example:
225+
```pascal
226+
WriteLn Anvil.CanSmith('Rune 2h sword');
227+
```
228+
*)
229+
function TRSAnvil.CanSmith(item: TRSItem): Boolean;
230+
var
231+
slot: Integer;
232+
begin
233+
slot := Self.Items.IndexOf([item]);
234+
if slot = -1 then Exit;
235+
236+
Result := Target.HasColor($00FF00, 0, 1, Self.Slots.Box(slot));
237+
end;
238+
239+
216240
(*
217241
## Anvil.Smith
218242
```pascal

osrs/interfaces/mainscreen/finders/colorfinder.simba

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ begin
320320
Result := atpa <> [];
321321
end;
322322

323-
function TColorFinder.Find(out atpa: T2DPointArray; areas: TPolygonArray): Boolean; overload;
323+
function TColorFinder.Find(out atpa: T2DPointArray; areas: T2DPointArray; polygon: Boolean): Boolean; overload;
324324
var
325325
transformer: TColorFinderTransformer;
326-
area: TPolygon;
326+
area: TPointArray;
327327
tpa, tmp: TPointArray;
328328
begin
329329
transformer := Self.Transformer.Normalize();
@@ -332,27 +332,10 @@ begin
332332
begin
333333
tmp := Self._FindHelper(area.Bounds());
334334
if tmp = [] then Continue;
335-
tpa += tmp.ExtractPolygon(area);
336-
tmp := [];
337-
end;
338-
339-
atpa := transformer.Process(tpa);
340-
Result := atpa <> [];
341-
end;
342-
343-
function TColorFinder.Find(out atpa: T2DPointArray; areas: TCuboidArray): Boolean; overload;
344-
var
345-
transformer: TColorFinderTransformer;
346-
area: TCuboid;
347-
tpa, tmp: TPointArray;
348-
begin
349-
transformer := Self.Transformer.Normalize();
350-
351-
for area in areas do
352-
begin
353-
tmp := Self._FindHelper(area.Bounds());
354-
if tmp = [] then Continue;
355-
tpa += tmp.ExtractPolygon(area.Polygon());
335+
if polygon then
336+
tpa += tmp.ExtractPolygon(area)
337+
else
338+
tpa += tmp.Intersection(area);
356339
tmp := [];
357340
end;
358341

@@ -385,7 +368,7 @@ begin
385368
Result := atpa <> [];
386369
end;
387370

388-
function TColorFinder.FindEx(out atpa: T2DPointArray; out found: TBooleanArray; areas: TPolygonArray): Boolean; overload;
371+
function TColorFinder.FindEx(out atpa: T2DPointArray; out found: TBooleanArray; areas: T2DPointArray; polygon: Boolean): Boolean; overload;
389372
var
390373
transformer: TColorFinderTransformer;
391374
i: Integer;
@@ -394,36 +377,32 @@ begin
394377
transformer := Self.Transformer.Normalize();
395378

396379
SetLength(found, Length(areas));
397-
for i := 0 to High(areas) do
380+
381+
if polygon then
398382
begin
399-
tpa := Self._FindHelper(areas[i].Bounds());
400-
if tpa = [] then Continue;
401-
tpa := transformer.Process(tpa.ExtractPolygon(areas[i])).Merge();
402-
if tpa = [] then Continue;
383+
for i := 0 to High(areas) do
384+
begin
385+
tpa := Self._FindHelper(areas[i].Bounds());
386+
if tpa = [] then Continue;
403387

404-
found[i] := True;
405-
atpa += tpa;
406-
tpa := [];
407-
end;
388+
tpa := tpa.ExtractPolygon(areas[i]);
389+
tpa := transformer.Process(tpa).Merge();
390+
if tpa = [] then Continue;
408391

409-
Result := atpa <> [];
410-
end;
392+
found[i] := True;
393+
atpa += tpa;
394+
tpa := [];
395+
end;
411396

412-
function TColorFinder.FindEx(out atpa: T2DPointArray; out found: TBooleanArray; areas: TCuboidArray): Boolean; overload;
413-
var
414-
transformer: TColorFinderTransformer;
415-
i: Integer;
416-
tpa: TPointArray;
417-
begin
418-
transformer := Self.Transformer.Normalize();
397+
Exit(atpa <> []);
398+
end;
419399

420-
SetLength(found, Length(areas));
421400
for i := 0 to High(areas) do
422401
begin
423402
tpa := Self._FindHelper(areas[i].Bounds());
424-
425403
if tpa = [] then Continue;
426-
tpa := transformer.Process(tpa.ExtractPolygon(areas[i].Polygon())).Merge();
404+
tpa := tpa.Intersection(areas[i]);
405+
tpa := transformer.Process(tpa).Merge();
427406
if tpa = [] then Continue;
428407

429408
found[i] := True;

osrs/position/map/entities.simba

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Main type to handle {ref}`RSEntity`.
2727
TRSEntity = record
2828
UpText: TStringArray;
2929
Size: TVector3;
30+
Model: TModel;
3031
Coordinates: TPointArray;
3132
Filter: TRSDotFilterArray;
3233
Finder: TColorFinder;
@@ -99,8 +100,9 @@ end;
99100

100101
function TRSEntity.Create(json: TJSONObject): TRSEntity; static; overload;
101102
var
102-
i: Integer;
103-
colors: TColorArray;
103+
i, j, l: Integer;
104+
unique: array of TColorArray;
105+
color: TColor;
104106
best: TBestColor;
105107
coord: TJSONArray;
106108
begin
@@ -134,12 +136,27 @@ begin
134136

135137
with json.Item[Ord(ENPCData.COLORS)] do
136138
for i := 0 to Count-1 do
137-
colors += Item[i].AsInt;
139+
begin
140+
color := Item[i].AsInt;
141+
142+
for j := 0 to High(unique) do
143+
begin
144+
for l := 0 to High(unique[j]) do
145+
if ColorDistance(color, unique[j, l], EColorSpace.HSL, [1.5, 1.5, 1.5]) < 15 then
146+
begin
147+
unique[j] += color;
148+
Continue(3);
149+
end;
150+
end;
151+
152+
unique += [color];
153+
end;
138154

139-
if colors <> [] then
155+
for i := 0 to High(unique) do
140156
begin
141-
best := GetBestColor(EColorSpace.HSV, colors);
142-
Result.Finder.Colors += [best.Color, best.Tolerance, EColorSpace.HSV, best.Mods];
157+
best := GetBestColor(EColorSpace.HSL, unique[i]);
158+
WriteLn best;
159+
Result.Finder.Colors += [best.Color, best.Tolerance*1.5, EColorSpace.HSL, [best.Mods[0]*1.5, best.Mods[1]*1.5, best.Mods[2]*1.5]];
143160
end;
144161

145162
Result.Walker := @Map.Walker;
@@ -181,19 +198,21 @@ end;
181198

182199

183200
(*
184-
## Entity._GetCuboid
201+
## Entity._GetBounds
185202
```pascal
186-
function TRSEntity._GetCuboid(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;
203+
function TRSEntity._GetBounds(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;
187204
```
188-
Internal helper function for {ref}`TRSEntity.GetCuboidArray`.
205+
Internal helper function for {ref}`TRSEntity.GetBoundsArray`.
189206
*)
190-
function TRSEntity._GetCuboid(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TCuboid;
207+
function TRSEntity._GetBounds(me: TPoint; vector: TVector2; size: TVector3; height, radians: Single): TPolygon;
191208
var
192209
corners: TVector3Array;
193210
pt: TPoint;
194-
arr: TPointArray;
195211
begin
196212
pt := me + vector.ToPoint() - Minimap.Center;
213+
if Self.Model <> nil then
214+
Exit(Self.Model.GetArea(Self.Model.Project(vector.ToVec3(Self.Walker^.Height(pt, False) - height), 0, radians)));
215+
197216

198217
size.X := size.X*2;
199218
size.Y := size.Y*2;
@@ -209,21 +228,18 @@ begin
209228
[vector.X-size.X, vector.Y+size.Y, Self.Walker^.Height(pt - [1,1], False) - height+size.Z]
210229
];
211230

212-
arr := Projection.Run(corners, radians);
213-
Result := [
214-
[arr[4], arr[5], arr[6], arr[7]], [arr[0], arr[1], arr[2], arr[3]]
215-
];
231+
Result := Projection.Run(corners, radians).ConvexHull();
216232
end;
217233

218234
(*
219-
## Entity.GetCuboidArray
235+
## Entity.GetBoundsArray
220236
```pascal
221-
function TRSEntity.GetCuboidArray(me: TPoint; angle: Single = $FFFF): TCuboidArray;
237+
function TRSEntity.GetBoundsArray(me: TPoint; angle: Single = $FFFF): TCuboidArray;
222238
```
223239
Internal function that returns an array of cuboids of the entity if it's visible
224240
on the {ref}`MainScreen`.
225241
*)
226-
function TRSEntity.GetCuboidArray(me: TPoint; out coordinates: TPointArray; radians: Single = $FFFF): TCuboidArray;
242+
function TRSEntity.GetBoundsArray(me: TPoint; out coordinates: TPointArray; radians: Single = $FFFF): TPolygonArray;
227243
var
228244
weights: TDoubleArray;
229245
meLocal, pt: TPoint;
@@ -255,7 +271,7 @@ begin
255271

256272
vector := Self.Walker^.Point2MMVec(me, pt, radians);
257273
vector := vector.Rotate(-radians, Minimap.Center);
258-
Result += Self._GetCuboid(meLocal, vector, Self.Size, h, radians);
274+
Result += Self._GetBounds(meLocal, vector, Self.Size, h, radians);
259275
end;
260276
Exit;
261277
end;
@@ -272,12 +288,12 @@ begin
272288

273289
vector := Self.Walker^.Point2MMVec(me, pt, radians);
274290
vector := vector.Rotate(-radians, Minimap.Center);
275-
Result += Self._GetCuboid(meLocal, vector, Self.Size, h, radians);
291+
Result += Self._GetBounds(meLocal, vector, Self.Size, h, radians);
276292
end;
277293

278294
if Result <> [] then
279295
begin
280-
Result.Sort(weights, True);
296+
Sort(Result, weights, True);
281297
coordinates.Sort(weights, True);
282298
end;
283299
end;
@@ -288,17 +304,17 @@ end;
288304
function TRSEntity.Find(cuboidArray: TCuboidArray): T2DPointArray;
289305
```
290306
Internal TRSEntity method responsible for filtering a TCuboidArray by what's visible in the mainscren.
291-
This is meant to filter TRSEntity.GetCuboidArray() so targets that are outside of the mainscreen are filtered out.
307+
This is meant to filter TRSEntity.GetBoundsArray() so targets that are outside of the mainscreen are filtered out.
292308
You will probably never need to use this directly.
293309
*)
294-
function TRSEntity.FindOnMainScreen(out coordinates: TPointArray; cuboidArray: TCuboidArray): T2DPointArray;
310+
function TRSEntity.FindOnMainScreen(out coordinates: TPointArray; boundsArray: TPolygonArray): T2DPointArray;
295311
var
296312
i: Integer;
297313
found: TBooleanArray;
298314
begin
299315
if Self.Finder <> Default(TColorFinder) then
300316
begin
301-
Self.Finder.FindEx(Result, found, cuboidArray);
317+
Self.Finder.FindEx(Result, found, boundsArray, Self.Model = nil);
302318

303319
for i := High(found) downto 0 do
304320
if not found[i] then
@@ -307,8 +323,8 @@ begin
307323
Exit;
308324
end;
309325

310-
for i := 0 to High(cuboidArray) do
311-
Result += cuboidArray[i].ShapeFill();
326+
for i := 0 to High(boundsArray) do
327+
Result += TPointArray(boundsArray[i]).ShapeFill();
312328
end;
313329

314330
(*
@@ -327,29 +343,29 @@ WriteLn RSObjects.GEBank.Find(atpa); //Be in ge and with a walker setup there.
327343
Debug(atpa);
328344
```
329345
*)
330-
function TRSEntity.FindEx(me: TPoint; out cuboids: TCuboidArray; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
346+
function TRSEntity.FindEx(me: TPoint; out boundsArray: TPolygonArray; out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
331347
begin
332-
cuboids := Self.GetCuboidArray(me, coordinates);
333-
if cuboids = [] then Exit;
334-
atpa := Self.FindOnMainScreen(coordinates, cuboids);
348+
boundsArray := Self.GetBoundsArray(me, coordinates);
349+
if boundsArray = [] then Exit;
350+
atpa := Self.FindOnMainScreen(coordinates, boundsArray);
335351

336352
Result := atpa <> [];
337353
end;
338354

339355

340356
function TRSEntity.Find(out coordinates: TPointArray; out atpa: T2DPointArray): Boolean;
341357
var
342-
cuboids: TCuboidArray;
358+
boundsArray: TPolygonArray;
343359
begin
344-
Result := Self.FindEx(Self.Walker^.Position(), cuboids, coordinates, atpa);
360+
Result := Self.FindEx(Self.Walker^.Position(), boundsArray, coordinates, atpa);
345361
end;
346362

347363
function TRSEntity.FindFrom(position: TPoint; out atpa: T2DPointArray): Boolean;
348364
var
349-
cuboids: TCuboidArray;
365+
boundsArray: TPolygonArray;
350366
coordinates: TPointArray;
351367
begin
352-
Result := Self.FindEx(position, cuboids, coordinates, atpa);
368+
Result := Self.FindEx(position, boundsArray, coordinates, atpa);
353369
end;
354370

355371
(*
@@ -803,7 +819,7 @@ procedure TImage.DrawEntity(entity: TRSEntity);
803819
var
804820
me: TPoint;
805821
atpa: T2DPointArray;
806-
cuboids: TCuboidArray;
822+
boundsArray: TPolygonArray;
807823
i: Integer;
808824
filters: TRSDotFilterArray;
809825
filter: TRSDotFilter;
@@ -826,22 +842,15 @@ begin
826842
Self.DrawCircle(filter.Circle);
827843
end;
828844

829-
if not entity.FindEx(me, cuboids, coordinates, atpa) then
830-
Exit;
831-
832-
Self.DrawColor := $00FFFF;
833-
for i := 0 to High(cuboids) do
845+
if entity.FindEx(me, boundsArray, coordinates, atpa) then
834846
begin
835-
Self.DrawTPA(cuboids[i].Bottom.Corners.Connect().Grow(1));
836-
Self.DrawTPA(cuboids[i].Top.Corners.Connect().Grow(1));
847+
Self.DrawColor := TColor.Random();
848+
Self.DrawATPA(atpa);
837849
end;
838850

839-
Self.DrawColor := TColor.Random();
840-
Self.DrawATPA(atpa);
841-
842-
Self.DrawColor := $FFFFFF;
843-
for i := 0 to High(cuboids) do
844-
Self.DrawTPA(cuboids[i].Edges());
851+
Self.DrawColor := $FFFFF;
852+
for i := 0 to High(boundsArray) do
853+
Self.DrawTPA(boundsArray[i].Connect());
845854
end;
846855

847856
procedure ShowOnTarget(entity: TRSEntity); overload;

0 commit comments

Comments
 (0)