@@ -31,7 +31,6 @@ Main type to handle {ref}`RSEntity`.
3131 Coordinates: TPointArray;
3232 Filter: TRSDotFilterArray;
3333 Finder: TColorFinder;
34- Track: Boolean;
3534 MinimapDots: ERSMinimapDots;
3635 LastCoordinate: TPoint;
3736 Walker: PRSWalker;
@@ -446,144 +445,6 @@ begin
446445 shouldExit := False;
447446end;
448447
449- (*
450- ## TRSEntity._HoverHelper
451- ```pascal
452- function TRSEntity._HoverHelper(action: TStringArray; attempts: Integer): Boolean;
453- ```
454- Internal helper method used to hover a TRSEntity target.
455- You should not use this directly.
456- *)
457- function TRSEntity._HoverHelper(action: TStringArray; attempts: Integer): Boolean;
458- var
459- shouldExit: Boolean;
460- attempt, i: Integer;
461- atpa: T2DPointArray;
462- coordinates, tpa: TPointArray;
463- begin
464- Result := Self._UpTextCheck(shouldExit, action);
465- if shouldExit then Exit;
466-
467- for attempt := 0 to attempts do
468- begin
469- if Self.Find(coordinates, atpa) then
470- begin
471- if Length(coordinates) <> Length(atpa) then
472- raise 'SOMETHING WENT WRONG CACHING COORDINATES.';
473-
474- if attempt < 2 then i := 0
475- else if Length(atpa) > (attempt - 2) then i := attempt - 2
476- else i := Random(Low(atpa), High(atpa));
477-
478- tpa := atpa[i];
479- Self.LastCoordinate := coordinates[i];
480-
481- Mouse.Move(tpa.RandomMean());
482-
483- if Self.UpText = [] then Exit(True);
484- end;
485-
486- if MainScreen.IsUpText(Self.UpText) then Exit(True);
487-
488- if attempt <> (attempts - 1) then
489- Continue;
490-
491- Minimap.CompassRadians := Minimap.CompassRadians + PI/3.6 * Random(-1,1);
492- end;
493- end;
494-
495- (*
496- ## TRSEntity._WalkHoverHelper
497- ```pascal
498- function TRSEntity._WalkHoverHelper(action: TStringArray; attempts: Integer): Boolean;
499- ```
500- Internal helper method used to walk and hover a TRSEntity target.
501- You should not use this directly.
502-
503- This is responsible for deciding wether we should walk to a TRSEntity target or not before attempting to hover it.
504- *)
505- function TRSEntity._WalkHoverHelper(action: TStringArray; attempts: Integer): Boolean;
506- var
507- shouldExit: Boolean;
508- attempt, i: Integer;
509- atpa: T2DPointArray;
510- coordinates, tpa: TPointArray;
511- path: TGraphNodeArray;
512- me, closest: TPoint;
513- begin
514- Result := Self._UpTextCheck(shouldExit, action) or Self.Walker^.RedClicked;
515- if shouldExit then Exit;
516-
517- for attempt := 0 to attempts do
518- begin
519- if Self.Find(coordinates, atpa) then
520- begin
521- if Length(coordinates) <> Length(atpa) then
522- raise 'SOMETHING WENT WRONG CACHING COORDINATES.';
523-
524- if attempt < 2 then i := 0
525- else if Length(atpa) > (attempt - 2) then i := attempt - 2
526- else i := Random(Low(atpa), High(atpa));
527-
528- tpa := atpa[i];
529- Self.LastCoordinate := coordinates[i];
530-
531- Mouse.Move(tpa.RandomMean());
532-
533- if Self.UpText = [] then Exit(True);
534- end;
535-
536- if MainScreen.IsUpText(Self.UpText) then Exit(True);
537-
538- me := Self.Walker^.Position();
539- closest := Self.Walker^.GetClosestPoint(me, Self.Coordinates, path);
540-
541- if path = [] then
542- begin
543- path := Self.Walker^.WebGraph^.PathToNear(me, closest, 0.33);
544- if path = [] then
545- raise GetDebugLn('TRSEntity', 'Can''t path to object.');
546- end;
547-
548- if me.DistanceTo(closest) > 50 then
549- begin
550- Self.Walker^.WebWalkEx(me, closest, Self.MinDistance, 0.15);
551- Continue;
552- end;
553-
554- if attempt <> (attempts - 1) then Continue;
555-
556- if me.DistanceTo(closest) > (Self.MinDistance div 2) then
557- begin
558- Self.Walker^.WebWalkEx(me, closest, Self.MinDistance div 2, 0.15);
559- Continue;
560- end;
561-
562- Minimap.CompassRadians := Minimap.CompassRadians + PI/3.6 * Random(-1,1);
563- end;
564- end;
565-
566- (*
567- ## TRSEntity._PreHoverHelper
568- ```pascal
569- function TRSEntity.PreHoverHelper(attempts: Integer): Boolean;
570- ```
571- Internal helper method used to pre-hover a TRSEntity target.
572- You should not use this directly.
573- *)
574- function TRSEntity._PreHoverHelper(me: TPoint; attempts: Integer = 2): Boolean;
575- var
576- attempt: Integer;
577- atpa: T2DPointArray;
578- begin
579- for attempt := 0 to attempts do
580- begin
581- if not Self.FindFrom(me, atpa) then Continue;
582- Mouse.Move(atpa.Random().Random());
583- Exit(True);
584- end;
585- end;
586-
587448
588449(*
589450## TRSEntity._ClickHelper
@@ -658,6 +519,12 @@ Example:
658519```
659520*)
660521function TRSEntity.Hover(action: TStringArray = []; attempts: Integer = 2): Boolean;
522+ var
523+ me: TPoint;
524+ shouldExit: Boolean;
525+ attempt, i: Integer;
526+ atpa: T2DPointArray;
527+ coordinates, tpa: TPointArray;
661528begin
662529 if ChooseOption.IsOpen() then
663530 begin
@@ -671,10 +538,32 @@ begin
671538 if Self.Coordinates = [] then
672539 raise GetDebugLn('TRSEntity', 'FindFrom requires the object to have coordinates.');
673540
674- //TODO:
675- //if not Self.Walker^.MakePointVisible(Self.Coordinates) then Exit;
541+ me := Self.Walker^.Position();
542+ if not Self.Walker^.MakePointVisible(me, Self.Coordinates.NearestPoint(me)) then
543+ Exit;
676544
677- Result := Self._HoverHelper(action, attempts);
545+ Result := Self._UpTextCheck(shouldExit, action);
546+ if shouldExit then Exit;
547+
548+ for attempt := 0 to attempts do
549+ begin
550+ if Self.Find(coordinates, atpa) then
551+ begin
552+ if attempt < 2 then i := 0
553+ else if Length(atpa) > (attempt - 2) then i := attempt - 2
554+ else i := Random(Low(atpa), High(atpa));
555+
556+ tpa := atpa[i];
557+ Self.LastCoordinate := coordinates[i];
558+
559+ Mouse.Move(tpa.RandomMean());
560+
561+ if Self.UpText = [] then Exit(True);
562+ end;
563+
564+ if TRSObject._HoverHelper(Self.UpText + action, attempt, attempts) then
565+ Exit(True);
566+ end;
678567end;
679568
680569(*
@@ -693,7 +582,10 @@ function TRSEntity.WalkHover(action: TStringArray = []; attempts: Integer = 2):
693582var
694583 me, closest: TPoint;
695584 path: TGraphNodeArray;
696- hasPath: Boolean;
585+ hasPath, shouldExit: Boolean;
586+ attempt, i: Integer;
587+ atpa: T2DPointArray;
588+ coordinates, tpa: TPointArray;
697589begin
698590 if ChooseOption.IsOpen() then
699591 begin
@@ -718,7 +610,7 @@ begin
718610 Self.Walker^.ActionUpText := action;
719611
720612 try
721- // check if doors need to be passed to reach target
613+ // check if doors need to be passed to reach target
722614 if hasPath or Self.Walker^.WebGraph^.WalkableClusters.InSameTPA(me, closest) then
723615 begin
724616 if not Self.Walker^.MakePointVisible(closest) and not Self.Walker^.WebWalkEx(me, closest, Self.MinDistance, 0.15) then
@@ -728,7 +620,34 @@ begin
728620 if not Self.Walker^.WebWalk(closest, Self.MinDistance, 0.15) then
729621 Exit;
730622
731- Result := Self._WalkHoverHelper(action, attempts);
623+ me := Self.Walker^.Position();
624+ if not Self.Walker^.MakePointVisible(me, Self.Coordinates.NearestPoint(me)) then
625+ Exit;
626+
627+ Result := Self._UpTextCheck(shouldExit, action) or Self.Walker^.RedClicked;
628+ if shouldExit then Exit;
629+
630+ for attempt := 0 to attempts do
631+ begin
632+ if Self.Find(coordinates, atpa) then
633+ begin
634+ if attempt < 2 then i := 0
635+ else if Length(atpa) > (attempt - 2) then i := attempt - 2
636+ else i := Random(Low(atpa), High(atpa));
637+
638+ tpa := atpa[i];
639+ Self.LastCoordinate := coordinates[i];
640+
641+ Mouse.Move(tpa.RandomMean());
642+
643+ if Self.UpText = [] then
644+ Exit(True);
645+ Sleep(50); //give uptext 1~ frame time to update
646+ end;
647+
648+ if TRSObject._WalkHoverHelper(Self.UpText + action, Self.Walker, Self.MinDistance, attempt, attempts, Self.Coordinates, path) then
649+ Exit(True);
650+ end;
732651 finally
733652 Self.Walker^.TargetUpText := [];
734653 Self.Walker^.ActionUpText := [];
@@ -925,6 +844,5 @@ begin
925844 ToString(entity.Size) + ', ' +
926845 ToString(entity.Coordinates) + ', ' +
927846 ToString(entity.Finder) + ', ' +
928- ToString(entity.MinimapDots) + ', ' +
929- ToString(entity.Track) + ']';
847+ ToString(entity.MinimapDots) + ']';
930848end;
0 commit comments