diff options
Diffstat (limited to 'server/lib/core/commands/change_stat_commands')
8 files changed, 407 insertions, 0 deletions
diff --git a/server/lib/core/commands/change_stat_commands/change_bless_command.dart b/server/lib/core/commands/change_stat_commands/change_bless_command.dart new file mode 100644 index 0000000..94f83ae --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_bless_command.dart @@ -0,0 +1,46 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeBlessCommand extends ChangeStatCommand { + ModifierDeck? deck; + ChangeBlessCommand( + super.change, + super.figureId, + super.ownerId, { + required super.gameState, + }); + ChangeBlessCommand.deck(this.deck, {required GameState gameState}) + : super(0, '', '', gameState: gameState); + + @override + void execute() { + if (deck == null) { + deck = gameState.modifierDeck; + for (final item in gameState.currentList) { + if (item.id == ownerId) { + if (item is Monster && + item.isAlly && + (gameState.allyDeckInOGGloom || + !GameMethods.isOgGloomEdition())) { + deck = gameState.modifierDeckAllies; + } + if (item is Character) { + deck = item.characterState.modifierDeck; + } + } + } + } + + deck?.addRemovableValue(stateAccess, "bless", change); + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdAddBless; + } + return commandL10n.cmdRemoveBless; + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_curse_command.dart b/server/lib/core/commands/change_stat_commands/change_curse_command.dart new file mode 100644 index 0000000..4505711 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_curse_command.dart @@ -0,0 +1,46 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeCurseCommand extends ChangeStatCommand { + ChangeCurseCommand( + super.change, + super.figureId, + super.ownerId, { + required super.gameState, + }); + ChangeCurseCommand.deck(this.deck, {required GameState gameState}) + : super(0, '', '', gameState: gameState); + + ModifierDeck? deck; + + @override + void execute() { + if (deck == null) { + deck = gameState.modifierDeck; + for (final item in gameState.currentList) { + if (item.id == ownerId) { + if (item is Monster && + item.isAlly && + (gameState.allyDeckInOGGloom || + !GameMethods.isOgGloomEdition())) { + deck = gameState.modifierDeckAllies; + } + if (item is Character) { + deck = item.characterState.modifierDeck; + } + } + } + } + deck?.addRemovableValue(stateAccess, "curse", change); + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdAddCurse; + } + return commandL10n.cmdRemoveCurse; + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_empower_command.dart b/server/lib/core/commands/change_stat_commands/change_empower_command.dart new file mode 100644 index 0000000..e4a8a52 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_empower_command.dart @@ -0,0 +1,47 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeEmpowerCommand extends ChangeStatCommand { + final String gfx; + ModifierDeck? deck; + ChangeEmpowerCommand( + super.change, + this.gfx, + super.figureId, + super.ownerId, { + required super.gameState, + }); + ChangeEmpowerCommand.deck(this.deck, this.gfx, {required GameState gameState}) + : super(0, '', '', gameState: gameState); + + @override + void execute() { + if (deck == null) { + deck = gameState.modifierDeck; + for (final item in gameState.currentList) { + if (item.id == ownerId) { + if (item is Monster && + item.isAlly && + (gameState.allyDeckInOGGloom || + !GameMethods.isOgGloomEdition())) { + deck = gameState.modifierDeckAllies; + } + if (item is Character) { + deck = item.characterState.modifierDeck; + } + } + } + } + deck?.addRemovableValue(stateAccess, gfx, change); + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdAddEmpower; + } + return commandL10n.cmdRemoveEmpower; + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_enfeeble_command.dart b/server/lib/core/commands/change_stat_commands/change_enfeeble_command.dart new file mode 100644 index 0000000..ecb9f64 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_enfeeble_command.dart @@ -0,0 +1,50 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeEnfeebleCommand extends ChangeStatCommand { + ModifierDeck? deck; + final String gfx; + ChangeEnfeebleCommand( + super.change, + this.gfx, + super.figureId, + super.ownerId, { + required super.gameState, + }); + ChangeEnfeebleCommand.deck( + this.deck, + this.gfx, { + required GameState gameState, + }) : super(0, '', '', gameState: gameState); + + @override + void execute() { + if (deck == null) { + deck = gameState.modifierDeck; + for (final item in gameState.currentList) { + if (item.id == ownerId) { + if (item is Monster && + item.isAlly && + (gameState.allyDeckInOGGloom || + !GameMethods.isOgGloomEdition())) { + deck = gameState.modifierDeckAllies; + } + if (item is Character) { + deck = item.characterState.modifierDeck; + } + } + } + } + deck?.addRemovableValue(stateAccess, gfx, change); + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdAddEnfeeble; + } + return commandL10n.cmdRemoveEnfeeble; + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_health_command.dart b/server/lib/core/commands/change_stat_commands/change_health_command.dart new file mode 100644 index 0000000..8d6b6f4 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_health_command.dart @@ -0,0 +1,54 @@ +import '../../game_event.dart'; +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeHealthCommand extends ChangeStatCommand { + ChangeHealthCommand( + super.change, + super.figureId, + super.ownerId, { + required super.gameState, + }); + + @override + void execute() { + FigureState? figure = GameMethods.getFigure(ownerId, figureId); + if (figure != null) { + final previousValue = figure.health; + if (previousValue + change < 0) { + //no negative values + figure.setHealth(stateAccess, 0); + } else { + figure.setHealth(stateAccess, figure.health + change); + } + final newValue = figure.health; + if (previousValue <= 0 && newValue > 0) { + //un death + gameState.notifyListeners(); + } + + if (newValue <= 0) { + handleDeath(); + } + } + } + + @override + GameEvent get event => HealthChangedEvent(figureId, ownerId ?? '', change); + + @override + String describe() { + if (change > 0) { + //TODO: looks bad + return commandL10n.cmdIncreaseHealth(figureId, change); + } + FigureState? figure = GameMethods.getFigure(ownerId, figureId); + if (figure == null || figure.health <= 0) { + return commandL10n.cmdKill(ownerId ?? ''); + } + //TODO: incorrect for character summons + return commandL10n.cmdDecreaseHealth(ownerId ?? '', -change); + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_max_health_command.dart b/server/lib/core/commands/change_stat_commands/change_max_health_command.dart new file mode 100644 index 0000000..70b26d9 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_max_health_command.dart @@ -0,0 +1,44 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeMaxHealthCommand extends ChangeStatCommand { + ChangeMaxHealthCommand( + super.change, + super.figureId, + super.ownerId, { + required super.gameState, + }); + + @override + void execute() { + final FigureState? figure = GameMethods.getFigure(ownerId, figureId); + if (figure == null) return; + + int newValue = figure.maxHealth + change; + if (newValue <= 0) { + //can't lower maxvalue less than 1 + return; + } + + figure.setMaxHealth(stateAccess, newValue); + + //lower health if max health lowers + if (figure.maxHealth < figure.health) { + figure.setHealth(stateAccess, figure.maxHealth); + } + //if health same as max health, then let health follow? + if (figure.maxHealth - change == figure.health) { + figure.setHealth(stateAccess, figure.maxHealth); + } + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdIncreaseMaxHealth(ownerId ?? ''); + } + return commandL10n.cmdDecreaseMaxHealth(ownerId ?? ''); + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_stat_command.dart b/server/lib/core/commands/change_stat_commands/change_stat_command.dart new file mode 100644 index 0000000..3f94375 --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_stat_command.dart @@ -0,0 +1,92 @@ +import '../../enums.dart'; +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import '../command_l10n.dart'; + +abstract class ChangeStatCommand extends Command { + final String? ownerId; + int change; + final String figureId; + // Public so subclasses in other files can access it + final GameState gameState; + + ChangeStatCommand( + this.change, + this.figureId, + this.ownerId, { + required this.gameState, + }); + + void setChange(int change) { + this.change = change; + } + + void handleDeath() { + for (final item in gameState.currentList) { + if (item is Monster) { + _handleMonsterDeath(item); + } else if (item is Character) { + _handleCharacterDeath(item); + } + } + } + + void _handleMonsterDeath(Monster monster) { + final instances = monster.monsterInstances; + final deadIndex = instances.indexWhere((i) => i.health == 0); + if (deadIndex == -1) return; + + final int deadStandeeNr = instances[deadIndex].standeeNr; + final newList = List<MonsterInstance>.from(instances)..removeAt(deadIndex); + monster.setMonsterInstances(stateAccess, newList); + // A note tied to this specific defeated standee is deleted with it. + RoundMethods.removeNoteRowsForStandee( + stateAccess, + monster.id, + deadStandeeNr, + gameState: gameState, + ); + + if (monster.monsterInstances.isEmpty) { + monster.setActive(stateAccess, false); + if (gameState.roundState == RoundState.chooseInitiative) { + RoundMethods.sortCharactersFirst(stateAccess); + } + _notifyUpdateList(); + } + } + + void _handleCharacterDeath(Character character) { + if (character.characterState.health <= 0) { + gameState.notifyListeners(); + } + _handleSummonDeath(character); + } + + void _handleSummonDeath(Character character) { + for (final instance in character.characterState.summonList) { + if (instance.health == 0 && + !GameMethods.summonDoesNotDie(character.id, instance.name)) { + character.characterState.removeSummon(stateAccess, instance); + if (character.characterState.summonList.isEmpty) { + _notifyUpdateList(); + } else { + gameState.notifyListeners(); + } + break; + } + } + } + + /// The reference app delayed this list update by 600 ms while a turn was in + /// play so the removal animation could finish; server-side the update is + /// immediate. + void _notifyUpdateList() { + gameState.notifyListeners(); + } + + @override + String describe() { + return commandL10n.cmdChangeStat; + } +} diff --git a/server/lib/core/commands/change_stat_commands/change_xp_command.dart b/server/lib/core/commands/change_stat_commands/change_xp_command.dart new file mode 100644 index 0000000..423b16d --- /dev/null +++ b/server/lib/core/commands/change_stat_commands/change_xp_command.dart @@ -0,0 +1,28 @@ +import '../../game_methods.dart'; +import '../../state/game_state.dart'; +import 'change_stat_command.dart'; +import '../command_l10n.dart'; + +class ChangeXPCommand extends ChangeStatCommand { + ChangeXPCommand( + super.change, + super.figureId, + super.ownerId, { + required super.gameState, + }); + + @override + void execute() { + final figure = GameMethods.getFigure(ownerId, figureId); + if (figure is! CharacterState) return; + figure.setXp(stateAccess, figure.xp + change); + } + + @override + String describe() { + if (change > 0) { + return commandL10n.cmdIncreaseXp(figureId, change); + } + return commandL10n.cmdDecreaseXp(figureId, change.abs()); + } +} |
