@@ -256,6 +256,45 @@ begin
256256 Result := [arr[0], arr[1], arr[2], arr[3]];
257257end;
258258
259+ function TRSWalker.GetCuboidMS(me, mapPoint: TPoint; size: TVector3; radians: Single = $FFFF): TCuboid;
260+ var
261+ vector: TVector2;
262+ corners: TVector3Array;
263+ h: Single;
264+ pt, currLoc: TPoint;
265+ arr: TPointArray;
266+ begin
267+ if not me.InRange(mapPoint, MM2MS.MAX_RENDER_DISTANCE) then Exit;
268+ if radians = $FFFF then radians := Minimap.GetCompassAngle(False);
269+ vector := Self.Point2MMVec(me, mapPoint, radians);
270+ pt := vector.ToPoint();
271+
272+ vector := Minimap.NormalizeEx(vector, radians);
273+ me := Self.GetLocal(me);
274+
275+ h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
276+ Self.Height(me + [3,1], False) + Self.Height(me - [1,1], False);
277+ h := h/4;
278+
279+ currLoc := me + vector.ToPoint() - Minimap.Center;
280+
281+ corners := [
282+ [vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc - [1,3], False) - h],
283+ [vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [3,-3], False) - h],
284+ [vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [3,1], False) - h],
285+ [vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc - [1,1], False) - h],
286+ [vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc - [1,3], False) - h+size.Z],
287+ [vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [3,-3], False) - h+size.Z],
288+ [vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [3,1], False) - h+size.Z],
289+ [vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc - [1,1], False) - h+size.Z]
290+ ];
291+
292+ arr := MM2MS.Run(corners, radians);
293+ Result := [
294+ [arr[4], arr[5], arr[6], arr[7]], [arr[0], arr[1], arr[2], arr[3]]
295+ ];
296+ end;
297+
259298function TRSWalker.MM2Map(me, minimapPoint: TPoint; radians: Single = $FFFF): TPoint;
260299begin
261300 Result := me + minimapPoint - Minimap.Center;
@@ -265,22 +304,34 @@ begin
265304end;
266305
267306
268- procedure TRSWalker.SetFlag(me: TPoint; radians: Single = $FFFF);
307+ function TRSWalker.FindFlag(me: TPoint; out flag: TPoint; radians: Single = $FFFF): Boolean;
308+ begin
309+ Result := Minimap.FindFlag(flag);
310+ if Result then
311+ flag := Self.MM2Map(me, flag, radians);
312+ end;
313+
314+ function TRSWalker.WaitFlag(out flag: TPoint; radians: Single = $FFFF): Boolean;
269315begin
270- if Minimap.FindFlag(Self._Flag) then
271- Self._Flag := Self.MM2Map(me, Self._Flag, radians);
316+ Result := SleepUntil(Self.FindFlag(Self.Position(), flag, radians), 100, 600);
272317end;
273318
274- function TRSWalker.FlagMoved(me : TPoint; radians: Single = $FFFF): Boolean;
319+ function TRSWalker.FlagMoved(out flag : TPoint; radians: Single = $FFFF): Boolean;
275320var
276- pt : TPoint;
321+ newFlag : TPoint;
277322begin
278- pt := Self._Flag;
279- Self.SetFlag(me, radians);
280- if not pt.InRange(Self._Flag, 3) then
281- Exit(True);
323+
324+ Result := SleepUntil(
325+ Self.FindFlag(Self.Position(), newFlag, radians) and not newFlag.InRange(flag, 4),
326+ 100,
327+ 600
328+ );
329+
330+ flag := newFlag;
282331end;
283332
333+
334+
284335(*
285336## TRSWalker.InRange
286337```pascal
@@ -460,7 +511,7 @@ begin
460511 if position.Current <> position.Previous then
461512 countdown.Restart();
462513
463- if (Self._Node <> EGraphNode.NORMAL) and Self.FlagMoved(position.Current, Minimap.GetCompassAngle(False)) then
514+ // if (Self._Node <> EGraphNode.NORMAL) and Self.FlagMoved(position.Current, Minimap.GetCompassAngle(False)) then
464515 begin
465516 Self.Walking := False;
466517 Break;
@@ -552,7 +603,6 @@ begin
552603 Self.RedClicked := ChooseOption.Select(Self.ActionUpText);
553604 if Self.RedClicked then
554605 Self.Walking := False;
555- Self.SetFlag(me, Minimap.GetCompassAngle(False));
556606 Exit(Self.RedClicked);
557607 end;
558608 end
@@ -584,26 +634,25 @@ begin
584634
585635 if Self.RedClicked then
586636 Self.Walking := False;
587- Self.SetFlag(me, Minimap.GetCompassAngle(False));
588637end;
589638
590639(*
591640## Walker.IsWalkable
592641```pascal
593- function TRSWalker.IsWalkable(mapPoint: TPoint; me: TPoint; out mmPoint: TPoint; angle : Double): Boolean;
642+ function TRSWalker.IsWalkable(mapPoint: TPoint; me: TPoint; out mmPoint: TPoint; radians : Double): Boolean;
594643```
595644Internal method used by walker to decide if the destination point is within 1 click reach.
596645You will probably never need to call this directly.
597646*)
598- function TRSWalker.IsWalkable(mapPoint, me: TPoint; out mmPoint: TPoint; angle : Double): Boolean;
647+ function TRSWalker.IsWalkable(mapPoint, me: TPoint; out mmPoint: TPoint; radians : Double): Boolean;
599648var
600649 corner: TPoint;
601650begin
602- mmPoint := Self.Point2MM(me, mapPoint, angle );
651+ mmPoint := Self.Point2MM(me, mapPoint, radians );
603652 if not Self.ScreenWalk then
604653 Exit(Minimap.Polygon.Expand(-1).Contains(mmPoint));
605654
606- for corner in Self.GetQuadMS(me, mapPoint, angle ).Expand(-8).Corners do
655+ for corner in Self.GetQuadMS(me, mapPoint, radians ).Expand(-8).Corners do
607656 if MainScreen.Bounds.Contains(corner) then
608657 Exit(True);
609658end;
@@ -668,27 +717,65 @@ begin
668717 Result := Self.Position().InRange(mapPt, Max(minDist, 3));
669718end;
670719
671- function TRSWalker.CrossDoor(me: TPoint; index: Integer): Boolean;
720+ function TRSWalker.CrossDoor(me: TPoint; index: Integer; attempts: Integer = 3 ): Boolean;
672721var
673722 tmp: TPoint;
674723 door, furthest: Integer;
675- angle: Double;
724+ radians: Double;
725+ mapPt, minimapPt, flag: TPoint;
726+ shouldExit, handleDoor: Boolean;
727+ cuboid: TCuboid;
676728begin
729+ WriteLn GetDebugLn(Self.Name, 'Attempting to cross door');
730+ if attempts = 0 then Exit;
731+
677732 if index = High(Self._Path) then
678733 raise GetDebugLn(Self.Name, 'Paths should not end at a door node.');
679734
680735 door := Self._Path.IndexOf(Self._Path[index].Node);
681736 furthest := door;
682737
683- angle := Minimap.GetCompassAngle(False);
684- while (furthest < High(Self._Path)) and Self.IsWalkable(Self._Path[furthest+1].Node, me, tmp, angle ) do
738+ radians := Minimap.GetCompassAngle(False);
739+ while (furthest < High(Self._Path)) and Self.IsWalkable(Self._Path[furthest+1].Node, me, tmp, radians ) do
685740 if Self._Path[furthest+1].Typ = EGraphNode.NORMAL then
686741 Inc(furthest);
687742
688743 if Biometrics.RandomBoolean(0.002) then
689744 furthest := Random(door, furthest);
690745
691- //TODO: ... Handle door
746+ mapPt := Self._Path[furthest].Node;
747+ if not Self._WalkStepHelper(me, mapPt, 0, minimapPt, shouldExit) then
748+ Exit;
749+
750+ if shouldExit then Exit;
751+
752+ if Self.WaitFlag(flag) then
753+ handleDoor := Self.FlagMoved(flag, radians)
754+ else
755+ handleDoor := True;
756+
757+ if not handleDoor then
758+ begin
759+ Self.WaitMoving(mapPt, 4);
760+ if not Self.WebGraph^.WalkableClusters.InSameTPA(Self.Position(), mapPt) then
761+ handleDoor := True;
762+ end;
763+
764+ me := Self.Position();
765+
766+ if handleDoor then
767+ begin
768+ WriteLn GetDebugLn(Self.Name, 'Attempting to open door');
769+ cuboid := Self.GetCuboidMS(me, Self._Path[door].Node, [0.6,0.6,4], radians);
770+ ShowOnTarget(cuboid);
771+ Mouse.Move(cuboid.ShapeFill().RandomMean());
772+ if MainScreen.IsUpText('Open') then
773+ Mouse.Click(EMouseButton.LEFT)
774+ else if not ChooseOption.Select('Open') then
775+ Exit;
776+ end;
777+
778+ Result := Self.CrossDoor(me, index, Dec(attempts));
692779end;
693780
694781function TRSWalker.UseStairs(me: TPoint; index: Integer): Boolean;
0 commit comments