Class ItemProximityTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.ProximityTask
com.csse3200.game.components.tasks.ItemProximityTask
- All Implemented Interfaces:
PriorityTask
,Task
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.csse3200.game.ai.tasks.Task
Task.Status
-
Field Summary
Fields inherited from class com.csse3200.game.components.tasks.ProximityTask
hasApproached, priority, proximityThreshold, target
Fields inherited from class com.csse3200.game.ai.tasks.DefaultTask
owner, status
-
Constructor Summary
ConstructorsConstructorDescriptionItemProximityTask
(Entity target, int priority, float proximityThreshold, AbstractItem item) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 eventint
Returns the priority of this task, which is based on whether the player is near the item or has just picked it upvoid
Abstract method to handle the case when the target entity moves away from the owner entity.void
Abstract method to handle the case when the target entity moves away from the owner entity.void
start()
Starts the task by adding an event listener for the "pickupItem" event.Methods inherited from class com.csse3200.game.components.tasks.ProximityTask
targetInProximity, update
Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus, setOwner, stop
-
Constructor Details
-
ItemProximityTask
-
-
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 interfaceTask
- Overrides:
start
in classDefaultTask
-
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 interfacePriorityTask
- Overrides:
getPriority
in classProximityTask
- 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 classProximityTask
-
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 classProximityTask
-