Class ItemProximityTask

All Implemented Interfaces:
PriorityTask, Task

public class ItemProximityTask extends ProximityTask
A task that monitors when the proximity of a player to an item and handles item pick-up interactions. When the player is within a specified distance of the item, an overlay is displayed, allowing the player to pick up the item and add it to their inventory.
  • Constructor Details

    • ItemProximityTask

      public ItemProximityTask(Entity target, int priority, float proximityThreshold, AbstractItem item)
  • Method Details

    • start

      public void start()
      Starts the task by adding an event listener for the "pickupItem" event. The event is triggered when the Player presses P.
      Specified by:
      start in interface Task
      Overrides:
      start in class DefaultTask
    • addToInventory

      public void addToInventory()
      Adds the item to the players' inventory if they are near the item and haven't picked it up Disposes of the item entity once it has been picked up and logs the event
    • getPriority

      public int getPriority()
      Returns the priority of this task, which is based on whether the player is near the item or has just picked it up
      Specified by:
      getPriority in interface PriorityTask
      Overrides:
      getPriority in class ProximityTask
      Returns:
      The priority level of this task
    • handleTargetMovedAway

      public void handleTargetMovedAway()
      Description copied from class: ProximityTask
      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.
      Specified by:
      handleTargetMovedAway in class ProximityTask
    • handleTargetMovedClose

      public void handleTargetMovedClose()
      Description copied from class: ProximityTask
      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.
      Specified by:
      handleTargetMovedClose in class ProximityTask