Class ProximityTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.ProximityTask
- All Implemented Interfaces:
PriorityTask
,Task
- Direct Known Subclasses:
ItemProximityTask
An abstract task that monitors the proximity of a specified target entity.
The task performs specific actions when the target entity moves within a
defined proximity threshold and when it moves away. This task is designed
to be used within an AI task system.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.csse3200.game.ai.tasks.Task
Task.Status
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected final int
protected final float
protected final Entity
Fields inherited from class com.csse3200.game.ai.tasks.DefaultTask
owner, status
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ProximityTask
(Entity target, int priority, float proximityThreshold) Constructs a new ProximityTask. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the priority of this task, which is based on whether the target entity is near the owner entity.abstract void
Abstract method to handle the case when the target entity moves away from the owner entity.abstract void
Abstract method to handle the case when the target entity moves away from the owner entity.protected boolean
Checks if the target entity is near the owner entity by calculating the distance between them and comparing it to the proximity threshold.void
update()
Updates the task each frame.Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus, setOwner, start, stop
-
Field Details
-
target
-
priority
protected final int priority -
proximityThreshold
protected final float proximityThreshold -
hasApproached
protected boolean hasApproached
-
-
Constructor Details
-
ProximityTask
Constructs a new ProximityTask.- Parameters:
target
- The entity that the task will monitor for proximitypriority
- The priority level of this task, used in the AI task system.proximityThreshold
- The distance within which the task will consider the target entity "near".
-
-
Method Details
-
update
public void update()Updates the task each frame. It checks the proximity of the target entity to the owner entity and triggers the appropriate handler methods when the target moves close or moves away.- Specified by:
update
in interfaceTask
- Overrides:
update
in classDefaultTask
-
handleTargetMovedAway
public abstract void handleTargetMovedAway()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. -
handleTargetMovedClose
public abstract void handleTargetMovedClose()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. -
getPriority
public int getPriority()Returns the priority of this task, which is based on whether the target entity is near the owner entity.- Specified by:
getPriority
in interfacePriorityTask
- Returns:
- The priority level of this task. Returns the configured priority if the target is within the proximity threshold, otherwise returns 0.
-
targetInProximity
protected boolean targetInProximity()Checks if the target entity is near the owner entity by calculating the distance between them and comparing it to the proximity threshold.- Returns:
- true if the target entity is within the proximity threshold, false otherwise.
-