summaryrefslogtreecommitdiff
path: root/server/test/resource/game_methods_test.dart
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-12 00:28:50 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-12 00:28:50 +0100
commit808294adad3f378ad8d66b698acf8df7f49c2302 (patch)
treecfd11a1395a8ad482311969f86abbbad97e7e0b4 /server/test/resource/game_methods_test.dart
parentf6955e34489c79f6d5b764cb6a39b1387366b433 (diff)
Phase 1: headless game engine on the server (M1)
Complete mechanical port of the reference app's game engine to server/lib/core/ so later phases are UI-only: - models/ (7), state/ (GameState + 18 part files), methods/ (7), game_methods, 79 command files, enums, card_stack, stat_calculator, action_handler (index, 250-deep history, save-per-action, undo/redo), disk-based game_data, l10n, translation_service, service_locator - ValueNotifier/ChangeNotifier removed in favor of plain fields with a minimal GameState listener hook for the Phase 2 broadcast layer; shared_preferences replaced by the SaveStore abstraction (InMemory for tests, File-backed for bin/main.dart) - command registry: 82 entries mapping wire names to constructors with arg validation; live-object args (loot/ability cards, figure lists) travel as id/name/nr and resolve against live state, enums by name, injected singletons never serialize - line_builder ported to Phase 1 scope: stat_applier + minimal LineBuilder (isElement, tokens); widget rendering deferred to Phase 4 - ported test suite: 81 test files, 562 tests green (command tests 1:1 with the reference, resource tests, registry smoke tests) - new headless integration test drives a full round: scenario setup, characters + standee, secret-initiative gate, draw, every figure's turn (incl. undo/redo), next round, round 2, round 3 - PORTING.md: the conventions contract used for the port - bin/main.dart boots the engine (file save store, assets/data) before serving; pubspec gains built_collection, collection, get_it, intl - dart format drift on pre-existing net/test files from the current formatter (whitespace only) dart analyze warning-free; dart test 562/562.
Diffstat (limited to 'server/test/resource/game_methods_test.dart')
-rw-r--r--server/test/resource/game_methods_test.dart1292
1 files changed, 1292 insertions, 0 deletions
diff --git a/server/test/resource/game_methods_test.dart b/server/test/resource/game_methods_test.dart
new file mode 100644
index 0000000..f960ca9
--- /dev/null
+++ b/server/test/resource/game_methods_test.dart
@@ -0,0 +1,1292 @@
+// ignore_for_file: avoid-late-keyword, no-empty-block, no-magic-number, avoid-non-null-assertion, prefer-first
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/models/character_class.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_perk_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/commands/draw_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_init_command.dart';
+import 'package:x_haven_server/core/commands/set_level_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/turn_done_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../command/test_helpers.dart';
+
+void main() async {
+ await setUpGame();
+
+ group('GameMethods', () {
+ group('getTrapValue', () {
+ test('should return 2 + game level when level is 4', () {
+ // Act: Call the method we are testing.
+ SetLevelCommand(4, null).execute();
+ String oldState = gameState.toString();
+ final result = GameMethods.getTrapValue();
+
+ // Assert: Check if the result is what we expect.
+ expect(result, 6);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return 2 when game level is 0', () {
+ SetLevelCommand(0, null).execute();
+ String oldState = gameState.toString();
+ // Act
+ final result = GameMethods.getTrapValue();
+
+ // Assert
+ expect(result, 2);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return 9 when game level is 7', () {
+ SetLevelCommand(7, null).execute();
+ String oldState = gameState.toString();
+ // Act
+ final result = GameMethods.getTrapValue();
+
+ // Assert
+ expect(result, 9);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should bork when game level is out of bounds', () {
+ expect(
+ () => SetLevelCommand(77, null).execute(),
+ throwsA(isA<AssertionError>()),
+ );
+ });
+
+ test('should bork when game level is out of bounds low', () {
+ expect(
+ () => SetLevelCommand(-77, null).execute(),
+ throwsA(isA<AssertionError>()),
+ );
+ });
+ });
+
+ group('getHazardValue', () {
+ test('should return 1 + ceil(level / 3) for Frosthaven', () {
+ getIt<Settings>().style = Style.frosthaven;
+ SetLevelCommand(0, null).execute();
+ expect(GameMethods.getHazardValue(), 1);
+ SetLevelCommand(1, null).execute();
+ expect(GameMethods.getHazardValue(), 2);
+ SetLevelCommand(2, null).execute();
+ expect(GameMethods.getHazardValue(), 2);
+ SetLevelCommand(3, null).execute();
+ expect(GameMethods.getHazardValue(), 2);
+ SetLevelCommand(4, null).execute();
+ expect(GameMethods.getHazardValue(), 3);
+ SetLevelCommand(5, null).execute();
+ expect(GameMethods.getHazardValue(), 3);
+ SetLevelCommand(6, null).execute();
+ expect(GameMethods.getHazardValue(), 3);
+ SetLevelCommand(7, null).execute();
+ expect(GameMethods.getHazardValue(), 4);
+ });
+
+ test('should return floor(trapValue / 2) for Gloomhaven', () {
+ SetCampaignCommand("Gloomhaven").execute();
+ getIt<Settings>().fhHazTerrainCalcInOGGloom = false;
+
+ SetLevelCommand(0, null).execute();
+ expect(GameMethods.getHazardValue(), 1);
+ SetLevelCommand(1, null).execute();
+ expect(GameMethods.getHazardValue(), 1);
+ SetLevelCommand(2, null).execute();
+ expect(GameMethods.getHazardValue(), 2);
+ SetLevelCommand(3, null).execute();
+ expect(GameMethods.getHazardValue(), 2);
+ SetLevelCommand(4, null).execute();
+ expect(GameMethods.getHazardValue(), 3);
+ SetLevelCommand(5, null).execute();
+ expect(GameMethods.getHazardValue(), 3);
+ SetLevelCommand(6, null).execute();
+ expect(GameMethods.getHazardValue(), 4);
+ SetLevelCommand(7, null).execute();
+ expect(GameMethods.getHazardValue(), 4);
+ });
+ });
+
+ group('getXPValue', () {
+ test('should return 4 + 2 * level', () {
+ SetLevelCommand(0, null).execute();
+ expect(GameMethods.getXPValue(), 4);
+ SetLevelCommand(1, null).execute();
+ expect(GameMethods.getXPValue(), 6);
+ SetLevelCommand(7, null).execute();
+ expect(GameMethods.getXPValue(), 18);
+ });
+ });
+
+ group('getCoinValue', () {
+ test('should return correct coin value for level', () {
+ SetLevelCommand(0, null).execute();
+ expect(GameMethods.getCoinValue(), 2);
+ SetLevelCommand(1, null).execute();
+ expect(GameMethods.getCoinValue(), 2);
+ SetLevelCommand(2, null).execute();
+ expect(GameMethods.getCoinValue(), 3);
+ SetLevelCommand(3, null).execute();
+ expect(GameMethods.getCoinValue(), 3);
+ SetLevelCommand(4, null).execute();
+ expect(GameMethods.getCoinValue(), 4);
+ SetLevelCommand(5, null).execute();
+ expect(GameMethods.getCoinValue(), 4);
+ SetLevelCommand(6, null).execute();
+ expect(GameMethods.getCoinValue(), 5);
+ SetLevelCommand(7, null).execute();
+ expect(GameMethods.getCoinValue(), 6);
+ });
+ });
+
+ group('getRecommendedLevel', () {
+ test('should return 1 if no characters', () {
+ getIt<GameState>().clearList();
+
+ expect(GameMethods.getRecommendedLevel(), 1);
+ });
+
+ test('should calculate recommended level for multiple characters', () {
+ //getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ AddCharacterCommand(
+ 'Banner Spear',
+ 'Frosthaven',
+ 'Banner Spear',
+ 1,
+ ).execute();
+ SetCharacterLevelCommand(3, 'Blinkblade').execute();
+ SetCharacterLevelCommand(5, 'Banner Spear').execute();
+
+ expect(GameMethods.getRecommendedLevel(), 2);
+ });
+
+ test('should calculate recommended level for solo', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ SetCharacterLevelCommand(3, 'Blinkblade').execute();
+ SetSoloCommand(true).execute();
+
+ expect(GameMethods.getRecommendedLevel(), 2);
+ });
+ });
+
+ group('canDraw', () {
+ test('should return false if no characters', () {
+ getIt<GameState>().clearList();
+ expect(GameMethods.canDraw(), isFalse);
+ });
+
+ test('should return true if noInit setting is true', () {
+ getIt<Settings>().noInit = true;
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ expect(GameMethods.canDraw(), isTrue);
+ });
+
+ test('should return false if a character has no initiative', () {
+ getIt<Settings>().noInit = false;
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ expect(GameMethods.canDraw(), isFalse);
+ });
+
+ test('should return true if all characters have initiative', () {
+ getIt<Settings>().noInit = false;
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ SetInitCommand(
+ 'Blinkblade',
+ 25,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(GameMethods.canDraw(), isTrue);
+ });
+ });
+
+ //todo:
+ /*group('isInactiveForRule', () {
+ test('should return true if monster is inactive by rule', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ // In scenario 1, the Guard is inactive in round 1
+ expect(GameMethods.isInactiveForRule('Guard'), isTrue);
+ });
+
+ test('should return false if monster is not inactive by rule', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ expect(GameMethods.isInactiveForRule('Guard'), isFalse);
+ });
+ });*/
+
+ //todo:
+ /*group('getDeck', () {
+ test('should return the correct deck', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ final deck = GameMethods.getDeck('Guard');
+ expect(deck, isNotNull);
+ expect(deck!.name, 'Guard');
+ });
+
+ test('should return null if deck does not exist', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ final deck = GameMethods.getDeck('NonExistentDeck');
+ expect(deck, isNull);
+ });
+ });*/
+
+ group('getInitiative', () {
+ test('should return character initiative', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ SetInitCommand(
+ 'Blinkblade',
+ 35,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final character = getIt<GameState>().currentList.first as Character;
+ expect(GameMethods.getInitiative(character), 35);
+ checkNoSideEffects([], oldState);
+ });
+
+ //todo
+ /*test('should return monster initiative', () {
+ //getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ AddMonsterCommand(gameState: getIt<GameState>()).execute();
+ DrawAbilityCardCommand().execute();
+ final monster = getIt<GameState>()
+ .currentList
+ .firstWhere((m) => m is Monster) as Monster;
+ expect(GameMethods.getInitiative(monster), isNot(99));
+ expect(GameMethods.getInitiative(monster), isNot(0));
+ });*/
+ });
+
+ group('getCharacterByName', () {
+ test('should return the correct character', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ final character = GameMethods.getCharacterByName('Blinkblade');
+ expect(character, isNotNull);
+ expect(character!.id, 'Blinkblade');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return null if character does not exist', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ final character = GameMethods.getCharacterByName(
+ 'NonExistentCharacter',
+ );
+ expect(character, isNull);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getCurrentCharacters', () {
+ test('should return a list of current characters', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ final characters = GameMethods.getCurrentCharacters();
+ expect(characters.length, 2);
+ expect(characters[1].id, 'Blinkblade');
+ expect(characters[0].id, 'Banner Spear');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return an empty list if no characters', () {
+ getIt<GameState>().clearList();
+ String oldState = gameState.toString();
+ final characters = GameMethods.getCurrentCharacters();
+ expect(characters, isEmpty);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getCurrentCharacter', () {
+ test('should return the character whose turn it is', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ ).execute(); // It's now Banner Spear's turn
+ String oldState = gameState.toString();
+ final character = GameMethods.getCurrentCharacter();
+ expect(character, isNotNull);
+ expect(character!.id, 'Banner Spear');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return null if it is not a character turn', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Adds monsters
+ TurnDoneCommand(
+ getIt<GameState>().currentList.first.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // It's now a monster's turn
+ String oldState = gameState.toString();
+ final character = GameMethods.getCurrentCharacter();
+ expect(character, isNull);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getModifierDeck', () {
+ test('should return the monster modifier deck', () {
+ String oldState = gameState.toString();
+ final deck = GameMethods.getModifierDeck('', getIt<GameState>());
+ expect(deck, equals(getIt<GameState>().modifierDeck));
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return the allies modifier deck', () {
+ String oldState = gameState.toString();
+ final deck = GameMethods.getModifierDeck('allies', getIt<GameState>());
+ expect(deck, equals(getIt<GameState>().modifierDeckAllies));
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return a character modifier deck', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ String oldState = gameState.toString();
+ final deck = GameMethods.getModifierDeck(
+ 'Blinkblade',
+ getIt<GameState>(),
+ );
+ final character = getIt<GameState>().currentList.first as Character;
+ expect(deck, equals(character.characterState.modifierDeck));
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('canAddPerk', () {
+ test('should return true if perk can be added', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ String oldState = gameState.toString();
+ final character = getIt<GameState>().currentList.first as Character;
+ expect(GameMethods.canAddPerk(character, 0), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if perk cannot be added', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ AddPerkCommand(character.id, 0).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.canAddPerk(character, 0), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('canRemovePerk', () {
+ test('should return true if perk can be removed', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ AddPerkCommand(character.id, 0).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.canRemovePerk(character, 0), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if perk cannot be removed', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand(
+ 'Blinkblade',
+ 'Frosthaven',
+ 'Blinkblade',
+ 1,
+ ).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ AddPerkCommand(character.id, 12).execute();
+ AddPerkCommand(character.id, 13).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.canRemovePerk(character, 5), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('perkGfxIdToCardId', () {
+ test('should return the original gfx id if it is not a perk', () {
+ String oldState = gameState.toString();
+ final id = GameMethods.perkGfxIdToCardId(
+ 'test',
+ PerkModel("", const [], const []),
+ 0,
+ );
+ expect(id, 'test');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return the correct card id for a perk', () {
+ String oldState = gameState.toString();
+ final perk = PerkModel("", const [], const ['perks/test']);
+ final id = GameMethods.perkGfxIdToCardId('perks/test', perk, 0);
+ expect(id, 'P0');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return the correct card id for a perk with two images', () {
+ String oldState = gameState.toString();
+ final perk = PerkModel("", const [], const [
+ 'perks/test',
+ 'perks/test2',
+ ]);
+ final id = GameMethods.perkGfxIdToCardId('perks/test2', perk, 0);
+ expect(id, 'P0-2');
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getCurrentCharacterAmount', () {
+ test('should return the number of characters', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.getCurrentCharacterAmount(), 2);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return 0 if no characters', () {
+ getIt<GameState>().clearList();
+ String oldState = gameState.toString();
+ expect(GameMethods.getCurrentCharacterAmount(), 0);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getCurrentMonsters', () {
+ test('should return a list of current monsters', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monsters = GameMethods.getCurrentMonsters();
+ expect(monsters.length, 3);
+ expect(monsters[0].id, 'Zealot');
+ expect(monsters[1].id, 'Chaos Demon');
+ expect(monsters[2].id, 'Blood Tumor');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return an empty list if no monsters', () {
+ getIt<GameState>().clearList();
+ String oldState = gameState.toString();
+ final monsters = GameMethods.getCurrentMonsters();
+ expect(monsters, isEmpty);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ /*group('getNextAvailableBnBStandee', () {
+ test('should return the next available standee number', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Buttons and Bugs').execute();
+ //todo:
+ //SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt<GameState>()).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ AddStandeeCommand(1, null, monster.id, MonsterType.normal, false, gameState: getIt<GameState>())
+ .execute();
+ final nextStandee = GameMethods.getNextAvailableBnBStandee(monster);
+ expect(nextStandee, 2);
+ });
+ });*/
+
+ group('getRandomStandee', () {
+ test('should return a valid standee number', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final standee = GameMethods.getRandomStandee(monster);
+ expect(standee, isNot(0));
+ expect(standee, lessThanOrEqualTo(monster.type.count));
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getFigure', () {
+ test('should return a character', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ final figure = GameMethods.getFigure(null, 'Blinkblade');
+ expect(figure, isNotNull);
+ expect(figure, isA<CharacterState>());
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return a monster instance', () {
+ getIt<GameState>().clearList();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final figure = GameMethods.getFigure(
+ monster.id,
+ monster.monsterInstances.first.getId(),
+ );
+ expect(figure, isNotNull);
+ expect(figure, isA<MonsterInstance>());
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getFigureIdFromNr', () {
+ test('should return the figure id', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final id = GameMethods.getFigureIdFromNr(monster.id, 1);
+ expect(id, isNotNull);
+ expect(id, isNotEmpty);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isObjectiveOrEscort', () {
+ test('should return true for Objective', () {
+ final cmd = AddCharacterCommand("Objective", "na", "whatever", 1);
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isObjectiveOrEscort(cmd.character!.characterClass),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for Escort', () {
+ final cmd = AddCharacterCommand("Escort", "na", "whatever", 1);
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isObjectiveOrEscort(cmd.character!.characterClass),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for other characters', () {
+ final cmd = AddCharacterCommand(
+ "Blinkblade",
+ "Frosthaven",
+ "whatever",
+ 1,
+ );
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isObjectiveOrEscort(cmd.character!.characterClass),
+ isFalse,
+ );
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('shouldShowAlliesDeck', () {
+ test('should return true if showAllyDeck setting is true', () {
+ String oldState = gameState.toString();
+ getIt<Settings>().showAmdDeck = true;
+ ShowAllyDeckCommand().execute();
+ expect(GameMethods.shouldShowAlliesDeck(), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if showAmdDeck setting is false', () {
+ String oldState = gameState.toString();
+ getIt<Settings>().showAmdDeck = false;
+ expect(GameMethods.shouldShowAlliesDeck(), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true if an ally monster is in play', () {
+ getIt<Settings>().showAmdDeck = true;
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Adds monsters
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.shouldShowAlliesDeck(), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('canExpire', () {
+ test('should return true for conditions that expire', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.canExpire(Condition.strengthen), isTrue);
+ expect(GameMethods.canExpire(Condition.muddle), isTrue);
+ expect(GameMethods.canExpire(Condition.invisible), isTrue);
+ expect(GameMethods.canExpire(Condition.stun), isTrue);
+ expect(GameMethods.canExpire(Condition.disarm), isTrue);
+ expect(GameMethods.canExpire(Condition.immobilize), isTrue);
+ expect(GameMethods.canExpire(Condition.impair), isTrue);
+ expect(GameMethods.canExpire(Condition.chill), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for conditions that do not expire', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.canExpire(Condition.bane), isFalse);
+ expect(GameMethods.canExpire(Condition.poison), isFalse);
+ expect(GameMethods.canExpire(Condition.wound), isFalse);
+ expect(GameMethods.canExpire(Condition.regenerate), isFalse);
+ expect(GameMethods.canExpire(Condition.ward), isFalse);
+ expect(GameMethods.canExpire(Condition.brittle), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isFrosthavenStyledEdition', () {
+ test('should return true for Frosthaven', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyledEdition('Frosthaven'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for Buttons and Bugs', () {
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isFrosthavenStyledEdition('Buttons and Bugs'),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for Gloomhaven 2nd Edition', () {
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isFrosthavenStyledEdition('Gloomhaven 2nd Edition'),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for Mercenary Packs', () {
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.isFrosthavenStyledEdition('Mercenary Packs'),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for Gloomhaven', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyledEdition('Gloomhaven'), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isFrosthavenStyle', () {
+ test('should return true for Frosthaven monster', () {
+ final monster = Monster('Ancient Artillery (FH)', 1, false);
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyle(monster.type), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for Gloomhaven monster', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Adds monsters
+ String oldState = gameState.toString();
+ final monster = Monster('Zealot', 1, false);
+ getIt<Settings>().style = Style.original;
+ expect(GameMethods.isFrosthavenStyle(monster.type), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true if style is set to Frosthaven', () {
+ String oldState = gameState.toString();
+ getIt<Settings>().style = Style.frosthaven;
+ expect(GameMethods.isFrosthavenStyle(null), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isCustomCampaign', () {
+ test('should return true for Crimson Scales', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isCustomCampaign('Crimson Scales'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for Trail of Ashes', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isCustomCampaign('Trail of Ashes'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return true for CCUG', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isCustomCampaign('CCUG'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for Frosthaven', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.isCustomCampaign('Frosthaven'), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('findNrFromScenarioName', () {
+ test('should return the scenario number from the name', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.findNrFromScenarioName('#1 '), 1);
+ expect(
+ GameMethods.findNrFromScenarioName('#10.0 A Sticky Situation'),
+ 10,
+ );
+ expect(GameMethods.findNrFromScenarioName('#123 - Some Scenario'), 123);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return null if no number is found', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.findNrFromScenarioName('Some Scenario'), isNull);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isOgGloomEdition', () {
+ test('should return true for Gloomhaven', () {
+ SetCampaignCommand('Gloomhaven').execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.isOgGloomEdition(), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false for Frosthaven', () {
+ SetCampaignCommand('Frosthaven').execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.isOgGloomEdition(), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('hasLootDeck', () {
+ test('should return true if loot deck has cards', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ //DrawLootCardCommand(gameState: getIt<GameState>()).execute();
+ expect(GameMethods.hasLootDeck(), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if loot deck is empty', () {
+ //getIt<GameState>().clearLootDeck();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.hasLootDeck(), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if hideLootDeck setting is true', () {
+ String oldState = gameState.toString();
+ getIt<Settings>().hideLootDeck = true;
+ expect(GameMethods.hasLootDeck(), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getFactionCards', () {
+ test('should return the correct cards for Demons', () {
+ String oldState = gameState.toString();
+ final cards = GameMethods.getFactionCards('Demons');
+ expect(cards.length, 4);
+ expect(cards[0].gfx, 'Demons-perks/plus1any');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return the correct cards for Merchant-Guild', () {
+ String oldState = gameState.toString();
+ final cards = GameMethods.getFactionCards('Merchant-Guild');
+ expect(cards.length, 4);
+ expect(cards[0].gfx, 'Merchant-Guild-perks/plus1curse');
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return the correct cards for Military', () {
+ String oldState = gameState.toString();
+ final cards = GameMethods.getFactionCards('Military');
+ expect(cards.length, 4);
+ expect(cards[0].gfx, 'Military-perks/plus1strengthenally');
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isCardInAnyCharacterDeck', () {
+ test('should return true if card is in a character deck', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ AddPerkCommand(character.id, 3).execute(); // Adds a +1 card
+ String oldState = gameState.toString();
+ expect(GameMethods.isCardInAnyCharacterDeck('P3'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if card is not in any character deck', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ String oldState = gameState.toString();
+ expect(GameMethods.isCardInAnyCharacterDeck('P3'), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('hasRetaliate', () {
+ test('should return true if monster has retaliate', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ "Flame Demon (BnB)",
+ 3,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Monster without shield
+ AddStandeeCommand(
+ 1,
+ null,
+ "Flame Demon (BnB)",
+ MonsterType.boss,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final instance = monster.monsterInstances.first;
+ expect(GameMethods.hasRetaliate(monster, instance), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if monster does not have retaliate', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ "Black Sludge",
+ 3,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Monster without shield
+ AddStandeeCommand(
+ 1,
+ null,
+ "Black Sludge",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final instance = monster.monsterInstances.first;
+ expect(GameMethods.hasRetaliate(monster, instance), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('hasShield', () {
+ test('should return true if monster has shield', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ "Black Sludge",
+ 3,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Monster without shield
+ AddStandeeCommand(
+ 1,
+ null,
+ "Black Sludge",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final instance = monster.monsterInstances.first;
+ expect(GameMethods.hasShield(monster, instance), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('should return false if monster does not have shield', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute(); // Monster without shield
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final instance = monster.monsterInstances.first;
+ expect(GameMethods.hasShield(monster, instance), isFalse);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('canDraw - dead character bypasses initiative check', () {
+ test(
+ 'dead character (health=0) does not block draw even with no init',
+ () {
+ getIt<GameState>().clearList();
+ getIt<Settings>().noInit = false;
+ AddCharacterCommand('Blinkblade', 'Frosthaven', null, 1).execute();
+ // Kill the character so health = 0
+ final character = getIt<GameState>().currentList.first as Character;
+ // Reduce health to 0 via ChangeHealthCommand
+ ChangeHealthCommand(
+ -1000,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.health, 0);
+ // Dead character with 0 initiative should NOT block the draw
+ expect(GameMethods.canDraw(), isTrue);
+ },
+ );
+ });
+
+ group('getInitiative - inactive monster', () {
+ test('inactive monster returns initiative 99', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ // Monster is inactive by default (isActive = false until ability drawn)
+ expect(monster.isActive, isFalse);
+ String oldState = gameState.toString();
+ expect(GameMethods.getInitiative(monster), 99);
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('summonDoesNotDie', () {
+ test('Glacial Torrent Glacier does not die', () {
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.summonDoesNotDie('Glacial Torrent', 'Glacier'),
+ isTrue,
+ );
+ checkNoSideEffects([], oldState);
+ });
+
+ test('D.O.M.E. Barrier does not die', () {
+ String oldState = gameState.toString();
+ expect(GameMethods.summonDoesNotDie('D.O.M.E.', 'Barrier'), isTrue);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('arbitrary owner and id returns false', () {
+ String oldState = gameState.toString();
+ expect(
+ GameMethods.summonDoesNotDie('Blinkblade', 'Jade Falcon'),
+ isFalse,
+ );
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('getFigure - character summon lookup', () {
+ test('returns summon instance when found via character ownerId', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', null, 1).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ // Add a summon to the character
+ final summonData = SummonData(
+ 1,
+ 'Jade Falcon',
+ 3,
+ 2,
+ 2,
+ 0,
+ 'Jade Falcon',
+ );
+ AddStandeeCommand(
+ 1,
+ summonData,
+ 'Blinkblade',
+ MonsterType.normal,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(character.characterState.summonList, isNotEmpty);
+ final summon = character.characterState.summonList.first;
+ final figureId = summon.getId();
+
+ String oldState = gameState.toString();
+ final figure = GameMethods.getFigure('Blinkblade', figureId);
+ expect(figure, isNotNull);
+ expect(figure, isA<MonsterInstance>());
+ checkNoSideEffects([], oldState);
+ });
+ });
+
+ group('isFrosthavenStyledEdition - Solo edition', () {
+ test('Solo with Frosthaven scenario number is frosthaven styled', () {
+ // Directly set the scenario string to avoid SetScenarioCommand's loot-deck lookup
+ gameState.scenario = '#1 A Town Aflame';
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyledEdition('Solo'), isTrue);
+ checkNoSideEffects(['scenario'], oldState);
+ });
+
+ test(
+ 'Solo with #19 scenario is NOT frosthaven styled (Forgotten Circles)',
+ () {
+ gameState.scenario = '#19 Forgotten Circles';
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyledEdition('Solo'), isFalse);
+ checkNoSideEffects(['scenario'], oldState);
+ },
+ );
+
+ test(
+ 'Solo with scenario not in 1-100 range is not frosthaven styled',
+ () {
+ gameState.scenario = '#200 Some Scenario';
+ String oldState = gameState.toString();
+ expect(GameMethods.isFrosthavenStyledEdition('Solo'), isFalse);
+ checkNoSideEffects(['scenario'], oldState);
+ },
+ );
+ });
+
+ group('hasShield - boss type', () {
+ test('boss type standee checks boss attribute for shield', () {
+ getIt<GameState>().clearList();
+ // Flame Demon (BnB) is a boss with retaliate; use it to test boss path
+ AddMonsterCommand(
+ 'Flame Demon (BnB)',
+ 3,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Flame Demon (BnB)',
+ MonsterType.boss,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ final instance = monster.monsterInstances.first;
+ // Boss path is exercised; result depends on actual data, just verify no crash
+ expect(GameMethods.hasShield(monster, instance), isA<bool>());
+ expect(GameMethods.hasRetaliate(monster, instance), isA<bool>());
+ });
+ });
+
+ group('getNextAvailableBnBStandee', () {
+ test('returns next available standee number when one is taken', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Zealot',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ String oldState = gameState.toString();
+ final next = GameMethods.getNextAvailableBnBStandee(monster);
+ // Standee 1 is taken; next available should be 2
+ expect(next, 2);
+ checkNoSideEffects([], oldState);
+ });
+
+ test('returns 0 when all standees are taken', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster = getIt<GameState>().currentList.first as Monster;
+ for (int i = 1; i <= monster.type.count; i++) {
+ AddStandeeCommand(
+ i,
+ null,
+ 'Zealot',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ }
+ String oldState = gameState.toString();
+ final next = GameMethods.getNextAvailableBnBStandee(monster);
+ expect(next, 0);
+ checkNoSideEffects([], oldState);
+ });
+ });
+ });
+}