POH Handler

The POH Handler is a handler responsible for making sense of a player’s POH (Player Owned House) without knowing any info about it’s setup in advance.

Several rooms in a POH are unique on the minimap, with windows and/or doors of several sizes and different places. By having this rooms saved in the following format:

_images/poh.png

Most relevant rooms for a POH stripped of their floor colors

We can attempt to match what we have on the minimap to those rooms and slowly build a map of the POH.

Some rooms share the same room layout or are very similar to others and for those we use some mainscreen information to make up what the room is, e.g., Nexus room, Combat Hall and Quest Hall are all identical.


PRSWalker

TRSWalker pointer.


TRSWalker_OnWalkEventEx

Callback object method to use while walking. This can be used to perform custom tasks while walking.

Example:

procedure TRSWalker.WalkerTasks(Walker: PRSWalker; Position: TPoint; Destination: TPoint);
begin
  Antiban.RandomTab();
end;

var
  rsw: TRSWalker;

begin
  rsw.Setup('world');
  rsw.OnWalkingEventEx := @rsw.WalkerTasks;
end;

type TRSPOHHandler

type
  TRSPOHHandler = record
    Map: TPOHMap;
    RoomObjects: array [ERSRoomObject] of TRoomObject;
    EnableRunAtEnergy: Int32;
    Similarity: Double;
  end;

The core record used to handle navigating a POH.


POH.Init()

procedure TRSPOHHandler.Init();

Internal method automatically called for your on script startup along with SRL.Setup(). You do not have to call it yourself.


POH.GetAdjacentRooms()

function TRSPOHHandler.GetAdjacentRooms(p: TPoint): TPointArray; static;

Helper static method that returns coordinates that belong to the north, west, south and east rooms of the point passed in. This assumes the compass is set to 0 (North) or that you’ve rotated your coordinates so the math works as if you had the compass set that way. Ideally, you will want to pass in a room top left corner to this to get the top left corner of each adjacent room.


TRSPOHHandler.GetRoomCoordinate()

function TRSPOHHandler.GetRoomCoordinate(topLeft, p: TPoint; angle: Double; rotation: Int32): TPoint; static;

Helper static method that converts a room point p (which is always between [0,0] and [32,32] to a point on the minimap. Optionally the point can be rotated on the room’s center in 90º increments which is decided by rotation. For example, if rotation is 3, the point will be rotated 90*3=270º on the room’s center.

This is useful to look for mainscreen objects in a room we don’t know the rotation, we can brute force all the possible rotations and look for what we want.


POH.GetCuboid()

function TRSPOHHandler.GetCuboid(topLeft, p: TPoint; tile: Vector3; angle: Double; rotation: Int32): TCuboidEx; static;

Static mehod that returns a TCuboidEx on the mainscreen of a point we specify p with a given rotation on the room’s center. TRSPOHHandler.GetRoomCoordinate() is used to get the minimap point which then uses Minimap.GetCuboidMS() to give us a cuboid as a result.

To work, this requires the room’s topLeft TPoint and the compass angle.


POH.ContainsObject()

function TRSPOHHandler.ContainsObject(objType: ERSRoomObject; topLeft: TPoint; angle: Double; rotation: Int32): Boolean;

Checks if a TRoomObject stored in POH.RoomObjects exists in a room at a given rotation.


POH.MapRoomObjects()

procedure TRSPOHHandler.MapRoomObjects(room: ERSHouseRoom; topLeft: TPoint; roomIndex: TPoint; angle: Double);

Method responsible for mapping known TRoomObjectTRoomObject coordinates which later can be used to interact with them.


POH.MapAdjacentRooms()

procedure TRSPOHHandler.MapAdjacentRooms(minimapBMP: TMufasaBitmap; topLeft, currentRoom: TPoint; angle: Double);

The core of the “POH Handler”. This method is what’s responsible for mapping unknown adjacent rooms (north, west, south and east). If you know what you are doing you can call this directly, but this is called automatically by POH.GetPos() and POH.Setup().


POH.GetCleanMinimap()

function TRSPOHHandler.GetCleanMinimap(out angle: Double): TMufasaBitmap; static;

Basically the same as Walker.GetCleanMinimap() that returns the compass angle as well.


POH.Setup()

procedure TRSPOHHandler.Setup();

The method that sets up the “POH Handler” so it can be used. It’s your responsibility to call it and it must be called from your POH entrance. There is some wiggle room as from where you can use this on your garden and you might get away using it from anywhere but for best results you should use this from the tile right northwest to your exit portal. This is the tile that the POH.Setup() assumes you will be calling it from and it’s the tile you will always be in as soon as you enter your POH no matter the method you choose to enter it (teleport, using the portal, building or non building mode, …).

Example:

if MainScreen.WaitLoadingPOH(5000) then
  POH.Setup();

POH.LoadSuroundings()

procedure TRSPOHHandler.LoadSuroundings(minimapBMP: TMufasaBitmap; p: TPoint; angle: double);

Wrapper method that performs some common math required by POH.MapAdjacentRooms(). You can use this directly if you know what you are doing, but this is called automatically for you with POH.GetPos().


POH.GetPos()

function TRSPOHHandler.GetPos(): TPoint;

Returns the player position relative to the POH.Map. Whenever this method is called, if there’s unknown adjacent rooms (north, west, south and east), they will be mapped.


POH.DebugPos()

procedure TRSPOHHandler.DebugPos();

Debugs the current player position on the POH.Map.

Example:

{$I WaspLib/optional/handlers/poh.simba}
begin
  POH.Setup(); //call from the northwest tile of your exit portal.
  while True do
    POH.DebugPos();
end;

POH.GetCurrentRoom()

function TRSPOHHandler.GetCurrentRoom(): ERSHouseRoom;

Returns the current type ERSHouseRoom we are on.

Example:

POH.Setup(); //call from the northwest tile of your exit portal.
WriteLn POH.GetCurrentRoom();

POH Walking

The following methods are related to POH Handler walking.


POH.MapToMM()

function TRSPOHHandler.MapToMM(me, handlerPoint: TPoint; radians: Double): TPoint;
function TRSPOHHandler.MapToMM(walkerPoint: TPoint): TPoint; overload;
function TRSPOHHandler.MapToMM(me: TPoint; tpa: TPointArray; radians: Double): TPointArray; overload;
function TRSPOHHandler.MapToMM(tpa: TPointArray): TPointArray; overload;

Converts points from the POH.Map to points on the minimap. This can be used to walk or get mainscreen info with MM2MS.

Example:

POH.Setup(); //call from the northwest tile of your exit portal.
p := POH.MapToMM(Self.GetPos() + [16, 16]);
Debug(Minimap.GetCuboidMS(p, [1,1,5]));

POH.CheckRunEnergy

procedure TRSPOHHandler.CheckRunEnergy();

Internal method used to check and enable the player run. You will probably never need to call this directly.

The values used are hardcoded and if you don’t like them, it’s recommended you override the method. The following example shows how one could override the function to enable run at 50% energy everytime, keep in mind though, you shouldn’t do this, you should add randomness to it!


POH.AdaptiveWalkCheck

procedure TRSPOHHandler.AdaptiveWalkCheck(Position: TPoint);

Internal method used to check if adaptive walk should toggle and toggle POH.ScreenWalk. You will probably never need to call this directly.


POH.DoMouseAhead

procedure TRSPOHHandler.DoMouseAhead(Position: TPoint; Forced: Boolean = False);

Internal method used to pre-hover the next walking step. You will probably never need to call this directly.


POH.WaitMoving

procedure TRSPOHHandler.WaitMoving(destination: TPoint; WaitUntilDistance: Int32);

Internal method used to wait while we are moving using poh. You will probably never need to call this directly.

This is where TRSPOHHandler.OnWalkingEvent are called.


POH.MouseClick

function TRSPOHHandler.Click(minimapPoint: TPoint; Randomness: Int32): Boolean;

Internal method used by POHHandler to handle clicking while walking. You will probably never need to call this directly.

If you wish to modify certain POHHandler behaviors, it’s a good approach to override this function. For example, if you are screenwalking and you don’t like it right clicking > walk here when it hovers a tree you could use the following example.


POH.WalkStepHelper()

function TRSPOHHandler.WalkStepHelper(playerPoint, pohPoint: TPoint; out minimapPoint: TPoint): Boolean;

Internal method used by the POH to help walking steps. You will probably never need to call this directly.


POH.WalkFinalStep

function TRSPOHHandler.WalkFinalStep(playerPoint, pohPoint: TPoint; WaitUntilDistance: Int32): Boolean;

Internal method used by POH Handler when finishing walking a path. You will probably never need to call this directly but it can be used to take a single step.


POH.WalkStep

function TRSPOHHandler.WalkStep(playerPoint, pohPoint: TPoint): Boolean;

Internal method used by POH Handler while walking a path. You will probably never need to call this directly.


POH.IsWalkable()

function TRSPOHHandler.IsWalkable(pohPoint: TPoint; playerPoint: TPoint; angle: Double): Boolean;

Internal method used by walker to decide if the destination point is within 1 click reach. You will probably never need to call this directly.


POH.WalkPath()

function TRSPOHHandler.WalkPath(path: TPointArray; waitUntilDistance: Int32 = 0): Boolean;

Walks a path of points taken from the loaded map. We advice that WaitUntilDistance is not 0.

Parameters:

  • Path Array of points taken from the loaded map to walk. Must be ordered from start to finish.

  • WaitUntilDistance Determines when the method returns once the final point has been clicked. Default value: 0. | WaitUntilDistance=0 waits until the player has reached the final point. | WaitUntilDistance=20 waits until the player is within 20 pixels of the final point.

Example:

Walker.WalkPath([[100,100],[120,120],[140,140],[160,160],[180,180]]);

POH.WalkBlind

function TRSPOHHandler.WalkBlind(Destination: TPoint; WaitUntilDistance: Int32 = 0): Boolean;

“Blindly” walks to a point taken from the loaded map. A straight line is generated between the player’s position and destination which is then walked.

Parameters:

  • Destination Destination point taken from the loaded map.

  • WaitUntilDistance Determines when the method returns once the final point has been clicked. Default value: 0. | WaitUntilDistance=0 waits until the player has reached the final point. | WaitUntilDistance=20 waits until the player is within 20 pixels of the final point.

Example:

Walker.WalkBlind([300, 300]);

TRSWalker.GetClosestPoint

function TRSWalker.GetClosestPoint(worldPointArray: TPointArray): TPoint;

method used to get the closest Point to the Player out of a TPA.

This is a TRSWalker method so it will exist both on TRSWalker and TRSWalker.


POH.WebWalk

function TRSPOHHandler.WebWalk(Destination: TPoint; WaitUntilDistance: Int32 = 0; PathRandomness: Double = 0): Boolean;

Web walks to the destination point on the loaded map. Does not handle any obstacles. Please run webber.simba to see how webgraphs are built.

Pre built webgraphs are available for “World” and “Zeah” when used.

Parameters:

  • Destination Destination point taken from the loaded map.

  • WaitUntilDistance Determines when the method returns once the final point has been clicked. Default value: 0. | WaitUntilDistance=0 waits until the player has reached the final point. | WaitUntilDistance=20 waits until the player is within 20 pixels of the final point.

  • PathRandomness Randomness to add to the path so the absoulte shortest path isn’t always taken. Must be between 0..1

Example:

var Walker: TRSWalker;

Walker.Setup('world');
Walker.WebWalk([4595, 3575]); // Lumbridge

// Or use a location from the webgraph
Walker.WebWalk(WorldWeb.LOCATION_LUMBRIDGE);

TRSWalker.WebWalk

function TRSWalker.WebWalk(destinations: TPointArray; waitUntilDistance: Int32 = 0; pathRandomness: Double = 0): Boolean; overload;

method used to webwalk to the closest Point to the player. An example use case is for example, if you have sevel bank booths you can use, those would be your Destination TPA. You will likely want to use the closest bank booth to you, so you use this.

This is a TRSWalker method so it will exist both on TRSWalker and TRSWalker.


POH Objects

The following methods are related to interacting with POH Handler TRoomObject.


POH.Find

function TRSPOHHandler.FindEx(objType: ERSRoomObject; out cuboids: TCuboidExArray; out atpa: T2DPointArray):
function TRSPOHHandler.FindAny(objType: ERSRoomObject; out tpa: TPointArray): Boolean;
function TRSPOHHandler.FindAll(objType: ERSRoomObject; out atpa: T2DPointArray): Boolean;

Method used to find a TRoomObject by specifying a ERSRoomObject. You can find any occurence of the object or all of them depending on the method you use. The extended version of the method is mostly for debugging.


TRSPOHHandler.Draw()

procedure TRSPOHHandler.Draw(out bitmap: TMufasaBitmap; objType: ERSRoomObject);

Internal method used to draw found TRoomObject in a TMufasaBitmap. An easy way to see this in action is to use Debug(ERSRoomObject).


POH.Interact

function TRSPOHHandler.Hover(objType: ERSRoomObject): Boolean;
function TRSPOHHandler.Click(objType: ERSRoomObject): Boolean;
function TRSPOHHandler.Select(objType: ERSRoomObject; options: TStringArray): Boolean;

Method used to interact with a TRoomObject by specifying a ERSRoomObject. The interactions are self explanatory.

Example:

POH.Setup(); //call from the northwest tile of your exit portal.
WriteLn POH.Hover(ERSRoomObject.POOL); //pool has to be on the same room, north, west, south or east.

POH.WalkInteract

function TRSPOHHandler.WalkHover(objType: ERSRoomObject): Boolean;
function TRSPOHHandler.WalkClick(objType: ERSRoomObject): Boolean;
function TRSPOHHandler.WalkSelect(objType: ERSRoomObject; options: TStringArray): Boolean;

Method used to walk and interact with a TRoomObject by specifying a ERSRoomObject. The interactions are self explanatory.

Example:

POH.Setup(); //call from the northwest tile of your exit portal.
WriteLn POH.Hover(ERSRoomObject.POOL); //pool has to be on the same room, north, west, south or east.

var POH

var POH

Global variable to use the type TRSPOHHandler.


Debug

procedure Debug(pohObject: ERSRoomObject); overload;

Method used to debug TRoomObject.