Class BattleManager
java.lang.Object
model.battle.BattleManager
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether side A has submitted an action.private booleanWhether side B has submitted an action.private final EntityEntity on side A (Player 1 or the first to enter the battle).private final EntityEntity on side B (Player 2 or the Goblin).private final BattleManager.BattleModeThe battle mode in use.private BattleActionPending action chosen by side A, awaiting resolution.private BattleActionPending action chosen by side B, awaiting resolution. -
Constructor Summary
ConstructorsConstructorDescriptionBattleManager(BattleManager.BattleMode mode, Entity entityA, Entity entityB) Creates a BattleManager for a new battle. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidapplySkillEffect(Player actor, Skill skill, Entity target, ActionResult res) Applies the skill's effect according to its SkillEffect type.private BattleResultgetBattleResult(ActionResult resA, ActionResult resB) Evaluates the outcomes of both sides' actions and determines the winner/loser.getMode()booleanbooleanbooleanChecks whether the turn is ready to be resolved.private ActionResultprocessAction(Entity actor, BattleAction action, Entity target) Processes one entity's action.private voidResets submission flags for both sides after the turn ends.Resolves the turn — both sides act simultaneously.voidsubmitActionA(BattleAction action) Side A submits an action for this turn.voidsubmitActionB(BattleAction action) Side B submits an action for this turn (PvP mode only).
-
Field Details
-
mode
The battle mode in use. -
entityA
Entity on side A (Player 1 or the first to enter the battle). -
entityB
Entity on side B (Player 2 or the Goblin). -
pendingActionA
Pending action chosen by side A, awaiting resolution. -
pendingActionB
Pending action chosen by side B, awaiting resolution. -
actionASubmitted
private boolean actionASubmittedWhether side A has submitted an action. -
actionBSubmitted
private boolean actionBSubmittedWhether side B has submitted an action.
-
-
Constructor Details
-
BattleManager
Creates a BattleManager for a new battle.- Parameters:
mode- Battle modeentityA- Entity on side AentityB- Entity on side B
-
-
Method Details
-
submitActionA
Side A submits an action for this turn.- Parameters:
action- The chosen action
-
submitActionB
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:
trueif the turn is ready to resolve
-
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
Evaluates the outcomes of both sides' actions and determines the winner/loser.- Parameters:
resA- ActionResult for side AresB- ActionResult for side B- Returns:
- A BattleResult summarising this turn
-
processAction
Processes one entity's action. Alien attacks use magic damage that bypasses defense; all other entities use takeDamage normally.- Parameters:
actor- Entity performing the actionaction- The chosen actiontarget- The target entity- Returns:
- ActionResult describing the outcome of this action
-
applySkillEffect
Applies the skill's effect according to its SkillEffect type.- Parameters:
actor- Player using the skillskill- Skill to applytarget- Target entityres- ActionResult to update
-
resetFlags
private void resetFlags()Resets submission flags for both sides after the turn ends. -
getMode
- Returns:
- The battle mode
-
getEntityA
- Returns:
- Entity on side A
-
getEntityB
- Returns:
- Entity on side B
-
isActionASubmitted
public boolean isActionASubmitted()- Returns:
trueif side A has submitted an action
-
isActionBSubmitted
public boolean isActionBSubmitted()- Returns:
trueif side B has submitted an action
-