Class MeleeAvoidObstacleTask

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

public class MeleeAvoidObstacleTask extends DefaultTask implements PriorityTask
task that gets enemies to avoid obstacles. The algorithm is pretty simple: task is given a random rotation direction (right or left) at startup and on collision with a non-destroyable object that impedes movement, it will turn that direction and walk until (a) collision ends or (b) another collision occurs, at which point they will turn in that same direction again. After collision ends, task rotates in the inverse direction to its given rotation direction and walks for 10 update() cycles before resuming normal pathfinding. This will (hopefully) prevent getting stuck repeatedly in the same 'bucket'
  • Nested Class Summary

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

    Task.Status
  • Field Summary

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

    owner, status
  • Constructor Summary

    Constructors
    Constructor
    Description
    initialise the avoidance task.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    gets the priority of this task.
    void
    must be called after task, component, and entity are attached registers collision listeners for the entity
    void
    set a new target perpendicular to the direction of the previous target Note this is only called when priority is highest (i.e.
    void
    Stop the task immediately.
    void
    update checks if the new direction has run into any obstacles that stopped movement, and adjusts direction if necessary

    Methods inherited from class com.deco2800.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.deco2800.game.ai.tasks.Task

    create, getStatus
  • Constructor Details

    • MeleeAvoidObstacleTask

      public MeleeAvoidObstacleTask(Entity target)
      initialise the avoidance task. Task should get its entity registered using registerEntity() after creation (must be done after creation as the entity doesn't exist yet
      Parameters:
      target - the Entity this NPC is trying to reach
  • Method Details

    • registerEntityEvents

      public void registerEntityEvents()
      must be called after task, component, and entity are attached registers collision listeners for the entity
    • start

      public void start()
      set a new target perpendicular to the direction of the previous target Note this is only called when priority is highest (i.e. the entity is already not moving)
      Specified by:
      start in interface Task
      Overrides:
      start in class DefaultTask
    • update

      public void update()
      update checks if the new direction has run into any obstacles that stopped movement, and adjusts direction if necessary
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • getPriority

      public int getPriority()
      gets the priority of this task.
      Specified by:
      getPriority in interface PriorityTask
      Returns:
      -1 if it's not nighttime, otherwise active priority if active, inactive priority if inactive
    • stop

      public void stop()
      Description copied from interface: Task
      Stop the task immediately. This can be called at any time by the AI controller.
      Specified by:
      stop in interface Task
      Overrides:
      stop in class DefaultTask