diff options
Diffstat (limited to 'server/lib/core/commands/add_condition_command.dart')
| -rw-r--r-- | server/lib/core/commands/add_condition_command.dart | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/server/lib/core/commands/add_condition_command.dart b/server/lib/core/commands/add_condition_command.dart new file mode 100644 index 0000000..663d6b0 --- /dev/null +++ b/server/lib/core/commands/add_condition_command.dart @@ -0,0 +1,56 @@ +import '../enums.dart'; +import '../game_methods.dart'; +import '../state/game_state.dart'; +import 'command_l10n.dart'; + +class AddConditionCommand extends Command { + final Condition condition; + final String? ownerId; + final String figureId; + final GameState _gameState; + + AddConditionCommand( + this.condition, + this.figureId, + this.ownerId, { + required GameState gameState, + }) : _gameState = gameState; + + @override + void execute() { + FigureState? figure = GameMethods.getFigure(ownerId, figureId); + if (figure != null) { + List<Condition> newList = []; + newList.addAll(figure.conditions); + if (!newList.contains(condition) || //block from adding same condition + condition == Condition.chill || + condition == Condition.plague) { + newList.add(condition); + } + figure.setConditions(stateAccess, newList); + + if (condition == Condition.chill) { + figure.setChill(stateAccess, figure.chill + 1); + } + if (condition == Condition.plague) { + figure.setPlague(stateAccess, figure.plague + 1); + } + + //only added this turn if is current or done + for (final item in _gameState.currentList) { + if (item.id == ownerId) { + if (item.turnState != TurnsState.notDone && + _gameState.roundState == RoundState.playTurns) { + figure.addToConditionsThisTurn(stateAccess, condition); + } + } + } + _gameState.notifyListeners(); + } + } + + @override + String describe() { + return commandL10n.cmdAddCondition(condition.getName()); + } +} |
