Class TargetDetectionTasks
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.TargetDetectionTasks
- All Implemented Interfaces:
PriorityTask
,Task
- Direct Known Subclasses:
AttackTask
,IdleTask
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.csse3200.game.ai.tasks.Task
Task.Status
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final float
protected final DebugRenderer
protected final RaycastHit
protected final PhysicsEngine
Fields inherited from class com.csse3200.game.ai.tasks.DefaultTask
owner, status
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
getActivePriority
(float distance, Entity target) Gets the priority when the task is active.protected float
Gets the distance to the nearest visible targetprotected abstract int
getInactivePriority
(float distance, Entity target) Gets the priority when the task is inactive.protected Entity
Finds the nearest visible target within attack range.int
Determines the tasks priority When active: returns1
if target is in range and visible, otherwise-1
.protected boolean
isTargetVisible
(Entity target) Determines if a target is visible by checking for obstacles in the current entities line of sightMethods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus, start, stop, update
-
Field Details
-
attackRange
protected final float attackRange -
physics
-
debugRenderer
-
hit
-
-
Constructor Details
-
TargetDetectionTasks
protected TargetDetectionTasks(float attackRange)
-
-
Method Details
-
getDistanceToTarget
protected float getDistanceToTarget()Gets the distance to the nearest visible target- Returns:
- the distance to the nearest target or a MAX VALUE if there is no target
-
getActivePriority
Gets the priority when the task is active.- Parameters:
distance
- the distance to the targettarget
- the target entity- Returns:
- the priority value
-
getInactivePriority
Gets the priority when the task is inactive.- Parameters:
distance
- the distance to the targettarget
- the target entity- Returns:
- the priority value
-
getPriority
public int getPriority()Determines the tasks priority- When active: returns
1
if target is in range and visible, otherwise-1
. - When inactive: returns
1
if target is in range and visible, otherwise-1
.
- Specified by:
getPriority
in interfacePriorityTask
- Returns:
- the tasks priority
- When active: returns
-
isTargetVisible
Determines if a target is visible by checking for obstacles in the current entities line of sight- Parameters:
target
- the target to check- Returns:
true
if the target is visible,false
otherwise
-
getNearestVisibleTarget
Finds the nearest visible target within attack range.- Returns:
- the closest visible target within range, or
null
if none
-
getAllTargets
-