Class ProximityTask

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

public abstract class ProximityTask extends DefaultTask implements PriorityTask
An abstract task that monitors the proximity of a specified target entity. The task performs specific actions when the target entity moves within a defined proximity threshold and when it moves away. This task is designed to be used within an AI task system.
  • Field Details

    • target

      protected final Entity target
    • priority

      protected final int priority
    • proximityThreshold

      protected final float proximityThreshold
    • hasApproached

      protected boolean hasApproached
  • Constructor Details

    • ProximityTask

      protected ProximityTask(Entity target, int priority, float proximityThreshold)
      Constructs a new ProximityTask.
      Parameters:
      target - The entity that the task will monitor for proximity
      priority - The priority level of this task, used in the AI task system.
      proximityThreshold - The distance within which the task will consider the target entity "near".
  • Method Details

    • update

      public void update()
      Updates the task each frame. It checks the proximity of the target entity to the owner entity and triggers the appropriate handler methods when the target moves close or moves away.
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • handleTargetMovedAway

      public abstract void handleTargetMovedAway()
      Abstract method to handle the case when the target entity moves away from the owner entity. Subclasses must implement this method to define the specific behavior when the target moves away.
    • handleTargetMovedClose

      public abstract void handleTargetMovedClose()
      Abstract method to handle the case when the target entity moves away from the owner entity. Subclasses must implement this method to define the specific behavior when the target moves away.
    • getPriority

      public int getPriority()
      Returns the priority of this task, which is based on whether the target entity is near the owner entity.
      Specified by:
      getPriority in interface PriorityTask
      Returns:
      The priority level of this task. Returns the configured priority if the target is within the proximity threshold, otherwise returns 0.
    • targetInProximity

      protected boolean targetInProximity()
      Checks if the target entity is near the owner entity by calculating the distance between them and comparing it to the proximity threshold.
      Returns:
      true if the target entity is within the proximity threshold, false otherwise.