Class CombatManager

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.combat.CombatManager

public class CombatManager extends Component
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.
  • Constructor Details

    • CombatManager

      public CombatManager(Entity player, Entity enemy)
      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.
      Overrides:
      create in class Component
    • usePlayerItem

      public 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.
      Parameters:
      item - to be used.
      index - of the item in the original inventory.
      context - of the item.
    • onPlayerActionSelected

      public void onPlayerActionSelected(String playerActionStr)
      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

      public Entity getPlayer()
      Returns:
      the player entity.
    • getEnemy

      public Entity getEnemy()
      Returns:
      the enemy entity.
    • getPlayerStats

      public CombatStatsComponent getPlayerStats()
      Returns:
      the stats component of the player.
    • getEnemyStats

      public CombatStatsComponent getEnemyStats()
      Returns:
      the stats component of the enemy.