Class CombatManager
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.combat.CombatManager
The CombatManager class is responsible for managing the turn-based combat loop between two entities (player and enemy).
It handles the selection of moves, the sequence in which they are performed, and applies the effects of moves such as
attacks, guards, and special actions. The class also checks for any status effects (like confusion or bleeding) and determines
when combat has ended based on the health of the player and the enemy.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum representing the possible actions in combat: ATTACK, GUARD, SLEEP, SPECIAL, or ITEM. -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCombatManager
(Entity player, Entity enemy) Creates a CombatManager that handles the combat sequence between the player and enemy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Initialises the event listeners.getEnemy()
void
Randomly select a move to replace the player's selected move if the player has the Confusion status effectvoid
Process Special Move status effects on the Player by reducing Player health and/or hunger.void
onPlayerActionSelected
(String playerActionStr) Sets the player's action based on input and triggers enemy action selection.void
usePlayerItem
(AbstractItem item, int index, ItemUsageContext context) Sets player's item as the one passed into this function, then calls for moves to be completed with the player's move being ITEM.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CombatManager
Creates a CombatManager that handles the combat sequence between the player and enemy. It initializes player and enemy stats, their moves, and actions.- Parameters:
player
- the player entity involved in combat.enemy
- the enemy entity involved in combat.
-
-
Method Details
-
create
public void create()Initialises the event listeners. -
usePlayerItem
Sets player's item as the one passed into this function, then calls for moves to be completed with the player's move being ITEM.- Parameters:
item
- to be used.index
- of the item in the original inventory.context
- of the item.
-
onPlayerActionSelected
Sets the player's action based on input and triggers enemy action selection. The move combination is then executed, and status effects are processed at the end of the turn.- Parameters:
playerActionStr
- the action chosen by the player as a string.
-
handlePlayerConfusion
public void handlePlayerConfusion()Randomly select a move to replace the player's selected move if the player has the Confusion status effect -
handleStatusEffects
public void handleStatusEffects()Process Special Move status effects on the Player by reducing Player health and/or hunger. Updates the statusEffectDuration and removes expired effects. Confusion only lasts 1 round and is always removed. -
getPlayer
- Returns:
- the player entity.
-
getEnemy
- Returns:
- the enemy entity.
-
getPlayerStats
- Returns:
- the stats component of the player.
-
getEnemyStats
- Returns:
- the stats component of the enemy.
-