Class PatrolTask

java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.PatrolTask
All Implemented Interfaces:
PriorityTask, Task

public class PatrolTask extends DefaultTask implements PriorityTask
Task that makes an entity move through a sequence of waypoints, pausing briefly at each. The entity patrols back and forth along its route, reversing direction when it reaches the end, and repeats this indefinitely. Requires the entity to have a PatrolRouteComponent which defines the set of waypoints to follow. Note: This task only controls behaviour during the patrol itself. Resetting the entity back to its starting waypoint (e.g. after switching from chase mode back to patrol) is handled separately by a cooldown task. For full patrol-chase-cooldown cycles, both tasks should be added to the entity's AITaskComponent.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.csse3200.game.ai.tasks.Task

    Task.Status
  • Field Summary

    Fields inherited from class com.csse3200.game.ai.tasks.DefaultTask

    owner, status
  • Constructor Summary

    Constructors
    Constructor
    Description
    PatrolTask(float waitTime)
    Creates a patrol starting from a fixed start position.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the current index pointing to a waypoint.
    int
    Return a low priority of 1.
    com.badlogic.gdx.math.Vector2
    Get the waypoint of current index
    boolean
    Check if moving.
    boolean
    Check patrol direction.
    boolean
    Check if waiting.
    void
    Set up subtasks (wait, movement) and begin moving toward first waypoint.
    void
    Stop the patrol task and its current subtask
    void
    Advance the patrol state.

    Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask

    create, getStatus

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.csse3200.game.ai.tasks.Task

    create, getStatus
  • Constructor Details

    • PatrolTask

      public PatrolTask(float waitTime)
      Creates a patrol starting from a fixed start position.
      Parameters:
      waitTime - specifies how long to wait at each waypoint before moving to the next.
  • Method Details

    • getPriority

      public int getPriority()
      Return a low priority of 1.
      Specified by:
      getPriority in interface PriorityTask
    • start

      public void start()
      Set up subtasks (wait, movement) and begin moving toward first waypoint.
      Specified by:
      start in interface Task
      Overrides:
      start in class DefaultTask
    • update

      public void update()
      Advance the patrol state. Handles swapping between wait and movement tasks based on their status.
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • stop

      public void stop()
      Stop the patrol task and its current subtask
      Specified by:
      stop in interface Task
      Overrides:
      stop in class DefaultTask
    • isWaiting

      public boolean isWaiting()
      Check if waiting.
      Returns:
      true if currentTask is waitTask
    • isMoving

      public boolean isMoving()
      Check if moving.
      Returns:
      true if currentTask is movementTask
    • getIndex

      public int getIndex()
      Get the current index pointing to a waypoint.
    • isMovingForward

      public boolean isMovingForward()
      Check patrol direction.
      Returns:
      true for forward, otherwise false
    • getTargetWaypoint

      public com.badlogic.gdx.math.Vector2 getTargetWaypoint()
      Get the waypoint of current index
      Returns:
      target waypoint