Class BattleManager

java.lang.Object
model.battle.BattleManager

public class BattleManager extends Object
Controls a turn-based battle between 2 entities. Supports 2 modes: player vs. Goblin (AI) and player vs. player (PvP). Both sides act simultaneously within a single turn.
  • Field Details

    • mode

      private final BattleManager.BattleMode mode
      The battle mode in use.
    • entityA

      private final Entity entityA
      Entity on side A (Player 1 or the first to enter the battle).
    • entityB

      private final Entity entityB
      Entity on side B (Player 2 or the Goblin).
    • pendingActionA

      private BattleAction pendingActionA
      Pending action chosen by side A, awaiting resolution.
    • pendingActionB

      private BattleAction pendingActionB
      Pending action chosen by side B, awaiting resolution.
    • actionASubmitted

      private boolean actionASubmitted
      Whether side A has submitted an action.
    • actionBSubmitted

      private boolean actionBSubmitted
      Whether side B has submitted an action.
  • Constructor Details

    • BattleManager

      public BattleManager(BattleManager.BattleMode mode, Entity entityA, Entity entityB)
      Creates a BattleManager for a new battle.
      Parameters:
      mode - Battle mode
      entityA - Entity on side A
      entityB - Entity on side B
  • Method Details

    • submitActionA

      public void submitActionA(BattleAction action)
      Side A submits an action for this turn.
      Parameters:
      action - The chosen action
    • submitActionB

      public void submitActionB(BattleAction action)
      Side B submits an action for this turn (PvP mode only).
      Parameters:
      action - The chosen action
    • isReadyToResolve

      public boolean isReadyToResolve()
      Checks whether the turn is ready to be resolved. In PvP both sides must submit; against a Goblin only side A's submission is required.
      Returns:
      true if the turn is ready to resolve
    • resolveTurn

      public BattleResult resolveTurn()
      Resolves the turn — both sides act simultaneously. The Goblin AI decides its action at this point. After resolution, all skills tick their cooldown.
      Returns:
      The result of this turn
    • getBattleResult

      private BattleResult getBattleResult(ActionResult resA, ActionResult resB)
      Evaluates the outcomes of both sides' actions and determines the winner/loser.
      Parameters:
      resA - ActionResult for side A
      resB - ActionResult for side B
      Returns:
      A BattleResult summarising this turn
    • processAction

      private ActionResult processAction(Entity actor, BattleAction action, Entity target)
      Processes one entity's action. Alien attacks use magic damage that bypasses defense; all other entities use takeDamage normally.
      Parameters:
      actor - Entity performing the action
      action - The chosen action
      target - The target entity
      Returns:
      ActionResult describing the outcome of this action
    • applySkillEffect

      private void applySkillEffect(Player actor, Skill skill, Entity target, ActionResult res)
      Applies the skill's effect according to its SkillEffect type.
      Parameters:
      actor - Player using the skill
      skill - Skill to apply
      target - Target entity
      res - ActionResult to update
    • resetFlags

      private void resetFlags()
      Resets submission flags for both sides after the turn ends.
    • getMode

      public BattleManager.BattleMode getMode()
      Returns:
      The battle mode
    • getEntityA

      public Entity getEntityA()
      Returns:
      Entity on side A
    • getEntityB

      public Entity getEntityB()
      Returns:
      Entity on side B
    • isActionASubmitted

      public boolean isActionASubmitted()
      Returns:
      true if side A has submitted an action
    • isActionBSubmitted

      public boolean isActionBSubmitted()
      Returns:
      true if side B has submitted an action