Class MovementService


  • public class MovementService
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      MovementService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<net.runelite.api.coords.WorldPoint> applyVariableStride​(java.util.List<net.runelite.api.coords.WorldPoint> densePath)
      Converts a dense path (every tile) into a strided path.
      void moveTo​(net.runelite.api.coords.LocalPoint point)
      Moves the player to a specified LocalPoint.
      void moveTo​(net.runelite.api.coords.WorldPoint point)
      Moves the player to the specified WorldPoint, handling instanced areas conversion when necessary.
      boolean traversePath​(net.runelite.api.Client client, MovementService movement, java.util.List<net.runelite.api.coords.WorldPoint> path)
      Traverses a given path made up of waypoints, attempting to successfully move the player to each WorldPoint in the sequence.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MovementService

        public MovementService()
    • Method Detail

      • moveTo

        public void moveTo​(net.runelite.api.coords.WorldPoint point)
        Moves the player to the specified WorldPoint, handling instanced areas conversion when necessary. This method ensures accurate movement by checking if the player is within an instance and applying the respective LocalPoint to WorldPoint conversion.

        The operation involves:

        • Converting the given WorldPoint to handle instanced logic if the player is in an instance.
        • Obtaining a click position on the game canvas for the target point.
        • Sending interaction packets to queue both mouse clicks and movement commands.
        Parameters:
        point - The WorldPoint representing the destination to move towards.
      • moveTo

        public void moveTo​(net.runelite.api.coords.LocalPoint point)
        Moves the player to a specified LocalPoint. This method accounts for whether the player is within an instance and converts the LocalPoint to a WorldPoint to enable movement. If the current top-level world view is an instance, additional conversion logic is applied to ensure accuracy.

        The method performs the following actions:

        • Converts the provided LocalPoint to a WorldPoint, handling instance logic if needed.
        • Determines the clickbox for the target WorldPoint to simulate a mouse click.
        • Queues packets to notify the game client of the movement and corresponding mouse interaction.
        Parameters:
        point - The LocalPoint representing the target destination to move towards.
      • applyVariableStride

        public java.util.List<net.runelite.api.coords.WorldPoint> applyVariableStride​(java.util.List<net.runelite.api.coords.WorldPoint> densePath)
        Converts a dense path (every tile) into a strided path. Logic: Start with a stride of 5, increase by 1 every step, cap at 12.
        Parameters:
        densePath - The dense path with which to apply variable strides.
        Returns:
        A list of WorldPoint representing the strided path.
      • traversePath

        public boolean traversePath​(net.runelite.api.Client client,
                                    MovementService movement,
                                    java.util.List<net.runelite.api.coords.WorldPoint> path)
                             throws java.lang.InterruptedException
        Traverses a given path made up of waypoints, attempting to successfully move the player to each WorldPoint in the sequence. This method invokes movement commands and uses retries if a waypoint fails to be reached. It aborts if a waypoint cannot be reached after multiple attempts.

        The method performs the following tasks for each waypoint in the path:

        • Sends a movement command to the client to move towards the target waypoint.
        • Calculates a dynamic timeout based on distance and walking speed, with a buffer for path variance.
        • Waits for the player to reach the waypoint within the allowed timeout.
        • Retries the movement command up to two times if the waypoint is not reached within the timeout.
        • Aborts and returns failure if retries are exhausted for any waypoint.
        Parameters:
        client - The client instance used to interact with the game world and retrieve the player's location.
        movement - The MovementService instance responsible for managing player movement commands.
        path - A list of WorldPoint objects representing the sequence of waypoints to traverse.
        Returns:
        true if the path was successfully traversed to the end, false if any waypoint could not be reached after retries.
        Throws:
        java.lang.InterruptedException - If the thread running the method is interrupted during execution.