Class AttackTask

All Implemented Interfaces:
PriorityTask, Task

public class AttackTask extends TargetDetectionTasks
Allows an entity to attack the closest target entity from a list of potential targets. This task runs when there is a target within the entities range of attack
  • Constructor Details

    • AttackTask

      public AttackTask(float attackRange)
      Creates an attack task
      Parameters:
      attackRange - the maximum distance the entity can find a target to attack
  • Method Details

    • start

      public void start()
      Starts the attack task. The closest visible target within the entity's attack range is found and ATTACK LOGIC BEGINS.
      Specified by:
      start in interface Task
      Overrides:
      start in class DefaultTask
    • update

      public void update()
      Updates the task each game frame
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • getActivePriority

      protected int getActivePriority(float dst, Entity target)
      Determines the tasks priority when the task is running.
      Specified by:
      getActivePriority in class TargetDetectionTasks
      Parameters:
      dst - the distance to the target
      target - the target entity
      Returns:
      1 if a target is visible and within attack range, otherwise -1
    • getInactivePriority

      protected int getInactivePriority(float dst, Entity target)
      Computes the priority when the task is inactive.
      Specified by:
      getInactivePriority in class TargetDetectionTasks
      Parameters:
      dst - the distance to the target
      target - the target entity
      Returns:
      1 if the target is visible and within attack range, otherwise -1