Class IdleTask

All Implemented Interfaces:
PriorityTask, Task

public class IdleTask extends TargetDetectionTasks
Keeps an entity idle until a target entity is detected within the attack range.

A list of available target entities is monitored to determine whether the current entity should remain idle or prepare for an attack, based on the target's distance and visibility. The closest visible target is found and if the target is outside the entity's range of attack, entity remains idle. Otherwise, this task becomes inactive and another task (attack task) takes over.

  • Constructor Details

    • IdleTask

      public IdleTask(float attackRange)
      Creates an IdleTask
      Parameters:
      attackRange - the maximum distance at which the entity can attack a target
  • Method Details

    • update

      public void update()
      Description copied from interface: Task
      Run one frame of the task. Similar to the update() in Components.
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • getActivePriority

      protected int getActivePriority(float dst, Entity target)
      If task is currently running, determine whether to stay running
      Specified by:
      getActivePriority in class TargetDetectionTasks
      Parameters:
      dst - the distance to the target
      target - the target entity
      Returns:
      -1 if an enemy is within attack range (deactivate), otherwise 1 (stay idle)
    • getInactivePriority

      protected int getInactivePriority(float dst, Entity target)
      If task is not currently running, determine if it should run
      Specified by:
      getInactivePriority in class TargetDetectionTasks
      Parameters:
      dst - the distance to the target
      target - the target entity
      Returns:
      -1 if an enemy is within attack range otherwise 1 (start task)