// 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(); final 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(); final 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(); final 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()), ); }); test('should bork when game level is out of bounds low', () { expect( () => SetLevelCommand(-77, null).execute(), throwsA(isA()), ); }); }); group('getHazardValue', () { test('should return 1 + ceil(level / 3) for Frosthaven', () { getIt().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().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().clearList(); expect(GameMethods.getRecommendedLevel(), 1); }); test('should calculate recommended level for multiple characters', () { //getIt().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().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().clearList(); expect(GameMethods.canDraw(), isFalse); }); test('should return true if noInit setting is true', () { getIt().noInit = true; getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); expect(GameMethods.canDraw(), isTrue); }); test('should return false if a character has no initiative', () { getIt().noInit = false; getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); expect(GameMethods.canDraw(), isFalse); }); test('should return true if all characters have initiative', () { getIt().noInit = false; getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); SetInitCommand( 'Blinkblade', 25, gameState: getIt(), ).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()).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()).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()).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()).execute(); final deck = GameMethods.getDeck('NonExistentDeck'); expect(deck, isNull); }); });*/ group('getInitiative', () { test('should return character initiative', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); SetInitCommand( 'Blinkblade', 35, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final character = getIt().currentList.first as Character; expect(GameMethods.getInitiative(character), 35); checkNoSideEffects([], oldState); }); //todo /*test('should return monster initiative', () { //getIt().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt()).execute(); AddMonsterCommand(gameState: getIt()).execute(); DrawAbilityCardCommand().execute(); final monster = getIt() .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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); final 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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); final 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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute(); final 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().clearList(); final 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().clearList(); AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); DrawCommand(gameState: getIt()).execute(); TurnDoneCommand( 'Blinkblade', gameState: getIt(), ).execute(); // It's now Banner Spear's turn final 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().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); // Adds monsters TurnDoneCommand( getIt().currentList.first.id, gameState: getIt(), ).execute(); // It's now a monster's turn final String oldState = gameState.toString(); final character = GameMethods.getCurrentCharacter(); expect(character, isNull); checkNoSideEffects([], oldState); }); }); group('getModifierDeck', () { test('should return the monster modifier deck', () { final String oldState = gameState.toString(); final deck = GameMethods.getModifierDeck('', getIt()); expect(deck, equals(getIt().modifierDeck)); checkNoSideEffects([], oldState); }); test('should return the allies modifier deck', () { final String oldState = gameState.toString(); final deck = GameMethods.getModifierDeck('allies', getIt()); expect(deck, equals(getIt().modifierDeckAllies)); checkNoSideEffects([], oldState); }); test('should return a character modifier deck', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); final String oldState = gameState.toString(); final deck = GameMethods.getModifierDeck( 'Blinkblade', getIt(), ); final character = getIt().currentList.first as Character; expect(deck, equals(character.characterState.modifierDeck)); checkNoSideEffects([], oldState); }); }); group('canAddPerk', () { test('should return true if perk can be added', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); final String oldState = gameState.toString(); final character = getIt().currentList.first as Character; expect(GameMethods.canAddPerk(character, 0), isTrue); checkNoSideEffects([], oldState); }); test('should return false if perk cannot be added', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); final character = getIt().currentList.first as Character; AddPerkCommand(character.id, 0).execute(); final String oldState = gameState.toString(); expect(GameMethods.canAddPerk(character, 0), isFalse); checkNoSideEffects([], oldState); }); }); group('canRemovePerk', () { test('should return true if perk can be removed', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); final character = getIt().currentList.first as Character; AddPerkCommand(character.id, 0).execute(); final String oldState = gameState.toString(); expect(GameMethods.canRemovePerk(character, 0), isTrue); checkNoSideEffects([], oldState); }); test('should return false if perk cannot be removed', () { getIt().clearList(); AddCharacterCommand( 'Blinkblade', 'Frosthaven', 'Blinkblade', 1, ).execute(); final character = getIt().currentList.first as Character; AddPerkCommand(character.id, 12).execute(); AddPerkCommand(character.id, 13).execute(); final 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', () { final 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', () { final 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', () { final 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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); AddCharacterCommand('Banner Spear', 'Frosthaven', "", 1).execute(); final String oldState = gameState.toString(); expect(GameMethods.getCurrentCharacterAmount(), 2); checkNoSideEffects([], oldState); }); test('should return 0 if no characters', () { getIt().clearList(); final String oldState = gameState.toString(); expect(GameMethods.getCurrentCharacterAmount(), 0); checkNoSideEffects([], oldState); }); }); group('getCurrentMonsters', () { test('should return a list of current monsters', () { getIt().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); final 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().clearList(); final String oldState = gameState.toString(); final monsters = GameMethods.getCurrentMonsters(); expect(monsters, isEmpty); checkNoSideEffects([], oldState); }); }); /*group('getNextAvailableBnBStandee', () { test('should return the next available standee number', () { getIt().clearList(); SetCampaignCommand('Buttons and Bugs').execute(); //todo: //SetScenarioCommand('#5 A Deeper Understanding', false, gameState: getIt()).execute(); final monster = getIt().currentList.first as Monster; AddStandeeCommand(1, null, monster.id, MonsterType.normal, false, gameState: getIt()) .execute(); final nextStandee = GameMethods.getNextAvailableBnBStandee(monster); expect(nextStandee, 2); }); });*/ group('getRandomStandee', () { test('should return a valid standee number', () { getIt().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final monster = getIt().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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); final String oldState = gameState.toString(); final figure = GameMethods.getFigure(null, 'Blinkblade'); expect(figure, isNotNull); expect(figure, isA()); checkNoSideEffects([], oldState); }); test('should return a monster instance', () { getIt().clearList(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); final monster = getIt().currentList.first as Monster; AddStandeeCommand( 1, null, monster.id, MonsterType.normal, false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final figure = GameMethods.getFigure( monster.id, monster.monsterInstances.first.getId(), ); expect(figure, isNotNull); expect(figure, isA()); checkNoSideEffects([], oldState); }); }); group('getFigureIdFromNr', () { test('should return the figure id', () { getIt().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); final monster = getIt().currentList.first as Monster; AddStandeeCommand( 1, null, monster.id, MonsterType.normal, false, gameState: getIt(), ).execute(); final 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); final 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); final 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, ); final String oldState = gameState.toString(); expect( GameMethods.isObjectiveOrEscort(cmd.character!.characterClass), isFalse, ); checkNoSideEffects([], oldState); }); }); group('shouldShowAlliesDeck', () { test('should return true if showAllyDeck setting is true', () { final String oldState = gameState.toString(); getIt().showAmdDeck = true; ShowAllyDeckCommand().execute(); expect(GameMethods.shouldShowAlliesDeck(), isTrue); checkNoSideEffects([], oldState); }); test('should return false if showAmdDeck setting is false', () { final String oldState = gameState.toString(); getIt().showAmdDeck = false; expect(GameMethods.shouldShowAlliesDeck(), isFalse); checkNoSideEffects([], oldState); }); test('should return true if an ally monster is in play', () { getIt().showAmdDeck = true; getIt().clearList(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); // Adds monsters AddMonsterCommand( "Zealot", 1, true, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); expect(GameMethods.shouldShowAlliesDeck(), isTrue); checkNoSideEffects([], oldState); }); }); group('canExpire', () { test('should return true for conditions that expire', () { final 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', () { final 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', () { final String oldState = gameState.toString(); expect(GameMethods.isFrosthavenStyledEdition('Frosthaven'), isTrue); checkNoSideEffects([], oldState); }); test('should return true for Buttons and Bugs', () { final String oldState = gameState.toString(); expect( GameMethods.isFrosthavenStyledEdition('Buttons and Bugs'), isTrue, ); checkNoSideEffects([], oldState); }); test('should return true for Gloomhaven 2nd Edition', () { final String oldState = gameState.toString(); expect( GameMethods.isFrosthavenStyledEdition('Gloomhaven 2nd Edition'), isTrue, ); checkNoSideEffects([], oldState); }); test('should return true for Mercenary Packs', () { final String oldState = gameState.toString(); expect( GameMethods.isFrosthavenStyledEdition('Mercenary Packs'), isTrue, ); checkNoSideEffects([], oldState); }); test('should return false for Gloomhaven', () { final 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); final 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(), ).execute(); // Adds monsters final String oldState = gameState.toString(); final monster = Monster('Zealot', 1, false); getIt().style = Style.original; expect(GameMethods.isFrosthavenStyle(monster.type), isFalse); checkNoSideEffects([], oldState); }); test('should return true if style is set to Frosthaven', () { final String oldState = gameState.toString(); getIt().style = Style.frosthaven; expect(GameMethods.isFrosthavenStyle(null), isTrue); checkNoSideEffects([], oldState); }); }); group('isCustomCampaign', () { test('should return true for Crimson Scales', () { final String oldState = gameState.toString(); expect(GameMethods.isCustomCampaign('Crimson Scales'), isTrue); checkNoSideEffects([], oldState); }); test('should return true for Trail of Ashes', () { final String oldState = gameState.toString(); expect(GameMethods.isCustomCampaign('Trail of Ashes'), isTrue); checkNoSideEffects([], oldState); }); test('should return true for CCUG', () { final String oldState = gameState.toString(); expect(GameMethods.isCustomCampaign('CCUG'), isTrue); checkNoSideEffects([], oldState); }); test('should return false for Frosthaven', () { final String oldState = gameState.toString(); expect(GameMethods.isCustomCampaign('Frosthaven'), isFalse); checkNoSideEffects([], oldState); }); }); group('findNrFromScenarioName', () { test('should return the scenario number from the name', () { final 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', () { final String oldState = gameState.toString(); expect(GameMethods.findNrFromScenarioName('Some Scenario'), isNull); checkNoSideEffects([], oldState); }); }); group('isOgGloomEdition', () { test('should return true for Gloomhaven', () { SetCampaignCommand('Gloomhaven').execute(); final String oldState = gameState.toString(); expect(GameMethods.isOgGloomEdition(), isTrue); checkNoSideEffects([], oldState); }); test('should return false for Frosthaven', () { SetCampaignCommand('Frosthaven').execute(); final String oldState = gameState.toString(); expect(GameMethods.isOgGloomEdition(), isFalse); checkNoSideEffects([], oldState); }); }); group('hasLootDeck', () { test('should return true if loot deck has cards', () { getIt().clearList(); SetCampaignCommand('Frosthaven').execute(); SetScenarioCommand( '#0 Howling in the Snow', false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); //DrawLootCardCommand(gameState: getIt()).execute(); expect(GameMethods.hasLootDeck(), isTrue); checkNoSideEffects([], oldState); }); test('should return false if loot deck is empty', () { //getIt().clearLootDeck(); SetCampaignCommand('Jaws of the Lion').execute(); SetScenarioCommand( '#5 A Deeper Understanding', false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); expect(GameMethods.hasLootDeck(), isFalse); checkNoSideEffects([], oldState); }); test('should return false if hideLootDeck setting is true', () { final String oldState = gameState.toString(); getIt().hideLootDeck = true; expect(GameMethods.hasLootDeck(), isFalse); checkNoSideEffects([], oldState); }); }); group('getFactionCards', () { test('should return the correct cards for Demons', () { final 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', () { final 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', () { final 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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); final character = getIt().currentList.first as Character; AddPerkCommand(character.id, 3).execute(); // Adds a +1 card final String oldState = gameState.toString(); expect(GameMethods.isCardInAnyCharacterDeck('P3'), isTrue); checkNoSideEffects([], oldState); }); test('should return false if card is not in any character deck', () { getIt().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute(); final String oldState = gameState.toString(); expect(GameMethods.isCardInAnyCharacterDeck('P3'), isFalse); checkNoSideEffects([], oldState); }); }); group('hasRetaliate', () { test('should return true if monster has retaliate', () { getIt().clearList(); AddMonsterCommand( "Flame Demon (BnB)", 3, false, gameState: getIt(), ).execute(); // Monster without shield AddStandeeCommand( 1, null, "Flame Demon (BnB)", MonsterType.boss, false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final monster = getIt().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().clearList(); AddMonsterCommand( "Black Sludge", 3, false, gameState: getIt(), ).execute(); // Monster without shield AddStandeeCommand( 1, null, "Black Sludge", MonsterType.normal, false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final monster = getIt().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().clearList(); AddMonsterCommand( "Black Sludge", 3, false, gameState: getIt(), ).execute(); // Monster without shield AddStandeeCommand( 1, null, "Black Sludge", MonsterType.normal, false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final monster = getIt().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().clearList(); AddMonsterCommand( "Zealot", 1, false, gameState: getIt(), ).execute(); // Monster without shield AddStandeeCommand( 1, null, "Zealot", MonsterType.normal, false, gameState: getIt(), ).execute(); final String oldState = gameState.toString(); final monster = getIt().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().clearList(); getIt().noInit = false; AddCharacterCommand('Blinkblade', 'Frosthaven', null, 1).execute(); // Kill the character so health = 0 final character = getIt().currentList.first as Character; // Reduce health to 0 via ChangeHealthCommand ChangeHealthCommand( -1000, 'Blinkblade', 'Blinkblade', gameState: getIt(), ).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().clearList(); AddMonsterCommand( 'Zealot', 1, false, gameState: getIt(), ).execute(); final monster = getIt().currentList.first as Monster; // Monster is inactive by default (isActive = false until ability drawn) expect(monster.isActive, isFalse); final String oldState = gameState.toString(); expect(GameMethods.getInitiative(monster), 99); checkNoSideEffects([], oldState); }); }); group('summonDoesNotDie', () { test('Glacial Torrent Glacier does not die', () { final String oldState = gameState.toString(); expect( GameMethods.summonDoesNotDie('Glacial Torrent', 'Glacier'), isTrue, ); checkNoSideEffects([], oldState); }); test('D.O.M.E. Barrier does not die', () { final String oldState = gameState.toString(); expect(GameMethods.summonDoesNotDie('D.O.M.E.', 'Barrier'), isTrue); checkNoSideEffects([], oldState); }); test('arbitrary owner and id returns false', () { final 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().clearList(); AddCharacterCommand('Blinkblade', 'Frosthaven', null, 1).execute(); final character = getIt().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(), ).execute(); expect(character.characterState.summonList, isNotEmpty); final summon = character.characterState.summonList.first; final figureId = summon.getId(); final String oldState = gameState.toString(); final figure = GameMethods.getFigure('Blinkblade', figureId); expect(figure, isNotNull); expect(figure, isA()); 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'; final 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'; final 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'; final 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().clearList(); // Flame Demon (BnB) is a boss with retaliate; use it to test boss path AddMonsterCommand( 'Flame Demon (BnB)', 3, false, gameState: getIt(), ).execute(); AddStandeeCommand( 1, null, 'Flame Demon (BnB)', MonsterType.boss, false, gameState: getIt(), ).execute(); final monster = getIt().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()); expect(GameMethods.hasRetaliate(monster, instance), isA()); }); }); group('getNextAvailableBnBStandee', () { test('returns next available standee number when one is taken', () { getIt().clearList(); AddMonsterCommand( 'Zealot', 1, false, gameState: getIt(), ).execute(); final monster = getIt().currentList.first as Monster; AddStandeeCommand( 1, null, 'Zealot', MonsterType.normal, false, gameState: getIt(), ).execute(); final 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().clearList(); AddMonsterCommand( 'Zealot', 1, false, gameState: getIt(), ).execute(); final monster = getIt().currentList.first as Monster; for (int i = 1; i <= monster.type.count; i++) { AddStandeeCommand( i, null, 'Zealot', MonsterType.normal, false, gameState: getIt(), ).execute(); } final String oldState = gameState.toString(); final next = GameMethods.getNextAvailableBnBStandee(monster); expect(next, 0); checkNoSideEffects([], oldState); }); }); }); }