Class ChaseTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.ChaseTask
- All Implemented Interfaces:
PriorityTask
,Task
- Direct Known Subclasses:
FollowTask
,RunAwayTask
Chases a target entity until they get too far away or line of sight is lost
-
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.ai.tasks.DefaultTask
owner, status
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Determines the priority when the chase task is active based on the distance to the target and the visibility of the target entity.protected float
Calculates the distance between the owner's entity and the target entity.protected int
Determines the priority when the chase task is inactive based on the distance to the target and the visibility of the target entity.Gets the movement task associated with this run away task.int
Gets the priority level of the chase task based on the current status and conditions.int
Getter for the raw priority of this taskGetter for the target entity that this task is related tofloat
Getter for distance that the entity can eeprotected boolean
Checks if the target entity is visible from the owner's entity position by performing a raycast.void
setMovementTask
(MovementTask movementTask) Setter for movementTaskvoid
start()
Starts the chase task by initializing the movement task and triggering the "chaseStart" event.void
stop()
Stops the chase task and the associated movement task.void
update()
Updates the chase task by updating the movement task and restarting it if necessary.Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus
-
Constructor Details
-
ChaseTask
public ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed) - Parameters:
target
- The entity to chase.priority
- Task priority when chasing (0 when not chasing).viewDistance
- Maximum distance from the entity at which chasing can start.maxChaseDistance
- Maximum distance from the entity while chasing before giving up.speed
- Speed at which to chase the player.
-
ChaseTask
public ChaseTask(Entity target, int priority, float viewDistance, float maxChaseDistance, com.badlogic.gdx.math.Vector2 speed, boolean checkVisibility) - Parameters:
target
- The entity to chase.priority
- Task priority when chasing (0 when not chasing).viewDistance
- Maximum distance from the entity at which chasing can start.maxChaseDistance
- Maximum distance from the entity while chasing before giving up.speed
- Speed at which to chase the player.checkVisibility
- Whether to consider visibility when chasing.
-
-
Method Details
-
start
public void start()Starts the chase task by initializing the movement task and triggering the "chaseStart" event.- Specified by:
start
in interfaceTask
- Overrides:
start
in classDefaultTask
-
update
public void update()Updates the chase task by updating the movement task and restarting it if necessary.- Specified by:
update
in interfaceTask
- Overrides:
update
in classDefaultTask
-
stop
public void stop()Stops the chase task and the associated movement task.- Specified by:
stop
in interfaceTask
- Overrides:
stop
in classDefaultTask
-
getPriority
public int getPriority()Gets the priority level of the chase task based on the current status and conditions.- Specified by:
getPriority
in interfacePriorityTask
- Returns:
- The priority level.
-
getDistanceToTarget
protected float getDistanceToTarget()Calculates the distance between the owner's entity and the target entity.- Returns:
- The distance between the owner's entity and the target entity.
-
getActivePriority
protected int getActivePriority()Determines the priority when the chase task is active based on the distance to the target and the visibility of the target entity.- Returns:
- The active priority level or -1 if chasing conditions are not met.
-
getInactivePriority
protected int getInactivePriority()Determines the priority when the chase task is inactive based on the distance to the target and the visibility of the target entity.- Returns:
- The inactive priority level or -1 if conditions are not met.
-
isTargetVisible
protected boolean isTargetVisible()Checks if the target entity is visible from the owner's entity position by performing a raycast.- Returns:
- True if the target entity is visible, false otherwise.
-
getMovementTask
Gets the movement task associated with this run away task.- Returns:
- The movement task instance.
-
setMovementTask
Setter for movementTask- Parameters:
movementTask
- the movement task that is assigned
-
getRawPriority
public int getRawPriority()Getter for the raw priority of this task- Returns:
- priority of this task
-
getTarget
Getter for the target entity that this task is related to- Returns:
- target entity
-
getViewDistance
public float getViewDistance()Getter for distance that the entity can ee- Returns:
- viewDistance of the chasing entity
-