Class RunAwayTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.ChaseTask
com.csse3200.game.components.tasks.RunAwayTask
- All Implemented Interfaces:
PriorityTask
,Task
Runs from 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
ConstructorsConstructorDescriptionRunAwayTask
(Entity target, int priority, float viewDistance, float maxRunDistance, com.badlogic.gdx.math.Vector2 runSpeed) RunAwayTask
(Entity target, int priority, float viewDistance, float maxRunDistance, com.badlogic.gdx.math.Vector2 runSpeed, boolean checkVisibility) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Determines the priority when the RunAwayTask is active based on the distance to the target and the visibility of the target entity and whether the animal is tamed.protected int
Determines the priority when the RunAwayTask is inactive based on the distance to the target and the visibility of the target entity and whether the animal is tamed.void
start()
Starts the chase task by initializing the movement task and triggering the run events.void
stop()
Stops the RunAwayTask and the associated movement task, and triggers the "runAwayStop" event.void
update()
Updates the RunAwayTask by updating the movement task and restarting it if necessary.Methods inherited from class com.csse3200.game.components.tasks.ChaseTask
getDistanceToTarget, getMovementTask, getPriority, getRawPriority, getTarget, getViewDistance, isTargetVisible, setMovementTask
Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus
-
Constructor Details
-
RunAwayTask
public RunAwayTask(Entity target, int priority, float viewDistance, float maxRunDistance, com.badlogic.gdx.math.Vector2 runSpeed) - Parameters:
target
- The entity to run from.priority
- Task priority when running (0 when not running away).viewDistance
- Maximum distance from the entity at which running away can start.maxRunDistance
- Maximum distance from the entity before stopping.
-
RunAwayTask
public RunAwayTask(Entity target, int priority, float viewDistance, float maxRunDistance, com.badlogic.gdx.math.Vector2 runSpeed, boolean checkVisibility) - Parameters:
target
- The entity to run from.priority
- Task priority when running (0 when not running away).viewDistance
- Maximum distance from the entity at which running away can start.maxRunDistance
- Maximum distance from the entity before stopping.checkVisibility
- Whether to consider visability when running away.
-
-
Method Details
-
start
public void start()Starts the chase task by initializing the movement task and triggering the run events. -
update
public void update()Updates the RunAwayTask by updating the movement task and restarting it if necessary. -
stop
public void stop()Stops the RunAwayTask and the associated movement task, and triggers the "runAwayStop" event. -
getActivePriority
protected int getActivePriority()Determines the priority when the RunAwayTask is active based on the distance to the target and the visibility of the target entity and whether the animal is tamed.- Overrides:
getActivePriority
in classChaseTask
- Returns:
- The active priority level or -1 if conditions are not met.
-
getInactivePriority
protected int getInactivePriority()Determines the priority when the RunAwayTask is inactive based on the distance to the target and the visibility of the target entity and whether the animal is tamed.- Overrides:
getInactivePriority
in classChaseTask
- Returns:
- The inactive priority level or -1 if conditions are not met.
-