Skip to content

Commit 3f69400

Browse files
committed
feat(MainScreen): MainScreen.Interact read notes
- Added `MainScreen.Interact()` that interacts with the mainscreen with the "option" you specify, using left click or `ChooseOption` as needed. - Renamed `TRSObject.Select`, `TRSObject.WalkSelect`, `TRSEntity.Select` and `TRSEntity.WalkSelect` to `Interact` - fixed a typo on fairy ring that wouldn't let WL compile, - added some TODO placeholders - made some old code use the new `MainScreen.Interact` methods. - `TRSWalker.CrossDoor` is not finished but almost working now
1 parent d68b7e1 commit 3f69400

File tree

9 files changed

+81
-68
lines changed

9 files changed

+81
-68
lines changed

osrs/interfaces/mainscreen/anvil.simba

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,12 @@ begin
325325
obj := Self.Anvils[Self.Anvils.ClosestIndex(Map.Position())];
326326

327327
if walk then
328-
Result := obj.WalkSelect(['nvil'])
328+
Result := obj.WalkInteract(['nvil'])
329329
else
330-
Result := obj.Select(['nvil']);
330+
Result := obj.Interact(['nvil']);
331331

332-
if not Result then
333-
if not MainScreen.IsUpText('Smith') or not ChooseOption.Select(['Smith']) then
334-
Exit;
332+
if not Result and not MainScreen.Interact(['Smith']) then
333+
Exit;
335334

336335
obj.Walker^.WaitMoving();
337336
Result := Self.WaitOpen(3000);

osrs/interfaces/mainscreen/bank.simba

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,9 @@ end.
13221322
function TRSBank.Open(constref obj: TRSObject; walk: Boolean = True): Boolean;
13231323
begin
13241324
if walk then
1325-
Result := obj.WalkSelect(['Bank B', 'Bank E', 'Bank G', 'Use B'])
1325+
Result := obj.WalkInteract(['Bank B', 'Bank E', 'Bank G', 'Use B'])
13261326
else
1327-
Result := obj.Select(['Bank B', 'Bank E', 'Bank G', 'Use B']);
1327+
Result := obj.Interact(['Bank B', 'Bank E', 'Bank G', 'Use B']);
13281328

13291329
if not Result then
13301330
if not MainScreen.IsUpText('Bank') or not ChooseOption.Select(['Bank B', 'Bank E']) then
@@ -1337,13 +1337,12 @@ end;
13371337
function TRSBank.Open(constref npc: TRSEntity; walk: Boolean = True): Boolean; overload;
13381338
begin
13391339
if walk then
1340-
Result := npc.WalkSelect(['Bank B', 'Bank E'])
1340+
Result := npc.WalkInteract(['Bank B', 'Bank E'])
13411341
else
1342-
Result := npc.Select(['Bank B', 'Bank E']);
1342+
Result := npc.Interact(['Bank B', 'Bank E']);
13431343

1344-
if not Result then
1345-
if not MainScreen.IsUpText('Bank') or not ChooseOption.Select(['Bank B', 'Bank E']) then
1346-
Exit;
1344+
if not Result and not MainScreen.Interact(['Bank B', 'Bank E']) then
1345+
Exit;
13471346

13481347
npc.Walker^.WaitMoving();
13491348
Result := Self.WaitOpen(3000);

osrs/interfaces/mainscreen/collectionbox.simba

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ begin
318318

319319
if obj.DistanceTo(me) < npc.DistanceTo(me) then
320320
begin
321-
if walk then Result := obj.WalkSelect(['Collect'])
322-
else Result := obj.Select(['Collect']);
321+
if walk then Result := obj.WalkInteract(['Collect'])
322+
else Result := obj.Interact(['Collect']);
323323

324324
if not Result then
325325
begin
@@ -332,8 +332,8 @@ begin
332332
Exit;
333333
end;
334334

335-
if walk then Result := npc.WalkSelect(['Collect'])
336-
else Result := npc.Select(['Collect']);
335+
if walk then Result := npc.WalkInteract(['Collect'])
336+
else Result := npc.Interact(['Collect']);
337337

338338
if not Result then
339339
begin

osrs/interfaces/mainscreen/fairyring.simba

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ WriteLn FairyRing.Item;
172172
*)
173173
function TRSFairyRing.HandleItem(attempts: Int32 = 2): Boolean;
174174
begin
175+
Result := attempts = 2; //Todo...
175176
end;
176177

177178

@@ -199,13 +200,7 @@ begin
199200
if not Self.HandleItem() then
200201
Exit;
201202

202-
Mouse.Move(cuboid.ShapeFill().RandomMean());
203-
if not MainScreen.IsUpText('Fairy ring') then
204-
Exit;
205-
206-
if MainScreen.IsUpText('onfigure') then
207-
Mouse.Click(EMouseButton.LEFT)
208-
else if not ChooseOption.Select('onfigure') then
203+
if not MainScreen.Interact(cuboid.ShapeFill().RandomMean(), ['onfigure']) then
209204
Exit;
210205

211206
Minimap.WaitMoving();
@@ -639,7 +634,7 @@ function TRSFairyRing.ClickLogCode(fairyCode: String): Boolean;
639634
var
640635
b: TBox;
641636
begin
642-
code := code.Replace(' ', '').ToUpper();
637+
fairyCode := fairyCode.Replace(' ', '').ToUpper();
643638
if Self.Code = fairyCode then
644639
Exit(True);
645640

osrs/interfaces/mainscreen/mainscreen.simba

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,10 @@ begin
361361
end;
362362

363363

364-
{%codetools off}
365364
function TRSMainScreen._RedClicked(area: TBox): Boolean;
366365
begin
367366
Result := Target.HasColor($0000FF, 0, 1, area) or Target.HasColor($0401C8, 0, 1, area);
368367
end;
369-
{%codetools on}
370368

371369
(*
372370
## MainScreen.RedClicked
@@ -410,13 +408,10 @@ begin
410408
Result := SleepUntil(Self._RedClicked(area), 50, time);
411409
end;
412410

413-
414-
{%codetools off}
415411
function TRSMainScreen._YellowClicked(area: TBox): Boolean;
416412
begin
417413
Result := Target.HasColor(65535, 0, 1, area);
418414
end;
419-
{%codetools on}
420415

421416
(*
422417
## MainScreen.YellowClicked
@@ -460,6 +455,38 @@ begin
460455
Result := SleepUntil(Self._YellowClicked(area), 50, time);
461456
end;
462457

458+
(*
459+
## MainScreen.Interact
460+
```pascal
461+
function TRSMainScreen.Interact(strings: TStringArray): Boolean;
462+
function TRSMainScreen.Interact(pt: TPoint; strings: TStringArray): Boolean; overload;
463+
```
464+
Attempts to interact with something on the mainscreen.
465+
If the uptext matches `strings` wasplib will left click, otherwise it will use
466+
{ref}`ChooseOption`.
467+
468+
Example:
469+
```pascal
470+
WriteLn MainScreen.Interact('Pick-up');
471+
```
472+
*)
473+
function TRSMainScreen.Interact(strings: TStringArray): Boolean;
474+
begin
475+
if Self.IsUpText(strings) then
476+
begin
477+
Mouse.Click(EMouseButton.LEFT);
478+
Exit(Self.RedClicked());
479+
end;
480+
481+
if ChooseOption.Select(strings) then
482+
Exit(Self.RedClicked());
483+
end;
484+
485+
function TRSMainScreen.Interact(pt: TPoint; strings: TStringArray): Boolean; overload;
486+
begin
487+
Mouse.Move(pt);
488+
Result := Self.Interact(strings);
489+
end;
463490

464491
var
465492
(*

osrs/position/house/house.simba

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ begin
379379

380380
if Map.Position().AnyInRange(Self.Entrance.Coordinates, 60) then
381381
begin
382-
if not Self.Entrance.WalkSelect(['Home']) then Exit;
382+
if not Self.Entrance.WalkInteract(['Home']) then Exit;
383383
Exit(SleepUntil(Self.Inside(), 300, 10000));
384384
end;
385385

@@ -432,7 +432,7 @@ begin
432432
begin
433433
if Map.Position().AnyInRange(Self.Entrance.Coordinates, 60) then
434434
begin
435-
if not Self.Entrance.WalkSelect(['Home']) then Exit;
435+
if not Self.Entrance.WalkInteract(['Home']) then Exit;
436436
Exit(SleepUntil(Self.Inside(), 300, 4000));
437437
end;
438438
end;
@@ -444,7 +444,7 @@ begin
444444

445445
case Biometrics.RandomBoolean(0.95) of
446446
True: if not HouseOptions.LeaveHouse() then Exit;
447-
False: if not Self.Objects[EHouseObject.EXIT].WalkSelect(['Enter']) then Exit;
447+
False: if not Self.Objects[EHouseObject.EXIT].WalkInteract(['Enter']) then Exit;
448448
end;
449449

450450
Result := SleepUntil(not Self.Inside(), 300, 3000);

osrs/position/map/entities.simba

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -625,19 +625,13 @@ begin
625625
end;
626626

627627
(*
628-
## TRSEntity.SelectOption
628+
## TRSEntity.Interact
629629
```pascal
630-
function TRSEntity.SelectOption(action: TStringArray; attempts: Integer = 2): Boolean;
630+
function TRSEntity.Interact(action: TStringArray; attempts: Integer = 2): Boolean;
631631
```
632632
Method used to select an option on a TRSEntity target if it's found on the mainscreen.
633-
634-
Example:
635-
```pascal
636-
//Be in ge with a ge map loaded.
637-
WriteLn RSObjects.GEBank.SelectOption(['Collect']);
638-
```
639633
*)
640-
function TRSEntity.Select(action: TStringArray; attempts: Integer = 2): Boolean;
634+
function TRSEntity.Interact(action: TStringArray; attempts: Integer = 2): Boolean;
641635
begin
642636
Self.Walker^.ActionUpText := action;
643637
Result := Self.Hover(attempts) and Self._SelectHelper(action);
@@ -669,19 +663,13 @@ begin
669663
end;
670664

671665
(*
672-
## TRSEntity.WalkSelectOption
666+
## TRSEntity.WalkInteract
673667
```pascal
674-
function TRSEntity.WalkSelectOption(action: TStringArray; attempts: Integer = 2): Boolean;
668+
function TRSEntity.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean;
675669
```
676670
Method used to walk and select an option on a TRSEntity target if it's found on the mainscreen.
677-
678-
Example:
679-
```pascal
680-
//Be in ge with a ge map loaded, preferably far away so it has to walk.
681-
WriteLn RSObjects.GEBank.WalkSelectOption(['Collect']);
682-
```
683671
*)
684-
function TRSEntity.WalkSelect(action: TStringArray; attempts: Integer = 2): Boolean;
672+
function TRSEntity.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean;
685673
begin
686674
if Self.Walker = nil then
687675
raise GetDebugLn('TRSEntity', 'Missing the walker pointer.');

osrs/position/map/objects.simba

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,9 @@ begin
748748
end;
749749

750750
(*
751-
## RSObject.Select
751+
## RSObject.Interact
752752
```pascal
753-
function TRSObject.Select(action: TStringArray; attempts: Integer = 2): Boolean;
753+
function TRSObject.Interact(action: TStringArray; attempts: Integer = 2): Boolean;
754754
```
755755
Method used to select an option on a `TRSObject` target if it's found on the
756756
mainscreen.
@@ -769,14 +769,14 @@ var
769769
begin
770770
Map.Setup([ERSChunk.VARROCK]);
771771
objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
772-
objs[1].Select(['Collect']);
772+
objs[1].Interact(['Collect']);
773773
end.
774774
```
775775

776776
```{figure} ../../images/obj_select.gif
777777
```
778778
*)
779-
function TRSObject.Select(action: TStringArray; attempts: Integer = 2): Boolean;
779+
function TRSObject.Interact(action: TStringArray; attempts: Integer = 2): Boolean;
780780
begin
781781
Self.Walker^.ActionUpText := action;
782782
Result := Self.Hover(action, attempts) and Self._SelectHelper(action);
@@ -824,9 +824,9 @@ begin
824824
end;
825825

826826
(*
827-
## RSObject.WalkSelect
827+
## RSObject.WalkInteract
828828
```pascal
829-
function TRSObject.WalkSelect(action: TStringArray; attempts: Integer = 2): Boolean;
829+
function TRSObject.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean;
830830
```
831831
Method used to walk towards and select an option on a `TRSObject` target if it's
832832
found on the mainscreen.
@@ -845,14 +845,14 @@ var
845845
begin
846846
Map.Setup([ERSChunk.VARROCK]);
847847
objs := TRSObjectArray.Create(ObjectsJSON.GetByAction('Bank'));
848-
objs[1].WalkSelect(['Collect']);
848+
objs[1].WalkInteract(['Collect']);
849849
end.
850850
```
851851

852852
```{figure} ../../images/obj_walkselect.gif
853853
```
854854
*)
855-
function TRSObject.WalkSelect(action: TStringArray; attempts: Integer = 2): Boolean;
855+
function TRSObject.WalkInteract(action: TStringArray; attempts: Integer = 2): Boolean;
856856
begin
857857
if Self.Walker = nil then
858858
raise GetDebugLn('TRSObject', 'Walker pointer missing.');

osrs/walker.simba

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ end;
700700
function TRSWalker.CrossDoor(me: TPoint; index: Integer; attempts: Integer = 3): Boolean;
701701
var
702702
tmp: TPoint;
703-
furthest: Integer;
703+
furthest, doorAttempts: Integer;
704704
radians: Double;
705705
mapPt, minimapPt, flag: TPoint;
706706
shouldExit, handleDoor: Boolean;
@@ -743,14 +743,17 @@ begin
743743

744744
if handleDoor then
745745
begin
746-
WriteLn GetDebugLn(Self.Name, 'Attempting to open door');
747-
cuboid := Self.GetCuboidMS(me, Self._Path[index].Node, [0.6,0.6,4], radians);
748-
ShowOnTarget(cuboid);
749-
Mouse.Move(cuboid.ShapeFill().RandomMean());
750-
if MainScreen.IsUpText('Open') then
751-
Mouse.Click(EMouseButton.LEFT)
752-
else if not ChooseOption.Select('Open') then
753-
Exit;
746+
for doorAttempts := 0 to 2 do
747+
begin
748+
WriteLn GetDebugLn(Self.Name, 'Attempt to open door number: ' + ToStr(doorAttempts+1));
749+
cuboid := Self.GetCuboidMS(me, Self._Path[index].Node, [0.6,0.6,4], radians);
750+
ShowOnTarget(cuboid);
751+
if MainScreen.Interact(cuboid.ShapeFill().RandomMean(), ['Open']) then
752+
Break;
753+
end;
754+
Self.WaitMoving(mapPt, 4);
755+
Biometrics.Sleep(600, 800);
756+
WriteLn GetDebugLn(Self.Name, 'Door should now be open.');
754757
end;
755758

756759
Result := Self.CrossDoor(me, index, Dec(attempts));
@@ -764,7 +767,9 @@ begin
764767
raise GetDebugLn(Self.Name, 'Paths should not end at a stairs node.');
765768

766769
if Abs(Self._Path[index].Node.X - Self._Path[index+1].Node.X) < RSTranslator.MapWidth then
767-
'Down';
770+
direction := 'Down';
771+
772+
Result := me = me; //todo...
768773
end;
769774

770775
function TRSWalker.UseShortcut(me: TPoint; index: Integer): Boolean;

0 commit comments

Comments
 (0)