Class ChaseTask

java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.ChaseTask
All Implemented Interfaces:
PriorityTask, Task
Direct Known Subclasses:
FollowTask, RunAwayTask

public class ChaseTask extends DefaultTask implements PriorityTask
Chases a target entity until they get too far away or line of sight is lost
  • 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
    ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed)
     
    ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed, boolean checkVisibility)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    Determines the priority when the chase task is active based on the distance to the target and the visibility of the target entity.
    protected float
    Calculates the distance between the owner's entity and the target entity.
    protected int
    Determines the priority when the chase task is inactive based on the distance to the target and the visibility of the target entity.
    Gets the movement task associated with this run away task.
    int
    Gets the priority level of the chase task based on the current status and conditions.
    int
    Getter for the raw priority of this task
    Getter for the target entity that this task is related to
    float
    Getter for distance that the entity can ee
    protected boolean
    Checks if the target entity is visible from the owner's entity position by performing a raycast.
    void
    Setter for movementTask
    void
    Starts the chase task by initializing the movement task and triggering the "chaseStart" event.
    void
    Stops the chase task and the associated movement task.
    void
    Updates the chase task by updating the movement task and restarting it if necessary.

    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

    • ChaseTask

      public ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed)
      Parameters:
      target - The entity to chase.
      priority - Task priority when chasing (0 when not chasing).
      viewDistance - Maximum distance from the entity at which chasing can start.
      maxChaseDistance - Maximum distance from the entity while chasing before giving up.
      speed - Speed at which to chase the player.
    • ChaseTask

      public ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed, boolean checkVisibility)
      Parameters:
      target - The entity to chase.
      priority - Task priority when chasing (0 when not chasing).
      viewDistance - Maximum distance from the entity at which chasing can start.
      maxChaseDistance - Maximum distance from the entity while chasing before giving up.
      speed - Speed at which to chase the player.
      checkVisibility - Whether to consider visibility when chasing.
  • Method Details

    • start

      public void start()
      Starts the chase task by initializing the movement task and triggering the "chaseStart" event.
      Specified by:
      start in interface Task
      Overrides:
      start in class DefaultTask
    • update

      public void update()
      Updates the chase task by updating the movement task and restarting it if necessary.
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • stop

      public void stop()
      Stops the chase task and the associated movement task.
      Specified by:
      stop in interface Task
      Overrides:
      stop in class DefaultTask
    • getPriority

      public int getPriority()
      Gets the priority level of the chase task based on the current status and conditions.
      Specified by:
      getPriority in interface PriorityTask
      Returns:
      The priority level.
    • getDistanceToTarget

      protected float getDistanceToTarget()
      Calculates the distance between the owner's entity and the target entity.
      Returns:
      The distance between the owner's entity and the target entity.
    • getActivePriority

      protected int getActivePriority()
      Determines the priority when the chase task is active based on the distance to the target and the visibility of the target entity.
      Returns:
      The active priority level or -1 if chasing conditions are not met.
    • getInactivePriority

      protected int getInactivePriority()
      Determines the priority when the chase task is inactive based on the distance to the target and the visibility of the target entity.
      Returns:
      The inactive priority level or -1 if conditions are not met.
    • isTargetVisible

      protected boolean isTargetVisible()
      Checks if the target entity is visible from the owner's entity position by performing a raycast.
      Returns:
      True if the target entity is visible, false otherwise.
    • getMovementTask

      public MovementTask getMovementTask()
      Gets the movement task associated with this run away task.
      Returns:
      The movement task instance.
    • setMovementTask

      public void setMovementTask(MovementTask movementTask)
      Setter for movementTask
      Parameters:
      movementTask - the movement task that is assigned
    • getRawPriority

      public int getRawPriority()
      Getter for the raw priority of this task
      Returns:
      priority of this task
    • getTarget

      public Entity getTarget()
      Getter for the target entity that this task is related to
      Returns:
      target entity
    • getViewDistance

      public float getViewDistance()
      Getter for distance that the entity can ee
      Returns:
      viewDistance of the chasing entity