Skip to content

Commit be7eead

Browse files
committed
fix(TRSObject): tweaks
It didn't make sense that `TRSObject.Walker^.ActionUpText` was tracking the action uptext even when walker was not being used at all, this commit changes that for both TRSObject and TRSEntity
1 parent 42f7b60 commit be7eead

File tree

3 files changed

+90
-112
lines changed

3 files changed

+90
-112
lines changed

osrs/miscform.simba

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ end;
5555

5656
procedure TMiscFormHelper.SetupLoginPanel(parent: TLazComponent);
5757
var
58-
panel: TLazPanel;
5958
info: TLazLabel;
6059
btn: TLazButton;
6160
begin
@@ -82,7 +81,6 @@ end;
8281

8382
procedure TMiscFormHelper.SetupClientPanel(parent: TLazComponent);
8483
var
85-
panel: TLazPanel;
8684
info: TLazLabel;
8785
btn: TLazButton;
8886
begin

osrs/position/map/entities.simba

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ begin
155155
for i := 0 to High(unique) do
156156
begin
157157
best := GetBestColor(EColorSpace.HSL, unique[i]);
158-
WriteLn best;
159158
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]];
160159
end;
161160

@@ -395,12 +394,12 @@ end;
395394
(*
396395
## TRSEntity._UpTextCheck
397396
```pascal
398-
function TRSEntity._UpTextCheck(out shouldExit: Boolean): Boolean;
397+
function TRSEntity._UpTextCheck(out shouldExit: Boolean; action: TStringArray): Boolean;
399398
```
400399
Internal TRSEntity helper method that is used by all hovering methods.
401400
You probably don't need to use this directly.
402401
*)
403-
function TRSEntity._UpTextCheck(out shouldExit: Boolean): Boolean;
402+
function TRSEntity._UpTextCheck(out shouldExit: Boolean; action: TStringArray): Boolean;
404403
var
405404
text: String;
406405
begin
@@ -414,7 +413,7 @@ begin
414413

415414
text := MainScreen.UpText;
416415

417-
if text.Contains('>') and not Self.Walker^.ActionUpText.Contains(['>']) then
416+
if text.Contains('>') and not action.Contains(['>']) then
418417
begin
419418
ChooseOption.Close();
420419
Exit;
@@ -429,19 +428,19 @@ end;
429428
(*
430429
## TRSEntity._HoverHelper
431430
```pascal
432-
function TRSEntity._HoverHelper(attempts: Integer; trackTarget: Boolean): Boolean;
431+
function TRSEntity._HoverHelper(action: TStringArray; attempts: Integer): Boolean;
433432
```
434433
Internal helper method used to hover a TRSEntity target.
435434
You should not use this directly.
436435
*)
437-
function TRSEntity._HoverHelper(attempts: Integer): Boolean;
436+
function TRSEntity._HoverHelper(action: TStringArray; attempts: Integer): Boolean;
438437
var
439438
shouldExit: Boolean;
440439
attempt, i: Integer;
441440
atpa: T2DPointArray;
442441
coordinates, tpa: TPointArray;
443442
begin
444-
Result := Self._UpTextCheck(shouldExit);
443+
Result := Self._UpTextCheck(shouldExit, action);
445444
if shouldExit then Exit;
446445

447446
for attempt := 0 to attempts do
@@ -475,14 +474,14 @@ end;
475474
(*
476475
## TRSEntity._WalkHoverHelper
477476
```pascal
478-
function TRSEntity._WalkHoverHelper(attempts: Integer; trackTarget: Boolean): Boolean;
477+
function TRSEntity._WalkHoverHelper(action: TStringArray; attempts: Integer): Boolean;
479478
```
480479
Internal helper method used to walk and hover a TRSEntity target.
481480
You should not use this directly.
482481

483482
This is responsible for deciding wether we should walk to a TRSEntity target or not before attempting to hover it.
484483
*)
485-
function TRSEntity._WalkHoverHelper(attempts: Integer): Boolean;
484+
function TRSEntity._WalkHoverHelper(action: TStringArray; attempts: Integer): Boolean;
486485
var
487486
shouldExit: Boolean;
488487
attempt, i: Integer;
@@ -491,7 +490,7 @@ var
491490
path: TGraphNodeArray;
492491
me, closest: TPoint;
493492
begin
494-
Result := Self._UpTextCheck(shouldExit) or Self.Walker^.RedClicked;
493+
Result := Self._UpTextCheck(shouldExit, action) or Self.Walker^.RedClicked;
495494
if shouldExit then Exit;
496495

497496
for attempt := 0 to attempts do
@@ -577,9 +576,6 @@ This is what's responsible for deciding if we click a target we are hovering or
577576
*)
578577
function TRSEntity._ClickHelper(leftClick: Boolean): Boolean;
579578
begin
580-
Self.Walker^.TargetUpText := [];
581-
Self.Walker^.ActionUpText := [];
582-
583579
if Self.Walker^.RedClicked then
584580
begin
585581
Self.Walker^.RedClicked := False;
@@ -612,9 +608,6 @@ This is what is responsible for deciding if we just left click a target we are h
612608
*)
613609
function TRSEntity._SelectHelper(action: TStringArray): Boolean;
614610
begin
615-
Self.Walker^.TargetUpText := [];
616-
Self.Walker^.ActionUpText := [];
617-
618611
if Self.Walker^.RedClicked then
619612
begin
620613
Self.Walker^.RedClicked := False;
@@ -634,18 +627,16 @@ end;
634627
(*
635628
## TRSEntity.Hover
636629
```pascal
637-
function TRSEntity.Hover(attempts: Integer = 2; trackTarget: Boolean = TRSEntity.TrackTarget): Boolean;
630+
function TRSEntity.Hover(action: TStringArray = []; attempts: Integer = 2): Boolean;
638631
```
639632
Method used to hover a TRSEntity target if it's found on the mainscreen.
640-
It can update the target position while the mouse moves with **trackTarget**.
641633

642634
Example:
643635
```pascal
644-
RSW.WebWalk(WaspWeb.LOCATION_VARROCK);
645-
RSObjects.GEBank.Hover(); //Be in GE with a walker setup there.
636+
//TODO...
646637
```
647638
*)
648-
function TRSEntity.Hover(attempts: Integer = 2): Boolean;
639+
function TRSEntity.Hover(action: TStringArray = []; attempts: Integer = 2): Boolean;
649640
begin
650641
if ChooseOption.IsOpen() then
651642
begin
@@ -662,25 +653,22 @@ begin
662653
//TODO:
663654
//if not Self.Walker^.MakePointVisible(Self.Coordinates) then Exit;
664655

665-
Result := Self._HoverHelper(attempts);
656+
Result := Self._HoverHelper(action, attempts);
666657
end;
667658

668659
(*
669660
## TRSEntity.WalkHover
670661
```pascal
671-
function TRSEntity.WalkHover(attempts: Integer = 2; trackTarget: Boolean = TRSEntity.TrackTarget): Boolean;
662+
function TRSEntity.WalkHover(action: TStringArray = []; attempts: Integer = 2): Boolean;
672663
```
673664
Method used to walk and hover a TRSEntity target if it's found on the mainscreen after walking.
674-
It can update the target position while the mouse moves with **trackTarget**.
675665

676666
Example:
677667
```pascal
678-
//Be in varrock with a varrock map loaded.
679-
RSW.WebWalk(WaspWeb.LOCATION_VARROCK);
680-
RSObjects.GEBank.WalkHover();
668+
//TODO...
681669
```
682670
*)
683-
function TRSEntity.WalkHover(attempts: Integer = 2): Boolean;
671+
function TRSEntity.WalkHover(action: TStringArray = []; attempts: Integer = 2): Boolean;
684672
var
685673
me, closest: TPoint;
686674
path: TGraphNodeArray;
@@ -693,9 +681,6 @@ begin
693681
ChooseOption.Close();
694682
end;
695683

696-
if Self.UpText <> [] then
697-
Self.Walker^.TargetUpText := Copy(Self.UpText);
698-
699684
me := Self.Walker^.Position();
700685
closest := Self.Walker^.GetClosestPoint(me, Self.Coordinates, path);
701686

@@ -708,17 +693,25 @@ begin
708693
hasPath := True;
709694
end;
710695

696+
Self.Walker^.TargetUpText := Copy(Self.UpText);
697+
Self.Walker^.ActionUpText := action;
698+
699+
try
711700
// check if doors need to be passed to reach target
712-
if hasPath or Self.Walker^.WebGraph^.WalkableClusters.InSameTPA(me, closest) then
713-
begin
714-
if not Self.Walker^.MakePointVisible(closest) and not Self.Walker^.WebWalkEx(me, closest, 30, 0.15) then
701+
if hasPath or Self.Walker^.WebGraph^.WalkableClusters.InSameTPA(me, closest) then
702+
begin
703+
if not Self.Walker^.MakePointVisible(closest) and not Self.Walker^.WebWalkEx(me, closest, 30, 0.15) then
704+
Exit;
705+
end
706+
else
707+
if not Self.Walker^.WebWalk(closest, 30, 0.15) then
715708
Exit;
716-
end
717-
else
718-
if not Self.Walker^.WebWalk(closest, 30, 0.15) then
719-
Exit;
720709

721-
Result := Self._WalkHoverHelper(attempts);
710+
Result := Self._WalkHoverHelper(action, attempts);
711+
finally
712+
Self.Walker^.TargetUpText := [];
713+
Self.Walker^.ActionUpText := [];
714+
end;
722715
end;
723716

724717

@@ -737,7 +730,7 @@ WriteLn RSObjects.GEBank.Click();
737730
*)
738731
function TRSEntity.Click(leftClick: Boolean = True; attempts: Integer = 2): Boolean;
739732
begin
740-
Result := Self.Hover(attempts) and Self._ClickHelper(leftClick);
733+
Result := Self.Hover([], attempts) and Self._ClickHelper(leftClick);
741734
end;
742735

743736
(*
@@ -749,9 +742,7 @@ Method used to select an option on a TRSEntity target if it's found on the mains
749742
*)
750743
function TRSEntity.Interact(action: TStringArray; attempts: Integer = 2): Boolean;
751744
begin
752-
Self.Walker^.ActionUpText := action;
753-
Result := Self.Hover(attempts) and Self._SelectHelper(action);
754-
Self.Walker^.ActionUpText := [];
745+
Result := Self.Hover(action, attempts) and Self._SelectHelper(action);
755746
end;
756747

757748
(*
@@ -774,8 +765,7 @@ begin
774765
if Self.Coordinates = [] then
775766
raise GetDebugLn('TRSEntity', 'FindFrom requires the object to have coordinates.');
776767

777-
Result := Self.WalkHover(attempts) and Self._ClickHelper(leftClick);
778-
Self.Walker^.TargetUpText := [];
768+
Result := Self.WalkHover([], attempts) and Self._ClickHelper(leftClick);
779769
end;
780770

781771
(*
@@ -792,12 +782,7 @@ begin
792782
if Self.Coordinates = [] then
793783
raise GetDebugLn('TRSEntity', 'FindFrom requires the object to have coordinates.');
794784

795-
Self.Walker^.ActionUpText := action;
796-
797-
Result := Self.WalkHover(attempts) and Self._SelectHelper(action);
798-
799-
Self.Walker^.TargetUpText := [];
800-
Self.Walker^.ActionUpText := [];
785+
Result := Self.WalkHover(action, attempts) and Self._SelectHelper(action);
801786
end;
802787

803788

0 commit comments

Comments
 (0)