summaryrefslogtreecommitdiff
path: root/server/lib/core/commands
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/core/commands')
-rw-r--r--server/lib/core/commands/activate_monster_type_command.dart53
-rw-r--r--server/lib/core/commands/add_character_command.dart47
-rw-r--r--server/lib/core/commands/add_condition_command.dart56
-rw-r--r--server/lib/core/commands/add_cs_party_card_command.dart26
-rw-r--r--server/lib/core/commands/add_faction_card_command.dart34
-rw-r--r--server/lib/core/commands/add_loot_card_command.dart19
-rw-r--r--server/lib/core/commands/add_monster_command.dart30
-rw-r--r--server/lib/core/commands/add_note_row_command.dart26
-rw-r--r--server/lib/core/commands/add_perk_command.dart28
-rw-r--r--server/lib/core/commands/add_special_loot_card_command.dart28
-rw-r--r--server/lib/core/commands/add_standee_command.dart64
-rw-r--r--server/lib/core/commands/amd_add_minus_one_command.dart22
-rw-r--r--server/lib/core/commands/amd_cassandra_special_command.dart30
-rw-r--r--server/lib/core/commands/amd_imbue1_command.dart19
-rw-r--r--server/lib/core/commands/amd_imbue2_command.dart19
-rw-r--r--server/lib/core/commands/amd_remove_imbue_command.dart20
-rw-r--r--server/lib/core/commands/amd_remove_minus_1_command.dart22
-rw-r--r--server/lib/core/commands/amd_remove_minus_2_command.dart32
-rw-r--r--server/lib/core/commands/amd_remove_plus_0_command.dart29
-rw-r--r--server/lib/core/commands/amd_reveal_command.dart27
-rw-r--r--server/lib/core/commands/bad_omen_command.dart32
-rw-r--r--server/lib/core/commands/change_name_command.dart28
-rw-r--r--server/lib/core/commands/change_stat_commands/change_bless_command.dart46
-rw-r--r--server/lib/core/commands/change_stat_commands/change_curse_command.dart46
-rw-r--r--server/lib/core/commands/change_stat_commands/change_empower_command.dart47
-rw-r--r--server/lib/core/commands/change_stat_commands/change_enfeeble_command.dart50
-rw-r--r--server/lib/core/commands/change_stat_commands/change_health_command.dart54
-rw-r--r--server/lib/core/commands/change_stat_commands/change_max_health_command.dart44
-rw-r--r--server/lib/core/commands/change_stat_commands/change_stat_command.dart92
-rw-r--r--server/lib/core/commands/change_stat_commands/change_xp_command.dart28
-rw-r--r--server/lib/core/commands/clear_unlocked_classes_command.dart16
-rw-r--r--server/lib/core/commands/command_l10n.dart20
-rw-r--r--server/lib/core/commands/command_registry.dart1109
-rw-r--r--server/lib/core/commands/corrosive_spew_command.dart22
-rw-r--r--server/lib/core/commands/donate_cs_sanctuary_command.dart22
-rw-r--r--server/lib/core/commands/draw_ability_card_command.dart28
-rw-r--r--server/lib/core/commands/draw_command.dart27
-rw-r--r--server/lib/core/commands/draw_loot_card_command.dart24
-rw-r--r--server/lib/core/commands/draw_modifier_card_command.dart29
-rw-r--r--server/lib/core/commands/enhance_loot_card_command.dart28
-rw-r--r--server/lib/core/commands/hide_ally_deck_command.dart16
-rw-r--r--server/lib/core/commands/ice_wraith_change_form_command.dart37
-rw-r--r--server/lib/core/commands/imbue_element_command.dart27
-rw-r--r--server/lib/core/commands/load_character_save_command.dart42
-rw-r--r--server/lib/core/commands/load_save_command.dart22
-rw-r--r--server/lib/core/commands/next_round_command.dart134
-rw-r--r--server/lib/core/commands/remove__special_loot_card_command.dart28
-rw-r--r--server/lib/core/commands/remove_amd_card_command.dart33
-rw-r--r--server/lib/core/commands/remove_card_command.dart38
-rw-r--r--server/lib/core/commands/remove_character_command.dart30
-rw-r--r--server/lib/core/commands/remove_condition_command.dart47
-rw-r--r--server/lib/core/commands/remove_cs_party_card_command.dart22
-rw-r--r--server/lib/core/commands/remove_cs_sanctuary_donation_command.dart24
-rw-r--r--server/lib/core/commands/remove_monster_command.dart24
-rw-r--r--server/lib/core/commands/remove_note_row_command.dart19
-rw-r--r--server/lib/core/commands/reorder_ability_list_command.dart31
-rw-r--r--server/lib/core/commands/reorder_list_command.dart23
-rw-r--r--server/lib/core/commands/reorder_modifier_list_command.dart28
-rw-r--r--server/lib/core/commands/return_loot_card_command.dart20
-rw-r--r--server/lib/core/commands/return_modifier_card_command.dart18
-rw-r--r--server/lib/core/commands/return_removed_amd_card_command.dart31
-rw-r--r--server/lib/core/commands/set_ally_deck_in_og_gloom_command.dart23
-rw-r--r--server/lib/core/commands/set_as_summon_command.dart37
-rw-r--r--server/lib/core/commands/set_auto_level_adjust_command.dart21
-rw-r--r--server/lib/core/commands/set_campaign_command.dart18
-rw-r--r--server/lib/core/commands/set_character_level_command.dart19
-rw-r--r--server/lib/core/commands/set_difficulty_command.dart21
-rw-r--r--server/lib/core/commands/set_figure_note_command.dart30
-rw-r--r--server/lib/core/commands/set_init_command.dart26
-rw-r--r--server/lib/core/commands/set_level_command.dart22
-rw-r--r--server/lib/core/commands/set_loot_owner_command.dart19
-rw-r--r--server/lib/core/commands/set_note_row_color_command.dart30
-rw-r--r--server/lib/core/commands/set_note_row_link_command.dart35
-rw-r--r--server/lib/core/commands/set_note_row_text_command.dart27
-rw-r--r--server/lib/core/commands/set_scenario_command.dart26
-rw-r--r--server/lib/core/commands/set_solo_command.dart22
-rw-r--r--server/lib/core/commands/show_ally_deck_command.dart16
-rw-r--r--server/lib/core/commands/shuffle_ability_card_command.dart26
-rw-r--r--server/lib/core/commands/shuffle_amd_card_command.dart22
-rw-r--r--server/lib/core/commands/shuffle_drawn_ability_card_command.dart26
-rw-r--r--server/lib/core/commands/track_standees_command.dart48
-rw-r--r--server/lib/core/commands/turn_done_command.dart34
-rw-r--r--server/lib/core/commands/unlock_special_command.dart32
-rw-r--r--server/lib/core/commands/use_element_command.dart21
-rw-r--r--server/lib/core/commands/use_fh_perks_command.dart28
85 files changed, 3746 insertions, 0 deletions
diff --git a/server/lib/core/commands/activate_monster_type_command.dart b/server/lib/core/commands/activate_monster_type_command.dart
new file mode 100644
index 0000000..cc967ec
--- /dev/null
+++ b/server/lib/core/commands/activate_monster_type_command.dart
@@ -0,0 +1,53 @@
+import '../enums.dart';
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ActivateMonsterTypeCommand extends Command {
+ final String name;
+ final bool activate;
+ final GameState _gameState;
+
+ ActivateMonsterTypeCommand(
+ this.name,
+ this.activate, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ Monster? monster;
+ for (final item in _gameState.currentList) {
+ if (item.id == name) {
+ if (item is Monster) {
+ item.setActive(stateAccess, activate);
+ monster = item;
+ }
+ }
+ }
+ if (activate) {
+ final roundState = _gameState.roundState;
+ if (roundState == RoundState.chooseInitiative) {
+ RoundMethods.sortCharactersFirst(stateAccess);
+ } else if (roundState == RoundState.playTurns) {
+ DeckMethods.drawAbilityCardFromInactiveDeck(stateAccess);
+ if (monster != null) {
+ RoundMethods.sortItemToPlace(
+ stateAccess,
+ name,
+ GameMethods.getInitiative(monster),
+ );
+ }
+ }
+ }
+ _gameState.notifyListeners();
+ }
+
+ @override
+ String describe() {
+ if (activate) {
+ return commandL10n.cmdActivateMonster(name);
+ }
+ return commandL10n.cmdDeactivateMonster(name);
+ }
+}
diff --git a/server/lib/core/commands/add_character_command.dart b/server/lib/core/commands/add_character_command.dart
new file mode 100644
index 0000000..8510927
--- /dev/null
+++ b/server/lib/core/commands/add_character_command.dart
@@ -0,0 +1,47 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddCharacterCommand extends Command {
+ final String _id;
+ final String _edition;
+ final int _level;
+ final String? _display;
+ Character? character;
+
+ AddCharacterCommand(this._id, this._edition, this._display, this._level) {
+ final created = CharacterMethods.createCharacter(
+ stateAccess,
+ _id,
+ _edition,
+ _display,
+ _level,
+ );
+ if (created == null) {
+ throw StateError(
+ 'AddCharacterCommand: character class not found: $_id (edition: $_edition)',
+ );
+ }
+ character = created;
+ }
+
+ @override
+ void execute() {
+ final char = character;
+ if (char == null) return;
+ //add new character on top of list
+ RoundMethods.addToMainList(stateAccess, 0, char);
+
+ if (!GameMethods.isObjectiveOrEscort(char.characterClass)) {
+ ScenarioMethods.applyDifficulty(stateAccess);
+ }
+
+ RoundMethods.updateForSpecialRules(stateAccess);
+ ScenarioMethods.unlockClass(stateAccess, char.characterClass.id);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddCharacter(_id);
+ }
+}
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());
+ }
+}
diff --git a/server/lib/core/commands/add_cs_party_card_command.dart b/server/lib/core/commands/add_cs_party_card_command.dart
new file mode 100644
index 0000000..4f59e4b
--- /dev/null
+++ b/server/lib/core/commands/add_cs_party_card_command.dart
@@ -0,0 +1,26 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddCSPartyCardCommand extends Command {
+ final String characterId;
+ final int type;
+ final GameState _gameState;
+
+ AddCSPartyCardCommand(
+ this.characterId,
+ this.type, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState);
+ deck.addCSPartyCard(stateAccess, type);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddPartyCard(characterId, type.toString());
+ }
+}
diff --git a/server/lib/core/commands/add_faction_card_command.dart b/server/lib/core/commands/add_faction_card_command.dart
new file mode 100644
index 0000000..00bbf0d
--- /dev/null
+++ b/server/lib/core/commands/add_faction_card_command.dart
@@ -0,0 +1,34 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddFactionCardCommand extends Command {
+ final String characterId;
+ final String cardId;
+ final bool add;
+ final GameState _gameState;
+
+ AddFactionCardCommand(
+ this.characterId,
+ this.cardId,
+ this.add, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState);
+ if (add) {
+ deck.addCard(stateAccess, cardId, CardType.add);
+ } else {
+ deck.removeCard(stateAccess, cardId);
+ }
+ }
+
+ @override
+ String describe() {
+ return add
+ ? commandL10n.cmdAddFactionCard(characterId)
+ : commandL10n.cmdRemoveFactionCard(characterId);
+ }
+}
diff --git a/server/lib/core/commands/add_loot_card_command.dart b/server/lib/core/commands/add_loot_card_command.dart
new file mode 100644
index 0000000..9e446c5
--- /dev/null
+++ b/server/lib/core/commands/add_loot_card_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddLootCardCommand extends Command {
+ AddLootCardCommand(this.resourceType, {required GameState gameState})
+ : _gameState = gameState;
+ final String resourceType;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ _gameState.lootDeck.addExtraCard(stateAccess, resourceType);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddLootCard(resourceType);
+ }
+}
diff --git a/server/lib/core/commands/add_monster_command.dart b/server/lib/core/commands/add_monster_command.dart
new file mode 100644
index 0000000..0aeba27
--- /dev/null
+++ b/server/lib/core/commands/add_monster_command.dart
@@ -0,0 +1,30 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddMonsterCommand extends Command {
+ final String _name;
+ final int? _level;
+ final bool _isAlly;
+ Monster? monster;
+
+ AddMonsterCommand(
+ this._name,
+ this._level,
+ this._isAlly, {
+ required GameState gameState,
+ }) {
+ monster = MonsterMethods.createMonster(stateAccess, _name, _level, _isAlly);
+ }
+
+ @override
+ void execute() {
+ final m = monster;
+ if (m == null) return;
+ RoundMethods.addToMainList(stateAccess, null, m);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddMonster(monster?.type.display ?? '');
+ }
+}
diff --git a/server/lib/core/commands/add_note_row_command.dart b/server/lib/core/commands/add_note_row_command.dart
new file mode 100644
index 0000000..ff4d32f
--- /dev/null
+++ b/server/lib/core/commands/add_note_row_command.dart
@@ -0,0 +1,26 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+/// Adds a [NoteRow] to the main list. If the note is linked, the list's reflow
+/// step positions it directly beneath its target; otherwise it is appended.
+class AddNoteRowCommand extends Command {
+ AddNoteRowCommand(this.noteRow, {required GameState gameState})
+ : _gameState = gameState;
+ final NoteRow noteRow;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ RoundMethods.addToMainList(
+ stateAccess,
+ null,
+ noteRow,
+ gameState: _gameState,
+ );
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddNoteRow;
+ }
+}
diff --git a/server/lib/core/commands/add_perk_command.dart b/server/lib/core/commands/add_perk_command.dart
new file mode 100644
index 0000000..c961e05
--- /dev/null
+++ b/server/lib/core/commands/add_perk_command.dart
@@ -0,0 +1,28 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddPerkCommand extends Command {
+ final String characterId;
+ final int index;
+
+ AddPerkCommand(this.characterId, this.index);
+
+ @override
+ void execute() {
+ Character? character = GameMethods.getCharacterByName(characterId);
+ if (character != null) {
+ character.flipPerk(stateAccess, index);
+ }
+ }
+
+ @override
+ String describe() {
+ Character? character = GameMethods.getCharacterByName(characterId);
+ final charId = character?.id ?? characterId;
+ if (character != null && !character.characterState.perkList[index]) {
+ return commandL10n.cmdRemovePerk(charId, index);
+ }
+ return commandL10n.cmdAddPerk(charId, index);
+ }
+}
diff --git a/server/lib/core/commands/add_special_loot_card_command.dart b/server/lib/core/commands/add_special_loot_card_command.dart
new file mode 100644
index 0000000..3f34aed
--- /dev/null
+++ b/server/lib/core/commands/add_special_loot_card_command.dart
@@ -0,0 +1,28 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AddSpecialLootCardCommand extends Command {
+ static const int _kCard1418 = 1418;
+ static const int _kCard1419 = 1419;
+
+ int nr;
+ final GameState _gameState;
+
+ AddSpecialLootCardCommand(this.nr, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ if (nr == _kCard1418) {
+ _gameState.lootDeck.addSpecial1418(stateAccess);
+ }
+ if (nr == _kCard1419) {
+ _gameState.lootDeck.addSpecial1419(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddSpecialLootCard(nr);
+ }
+}
diff --git a/server/lib/core/commands/add_standee_command.dart b/server/lib/core/commands/add_standee_command.dart
new file mode 100644
index 0000000..ec10701
--- /dev/null
+++ b/server/lib/core/commands/add_standee_command.dart
@@ -0,0 +1,64 @@
+import 'package:x_haven_server/core/state/game_state.dart';
+
+import '../enums.dart';
+import 'command_l10n.dart';
+
+class AddStandeeCommand extends Command {
+ final int nr;
+ final SummonData? summon;
+ final MonsterType type;
+ final String ownerId;
+ final bool addAsSummon;
+ final GameState _gameState;
+
+ AddStandeeCommand(
+ this.nr,
+ this.summon,
+ this.ownerId,
+ this.type,
+ this.addAsSummon, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ MonsterMethods.executeAddStandee(
+ stateAccess,
+ nr,
+ summon,
+ type,
+ ownerId,
+ addAsSummon,
+ );
+
+ _gameState.notifyListeners();
+ }
+
+ @override
+ String describe() {
+ final sum = summon;
+ String name = sum == null ? ownerId : sum.name;
+
+ return commandL10n.cmdAddStandee(name, nr);
+ }
+}
+
+class SummonData {
+ int standeeNr;
+ String name;
+ int health;
+ int move;
+ int attack;
+ int range;
+ String gfx;
+
+ SummonData(
+ this.standeeNr,
+ this.name,
+ this.health,
+ this.move,
+ this.attack,
+ this.range,
+ this.gfx,
+ );
+}
diff --git a/server/lib/core/commands/amd_add_minus_one_command.dart b/server/lib/core/commands/amd_add_minus_one_command.dart
new file mode 100644
index 0000000..8958dba
--- /dev/null
+++ b/server/lib/core/commands/amd_add_minus_one_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AmdAddMinusOneCommand extends Command {
+ String name;
+ final GameState _gameState;
+
+ AmdAddMinusOneCommand(this.name, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.addMinusOne(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAddMinusOne;
+ }
+}
diff --git a/server/lib/core/commands/amd_cassandra_special_command.dart b/server/lib/core/commands/amd_cassandra_special_command.dart
new file mode 100644
index 0000000..b1d1d5f
--- /dev/null
+++ b/server/lib/core/commands/amd_cassandra_special_command.dart
@@ -0,0 +1,30 @@
+import 'package:x_haven_server/core/game_methods.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDCassandraSpecialCommand extends Command {
+ String deckId;
+ bool on;
+ final GameState _gameState;
+
+ AMDCassandraSpecialCommand(
+ this.deckId,
+ this.on, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = GameMethods.getModifierDeck(deckId, _gameState);
+ deck.setCassandraSpecial(stateAccess, on);
+ }
+
+ @override
+ String describe() {
+ if (on) {
+ return commandL10n.cmdCassandraLeaveRevealed(deckId);
+ }
+ return commandL10n.cmdCassandraSpecialOff(deckId);
+ }
+}
diff --git a/server/lib/core/commands/amd_imbue1_command.dart b/server/lib/core/commands/amd_imbue1_command.dart
new file mode 100644
index 0000000..3cf52bc
--- /dev/null
+++ b/server/lib/core/commands/amd_imbue1_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDImbue1Command extends Command {
+ final GameState _gameState;
+
+ AMDImbue1Command({required GameState gameState}) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = _gameState.modifierDeck;
+ deck.setImbue1(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdImbueMonsterDeck;
+ }
+}
diff --git a/server/lib/core/commands/amd_imbue2_command.dart b/server/lib/core/commands/amd_imbue2_command.dart
new file mode 100644
index 0000000..891d1f0
--- /dev/null
+++ b/server/lib/core/commands/amd_imbue2_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDImbue2Command extends Command {
+ final GameState _gameState;
+
+ AMDImbue2Command({required GameState gameState}) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = _gameState.modifierDeck;
+ deck.setImbue2(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdAdvancedImbueMonsterDeck;
+ }
+}
diff --git a/server/lib/core/commands/amd_remove_imbue_command.dart b/server/lib/core/commands/amd_remove_imbue_command.dart
new file mode 100644
index 0000000..0b37b5b
--- /dev/null
+++ b/server/lib/core/commands/amd_remove_imbue_command.dart
@@ -0,0 +1,20 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDRemoveImbueCommand extends Command {
+ final GameState _gameState;
+
+ AMDRemoveImbueCommand({required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = _gameState.modifierDeck;
+ deck.resetImbue(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveImbueMonsterDeck;
+ }
+}
diff --git a/server/lib/core/commands/amd_remove_minus_1_command.dart b/server/lib/core/commands/amd_remove_minus_1_command.dart
new file mode 100644
index 0000000..506c6fd
--- /dev/null
+++ b/server/lib/core/commands/amd_remove_minus_1_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDRemoveMinus1Command extends Command {
+ String name;
+ final GameState _gameState;
+
+ AMDRemoveMinus1Command(this.name, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.removeMinusOne(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveMinusOne;
+ }
+}
diff --git a/server/lib/core/commands/amd_remove_minus_2_command.dart b/server/lib/core/commands/amd_remove_minus_2_command.dart
new file mode 100644
index 0000000..401cc8c
--- /dev/null
+++ b/server/lib/core/commands/amd_remove_minus_2_command.dart
@@ -0,0 +1,32 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDRemoveMinus2Command extends Command {
+ bool allies;
+ bool remove = false;
+ final GameState _gameState;
+
+ AMDRemoveMinus2Command(this.allies, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = _gameState.modifierDeck;
+ if (allies) {
+ deck = _gameState.modifierDeckAllies;
+ }
+ remove = deck.hasMinus2();
+ if (remove) {
+ deck.removeMinusTwo(stateAccess);
+ } else {
+ deck.addMinusTwo(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return remove
+ ? commandL10n.cmdRemoveMinusTwo
+ : commandL10n.cmdAddBackMinusTwo;
+ }
+}
diff --git a/server/lib/core/commands/amd_remove_plus_0_command.dart b/server/lib/core/commands/amd_remove_plus_0_command.dart
new file mode 100644
index 0000000..c6878e0
--- /dev/null
+++ b/server/lib/core/commands/amd_remove_plus_0_command.dart
@@ -0,0 +1,29 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AmdRemovePlus0Command extends Command {
+ final String name;
+ final bool remove;
+ final GameState _gameState;
+
+ AmdRemovePlus0Command(this.name, this.remove, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ if (remove) {
+ deck.moveCardToRemovedPile(stateAccess, "plus0");
+ } else {
+ deck.restoreCardFromRemovedPile(stateAccess, "plus0", CardType.add);
+ }
+ }
+
+ @override
+ String describe() {
+ return remove
+ ? commandL10n.cmdRemovePlusZero
+ : commandL10n.cmdAddBackPlusZero;
+ }
+}
diff --git a/server/lib/core/commands/amd_reveal_command.dart b/server/lib/core/commands/amd_reveal_command.dart
new file mode 100644
index 0000000..1a0a1a3
--- /dev/null
+++ b/server/lib/core/commands/amd_reveal_command.dart
@@ -0,0 +1,27 @@
+import 'package:x_haven_server/core/game_methods.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class AMDRevealCommand extends Command {
+ final int amount;
+ final String name;
+ final GameState _gameState;
+
+ AMDRevealCommand({
+ required this.amount,
+ required this.name,
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.revealCards(stateAccess, amount);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRevealModifierCards(amount);
+ }
+}
diff --git a/server/lib/core/commands/bad_omen_command.dart b/server/lib/core/commands/bad_omen_command.dart
new file mode 100644
index 0000000..71fd85b
--- /dev/null
+++ b/server/lib/core/commands/bad_omen_command.dart
@@ -0,0 +1,32 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class BadOmenCommand extends Command {
+ static const int _kBadOmenIncrement = 6;
+
+ final bool allies;
+ final GameState _gameState;
+
+ BadOmenCommand(this.allies, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ if (allies) {
+ _gameState.modifierDeckAllies.setBadOmen(
+ stateAccess,
+ _gameState.modifierDeckAllies.badOmen + _kBadOmenIncrement,
+ );
+ } else {
+ _gameState.modifierDeck.setBadOmen(
+ stateAccess,
+ _gameState.modifierDeck.badOmen + _kBadOmenIncrement,
+ );
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.badOmen;
+ }
+}
diff --git a/server/lib/core/commands/change_name_command.dart b/server/lib/core/commands/change_name_command.dart
new file mode 100644
index 0000000..9a99da2
--- /dev/null
+++ b/server/lib/core/commands/change_name_command.dart
@@ -0,0 +1,28 @@
+import 'package:collection/collection.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ChangeNameCommand extends Command {
+ ChangeNameCommand(this.name, this.characterId, {required GameState gameState})
+ : _gameState = gameState;
+ final String name;
+ final String characterId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final match = _gameState.currentList.firstWhereOrNull(
+ (element) => element.id == characterId,
+ );
+ final Character? character = match is Character ? match : null;
+ if (character != null) {
+ character.characterState.setDisplay(stateAccess, name);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdChangeName;
+ }
+}
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());
+ }
+}
diff --git a/server/lib/core/commands/clear_unlocked_classes_command.dart b/server/lib/core/commands/clear_unlocked_classes_command.dart
new file mode 100644
index 0000000..78b17c6
--- /dev/null
+++ b/server/lib/core/commands/clear_unlocked_classes_command.dart
@@ -0,0 +1,16 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ClearUnlockedClassesCommand extends Command {
+ ClearUnlockedClassesCommand();
+
+ @override
+ void execute() {
+ ScenarioMethods.clearUnlockedClasses(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdClearUnlockedClasses;
+ }
+}
diff --git a/server/lib/core/commands/command_l10n.dart b/server/lib/core/commands/command_l10n.dart
new file mode 100644
index 0000000..ee11e78
--- /dev/null
+++ b/server/lib/core/commands/command_l10n.dart
@@ -0,0 +1,20 @@
+import 'package:x_haven_server/core/l10n/app_localizations.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../settings.dart';
+
+Locale _parseLocale(String code) {
+ final parts = code.split('_');
+ return parts.length == 2 ? Locale(parts[0], parts[1]) : Locale(parts[0]);
+}
+
+/// The localized command-description strings, selected by the server locale
+/// setting. Falls back to English on any error (as in the reference app).
+AppLocalizations get commandL10n {
+ try {
+ final code = getIt<Settings>().locale;
+ return lookupAppLocalizations(_parseLocale(code));
+ } catch (_) {
+ return lookupAppLocalizations(const Locale('en'));
+ }
+}
diff --git a/server/lib/core/commands/command_registry.dart b/server/lib/core/commands/command_registry.dart
new file mode 100644
index 0000000..9a05b97
--- /dev/null
+++ b/server/lib/core/commands/command_registry.dart
@@ -0,0 +1,1109 @@
+/// Command registry: wire name → command construction.
+///
+/// The Phase 2 network layer receives `{name, args}` messages from clients
+/// and calls [buildCommand] to turn them into a [Command] for the
+/// `ActionHandler`. [commandName] is the reverse lookup (runtime type →
+/// wire name), used by describe/tests.
+///
+/// Conventions (PORTING.md §9):
+///
+/// * Wire names are the class name minus the `Command` suffix in
+/// lower-camel case (acronym runs lower-cased in full): `DrawCommand` →
+/// `draw`, `AddMonsterCommand` → `addMonster`, `ChangeHealthCommand` →
+/// `changeHealth`, `AMDCassandraSpecialCommand` → `amdCassandraSpecial`.
+/// The wire name comes from the class name, never the file name (the file
+/// `remove__special_loot_card_command.dart` holds `RemoveSpecialLootCardCommand`
+/// → `removeSpecialLootCard`).
+/// * Args are a JSON `Map<String, dynamic>`. The wire keys are the
+/// constructor parameter names — positional parameters in positional
+/// order, leading underscores stripped — e.g. `AddPerkCommand(characterId,
+/// index)` takes `{'characterId': ..., 'index': ...}`.
+/// * Optional parameters may be omitted or given as JSON `null`.
+/// * `GameState`, `Settings` and `GameData` are never wire args — they are
+/// injected from the service locator (see [buildCommand]).
+/// * Enums travel as name strings (`'chill'`, `'fire'`, `'elite'`, ...).
+/// Complex object args are resolved against the live game state (see the
+/// per-entry doc comments in [_registry]).
+///
+/// Any failure — unknown command, missing required arg, wrong JSON type,
+/// unknown enum value, unresolvable object reference — is reported as
+/// [CommandRegistryError] with a human-readable message naming the command
+/// and the arg. Failures thrown by a command's own constructor (e.g.
+/// `AddCharacterCommand` for an unknown character id) are wrapped the same
+/// way so the network layer only ever sees [CommandRegistryError].
+library;
+
+import 'package:x_haven_server/core/commands/activate_monster_type_command.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/add_cs_party_card_command.dart';
+import 'package:x_haven_server/core/commands/add_faction_card_command.dart';
+import 'package:x_haven_server/core/commands/add_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_note_row_command.dart';
+import 'package:x_haven_server/core/commands/add_perk_command.dart';
+import 'package:x_haven_server/core/commands/add_special_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/amd_add_minus_one_command.dart';
+import 'package:x_haven_server/core/commands/amd_cassandra_special_command.dart';
+import 'package:x_haven_server/core/commands/amd_imbue1_command.dart';
+import 'package:x_haven_server/core/commands/amd_imbue2_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_imbue_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_minus_1_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_minus_2_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_plus_0_command.dart';
+import 'package:x_haven_server/core/commands/amd_reveal_command.dart';
+import 'package:x_haven_server/core/commands/bad_omen_command.dart';
+import 'package:x_haven_server/core/commands/change_name_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_bless_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_curse_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_empower_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_enfeeble_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_max_health_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_xp_command.dart';
+import 'package:x_haven_server/core/commands/clear_unlocked_classes_command.dart';
+import 'package:x_haven_server/core/commands/corrosive_spew_command.dart';
+import 'package:x_haven_server/core/commands/donate_cs_sanctuary_command.dart';
+import 'package:x_haven_server/core/commands/draw_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/commands/draw_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/draw_modifier_card_command.dart';
+import 'package:x_haven_server/core/commands/enhance_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/hide_ally_deck_command.dart';
+import 'package:x_haven_server/core/commands/ice_wraith_change_form_command.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/commands/load_character_save_command.dart';
+import 'package:x_haven_server/core/commands/load_save_command.dart';
+import 'package:x_haven_server/core/commands/next_round_command.dart';
+import 'package:x_haven_server/core/commands/remove__special_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_amd_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_character_command.dart';
+import 'package:x_haven_server/core/commands/remove_condition_command.dart';
+import 'package:x_haven_server/core/commands/remove_cs_party_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_cs_sanctuary_donation_command.dart';
+import 'package:x_haven_server/core/commands/remove_monster_command.dart';
+import 'package:x_haven_server/core/commands/remove_note_row_command.dart';
+import 'package:x_haven_server/core/commands/reorder_ability_list_command.dart';
+import 'package:x_haven_server/core/commands/reorder_list_command.dart';
+import 'package:x_haven_server/core/commands/reorder_modifier_list_command.dart';
+import 'package:x_haven_server/core/commands/return_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/return_modifier_card_command.dart';
+import 'package:x_haven_server/core/commands/return_removed_amd_card_command.dart';
+import 'package:x_haven_server/core/commands/set_ally_deck_in_og_gloom_command.dart';
+import 'package:x_haven_server/core/commands/set_as_summon_command.dart';
+import 'package:x_haven_server/core/commands/set_auto_level_adjust_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_character_level_command.dart';
+import 'package:x_haven_server/core/commands/set_difficulty_command.dart';
+import 'package:x_haven_server/core/commands/set_figure_note_command.dart';
+import 'package:x_haven_server/core/commands/set_init_command.dart';
+import 'package:x_haven_server/core/commands/set_level_command.dart';
+import 'package:x_haven_server/core/commands/set_loot_owner_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_color_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_link_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_text_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/commands/set_solo_command.dart';
+import 'package:x_haven_server/core/commands/show_ally_deck_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_amd_card_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_drawn_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/track_standees_command.dart';
+import 'package:x_haven_server/core/commands/turn_done_command.dart';
+import 'package:x_haven_server/core/commands/unlock_special_command.dart';
+import 'package:x_haven_server/core/commands/use_element_command.dart';
+import 'package:x_haven_server/core/commands/use_fh_perks_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_data.dart';
+import 'package:x_haven_server/core/models/monster_ability.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+
+/// One entry: wire name, arg parsing/validation, and command construction.
+class CommandDescriptor {
+ const CommandDescriptor(this.name, this.construct);
+ final String name; // e.g. 'draw', 'addMonster', 'changeHealth'
+ final Command Function(GameState gameState, Map<String, dynamic> args)
+ construct;
+}
+
+/// Thrown for unknown command names or invalid/missing args.
+class CommandRegistryError implements Exception {
+ CommandRegistryError(this.message);
+ final String message;
+ @override
+ String toString() => 'CommandRegistryError: $message';
+}
+
+/// Builds a [Command] from a wire name + JSON arg map.
+///
+/// Throws [CommandRegistryError] with a human-readable message on unknown
+/// names, invalid/missing args, or command-construction failure.
+Command buildCommand(
+ String name,
+ Map<String, dynamic> args,
+ GameState gameState,
+) {
+ final descriptor = _registry[name];
+ if (descriptor == null) {
+ throw CommandRegistryError(
+ 'Unknown command "$name". '
+ 'Known commands: ${_registry.keys.join(', ')}',
+ );
+ }
+ try {
+ return descriptor.construct(gameState, args);
+ } on StateError catch (error, stackTrace) {
+ Error.throwWithStackTrace(
+ CommandRegistryError('Command "$name": ${error.message}'),
+ stackTrace,
+ );
+ } on ArgumentError catch (error, stackTrace) {
+ Error.throwWithStackTrace(
+ CommandRegistryError(
+ 'Command "$name": ${error.message ?? 'invalid arguments'}',
+ ),
+ stackTrace,
+ );
+ }
+}
+
+/// Reverse lookup (for describe/tests): wire name of [command]'s runtime
+/// type.
+///
+/// Throws [CommandRegistryError] if [command]'s type is not registered.
+String commandName(Command command) {
+ final name = _nameByType[command.runtimeType];
+ if (name == null) {
+ throw CommandRegistryError(
+ 'No wire name registered for ${command.runtimeType}',
+ );
+ }
+ return name;
+}
+
+/// All registered commands, wire name → [CommandDescriptor].
+final Map<String, CommandDescriptor> _registry = {
+ 'activateMonsterType': CommandDescriptor(
+ 'activateMonsterType',
+ (gs, args) => ActivateMonsterTypeCommand(
+ _str('activateMonsterType', 'name', args),
+ _bool('activateMonsterType', 'activate', args),
+ gameState: gs,
+ ),
+ ),
+ 'addCharacter': CommandDescriptor(
+ 'addCharacter',
+ (gs, args) => AddCharacterCommand(
+ _str('addCharacter', 'id', args),
+ _str('addCharacter', 'edition', args),
+ _strOr('addCharacter', 'display', args),
+ _int('addCharacter', 'level', args),
+ ),
+ ),
+ 'addCondition': CommandDescriptor(
+ 'addCondition',
+ (gs, args) => AddConditionCommand(
+ _condition('addCondition', 'condition', args),
+ _str('addCondition', 'figureId', args),
+ _strOr('addCondition', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'addCSPartyCard': CommandDescriptor(
+ 'addCSPartyCard',
+ (gs, args) => AddCSPartyCardCommand(
+ _str('addCSPartyCard', 'characterId', args),
+ _int('addCSPartyCard', 'type', args),
+ gameState: gs,
+ ),
+ ),
+ 'addFactionCard': CommandDescriptor(
+ 'addFactionCard',
+ (gs, args) => AddFactionCardCommand(
+ _str('addFactionCard', 'characterId', args),
+ _str('addFactionCard', 'cardId', args),
+ _bool('addFactionCard', 'add', args),
+ gameState: gs,
+ ),
+ ),
+ 'addLootCard': CommandDescriptor(
+ 'addLootCard',
+ (gs, args) => AddLootCardCommand(
+ _str('addLootCard', 'resourceType', args),
+ gameState: gs,
+ ),
+ ),
+ 'addMonster': CommandDescriptor(
+ 'addMonster',
+ (gs, args) => AddMonsterCommand(
+ _str('addMonster', 'name', args),
+ _intOr('addMonster', 'level', args),
+ _bool('addMonster', 'isAlly', args),
+ gameState: gs,
+ ),
+ ),
+ // `noteRow` is a JSON object `{id, text, color, linkedId, standeeNr}`;
+ // `id` is a client-generated unique string.
+ 'addNoteRow': CommandDescriptor(
+ 'addNoteRow',
+ (gs, args) =>
+ AddNoteRowCommand(_noteRow('addNoteRow', args), gameState: gs),
+ ),
+ 'addPerk': CommandDescriptor(
+ 'addPerk',
+ (gs, args) => AddPerkCommand(
+ _str('addPerk', 'characterId', args),
+ _int('addPerk', 'index', args),
+ ),
+ ),
+ 'addSpecialLootCard': CommandDescriptor(
+ 'addSpecialLootCard',
+ (gs, args) => AddSpecialLootCardCommand(
+ _int('addSpecialLootCard', 'nr', args),
+ gameState: gs,
+ ),
+ ),
+ // `summon` is an optional JSON object
+ // `{standeeNr, name, health, move, attack, range, gfx}`; absent/null → null.
+ 'addStandee': CommandDescriptor(
+ 'addStandee',
+ (gs, args) => AddStandeeCommand(
+ _int('addStandee', 'nr', args),
+ _summonData('addStandee', args),
+ _str('addStandee', 'ownerId', args),
+ _monsterType('addStandee', 'type', args),
+ _bool('addStandee', 'addAsSummon', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdAddMinusOne': CommandDescriptor(
+ 'amdAddMinusOne',
+ (gs, args) => AmdAddMinusOneCommand(
+ _str('amdAddMinusOne', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdCassandraSpecial': CommandDescriptor(
+ 'amdCassandraSpecial',
+ (gs, args) => AMDCassandraSpecialCommand(
+ _str('amdCassandraSpecial', 'deckId', args),
+ _bool('amdCassandraSpecial', 'on', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdImbue1': CommandDescriptor(
+ 'amdImbue1',
+ (gs, args) => AMDImbue1Command(gameState: gs),
+ ),
+ 'amdImbue2': CommandDescriptor(
+ 'amdImbue2',
+ (gs, args) => AMDImbue2Command(gameState: gs),
+ ),
+ 'amdRemoveImbue': CommandDescriptor(
+ 'amdRemoveImbue',
+ (gs, args) => AMDRemoveImbueCommand(gameState: gs),
+ ),
+ 'amdRemoveMinus1': CommandDescriptor(
+ 'amdRemoveMinus1',
+ (gs, args) => AMDRemoveMinus1Command(
+ _str('amdRemoveMinus1', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdRemoveMinus2': CommandDescriptor(
+ 'amdRemoveMinus2',
+ (gs, args) => AMDRemoveMinus2Command(
+ _bool('amdRemoveMinus2', 'allies', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdRemovePlus0': CommandDescriptor(
+ 'amdRemovePlus0',
+ (gs, args) => AmdRemovePlus0Command(
+ _str('amdRemovePlus0', 'name', args),
+ _bool('amdRemovePlus0', 'remove', args),
+ gameState: gs,
+ ),
+ ),
+ 'amdReveal': CommandDescriptor(
+ 'amdReveal',
+ (gs, args) => AMDRevealCommand(
+ amount: _int('amdReveal', 'amount', args),
+ name: _str('amdReveal', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'badOmen': CommandDescriptor(
+ 'badOmen',
+ (gs, args) =>
+ BadOmenCommand(_bool('badOmen', 'allies', args), gameState: gs),
+ ),
+ 'changeBless': CommandDescriptor(
+ 'changeBless',
+ (gs, args) => ChangeBlessCommand(
+ _int('changeBless', 'change', args),
+ _str('changeBless', 'figureId', args),
+ _strOr('changeBless', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeCurse': CommandDescriptor(
+ 'changeCurse',
+ (gs, args) => ChangeCurseCommand(
+ _int('changeCurse', 'change', args),
+ _str('changeCurse', 'figureId', args),
+ _strOr('changeCurse', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeEmpower': CommandDescriptor(
+ 'changeEmpower',
+ (gs, args) => ChangeEmpowerCommand(
+ _int('changeEmpower', 'change', args),
+ _str('changeEmpower', 'gfx', args),
+ _str('changeEmpower', 'figureId', args),
+ _strOr('changeEmpower', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeEnfeeble': CommandDescriptor(
+ 'changeEnfeeble',
+ (gs, args) => ChangeEnfeebleCommand(
+ _int('changeEnfeeble', 'change', args),
+ _str('changeEnfeeble', 'gfx', args),
+ _str('changeEnfeeble', 'figureId', args),
+ _strOr('changeEnfeeble', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeHealth': CommandDescriptor(
+ 'changeHealth',
+ (gs, args) => ChangeHealthCommand(
+ _int('changeHealth', 'change', args),
+ _str('changeHealth', 'figureId', args),
+ _strOr('changeHealth', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeMaxHealth': CommandDescriptor(
+ 'changeMaxHealth',
+ (gs, args) => ChangeMaxHealthCommand(
+ _int('changeMaxHealth', 'change', args),
+ _str('changeMaxHealth', 'figureId', args),
+ _strOr('changeMaxHealth', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeName': CommandDescriptor(
+ 'changeName',
+ (gs, args) => ChangeNameCommand(
+ _str('changeName', 'name', args),
+ _str('changeName', 'characterId', args),
+ gameState: gs,
+ ),
+ ),
+ 'changeXP': CommandDescriptor(
+ 'changeXP',
+ (gs, args) => ChangeXPCommand(
+ _int('changeXP', 'change', args),
+ _str('changeXP', 'figureId', args),
+ _strOr('changeXP', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'clearUnlockedClasses': CommandDescriptor(
+ 'clearUnlockedClasses',
+ (gs, args) => ClearUnlockedClassesCommand(),
+ ),
+ 'corrosiveSpew': CommandDescriptor(
+ 'corrosiveSpew',
+ (gs, args) => CorrosiveSpewCommand(gameState: gs),
+ ),
+ 'donateCSSanctuary': CommandDescriptor(
+ 'donateCSSanctuary',
+ (gs, args) => DonateCSSanctuaryCommand(
+ _str('donateCSSanctuary', 'characterId', args),
+ gameState: gs,
+ ),
+ ),
+ 'draw': CommandDescriptor('draw', (gs, args) => DrawCommand(gameState: gs)),
+ 'drawAbilityCard': CommandDescriptor(
+ 'drawAbilityCard',
+ (gs, args) =>
+ DrawAbilityCardCommand(_str('drawAbilityCard', 'ownerId', args)),
+ ),
+ 'drawLootCard': CommandDescriptor(
+ 'drawLootCard',
+ (gs, args) => DrawLootCardCommand(gameState: gs),
+ ),
+ 'drawModifierCard': CommandDescriptor(
+ 'drawModifierCard',
+ (gs, args) => DrawModifierCardCommand(
+ _str('drawModifierCard', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'enhanceLootCard': CommandDescriptor(
+ 'enhanceLootCard',
+ (gs, args) => EnhanceLootCardCommand(
+ _int('enhanceLootCard', 'id', args),
+ _int('enhanceLootCard', 'value', args),
+ _str('enhanceLootCard', 'resourceType', args),
+ gameState: gs,
+ ),
+ ),
+ 'hideAllyDeck': CommandDescriptor(
+ 'hideAllyDeck',
+ (gs, args) => HideAllyDeckCommand(),
+ ),
+ 'iceWraithChangeForm': CommandDescriptor(
+ 'iceWraithChangeForm',
+ (gs, args) => IceWraithChangeFormCommand(
+ _bool('iceWraithChangeForm', 'isElite', args),
+ _strOr('iceWraithChangeForm', 'ownerId', args),
+ _str('iceWraithChangeForm', 'figureId', args),
+ gameState: gs,
+ ),
+ ),
+ 'imbueElement': CommandDescriptor(
+ 'imbueElement',
+ (gs, args) => ImbueElementCommand(
+ _elements('imbueElement', 'element', args),
+ _bool('imbueElement', 'half', args),
+ gameState: gs,
+ ),
+ ),
+ 'loadCharacterSave': CommandDescriptor(
+ 'loadCharacterSave',
+ (gs, args) => LoadCharacterSaveCommand(
+ _str('loadCharacterSave', 'saveName', args),
+ _str('loadCharacterSave', 'saveData', args),
+ gameState: gs,
+ ),
+ ),
+ 'loadSave': CommandDescriptor(
+ 'loadSave',
+ (gs, args) => LoadSaveCommand(
+ _str('loadSave', 'saveName', args),
+ _str('loadSave', 'saveData', args),
+ gameState: gs,
+ ),
+ ),
+ // GameData and Settings are injected, never wire args.
+ 'nextRound': CommandDescriptor(
+ 'nextRound',
+ (gs, args) => NextRoundCommand(
+ gameState: gs,
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ),
+ ),
+ 'removeAMDCard': CommandDescriptor(
+ 'removeAMDCard',
+ (gs, args) => RemoveAMDCardCommand(
+ index: _int('removeAMDCard', 'index', args),
+ name: _str('removeAMDCard', 'name', args),
+ fromDrawPile: _boolOr('removeAMDCard', 'fromDrawPile', args, false),
+ gameState: gs,
+ ),
+ ),
+ // `deck` + `nr` resolve the live card model from the current ability decks
+ // (draw pile, then discard pile), mirroring the command's own execute().
+ 'removeCard': CommandDescriptor(
+ 'removeCard',
+ (gs, args) => RemoveCardCommand(
+ _abilityCard(
+ gs,
+ 'removeCard',
+ _str('removeCard', 'deck', args),
+ _int('removeCard', 'nr', args),
+ ),
+ gameState: gs,
+ ),
+ ),
+ // The reference constructor takes `List<Character> names`; the wire takes
+ // `ids` (List<String>) and resolves the live Character objects by id. An
+ // empty result is not an error (the reference tolerates no-ops).
+ 'removeCharacter': CommandDescriptor(
+ 'removeCharacter',
+ (gs, args) => RemoveCharacterCommand(
+ _characters(gs, _strList('removeCharacter', 'ids', args)),
+ gameState: gs,
+ ),
+ ),
+ 'removeCondition': CommandDescriptor(
+ 'removeCondition',
+ (gs, args) => RemoveConditionCommand(
+ _condition('removeCondition', 'condition', args),
+ _str('removeCondition', 'figureId', args),
+ _strOr('removeCondition', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'removeCSPartyCard': CommandDescriptor(
+ 'removeCSPartyCard',
+ (gs, args) => RemoveCSPartyCardCommand(
+ _str('removeCSPartyCard', 'characterId', args),
+ gameState: gs,
+ ),
+ ),
+ 'removeCSSanctuaryDonation': CommandDescriptor(
+ 'removeCSSanctuaryDonation',
+ (gs, args) => RemoveCSSanctuaryDonationCommand(
+ _str('removeCSSanctuaryDonation', 'characterId', args),
+ gameState: gs,
+ ),
+ ),
+ // The reference constructor takes `List<Monster> names`; the wire takes
+ // `ids` (List<String>) and resolves the live Monster objects by id. An
+ // empty result is not an error (the reference tolerates no-ops).
+ 'removeMonster': CommandDescriptor(
+ 'removeMonster',
+ (gs, args) => RemoveMonsterCommand(
+ _monsters(gs, _strList('removeMonster', 'ids', args)),
+ gameState: gs,
+ ),
+ ),
+ 'removeNoteRow': CommandDescriptor(
+ 'removeNoteRow',
+ (gs, args) => RemoveNoteRowCommand(
+ _str('removeNoteRow', 'noteId', args),
+ gameState: gs,
+ ),
+ ),
+ 'removeSpecialLootCard': CommandDescriptor(
+ 'removeSpecialLootCard',
+ (gs, args) => RemoveSpecialLootCardCommand(
+ _int('removeSpecialLootCard', 'nr', args),
+ gameState: gs,
+ ),
+ ),
+ 'reorderAbilityList': CommandDescriptor(
+ 'reorderAbilityList',
+ (gs, args) => ReorderAbilityListCommand(
+ _str('reorderAbilityList', 'deck', args),
+ _int('reorderAbilityList', 'newIndex', args),
+ _int('reorderAbilityList', 'oldIndex', args),
+ gameState: gs,
+ ),
+ ),
+ 'reorderList': CommandDescriptor(
+ 'reorderList',
+ (gs, args) => ReorderListCommand(
+ _int('reorderList', 'newIndex', args),
+ _int('reorderList', 'oldIndex', args),
+ gameState: gs,
+ ),
+ ),
+ 'reorderModifierList': CommandDescriptor(
+ 'reorderModifierList',
+ (gs, args) => ReorderModifierListCommand(
+ _int('reorderModifierList', 'newIndex', args),
+ _int('reorderModifierList', 'oldIndex', args),
+ _str('reorderModifierList', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'returnLootCard': CommandDescriptor(
+ 'returnLootCard',
+ (gs, args) => ReturnLootCardCommand(
+ _bool('returnLootCard', 'top', args),
+ gameState: gs,
+ ),
+ ),
+ 'returnModifierCard': CommandDescriptor(
+ 'returnModifierCard',
+ (gs, args) =>
+ ReturnModifierCardCommand(_str('returnModifierCard', 'name', args)),
+ ),
+ 'returnRemovedAMDCard': CommandDescriptor(
+ 'returnRemovedAMDCard',
+ (gs, args) => ReturnRemovedAMDCardCommand(
+ index: _int('returnRemovedAMDCard', 'index', args),
+ name: _str('returnRemovedAMDCard', 'name', args),
+ toDrawPile: _boolOr('returnRemovedAMDCard', 'toDrawPile', args, false),
+ gameState: gs,
+ ),
+ ),
+ 'setAllyDeckInOgGloom': CommandDescriptor(
+ 'setAllyDeckInOgGloom',
+ (gs, args) => SetAllyDeckInOgGloomCommand(
+ _bool('setAllyDeckInOgGloom', 'set', args),
+ gameState: gs,
+ ),
+ ),
+ 'setAsSummon': CommandDescriptor(
+ 'setAsSummon',
+ (gs, args) => SetAsSummonCommand(
+ _bool('setAsSummon', 'summoned', args),
+ _str('setAsSummon', 'figureId', args),
+ _strOr('setAsSummon', 'ownerId', args),
+ gameState: gs,
+ ),
+ ),
+ 'setAutoLevelAdjust': CommandDescriptor(
+ 'setAutoLevelAdjust',
+ (gs, args) => SetAutoLevelAdjustCommand(
+ _bool('setAutoLevelAdjust', 'on', args),
+ gameState: gs,
+ ),
+ ),
+ 'setCampaign': CommandDescriptor(
+ 'setCampaign',
+ (gs, args) => SetCampaignCommand(_str('setCampaign', 'campaign', args)),
+ ),
+ 'setCharacterLevel': CommandDescriptor(
+ 'setCharacterLevel',
+ (gs, args) => SetCharacterLevelCommand(
+ _int('setCharacterLevel', 'level', args),
+ _str('setCharacterLevel', 'characterId', args),
+ ),
+ ),
+ 'setDifficulty': CommandDescriptor(
+ 'setDifficulty',
+ (gs, args) => SetDifficultyCommand(
+ _int('setDifficulty', 'difficulty', args),
+ gameState: gs,
+ ),
+ ),
+ 'setFigureNote': CommandDescriptor(
+ 'setFigureNote',
+ (gs, args) => SetFigureNoteCommand(
+ _str('setFigureNote', 'note', args),
+ _str('setFigureNote', 'figureId', args),
+ gameState: gs,
+ ),
+ ),
+ 'setInit': CommandDescriptor(
+ 'setInit',
+ (gs, args) => SetInitCommand(
+ _str('setInit', 'characterId', args),
+ _int('setInit', 'init', args),
+ gameState: gs,
+ ),
+ ),
+ 'setLevel': CommandDescriptor(
+ 'setLevel',
+ (gs, args) => SetLevelCommand(
+ _int('setLevel', 'level', args),
+ _strOr('setLevel', 'monsterId', args),
+ ),
+ ),
+ // `cardId` resolves the live [LootCard] from the loot deck (draw pile,
+ // discard pile, and the material/herb pools).
+ 'setLootOwner': CommandDescriptor(
+ 'setLootOwner',
+ (gs, args) => SetLootOwnerCommand(
+ _str('setLootOwner', 'ownerId', args),
+ _lootCard(gs, 'setLootOwner', _int('setLootOwner', 'cardId', args)),
+ ),
+ ),
+ 'setNoteRowColor': CommandDescriptor(
+ 'setNoteRowColor',
+ (gs, args) => SetNoteRowColorCommand(
+ _int('setNoteRowColor', 'color', args),
+ _str('setNoteRowColor', 'noteId', args),
+ gameState: gs,
+ ),
+ ),
+ 'setNoteRowLink': CommandDescriptor(
+ 'setNoteRowLink',
+ (gs, args) => SetNoteRowLinkCommand(
+ _str('setNoteRowLink', 'noteId', args),
+ _str('setNoteRowLink', 'linkedId', args),
+ _int('setNoteRowLink', 'standeeNr', args),
+ gameState: gs,
+ ),
+ ),
+ 'setNoteRowText': CommandDescriptor(
+ 'setNoteRowText',
+ (gs, args) => SetNoteRowTextCommand(
+ _str('setNoteRowText', 'text', args),
+ _str('setNoteRowText', 'noteId', args),
+ gameState: gs,
+ ),
+ ),
+ 'setScenario': CommandDescriptor(
+ 'setScenario',
+ (gs, args) => SetScenarioCommand(
+ _str('setScenario', 'scenario', args),
+ _bool('setScenario', 'section', args),
+ gameState: gs,
+ ),
+ ),
+ 'setSolo': CommandDescriptor(
+ 'setSolo',
+ (gs, args) => SetSoloCommand(_bool('setSolo', 'solo', args)),
+ ),
+ 'showAllyDeck': CommandDescriptor(
+ 'showAllyDeck',
+ (gs, args) => ShowAllyDeckCommand(),
+ ),
+ 'shuffleAbilityCard': CommandDescriptor(
+ 'shuffleAbilityCard',
+ (gs, args) =>
+ ShuffleAbilityCardCommand(_str('shuffleAbilityCard', 'ownerId', args)),
+ ),
+ 'shuffleAMDCard': CommandDescriptor(
+ 'shuffleAMDCard',
+ (gs, args) => ShuffleAMDCardCommand(
+ _str('shuffleAMDCard', 'name', args),
+ gameState: gs,
+ ),
+ ),
+ 'shuffleDrawnAbilityCard': CommandDescriptor(
+ 'shuffleDrawnAbilityCard',
+ (gs, args) => ShuffleDrawnAbilityCardCommand(
+ _str('shuffleDrawnAbilityCard', 'deck', args),
+ ),
+ ),
+ // Settings is injected, never a wire arg.
+ 'trackStandees': CommandDescriptor(
+ 'trackStandees',
+ (gs, args) => TrackStandeesCommand(
+ _bool('trackStandees', 'track', args),
+ gameState: gs,
+ settings: getIt<Settings>(),
+ ),
+ ),
+ 'turnDone': CommandDescriptor(
+ 'turnDone',
+ (gs, args) => TurnDoneCommand(_str('turnDone', 'id', args), gameState: gs),
+ ),
+ 'unlockSpecial': CommandDescriptor(
+ 'unlockSpecial',
+ (gs, args) =>
+ UnlockSpecialCommand(_str('unlockSpecial', 'id', args), gameState: gs),
+ ),
+ 'useElement': CommandDescriptor(
+ 'useElement',
+ (gs, args) => UseElementCommand(
+ _elements('useElement', 'element', args),
+ gameState: gs,
+ ),
+ ),
+ 'useFHPerks': CommandDescriptor(
+ 'useFHPerks',
+ (gs, args) => UseFHPerksCommand(_str('useFHPerks', 'characterId', args)),
+ ),
+};
+
+/// Wire name of each registered command's runtime type, for [commandName].
+final Map<Type, String> _nameByType = {
+ ActivateMonsterTypeCommand: 'activateMonsterType',
+ AddCharacterCommand: 'addCharacter',
+ AddConditionCommand: 'addCondition',
+ AddCSPartyCardCommand: 'addCSPartyCard',
+ AddFactionCardCommand: 'addFactionCard',
+ AddLootCardCommand: 'addLootCard',
+ AddMonsterCommand: 'addMonster',
+ AddNoteRowCommand: 'addNoteRow',
+ AddPerkCommand: 'addPerk',
+ AddSpecialLootCardCommand: 'addSpecialLootCard',
+ AddStandeeCommand: 'addStandee',
+ AmdAddMinusOneCommand: 'amdAddMinusOne',
+ AMDCassandraSpecialCommand: 'amdCassandraSpecial',
+ AMDImbue1Command: 'amdImbue1',
+ AMDImbue2Command: 'amdImbue2',
+ AMDRemoveImbueCommand: 'amdRemoveImbue',
+ AMDRemoveMinus1Command: 'amdRemoveMinus1',
+ AMDRemoveMinus2Command: 'amdRemoveMinus2',
+ AmdRemovePlus0Command: 'amdRemovePlus0',
+ AMDRevealCommand: 'amdReveal',
+ BadOmenCommand: 'badOmen',
+ ChangeBlessCommand: 'changeBless',
+ ChangeCurseCommand: 'changeCurse',
+ ChangeEmpowerCommand: 'changeEmpower',
+ ChangeEnfeebleCommand: 'changeEnfeeble',
+ ChangeHealthCommand: 'changeHealth',
+ ChangeMaxHealthCommand: 'changeMaxHealth',
+ ChangeNameCommand: 'changeName',
+ ChangeXPCommand: 'changeXP',
+ ClearUnlockedClassesCommand: 'clearUnlockedClasses',
+ CorrosiveSpewCommand: 'corrosiveSpew',
+ DonateCSSanctuaryCommand: 'donateCSSanctuary',
+ DrawAbilityCardCommand: 'drawAbilityCard',
+ DrawCommand: 'draw',
+ DrawLootCardCommand: 'drawLootCard',
+ DrawModifierCardCommand: 'drawModifierCard',
+ EnhanceLootCardCommand: 'enhanceLootCard',
+ HideAllyDeckCommand: 'hideAllyDeck',
+ IceWraithChangeFormCommand: 'iceWraithChangeForm',
+ ImbueElementCommand: 'imbueElement',
+ LoadCharacterSaveCommand: 'loadCharacterSave',
+ LoadSaveCommand: 'loadSave',
+ NextRoundCommand: 'nextRound',
+ RemoveAMDCardCommand: 'removeAMDCard',
+ RemoveCardCommand: 'removeCard',
+ RemoveCharacterCommand: 'removeCharacter',
+ RemoveConditionCommand: 'removeCondition',
+ RemoveCSPartyCardCommand: 'removeCSPartyCard',
+ RemoveCSSanctuaryDonationCommand: 'removeCSSanctuaryDonation',
+ RemoveMonsterCommand: 'removeMonster',
+ RemoveNoteRowCommand: 'removeNoteRow',
+ RemoveSpecialLootCardCommand: 'removeSpecialLootCard',
+ ReorderAbilityListCommand: 'reorderAbilityList',
+ ReorderListCommand: 'reorderList',
+ ReorderModifierListCommand: 'reorderModifierList',
+ ReturnLootCardCommand: 'returnLootCard',
+ ReturnModifierCardCommand: 'returnModifierCard',
+ ReturnRemovedAMDCardCommand: 'returnRemovedAMDCard',
+ SetAllyDeckInOgGloomCommand: 'setAllyDeckInOgGloom',
+ SetAsSummonCommand: 'setAsSummon',
+ SetAutoLevelAdjustCommand: 'setAutoLevelAdjust',
+ SetCampaignCommand: 'setCampaign',
+ SetCharacterLevelCommand: 'setCharacterLevel',
+ SetDifficultyCommand: 'setDifficulty',
+ SetFigureNoteCommand: 'setFigureNote',
+ SetInitCommand: 'setInit',
+ SetLevelCommand: 'setLevel',
+ SetLootOwnerCommand: 'setLootOwner',
+ SetNoteRowColorCommand: 'setNoteRowColor',
+ SetNoteRowLinkCommand: 'setNoteRowLink',
+ SetNoteRowTextCommand: 'setNoteRowText',
+ SetScenarioCommand: 'setScenario',
+ SetSoloCommand: 'setSolo',
+ ShowAllyDeckCommand: 'showAllyDeck',
+ ShuffleAbilityCardCommand: 'shuffleAbilityCard',
+ ShuffleAMDCardCommand: 'shuffleAMDCard',
+ ShuffleDrawnAbilityCardCommand: 'shuffleDrawnAbilityCard',
+ TrackStandeesCommand: 'trackStandees',
+ TurnDoneCommand: 'turnDone',
+ UnlockSpecialCommand: 'unlockSpecial',
+ UseElementCommand: 'useElement',
+ UseFHPerksCommand: 'useFHPerks',
+};
+
+// --- arg helpers -----------------------------------------------------------
+//
+// Every helper throws [CommandRegistryError] with a message naming the
+// command and the offending arg. An arg that is missing or JSON `null` is
+// treated as "not provided" for optional parameters.
+
+Object _requiredArg(String command, String key, Map<String, dynamic> args) {
+ if (!args.containsKey(key)) {
+ throw CommandRegistryError(
+ 'Command "$command" is missing required argument "$key"',
+ );
+ }
+ return args[key]!;
+}
+
+Object? _optionalArg(String command, String key, Map<String, dynamic> args) {
+ if (!args.containsKey(key)) return null;
+ return args[key];
+}
+
+Never _typeError(String command, String key, String expected, Object actual) {
+ throw CommandRegistryError(
+ 'Command "$command" argument "$key" must be $expected, '
+ 'got ${actual.runtimeType}',
+ );
+}
+
+String _str(String command, String key, Map<String, dynamic> args) {
+ final value = _requiredArg(command, key, args);
+ if (value is! String) _typeError(command, key, 'a String', value);
+ return value;
+}
+
+String? _strOr(String command, String key, Map<String, dynamic> args) {
+ final value = _optionalArg(command, key, args);
+ if (value == null) return null;
+ if (value is! String) _typeError(command, key, 'a String', value);
+ return value;
+}
+
+int _int(String command, String key, Map<String, dynamic> args) {
+ final value = _requiredArg(command, key, args);
+ if (value is! int) _typeError(command, key, 'an int', value);
+ return value;
+}
+
+int? _intOr(String command, String key, Map<String, dynamic> args) {
+ final value = _optionalArg(command, key, args);
+ if (value == null) return null;
+ if (value is! int) _typeError(command, key, 'an int', value);
+ return value;
+}
+
+bool _bool(String command, String key, Map<String, dynamic> args) {
+ final value = _requiredArg(command, key, args);
+ if (value is! bool) _typeError(command, key, 'a bool', value);
+ return value;
+}
+
+bool _boolOr(
+ String command,
+ String key,
+ Map<String, dynamic> args,
+ bool defaultValue,
+) {
+ final value = _optionalArg(command, key, args);
+ if (value == null) return defaultValue;
+ if (value is! bool) _typeError(command, key, 'a bool', value);
+ return value;
+}
+
+List<String> _strList(String command, String key, Map<String, dynamic> args) {
+ final value = _requiredArg(command, key, args);
+ if (value is! List) _typeError(command, key, 'a List', value);
+ final result = <String>[];
+ int i = 0;
+ for (final item in value) {
+ if (item is! String) _typeError(command, '$key[$i]', 'a String', item);
+ result.add(item);
+ i++;
+ }
+ return result;
+}
+
+Map<String, dynamic> _map(
+ String command,
+ String key,
+ Map<String, dynamic> args,
+) {
+ final value = _requiredArg(command, key, args);
+ if (value is! Map) _typeError(command, key, 'a JSON object', value);
+ return Map<String, dynamic>.from(value);
+}
+
+Map<String, dynamic>? _mapOr(
+ String command,
+ String key,
+ Map<String, dynamic> args,
+) {
+ final value = _optionalArg(command, key, args);
+ if (value == null) return null;
+ if (value is! Map) _typeError(command, key, 'a JSON object', value);
+ return Map<String, dynamic>.from(value);
+}
+
+/// Resolves an enum wire arg (a name string) to a value of [values].
+T _enumValue<T extends Enum>(
+ String command,
+ String key,
+ Map<String, dynamic> args,
+ List<T> values,
+) {
+ final name = _str(command, key, args);
+ for (final value in values) {
+ if (value.name == name) return value;
+ }
+ throw CommandRegistryError(
+ 'Command "$command" argument "$key" has invalid value "$name"; '
+ 'expected one of: ${values.map((e) => e.name).join(', ')}',
+ );
+}
+
+Condition _condition(String command, String key, Map<String, dynamic> args) =>
+ _enumValue(command, key, args, Condition.values);
+
+Elements _elements(String command, String key, Map<String, dynamic> args) =>
+ _enumValue(command, key, args, Elements.values);
+
+MonsterType _monsterType(
+ String command,
+ String key,
+ Map<String, dynamic> args,
+) => _enumValue(command, key, args, MonsterType.values);
+
+/// Resolves the optional `summon` arg into a [SummonData].
+SummonData? _summonData(String command, Map<String, dynamic> args) {
+ final value = _mapOr(command, 'summon', args);
+ if (value == null) return null;
+ return SummonData(
+ _int(command, 'summon.standeeNr', value),
+ _str(command, 'summon.name', value),
+ _int(command, 'summon.health', value),
+ _int(command, 'summon.move', value),
+ _int(command, 'summon.attack', value),
+ _int(command, 'summon.range', value),
+ _str(command, 'summon.gfx', value),
+ );
+}
+
+/// Resolves the `noteRow` arg into a [NoteRow]. All five keys
+/// `{id, text, color, linkedId, standeeNr}` are required; `id` is a
+/// client-generated unique string.
+NoteRow _noteRow(String command, Map<String, dynamic> args) {
+ final value = _map(command, 'noteRow', args);
+ _str(command, 'noteRow.id', value);
+ _str(command, 'noteRow.text', value);
+ _int(command, 'noteRow.color', value);
+ _str(command, 'noteRow.linkedId', value);
+ _int(command, 'noteRow.standeeNr', value);
+ return NoteRow.fromJson(value);
+}
+
+/// Finds the live [LootCard] with [cardId] in the loot deck: the draw pile,
+/// the discard pile, and the material/herb pools (pool cards are the same
+/// instances that enter the deck, so this covers every live card).
+LootCard _lootCard(GameState gameState, String command, int cardId) {
+ final deck = gameState.lootDeck;
+ final all = <LootCard>[
+ ...deck.drawPileContents,
+ ...deck.discardPileContents,
+ ...deck.coinPool,
+ ...deck.lumberPool,
+ ...deck.hidePool,
+ ...deck.metalPool,
+ ...deck.corpsecapPool,
+ ...deck.arrowvinePool,
+ ...deck.flamefruitPool,
+ ...deck.axenutPool,
+ ...deck.rockrootPool,
+ ...deck.snowthistlePool,
+ ];
+ for (final card in all) {
+ if (card.id == cardId) return card;
+ }
+ throw CommandRegistryError(
+ 'Command "$command": no loot card with id $cardId in the loot deck',
+ );
+}
+
+/// Finds the live ability card with [nr] in the ability deck named
+/// [deckName] (draw pile, then discard pile) — the same lookup the command's
+/// own execute() does.
+MonsterAbilityCardModel _abilityCard(
+ GameState gameState,
+ String command,
+ String deckName,
+ int nr,
+) {
+ for (final deck in gameState.currentAbilityDecks) {
+ if (deck.name != deckName) continue;
+ for (final card in deck.drawPileContents) {
+ if (card.nr == nr) return card;
+ }
+ for (final card in deck.discardPileContents) {
+ if (card.nr == nr) return card;
+ }
+ }
+ throw CommandRegistryError(
+ 'Command "$command": no ability card with nr $nr in deck "$deckName"',
+ );
+}
+
+/// Resolves wire `ids` (character ids) to the live [Character] objects in the
+/// current list. An empty result is not an error.
+List<Character> _characters(GameState gameState, List<String> ids) {
+ return gameState.currentList
+ .where((item) => item is Character && ids.contains(item.id))
+ .cast<Character>()
+ .toList();
+}
+
+/// Resolves wire `ids` (monster ids) to the live [Monster] objects in the
+/// current list. An empty result is not an error.
+List<Monster> _monsters(GameState gameState, List<String> ids) {
+ return gameState.currentList
+ .where((item) => item is Monster && ids.contains(item.id))
+ .cast<Monster>()
+ .toList();
+}
diff --git a/server/lib/core/commands/corrosive_spew_command.dart b/server/lib/core/commands/corrosive_spew_command.dart
new file mode 100644
index 0000000..c7cae5e
--- /dev/null
+++ b/server/lib/core/commands/corrosive_spew_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class CorrosiveSpewCommand extends Command {
+ final GameState _gameState;
+
+ CorrosiveSpewCommand({required GameState gameState}) : _gameState = gameState;
+
+ @override
+ void execute() {
+ GameMethods.getModifierDeck(
+ "Ruinmaw",
+ _gameState,
+ ).setCorrosiveSpew(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.corrosiveSpew;
+ }
+}
diff --git a/server/lib/core/commands/donate_cs_sanctuary_command.dart b/server/lib/core/commands/donate_cs_sanctuary_command.dart
new file mode 100644
index 0000000..c1fdd0f
--- /dev/null
+++ b/server/lib/core/commands/donate_cs_sanctuary_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class DonateCSSanctuaryCommand extends Command {
+ final String characterId;
+ final GameState _gameState;
+
+ DonateCSSanctuaryCommand(this.characterId, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState);
+ deck.addCSSanctuary(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdDonateSanctuary(characterId);
+ }
+}
diff --git a/server/lib/core/commands/draw_ability_card_command.dart b/server/lib/core/commands/draw_ability_card_command.dart
new file mode 100644
index 0000000..8c8aebb
--- /dev/null
+++ b/server/lib/core/commands/draw_ability_card_command.dart
@@ -0,0 +1,28 @@
+import 'package:collection/collection.dart';
+
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class DrawAbilityCardCommand extends Command {
+ final String ownerId;
+ DrawAbilityCardCommand(this.ownerId);
+
+ @override
+ void execute() {
+ final Monster? monster = GameMethods.getCurrentMonsters().firstWhereOrNull(
+ (element) => element.id == ownerId,
+ );
+ if (monster == null) return;
+ final MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck);
+ if (deck == null) return;
+ if (deck.drawPileIsNotEmpty) {
+ deck.draw(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdDrawExtraAbilityCard;
+ }
+}
diff --git a/server/lib/core/commands/draw_command.dart b/server/lib/core/commands/draw_command.dart
new file mode 100644
index 0000000..fa1d38a
--- /dev/null
+++ b/server/lib/core/commands/draw_command.dart
@@ -0,0 +1,27 @@
+import '../enums.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class DrawCommand extends Command {
+ final GameState _gameState;
+
+ DrawCommand({required GameState gameState}) : _gameState = gameState;
+
+ @override
+ void execute() {
+ DeckMethods.drawAbilityCards(stateAccess);
+ RoundMethods.sortByInitiative(stateAccess);
+ RoundMethods.setRoundState(stateAccess, RoundState.playTurns);
+ if (_gameState.currentList.isNotEmpty) {
+ _gameState.currentList.first.setTurnState(
+ stateAccess,
+ TurnsState.current,
+ );
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdDraw;
+ }
+}
diff --git a/server/lib/core/commands/draw_loot_card_command.dart b/server/lib/core/commands/draw_loot_card_command.dart
new file mode 100644
index 0000000..be2187f
--- /dev/null
+++ b/server/lib/core/commands/draw_loot_card_command.dart
@@ -0,0 +1,24 @@
+import '../game_event.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class DrawLootCardCommand extends Command {
+ final GameState _gameState;
+
+ DrawLootCardCommand({required GameState gameState}) : _gameState = gameState;
+
+ @override
+ void execute() {
+ if (_gameState.lootDeck.drawPileIsNotEmpty) {
+ _gameState.lootDeck.draw(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdDrawLootCard;
+ }
+
+ @override
+ GameEvent get event => const LootCardDrawnEvent();
+}
diff --git a/server/lib/core/commands/draw_modifier_card_command.dart b/server/lib/core/commands/draw_modifier_card_command.dart
new file mode 100644
index 0000000..a9ca8e4
--- /dev/null
+++ b/server/lib/core/commands/draw_modifier_card_command.dart
@@ -0,0 +1,29 @@
+import '../game_event.dart';
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class DrawModifierCardCommand extends Command {
+ final String name;
+ final GameState _gameState;
+
+ DrawModifierCardCommand(this.name, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.draw(stateAccess);
+ }
+
+ @override
+ String describe() {
+ if (name.isNotEmpty) {
+ return commandL10n.cmdDrawModifierCard(name);
+ }
+ return commandL10n.cmdDrawMonsterModifierCard;
+ }
+
+ @override
+ GameEvent get event => ModifierCardDrawnEvent(name);
+}
diff --git a/server/lib/core/commands/enhance_loot_card_command.dart b/server/lib/core/commands/enhance_loot_card_command.dart
new file mode 100644
index 0000000..e7ed730
--- /dev/null
+++ b/server/lib/core/commands/enhance_loot_card_command.dart
@@ -0,0 +1,28 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class EnhanceLootCardCommand extends Command {
+ EnhanceLootCardCommand(
+ this.id,
+ this.value,
+ this.resourceType, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+ final int value;
+ final int id;
+ final String resourceType;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ _gameState.lootDeck.addEnhancement(stateAccess, id, value);
+ }
+
+ @override
+ String describe() {
+ if (value <= 0) {
+ return commandL10n.cmdRemoveLootEnhancement;
+ }
+ return commandL10n.cmdAddLootEnhancement;
+ }
+}
diff --git a/server/lib/core/commands/hide_ally_deck_command.dart b/server/lib/core/commands/hide_ally_deck_command.dart
new file mode 100644
index 0000000..a773517
--- /dev/null
+++ b/server/lib/core/commands/hide_ally_deck_command.dart
@@ -0,0 +1,16 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class HideAllyDeckCommand extends Command {
+ HideAllyDeckCommand();
+
+ @override
+ void execute() {
+ MonsterMethods.hideAllyDeck(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdHideAllyDeck;
+ }
+}
diff --git a/server/lib/core/commands/ice_wraith_change_form_command.dart b/server/lib/core/commands/ice_wraith_change_form_command.dart
new file mode 100644
index 0000000..1a4db55
--- /dev/null
+++ b/server/lib/core/commands/ice_wraith_change_form_command.dart
@@ -0,0 +1,37 @@
+import '../enums.dart';
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class IceWraithChangeFormCommand extends Command {
+ IceWraithChangeFormCommand(
+ this.isElite,
+ this.ownerId,
+ this.figureId, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+ final bool isElite;
+ final String? ownerId;
+ final String figureId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final figure = GameMethods.getFigure(ownerId, figureId);
+ if (figure is! MonsterInstance) return;
+ if (isElite) {
+ figure.setType(stateAccess, MonsterType.normal);
+ } else {
+ figure.setType(stateAccess, MonsterType.elite);
+ }
+ _gameState.notifyListeners();
+ }
+
+ @override
+ String describe() {
+ if (!isElite) {
+ return commandL10n.cmdIceWraithTurnNormal;
+ }
+ return commandL10n.cmdIceWraithTurnElite;
+ }
+}
diff --git a/server/lib/core/commands/imbue_element_command.dart b/server/lib/core/commands/imbue_element_command.dart
new file mode 100644
index 0000000..2f039d7
--- /dev/null
+++ b/server/lib/core/commands/imbue_element_command.dart
@@ -0,0 +1,27 @@
+import '../enums.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ImbueElementCommand extends Command {
+ final Elements element;
+ final bool half;
+ final GameState? _gameState;
+
+ ImbueElementCommand(this.element, this.half, {GameState? gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ElementMethods.imbueElement(
+ stateAccess,
+ element,
+ half,
+ gameState: _gameState,
+ );
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdImbueElement(element.name);
+ }
+}
diff --git a/server/lib/core/commands/load_character_save_command.dart b/server/lib/core/commands/load_character_save_command.dart
new file mode 100644
index 0000000..6014c47
--- /dev/null
+++ b/server/lib/core/commands/load_character_save_command.dart
@@ -0,0 +1,42 @@
+import 'dart:convert';
+
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class LoadCharacterSaveCommand extends Command {
+ String saveName;
+ String saveData;
+ final GameState _gameState;
+
+ LoadCharacterSaveCommand(
+ this.saveName,
+ this.saveData, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ final data = json.decode(saveData) as Map<String, dynamic>;
+ Character character = Character.fromSave(data);
+
+ //add new character on top of list, if not present.
+ final Character? currentCharacter = GameMethods.getCharacterByName(
+ character.id,
+ );
+ if (currentCharacter != null) {
+ CharacterMethods.removeCharacters(stateAccess, [currentCharacter]);
+ }
+
+ CharacterMethods.resetCharacter(stateAccess, character);
+ RoundMethods.addToMainList(stateAccess, 0, character);
+ ScenarioMethods.applyDifficulty(stateAccess);
+ _gameState.notifyListeners();
+ ScenarioMethods.unlockClass(stateAccess, character.characterClass.id);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdLoadCharacter(saveName);
+ }
+}
diff --git a/server/lib/core/commands/load_save_command.dart b/server/lib/core/commands/load_save_command.dart
new file mode 100644
index 0000000..56bd22e
--- /dev/null
+++ b/server/lib/core/commands/load_save_command.dart
@@ -0,0 +1,22 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class LoadSaveCommand extends Command {
+ String saveName;
+ String saveData;
+ final GameState _gameState;
+
+ LoadSaveCommand(this.saveName, this.saveData, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ _gameState.loadFromData(saveData);
+ _gameState.save();
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdLoadGame(saveName);
+ }
+}
diff --git a/server/lib/core/commands/next_round_command.dart b/server/lib/core/commands/next_round_command.dart
new file mode 100644
index 0000000..22385fa
--- /dev/null
+++ b/server/lib/core/commands/next_round_command.dart
@@ -0,0 +1,134 @@
+import 'package:collection/collection.dart';
+import 'package:x_haven_server/core/models/scenario.dart';
+
+import '../enums.dart';
+import '../game_data.dart';
+import '../game_methods.dart';
+import '../settings.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class NextRoundCommand extends Command {
+ final GameState _gameState;
+ final GameData _gameData;
+ final Settings _settings;
+
+ NextRoundCommand({
+ required GameState gameState,
+ required GameData gameData,
+ required Settings settings,
+ }) : _gameState = gameState,
+ _gameData = gameData,
+ _settings = settings;
+
+ @override
+ void execute() {
+ //todo: move code to GameMethods?
+ for (final item in _gameState.currentList) {
+ if (item is Character) {
+ item.nextRound(stateAccess);
+ }
+ if (item is Monster) {
+ //only really needed for ice wraiths
+ item.sortMonsterInstances(stateAccess);
+ }
+ }
+ DeckMethods.shuffleDecksIfNeeded(stateAccess);
+ ElementMethods.updateElements(stateAccess);
+ RoundMethods.setRoundState(stateAccess, RoundState.chooseInitiative);
+ if (_gameState.currentList.isNotEmpty &&
+ _gameState.currentList.last.turnState != TurnsState.done) {
+ RoundMethods.setTurnDone(stateAccess, _gameState.currentList.length - 1);
+ }
+ if (_gameState.currentList.isNotEmpty &&
+ _gameState.currentList.last.turnState != TurnsState.done) {
+ RoundMethods.setTurnDone(stateAccess, _gameState.currentList.length - 1);
+ }
+ RoundMethods.clearTurnState(stateAccess, false);
+ RoundMethods.sortCharactersFirst(stateAccess);
+
+ GameUtilMethods.setToastMessage("");
+
+ for (final rule in _gameState.scenarioSpecialRules) {
+ if (rule.type == "Timer" && !rule.startOfRound) {
+ for (int round in rule.list.cast<int>()) {
+ //minus 1 means always
+ if (round == _gameState.round || round == -1) {
+ if (_settings.showReminders) {
+ GameUtilMethods.setToastMessage(rule.note);
+ }
+
+ _handleTimedSpawns(rule);
+ }
+ }
+ }
+ }
+
+ //start of next round is now
+ for (final rule in _gameState.scenarioSpecialRules) {
+ if (rule.type == "Timer" && rule.startOfRound) {
+ for (int round in rule.list.cast<int>()) {
+ //minus 1 means always
+ final toastMessage = _gameState.toastMessage;
+ if (round - 1 == _gameState.round || round == -1) {
+ if (toastMessage.isNotEmpty) {
+ GameUtilMethods.setToastMessage("$toastMessage\n\n${rule.note}");
+ } else {
+ if (_settings.showReminders) {
+ GameUtilMethods.setToastMessage("$toastMessage${rule.note}");
+ }
+ }
+ _handleTimedSpawns(rule);
+ }
+ }
+ }
+ }
+
+ RoundMethods.setRound(stateAccess, _gameState.round + 1);
+
+ if (_gameState.modifierDeck.needsShuffle) {
+ _gameState.modifierDeck.shuffle(stateAccess);
+ }
+ if (_gameState.modifierDeckAllies.needsShuffle) {
+ _gameState.modifierDeckAllies.shuffle(stateAccess);
+ }
+ final characters = GameMethods.getCurrentCharacters();
+ for (final character in characters) {
+ final modifierDeck = character.characterState.modifierDeck;
+ if (modifierDeck.needsShuffle) {
+ modifierDeck.shuffle(stateAccess);
+ }
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdNextRound;
+ }
+
+ void _handleTimedSpawns(SpecialRule rule) {
+ if (_settings.autoAddSpawns) {
+ if (rule.name.isNotEmpty) {
+ //get room data and deal with spawns
+ ScenarioModel? scenario = _gameData
+ .modelData[_gameState.currentCampaign]
+ ?.scenarios[_gameState.scenario];
+ if (scenario != null) {
+ ScenarioModel? spawnSection = scenario.sections.firstWhereOrNull(
+ (element) => element.name.substring(1) == rule.name,
+ );
+ if (spawnSection != null) {
+ final monsterStandees = spawnSection.monsterStandees;
+ if (monsterStandees != null) {
+ MonsterMethods.autoAddStandees(
+ stateAccess,
+ monsterStandees,
+ rule.note,
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/server/lib/core/commands/remove__special_loot_card_command.dart b/server/lib/core/commands/remove__special_loot_card_command.dart
new file mode 100644
index 0000000..2ef9b57
--- /dev/null
+++ b/server/lib/core/commands/remove__special_loot_card_command.dart
@@ -0,0 +1,28 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveSpecialLootCardCommand extends Command {
+ static const int _kCard1418 = 1418;
+ static const int _kCard1419 = 1419;
+
+ int nr;
+ final GameState _gameState;
+
+ RemoveSpecialLootCardCommand(this.nr, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ if (nr == _kCard1418) {
+ _gameState.lootDeck.removeSpecial1418(stateAccess);
+ }
+ if (nr == _kCard1419) {
+ _gameState.lootDeck.removeSpecial1419(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveSpecialLootCard(nr);
+ }
+}
diff --git a/server/lib/core/commands/remove_amd_card_command.dart b/server/lib/core/commands/remove_amd_card_command.dart
new file mode 100644
index 0000000..2700660
--- /dev/null
+++ b/server/lib/core/commands/remove_amd_card_command.dart
@@ -0,0 +1,33 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveAMDCardCommand extends Command {
+ final int index;
+ final String name;
+ final GameState _gameState;
+ final bool fromDrawPile;
+
+ RemoveAMDCardCommand({
+ required this.index,
+ required this.name,
+ required GameState gameState,
+ this.fromDrawPile = false,
+ }) : _gameState = gameState;
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ if (fromDrawPile) {
+ if (index >= deck.drawPileSize) return;
+ deck.removeCardFromDrawPile(stateAccess, index);
+ } else {
+ if (index >= deck.discardPileSize) return;
+ deck.removeCardFromDiscard(stateAccess, index);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveAmdCard;
+ }
+}
diff --git a/server/lib/core/commands/remove_card_command.dart b/server/lib/core/commands/remove_card_command.dart
new file mode 100644
index 0000000..438f66e
--- /dev/null
+++ b/server/lib/core/commands/remove_card_command.dart
@@ -0,0 +1,38 @@
+import 'package:x_haven_server/core/models/monster_ability.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveCardCommand extends Command {
+ final MonsterAbilityCardModel card;
+ final GameState _gameState;
+
+ RemoveCardCommand(this.card, {required GameState gameState})
+ : _gameState = gameState;
+ @override
+ void execute() {
+ for (final deck in _gameState.currentAbilityDecks) {
+ if (deck.name == card.deck) {
+ for (final drawPileCard in deck.drawPileContents) {
+ if (drawPileCard.nr == card.nr) {
+ deck.removeFromDrawPile(stateAccess, card);
+ break;
+ }
+ }
+ for (final discardPileCard in deck.discardPileContents) {
+ if (discardPileCard.nr == card.nr) {
+ deck.removeFromDiscardPile(stateAccess, card);
+ break;
+ }
+ }
+ deck.shuffle(stateAccess);
+ break;
+ }
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveCard(card.deck, card.nr);
+ }
+}
diff --git a/server/lib/core/commands/remove_character_command.dart b/server/lib/core/commands/remove_character_command.dart
new file mode 100644
index 0000000..ea1d982
--- /dev/null
+++ b/server/lib/core/commands/remove_character_command.dart
@@ -0,0 +1,30 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveCharacterCommand extends Command {
+ final List<Character> names;
+
+ RemoveCharacterCommand(this.names, {required GameState gameState});
+
+ @override
+ void execute() {
+ CharacterMethods.removeCharacters(stateAccess, names);
+
+ if (names.length != 1 ||
+ !GameMethods.isObjectiveOrEscort(names.first.characterClass)) {
+ ScenarioMethods.applyDifficulty(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ if (names.length > 1) {
+ return commandL10n.cmdRemoveAllCharacters;
+ }
+ if (names.isNotEmpty) {
+ return commandL10n.cmdRemoveCharacter(names.first.id);
+ }
+ return commandL10n.cmdRemoveNoCharacters;
+ }
+}
diff --git a/server/lib/core/commands/remove_condition_command.dart b/server/lib/core/commands/remove_condition_command.dart
new file mode 100644
index 0000000..04cdd40
--- /dev/null
+++ b/server/lib/core/commands/remove_condition_command.dart
@@ -0,0 +1,47 @@
+import '../enums.dart';
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveConditionCommand extends Command {
+ final Condition condition;
+ final String figureId;
+ final String? ownerId;
+ final GameState _gameState;
+
+ RemoveConditionCommand(
+ 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);
+ newList.remove(condition);
+ figure.setConditions(stateAccess, newList);
+ if (condition != Condition.chill ||
+ !figure.conditions.contains(Condition.chill)) {
+ figure.removeFromConditionsThisTurn(stateAccess, condition);
+ }
+ if (condition == Condition.chill) {
+ figure.setChill(stateAccess, figure.chill - 1);
+ }
+ if (condition == Condition.plague) {
+ figure.setPlague(stateAccess, figure.plague - 1);
+ }
+
+ figure.removeFromConditionsPreviousTurn(stateAccess, condition);
+ _gameState.notifyListeners();
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveCondition(condition.getName());
+ }
+}
diff --git a/server/lib/core/commands/remove_cs_party_card_command.dart b/server/lib/core/commands/remove_cs_party_card_command.dart
new file mode 100644
index 0000000..64f03bf
--- /dev/null
+++ b/server/lib/core/commands/remove_cs_party_card_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveCSPartyCardCommand extends Command {
+ final String characterId;
+ final GameState _gameState;
+
+ RemoveCSPartyCardCommand(this.characterId, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState);
+ deck.removeCSPartyCard(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemovePartyCard(characterId);
+ }
+}
diff --git a/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart b/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart
new file mode 100644
index 0000000..3751097
--- /dev/null
+++ b/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart
@@ -0,0 +1,24 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveCSSanctuaryDonationCommand extends Command {
+ final String characterId;
+ final GameState _gameState;
+
+ RemoveCSSanctuaryDonationCommand(
+ this.characterId, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState);
+ deck.removeCSSanctuary(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveSanctuaryDonation(characterId);
+ }
+}
diff --git a/server/lib/core/commands/remove_monster_command.dart b/server/lib/core/commands/remove_monster_command.dart
new file mode 100644
index 0000000..b64f1e6
--- /dev/null
+++ b/server/lib/core/commands/remove_monster_command.dart
@@ -0,0 +1,24 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveMonsterCommand extends Command {
+ final List<Monster> names;
+
+ RemoveMonsterCommand(this.names, {required GameState gameState});
+
+ @override
+ void execute() {
+ MonsterMethods.removeMonsters(stateAccess, names);
+ }
+
+ @override
+ String describe() {
+ if (names.length > 1) {
+ return commandL10n.cmdRemoveAllMonsters;
+ }
+ if (names.isNotEmpty) {
+ return commandL10n.cmdRemoveMonster(names.first.type.display);
+ }
+ return commandL10n.cmdRemoveNoMonsters;
+ }
+}
diff --git a/server/lib/core/commands/remove_note_row_command.dart b/server/lib/core/commands/remove_note_row_command.dart
new file mode 100644
index 0000000..b574208
--- /dev/null
+++ b/server/lib/core/commands/remove_note_row_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class RemoveNoteRowCommand extends Command {
+ RemoveNoteRowCommand(this.noteId, {required GameState gameState})
+ : _gameState = gameState;
+ final String noteId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ RoundMethods.removeFromMainList(stateAccess, noteId, gameState: _gameState);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdRemoveNoteRow;
+ }
+}
diff --git a/server/lib/core/commands/reorder_ability_list_command.dart b/server/lib/core/commands/reorder_ability_list_command.dart
new file mode 100644
index 0000000..f7e5781
--- /dev/null
+++ b/server/lib/core/commands/reorder_ability_list_command.dart
@@ -0,0 +1,31 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReorderAbilityListCommand extends Command {
+ final int newIndex;
+ final int oldIndex;
+ final String deck;
+ final GameState _gameState;
+
+ ReorderAbilityListCommand(
+ this.deck,
+ this.newIndex,
+ this.oldIndex, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ for (final item in _gameState.currentAbilityDecks) {
+ if (item.name == deck) {
+ item.reorderDrawPile(stateAccess, oldIndex, newIndex);
+ break;
+ }
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReorderAbilityCards;
+ }
+}
diff --git a/server/lib/core/commands/reorder_list_command.dart b/server/lib/core/commands/reorder_list_command.dart
new file mode 100644
index 0000000..d20f0d8
--- /dev/null
+++ b/server/lib/core/commands/reorder_list_command.dart
@@ -0,0 +1,23 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReorderListCommand extends Command {
+ final int newIndex;
+ final int oldIndex;
+
+ ReorderListCommand(
+ this.newIndex,
+ this.oldIndex, {
+ required GameState gameState,
+ });
+
+ @override
+ void execute() {
+ RoundMethods.reorderMainList(stateAccess, newIndex, oldIndex);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReorderList;
+ }
+}
diff --git a/server/lib/core/commands/reorder_modifier_list_command.dart b/server/lib/core/commands/reorder_modifier_list_command.dart
new file mode 100644
index 0000000..60f0bb4
--- /dev/null
+++ b/server/lib/core/commands/reorder_modifier_list_command.dart
@@ -0,0 +1,28 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReorderModifierListCommand extends Command {
+ final int newIndex;
+ final int oldIndex;
+ final String name;
+ final GameState _gameState;
+
+ ReorderModifierListCommand(
+ this.newIndex,
+ this.oldIndex,
+ this.name, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.reorderCards(stateAccess, newIndex, oldIndex);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReorderModifierCards;
+ }
+}
diff --git a/server/lib/core/commands/return_loot_card_command.dart b/server/lib/core/commands/return_loot_card_command.dart
new file mode 100644
index 0000000..91a95d5
--- /dev/null
+++ b/server/lib/core/commands/return_loot_card_command.dart
@@ -0,0 +1,20 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReturnLootCardCommand extends Command {
+ final bool top;
+ final GameState _gameState;
+
+ ReturnLootCardCommand(this.top, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ _gameState.lootDeck.returnLootCard(stateAccess, top);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReturnLootCard;
+ }
+}
diff --git a/server/lib/core/commands/return_modifier_card_command.dart b/server/lib/core/commands/return_modifier_card_command.dart
new file mode 100644
index 0000000..1f2f5ce
--- /dev/null
+++ b/server/lib/core/commands/return_modifier_card_command.dart
@@ -0,0 +1,18 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReturnModifierCardCommand extends Command {
+ final String name;
+
+ ReturnModifierCardCommand(this.name);
+
+ @override
+ void execute() {
+ DeckMethods.returnModifierCard(stateAccess, name);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReturnModifierCard;
+ }
+}
diff --git a/server/lib/core/commands/return_removed_amd_card_command.dart b/server/lib/core/commands/return_removed_amd_card_command.dart
new file mode 100644
index 0000000..dda3feb
--- /dev/null
+++ b/server/lib/core/commands/return_removed_amd_card_command.dart
@@ -0,0 +1,31 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ReturnRemovedAMDCardCommand extends Command {
+ final int index;
+ final String name;
+ final bool toDrawPile;
+ final GameState _gameState;
+
+ ReturnRemovedAMDCardCommand({
+ required this.index,
+ required this.name,
+ this.toDrawPile = false,
+ required GameState gameState,
+ }) : _gameState = gameState;
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ if (toDrawPile) {
+ deck.returnCardToDrawPileFromRemoved(stateAccess, index);
+ } else {
+ deck.returnCardToDiscard(stateAccess, index);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdReturnRemovedAmdCard;
+ }
+}
diff --git a/server/lib/core/commands/set_ally_deck_in_og_gloom_command.dart b/server/lib/core/commands/set_ally_deck_in_og_gloom_command.dart
new file mode 100644
index 0000000..fbff5d9
--- /dev/null
+++ b/server/lib/core/commands/set_ally_deck_in_og_gloom_command.dart
@@ -0,0 +1,23 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetAllyDeckInOgGloomCommand extends Command {
+ final GameState _gameState;
+ final bool set;
+
+ SetAllyDeckInOgGloomCommand(this.set, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ _gameState.setAllyDeckInOGGloom(stateAccess, set);
+ }
+
+ @override
+ String describe() {
+ if (!set) {
+ return commandL10n.cmdNoAllyDeckInOgGloom;
+ }
+ return commandL10n.cmdUseAllyDeckInOgGloom;
+ }
+}
diff --git a/server/lib/core/commands/set_as_summon_command.dart b/server/lib/core/commands/set_as_summon_command.dart
new file mode 100644
index 0000000..0337001
--- /dev/null
+++ b/server/lib/core/commands/set_as_summon_command.dart
@@ -0,0 +1,37 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetAsSummonCommand extends Command {
+ final bool summoned;
+ final String? ownerId;
+ final String figureId;
+ final GameState _gameState;
+
+ SetAsSummonCommand(
+ this.summoned,
+ this.figureId,
+ this.ownerId, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+
+ @override
+ void execute() {
+ final figure = GameMethods.getFigure(ownerId, figureId);
+ if (figure is! MonsterInstance) return;
+ if (summoned) {
+ figure.setRoundSummoned(stateAccess, _gameState.round);
+ } else {
+ figure.setRoundSummoned(stateAccess, -1);
+ }
+ _gameState.notifyListeners();
+ }
+
+ @override
+ String describe() {
+ if (summoned) {
+ return commandL10n.cmdMarkAsSummon(ownerId ?? '');
+ }
+ return commandL10n.cmdRemoveSummonMark(ownerId ?? '');
+ }
+}
diff --git a/server/lib/core/commands/set_auto_level_adjust_command.dart b/server/lib/core/commands/set_auto_level_adjust_command.dart
new file mode 100644
index 0000000..9be49ec
--- /dev/null
+++ b/server/lib/core/commands/set_auto_level_adjust_command.dart
@@ -0,0 +1,21 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetAutoLevelAdjustCommand extends Command {
+ SetAutoLevelAdjustCommand(this.on, {required GameState gameState})
+ : _gameState = gameState;
+
+ bool on;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ _gameState.setAutoScenarioLevel(stateAccess, on);
+ ScenarioMethods.applyDifficulty(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return on ? commandL10n.cmdAutoLevelOn : commandL10n.cmdAutoLevelOff;
+ }
+}
diff --git a/server/lib/core/commands/set_campaign_command.dart b/server/lib/core/commands/set_campaign_command.dart
new file mode 100644
index 0000000..da5c312
--- /dev/null
+++ b/server/lib/core/commands/set_campaign_command.dart
@@ -0,0 +1,18 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetCampaignCommand extends Command {
+ SetCampaignCommand(this.campaign);
+
+ String campaign;
+
+ @override
+ void execute() {
+ ScenarioMethods.setCampaign(stateAccess, campaign);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetCampaign(campaign);
+ }
+}
diff --git a/server/lib/core/commands/set_character_level_command.dart b/server/lib/core/commands/set_character_level_command.dart
new file mode 100644
index 0000000..66c28de
--- /dev/null
+++ b/server/lib/core/commands/set_character_level_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetCharacterLevelCommand extends Command {
+ final int level;
+ final String characterId;
+
+ SetCharacterLevelCommand(this.level, this.characterId);
+
+ @override
+ void execute() {
+ CharacterMethods.setCharacterLevel(stateAccess, level, characterId);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetCharacterLevel(characterId);
+ }
+}
diff --git a/server/lib/core/commands/set_difficulty_command.dart b/server/lib/core/commands/set_difficulty_command.dart
new file mode 100644
index 0000000..a7ce147
--- /dev/null
+++ b/server/lib/core/commands/set_difficulty_command.dart
@@ -0,0 +1,21 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetDifficultyCommand extends Command {
+ SetDifficultyCommand(this.difficulty, {required GameState gameState})
+ : _gameState = gameState;
+
+ int difficulty;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ _gameState.setDifficulty(stateAccess, difficulty);
+ ScenarioMethods.applyDifficulty(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetDifficulty(difficulty.toString());
+ }
+}
diff --git a/server/lib/core/commands/set_figure_note_command.dart b/server/lib/core/commands/set_figure_note_command.dart
new file mode 100644
index 0000000..1bd2f8f
--- /dev/null
+++ b/server/lib/core/commands/set_figure_note_command.dart
@@ -0,0 +1,30 @@
+import 'package:collection/collection.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+/// Sets the free-form inline note shown on a figure's row (character or
+/// monster). Undo is handled by the snapshot-based history in [ActionHandler],
+/// so no [onUndo] is needed.
+class SetFigureNoteCommand extends Command {
+ SetFigureNoteCommand(this.note, this.figureId, {required GameState gameState})
+ : _gameState = gameState;
+ final String note;
+ final String figureId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final match = _gameState.currentList.firstWhereOrNull(
+ (element) => element.id == figureId,
+ );
+ if (match != null) {
+ match.setNote(stateAccess, note);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetCharacterNote(figureId);
+ }
+}
diff --git a/server/lib/core/commands/set_init_command.dart b/server/lib/core/commands/set_init_command.dart
new file mode 100644
index 0000000..9ffb279
--- /dev/null
+++ b/server/lib/core/commands/set_init_command.dart
@@ -0,0 +1,26 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetInitCommand extends Command {
+ final GameState _gameState;
+ final String _characterId;
+ final int _init;
+
+ SetInitCommand(this._characterId, this._init, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ //add new character on top of list
+ for (final item in _gameState.currentList) {
+ if (item.id == _characterId && item is Character) {
+ item.characterState.setInitiative(stateAccess, _init);
+ }
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetInitiative(_characterId);
+ }
+}
diff --git a/server/lib/core/commands/set_level_command.dart b/server/lib/core/commands/set_level_command.dart
new file mode 100644
index 0000000..84efcd2
--- /dev/null
+++ b/server/lib/core/commands/set_level_command.dart
@@ -0,0 +1,22 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetLevelCommand extends Command {
+ final int level;
+ final String? monsterId;
+
+ SetLevelCommand(this.level, this.monsterId);
+
+ @override
+ void execute() {
+ ScenarioMethods.setLevel(stateAccess, level, monsterId);
+ }
+
+ @override
+ String describe() {
+ if (monsterId != null) {
+ return commandL10n.cmdSetMonsterLevel(monsterId!);
+ }
+ return commandL10n.cmdSetLevel;
+ }
+}
diff --git a/server/lib/core/commands/set_loot_owner_command.dart b/server/lib/core/commands/set_loot_owner_command.dart
new file mode 100644
index 0000000..f82531f
--- /dev/null
+++ b/server/lib/core/commands/set_loot_owner_command.dart
@@ -0,0 +1,19 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetLootOwnerCommand extends Command {
+ final String ownerId;
+ final LootCard card;
+
+ SetLootOwnerCommand(this.ownerId, this.card);
+
+ @override
+ void execute() {
+ card.owner = ownerId;
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetLootOwner;
+ }
+}
diff --git a/server/lib/core/commands/set_note_row_color_command.dart b/server/lib/core/commands/set_note_row_color_command.dart
new file mode 100644
index 0000000..ff9c91a
--- /dev/null
+++ b/server/lib/core/commands/set_note_row_color_command.dart
@@ -0,0 +1,30 @@
+import 'package:collection/collection.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetNoteRowColorCommand extends Command {
+ SetNoteRowColorCommand(
+ this.color,
+ this.noteId, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+ final int color;
+ final String noteId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final match = _gameState.currentList.firstWhereOrNull(
+ (element) => element.id == noteId,
+ );
+ if (match is NoteRow) {
+ match.setColor(stateAccess, color);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetNoteRowColor;
+ }
+}
diff --git a/server/lib/core/commands/set_note_row_link_command.dart b/server/lib/core/commands/set_note_row_link_command.dart
new file mode 100644
index 0000000..2e47bba
--- /dev/null
+++ b/server/lib/core/commands/set_note_row_link_command.dart
@@ -0,0 +1,35 @@
+import 'package:collection/collection.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+/// Attaches a note to a figure (character or monster) by [linkedId], optionally
+/// pinned to [standeeNr] for a monster standee, or detaches it when [linkedId]
+/// is empty. The list's reflow step repositions the note accordingly.
+class SetNoteRowLinkCommand extends Command {
+ SetNoteRowLinkCommand(
+ this.noteId,
+ this.linkedId,
+ this.standeeNr, {
+ required GameState gameState,
+ }) : _gameState = gameState;
+ final String noteId;
+ final String linkedId;
+ final int standeeNr;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final match = _gameState.currentList.firstWhereOrNull(
+ (element) => element.id == noteId,
+ );
+ if (match is NoteRow) {
+ match.setLink(stateAccess, linkedId, standeeNr);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdLinkNoteRow;
+ }
+}
diff --git a/server/lib/core/commands/set_note_row_text_command.dart b/server/lib/core/commands/set_note_row_text_command.dart
new file mode 100644
index 0000000..2b53cb9
--- /dev/null
+++ b/server/lib/core/commands/set_note_row_text_command.dart
@@ -0,0 +1,27 @@
+import 'package:collection/collection.dart';
+
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetNoteRowTextCommand extends Command {
+ SetNoteRowTextCommand(this.text, this.noteId, {required GameState gameState})
+ : _gameState = gameState;
+ final String text;
+ final String noteId;
+ final GameState _gameState;
+
+ @override
+ void execute() {
+ final match = _gameState.currentList.firstWhereOrNull(
+ (element) => element.id == noteId,
+ );
+ if (match is NoteRow) {
+ match.setText(stateAccess, text);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdSetNoteRowText;
+ }
+}
diff --git a/server/lib/core/commands/set_scenario_command.dart b/server/lib/core/commands/set_scenario_command.dart
new file mode 100644
index 0000000..56485eb
--- /dev/null
+++ b/server/lib/core/commands/set_scenario_command.dart
@@ -0,0 +1,26 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetScenarioCommand extends Command {
+ final String _scenario;
+ final bool _section;
+
+ SetScenarioCommand(
+ this._scenario,
+ this._section, {
+ required GameState gameState,
+ });
+
+ @override
+ void execute() {
+ ScenarioMethods.setScenario(stateAccess, _scenario, _section);
+ }
+
+ @override
+ String describe() {
+ if (!_section) {
+ return commandL10n.cmdSetScenario;
+ }
+ return commandL10n.cmdAddSection;
+ }
+}
diff --git a/server/lib/core/commands/set_solo_command.dart b/server/lib/core/commands/set_solo_command.dart
new file mode 100644
index 0000000..c2714b8
--- /dev/null
+++ b/server/lib/core/commands/set_solo_command.dart
@@ -0,0 +1,22 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class SetSoloCommand extends Command {
+ SetSoloCommand(this.solo);
+
+ bool solo;
+
+ @override
+ void execute() {
+ ScenarioMethods.setSolo(stateAccess, solo);
+ ScenarioMethods.applyDifficulty(stateAccess);
+ }
+
+ @override
+ String describe() {
+ if (solo) {
+ return commandL10n.cmdSetSoloOn;
+ }
+ return commandL10n.cmdSetSoloOff;
+ }
+}
diff --git a/server/lib/core/commands/show_ally_deck_command.dart b/server/lib/core/commands/show_ally_deck_command.dart
new file mode 100644
index 0000000..074d640
--- /dev/null
+++ b/server/lib/core/commands/show_ally_deck_command.dart
@@ -0,0 +1,16 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ShowAllyDeckCommand extends Command {
+ ShowAllyDeckCommand();
+
+ @override
+ void execute() {
+ MonsterMethods.showAllyDeck(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdShowAllyDeck;
+ }
+}
diff --git a/server/lib/core/commands/shuffle_ability_card_command.dart b/server/lib/core/commands/shuffle_ability_card_command.dart
new file mode 100644
index 0000000..8acd082
--- /dev/null
+++ b/server/lib/core/commands/shuffle_ability_card_command.dart
@@ -0,0 +1,26 @@
+import 'package:collection/collection.dart';
+
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ShuffleAbilityCardCommand extends Command {
+ final String ownerId;
+ ShuffleAbilityCardCommand(this.ownerId);
+
+ @override
+ void execute() {
+ final Monster? monster = GameMethods.getCurrentMonsters().firstWhereOrNull(
+ (element) => element.id == ownerId,
+ );
+ if (monster == null) return;
+ final MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck);
+ if (deck == null) return;
+ deck.shuffle(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdExtraAbilityShuffle;
+ }
+}
diff --git a/server/lib/core/commands/shuffle_amd_card_command.dart b/server/lib/core/commands/shuffle_amd_card_command.dart
new file mode 100644
index 0000000..5eabd3c
--- /dev/null
+++ b/server/lib/core/commands/shuffle_amd_card_command.dart
@@ -0,0 +1,22 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ShuffleAMDCardCommand extends Command {
+ final String name;
+ final GameState _gameState;
+
+ ShuffleAMDCardCommand(this.name, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ final deck = GameMethods.getModifierDeck(name, _gameState);
+ deck.shuffleUnDrawn(stateAccess);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdExtraAmdShuffle;
+ }
+}
diff --git a/server/lib/core/commands/shuffle_drawn_ability_card_command.dart b/server/lib/core/commands/shuffle_drawn_ability_card_command.dart
new file mode 100644
index 0000000..795b9b4
--- /dev/null
+++ b/server/lib/core/commands/shuffle_drawn_ability_card_command.dart
@@ -0,0 +1,26 @@
+import 'package:collection/collection.dart';
+
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class ShuffleDrawnAbilityCardCommand extends Command {
+ final String deck;
+ ShuffleDrawnAbilityCardCommand(this.deck);
+
+ @override
+ void execute() {
+ Monster? monster = GameMethods.getCurrentMonsters().firstWhereOrNull(
+ (element) => element.type.deck == deck,
+ );
+ if (monster != null) {
+ MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck);
+ deck?.shuffleUnDrawn(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdDrawnAbilityShuffle;
+ }
+}
diff --git a/server/lib/core/commands/track_standees_command.dart b/server/lib/core/commands/track_standees_command.dart
new file mode 100644
index 0000000..6ca8211
--- /dev/null
+++ b/server/lib/core/commands/track_standees_command.dart
@@ -0,0 +1,48 @@
+import '../settings.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class TrackStandeesCommand extends Command {
+ final GameState _gameState;
+ final Settings _settings;
+ final bool track;
+
+ TrackStandeesCommand(
+ this.track, {
+ required GameState gameState,
+ required Settings settings,
+ }) : _gameState = gameState,
+ _settings = settings;
+
+ @override
+ void execute() {
+ _settings.noStandees = !track;
+ _handleNoStandeesSettingChange();
+ }
+
+ @override
+ String describe() {
+ if (!track) {
+ return commandL10n.cmdDontTrackStandees;
+ }
+ return commandL10n.cmdTrackStandees;
+ }
+
+ void _handleNoStandeesSettingChange() {
+ if (_settings.noStandees) {
+ for (final item in _gameState.currentList) {
+ if (item is Monster) {
+ item.clearMonsterInstances(stateAccess);
+ item.notifyMonsterInstances(stateAccess);
+ }
+ }
+ } else {
+ for (final item in _gameState.currentList) {
+ if (item is Monster && item.isActive) {
+ item.setActive(stateAccess, false);
+ }
+ }
+ }
+ _gameState.notifyListeners();
+ }
+}
diff --git a/server/lib/core/commands/turn_done_command.dart b/server/lib/core/commands/turn_done_command.dart
new file mode 100644
index 0000000..d9c756a
--- /dev/null
+++ b/server/lib/core/commands/turn_done_command.dart
@@ -0,0 +1,34 @@
+import '../game_event.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class TurnDoneCommand extends Command {
+ int index = 0;
+ final String id;
+ final GameState _gameState;
+
+ TurnDoneCommand(this.id, {required GameState gameState})
+ : _gameState = gameState {
+ index = 0;
+ for (int i = 0; i < _gameState.currentList.length; i++) {
+ if (id == _gameState.currentList[i].id) {
+ index = i;
+ break;
+ }
+ }
+ }
+
+ @override
+ void execute() {
+ RoundMethods.setTurnDone(stateAccess, index);
+ _gameState.notifyListeners();
+ }
+
+ @override
+ GameEvent get event => TurnDoneEvent(id);
+
+ @override
+ String describe() {
+ return commandL10n.cmdTurnDone(id);
+ }
+}
diff --git a/server/lib/core/commands/unlock_special_command.dart b/server/lib/core/commands/unlock_special_command.dart
new file mode 100644
index 0000000..546b7ff
--- /dev/null
+++ b/server/lib/core/commands/unlock_special_command.dart
@@ -0,0 +1,32 @@
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class UnlockSpecialCommand extends Command {
+ final GameState _gameState;
+ final String _id;
+ bool _unlock = true;
+
+ UnlockSpecialCommand(this._id, {required GameState gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ if (_gameState.unlockedClasses.contains(_id)) {
+ _unlock = false;
+ ScenarioMethods.clearUnlockedClass(stateAccess, _id);
+ } else {
+ ScenarioMethods.unlockClass(stateAccess, _id);
+ }
+ }
+
+ @override
+ void onUndo();
+
+ @override
+ String describe() {
+ if (_unlock) {
+ return commandL10n.cmdUnlock(_id);
+ }
+ return commandL10n.cmdLock(_id);
+ }
+}
diff --git a/server/lib/core/commands/use_element_command.dart b/server/lib/core/commands/use_element_command.dart
new file mode 100644
index 0000000..5183106
--- /dev/null
+++ b/server/lib/core/commands/use_element_command.dart
@@ -0,0 +1,21 @@
+import '../enums.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class UseElementCommand extends Command {
+ final Elements element;
+ final GameState? _gameState;
+
+ UseElementCommand(this.element, {GameState? gameState})
+ : _gameState = gameState;
+
+ @override
+ void execute() {
+ ElementMethods.useElement(stateAccess, element, gameState: _gameState);
+ }
+
+ @override
+ String describe() {
+ return commandL10n.cmdUseElement(element.name);
+ }
+}
diff --git a/server/lib/core/commands/use_fh_perks_command.dart b/server/lib/core/commands/use_fh_perks_command.dart
new file mode 100644
index 0000000..8200ae7
--- /dev/null
+++ b/server/lib/core/commands/use_fh_perks_command.dart
@@ -0,0 +1,28 @@
+import '../game_methods.dart';
+import '../state/game_state.dart';
+import 'command_l10n.dart';
+
+class UseFHPerksCommand extends Command {
+ final String characterId;
+
+ UseFHPerksCommand(this.characterId);
+
+ @override
+ void execute() {
+ Character? character = GameMethods.getCharacterByName(characterId);
+ if (character != null) {
+ character.flipUseFHPerks(stateAccess);
+ }
+ }
+
+ @override
+ String describe() {
+ Character? character = GameMethods.getCharacterByName(characterId);
+ final charId = character?.id ?? characterId;
+ final use = character?.characterState.useFHPerks ?? false;
+ if (use) {
+ return commandL10n.cmdUseFhPerks(charId);
+ }
+ return commandL10n.cmdDontUseFhPerks(charId);
+ }
+}