summaryrefslogtreecommitdiff
path: root/server/lib/core/commands/add_character_command.dart
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/core/commands/add_character_command.dart')
-rw-r--r--server/lib/core/commands/add_character_command.dart47
1 files changed, 47 insertions, 0 deletions
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);
+ }
+}