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 intDetermines the priority when the chase task is active based on the distance to the target and the visibility of the target entity.protected floatCalculates the distance between the owner's entity and the target entity.protected intDetermines 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.intGets the priority level of the chase task based on the current status and conditions.intGetter for the raw priority of this taskGetter for the target entity that this task is related tofloatGetter for distance that the entity can eeprotected booleanChecks if the target entity is visible from the owner's entity position by performing a raycast.voidsetMovementTask(MovementTask movementTask) Setter for movementTaskvoidstart()Starts the chase task by initializing the movement task and triggering the "chaseStart" event.voidstop()Stops the chase task and the associated movement task.voidupdate()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:
startin interfaceTask- Overrides:
startin classDefaultTask
-
update
public void update()Updates the chase task by updating the movement task and restarting it if necessary.- Specified by:
updatein interfaceTask- Overrides:
updatein classDefaultTask
-
stop
public void stop()Stops the chase task and the associated movement task.- Specified by:
stopin interfaceTask- Overrides:
stopin classDefaultTask
-
getPriority
public int getPriority()Gets the priority level of the chase task based on the current status and conditions.- Specified by:
getPriorityin 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
-