From 7ee14396b1f1f96ed0472b5949ce82a7f9313276 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 23 Nov 2026 15:38:13 +0100 Subject: server: make local variables final (prefer_final_locals) 270 locals across 52 files. Six of them were declared with an unnecessarily nullable type (ModifierDeck? / LootDeckModel?) although the initializer is non-nullable; non-final locals were silently flow-promoted to the initializer's type, but final locals are not, so the nullability is dropped where it was wrong. --- server/lib/core/action_handler.dart | 4 +- .../lib/core/commands/add_condition_command.dart | 4 +- .../core/commands/add_cs_party_card_command.dart | 2 +- .../core/commands/add_faction_card_command.dart | 2 +- server/lib/core/commands/add_perk_command.dart | 4 +- server/lib/core/commands/add_standee_command.dart | 2 +- .../commands/amd_cassandra_special_command.dart | 2 +- server/lib/core/commands/amd_imbue1_command.dart | 2 +- server/lib/core/commands/amd_imbue2_command.dart | 2 +- .../core/commands/amd_remove_imbue_command.dart | 2 +- server/lib/core/commands/amd_reveal_command.dart | 2 +- .../change_health_command.dart | 4 +- .../change_max_health_command.dart | 2 +- .../core/commands/donate_cs_sanctuary_command.dart | 2 +- .../core/commands/load_character_save_command.dart | 2 +- server/lib/core/commands/next_round_command.dart | 4 +- .../core/commands/remove_condition_command.dart | 4 +- .../commands/remove_cs_party_card_command.dart | 2 +- .../remove_cs_sanctuary_donation_command.dart | 2 +- .../shuffle_drawn_ability_card_command.dart | 4 +- server/lib/core/commands/use_fh_perks_command.dart | 4 +- server/lib/core/enums.dart | 2 +- server/lib/core/game_data.dart | 8 ++-- server/lib/core/game_methods.dart | 18 ++++----- server/lib/core/line_builder/stat_applier.dart | 44 +++++++++++----------- server/lib/core/methods/character_methods.dart | 10 ++--- server/lib/core/methods/deck_methods.dart | 2 +- server/lib/core/methods/element_methods.dart | 2 +- server/lib/core/methods/monster_methods.dart | 24 ++++++------ server/lib/core/methods/round_methods.dart | 20 +++++----- server/lib/core/methods/scenario_methods.dart | 10 ++--- server/lib/core/models/campaign.dart | 10 ++--- server/lib/core/models/character_class.dart | 14 +++---- server/lib/core/models/monster.dart | 2 +- server/lib/core/models/monster_ability.dart | 16 ++++---- server/lib/core/models/room.dart | 14 +++---- server/lib/core/models/scenario.dart | 20 +++++----- server/lib/core/models/summon_model.dart | 2 +- server/lib/core/settings.dart | 4 +- server/lib/core/stat_calculator.dart | 6 +-- server/lib/core/state/game_save_state.dart | 18 ++++----- server/lib/core/state/game_state.dart | 6 +-- server/lib/core/state/loot_deck_state.dart | 20 +++++----- server/lib/core/state/modifier_deck.dart | 20 +++++----- server/lib/core/state/monster.dart | 2 +- server/lib/core/state/monster_ability_state.dart | 2 +- server/lib/core/state/monster_instance.dart | 6 +-- server/lib/core/state/sanctuary_deck.dart | 12 +++--- 48 files changed, 186 insertions(+), 186 deletions(-) (limited to 'server/lib') diff --git a/server/lib/core/action_handler.dart b/server/lib/core/action_handler.dart index 5b3f8d4..8bf6655 100644 --- a/server/lib/core/action_handler.dart +++ b/server/lib/core/action_handler.dart @@ -168,8 +168,8 @@ class ActionHandler { _gameState.save(); //save after each action //send last game state if connected - String description = command.describe(); - String eventJson = command.event.toJsonString(); + final String description = command.describe(); + final String eventJson = command.event.toJsonString(); _log.info('server sends, index: $commandIndex, description:$description'); onAction?.call(commandIndex, description, eventJson); diff --git a/server/lib/core/commands/add_condition_command.dart b/server/lib/core/commands/add_condition_command.dart index 663d6b0..a352abc 100644 --- a/server/lib/core/commands/add_condition_command.dart +++ b/server/lib/core/commands/add_condition_command.dart @@ -18,9 +18,9 @@ class AddConditionCommand extends Command { @override void execute() { - FigureState? figure = GameMethods.getFigure(ownerId, figureId); + final FigureState? figure = GameMethods.getFigure(ownerId, figureId); if (figure != null) { - List newList = []; + final List newList = []; newList.addAll(figure.conditions); if (!newList.contains(condition) || //block from adding same condition condition == Condition.chill || diff --git a/server/lib/core/commands/add_cs_party_card_command.dart b/server/lib/core/commands/add_cs_party_card_command.dart index 4f59e4b..2628d03 100644 --- a/server/lib/core/commands/add_cs_party_card_command.dart +++ b/server/lib/core/commands/add_cs_party_card_command.dart @@ -15,7 +15,7 @@ class AddCSPartyCardCommand extends Command { @override void execute() { - ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(characterId, _gameState); deck.addCSPartyCard(stateAccess, type); } diff --git a/server/lib/core/commands/add_faction_card_command.dart b/server/lib/core/commands/add_faction_card_command.dart index 00bbf0d..6848c9d 100644 --- a/server/lib/core/commands/add_faction_card_command.dart +++ b/server/lib/core/commands/add_faction_card_command.dart @@ -17,7 +17,7 @@ class AddFactionCardCommand extends Command { @override void execute() { - ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(characterId, _gameState); if (add) { deck.addCard(stateAccess, cardId, CardType.add); } else { diff --git a/server/lib/core/commands/add_perk_command.dart b/server/lib/core/commands/add_perk_command.dart index c961e05..1b654b6 100644 --- a/server/lib/core/commands/add_perk_command.dart +++ b/server/lib/core/commands/add_perk_command.dart @@ -10,7 +10,7 @@ class AddPerkCommand extends Command { @override void execute() { - Character? character = GameMethods.getCharacterByName(characterId); + final Character? character = GameMethods.getCharacterByName(characterId); if (character != null) { character.flipPerk(stateAccess, index); } @@ -18,7 +18,7 @@ class AddPerkCommand extends Command { @override String describe() { - Character? character = GameMethods.getCharacterByName(characterId); + final Character? character = GameMethods.getCharacterByName(characterId); final charId = character?.id ?? characterId; if (character != null && !character.characterState.perkList[index]) { return commandL10n.cmdRemovePerk(charId, index); diff --git a/server/lib/core/commands/add_standee_command.dart b/server/lib/core/commands/add_standee_command.dart index ec10701..51c7ab5 100644 --- a/server/lib/core/commands/add_standee_command.dart +++ b/server/lib/core/commands/add_standee_command.dart @@ -37,7 +37,7 @@ class AddStandeeCommand extends Command { @override String describe() { final sum = summon; - String name = sum == null ? ownerId : sum.name; + final String name = sum == null ? ownerId : sum.name; return commandL10n.cmdAddStandee(name, nr); } diff --git a/server/lib/core/commands/amd_cassandra_special_command.dart b/server/lib/core/commands/amd_cassandra_special_command.dart index b1d1d5f..69bcea2 100644 --- a/server/lib/core/commands/amd_cassandra_special_command.dart +++ b/server/lib/core/commands/amd_cassandra_special_command.dart @@ -16,7 +16,7 @@ class AMDCassandraSpecialCommand extends Command { @override void execute() { - ModifierDeck deck = GameMethods.getModifierDeck(deckId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(deckId, _gameState); deck.setCassandraSpecial(stateAccess, on); } diff --git a/server/lib/core/commands/amd_imbue1_command.dart b/server/lib/core/commands/amd_imbue1_command.dart index 3cf52bc..d678979 100644 --- a/server/lib/core/commands/amd_imbue1_command.dart +++ b/server/lib/core/commands/amd_imbue1_command.dart @@ -8,7 +8,7 @@ class AMDImbue1Command extends Command { @override void execute() { - ModifierDeck deck = _gameState.modifierDeck; + final ModifierDeck deck = _gameState.modifierDeck; deck.setImbue1(stateAccess); } diff --git a/server/lib/core/commands/amd_imbue2_command.dart b/server/lib/core/commands/amd_imbue2_command.dart index 891d1f0..14e9bde 100644 --- a/server/lib/core/commands/amd_imbue2_command.dart +++ b/server/lib/core/commands/amd_imbue2_command.dart @@ -8,7 +8,7 @@ class AMDImbue2Command extends Command { @override void execute() { - ModifierDeck deck = _gameState.modifierDeck; + final ModifierDeck deck = _gameState.modifierDeck; deck.setImbue2(stateAccess); } diff --git a/server/lib/core/commands/amd_remove_imbue_command.dart b/server/lib/core/commands/amd_remove_imbue_command.dart index 0b37b5b..bb7219c 100644 --- a/server/lib/core/commands/amd_remove_imbue_command.dart +++ b/server/lib/core/commands/amd_remove_imbue_command.dart @@ -9,7 +9,7 @@ class AMDRemoveImbueCommand extends Command { @override void execute() { - ModifierDeck deck = _gameState.modifierDeck; + final ModifierDeck deck = _gameState.modifierDeck; deck.resetImbue(stateAccess); } diff --git a/server/lib/core/commands/amd_reveal_command.dart b/server/lib/core/commands/amd_reveal_command.dart index 1a0a1a3..a000b5c 100644 --- a/server/lib/core/commands/amd_reveal_command.dart +++ b/server/lib/core/commands/amd_reveal_command.dart @@ -16,7 +16,7 @@ class AMDRevealCommand extends Command { @override void execute() { - ModifierDeck deck = GameMethods.getModifierDeck(name, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(name, _gameState); deck.revealCards(stateAccess, amount); } 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 index 8d6b6f4..2ee11df 100644 --- a/server/lib/core/commands/change_stat_commands/change_health_command.dart +++ b/server/lib/core/commands/change_stat_commands/change_health_command.dart @@ -14,7 +14,7 @@ class ChangeHealthCommand extends ChangeStatCommand { @override void execute() { - FigureState? figure = GameMethods.getFigure(ownerId, figureId); + final FigureState? figure = GameMethods.getFigure(ownerId, figureId); if (figure != null) { final previousValue = figure.health; if (previousValue + change < 0) { @@ -44,7 +44,7 @@ class ChangeHealthCommand extends ChangeStatCommand { //TODO: looks bad return commandL10n.cmdIncreaseHealth(figureId, change); } - FigureState? figure = GameMethods.getFigure(ownerId, figureId); + final FigureState? figure = GameMethods.getFigure(ownerId, figureId); if (figure == null || figure.health <= 0) { return commandL10n.cmdKill(ownerId ?? ''); } 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 index 70b26d9..38ad118 100644 --- 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 @@ -16,7 +16,7 @@ class ChangeMaxHealthCommand extends ChangeStatCommand { final FigureState? figure = GameMethods.getFigure(ownerId, figureId); if (figure == null) return; - int newValue = figure.maxHealth + change; + final int newValue = figure.maxHealth + change; if (newValue <= 0) { //can't lower maxvalue less than 1 return; diff --git a/server/lib/core/commands/donate_cs_sanctuary_command.dart b/server/lib/core/commands/donate_cs_sanctuary_command.dart index c1fdd0f..013850f 100644 --- a/server/lib/core/commands/donate_cs_sanctuary_command.dart +++ b/server/lib/core/commands/donate_cs_sanctuary_command.dart @@ -11,7 +11,7 @@ class DonateCSSanctuaryCommand extends Command { @override void execute() { - ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(characterId, _gameState); deck.addCSSanctuary(stateAccess); } diff --git a/server/lib/core/commands/load_character_save_command.dart b/server/lib/core/commands/load_character_save_command.dart index 6014c47..6ca4d82 100644 --- a/server/lib/core/commands/load_character_save_command.dart +++ b/server/lib/core/commands/load_character_save_command.dart @@ -18,7 +18,7 @@ class LoadCharacterSaveCommand extends Command { @override void execute() { final data = json.decode(saveData) as Map; - Character character = Character.fromSave(data); + final Character character = Character.fromSave(data); //add new character on top of list, if not present. final Character? currentCharacter = GameMethods.getCharacterByName( diff --git a/server/lib/core/commands/next_round_command.dart b/server/lib/core/commands/next_round_command.dart index 22385fa..0c0c218 100644 --- a/server/lib/core/commands/next_round_command.dart +++ b/server/lib/core/commands/next_round_command.dart @@ -110,11 +110,11 @@ class NextRoundCommand extends Command { if (_settings.autoAddSpawns) { if (rule.name.isNotEmpty) { //get room data and deal with spawns - ScenarioModel? scenario = _gameData + final ScenarioModel? scenario = _gameData .modelData[_gameState.currentCampaign] ?.scenarios[_gameState.scenario]; if (scenario != null) { - ScenarioModel? spawnSection = scenario.sections.firstWhereOrNull( + final ScenarioModel? spawnSection = scenario.sections.firstWhereOrNull( (element) => element.name.substring(1) == rule.name, ); if (spawnSection != null) { diff --git a/server/lib/core/commands/remove_condition_command.dart b/server/lib/core/commands/remove_condition_command.dart index 04cdd40..c7bfa3e 100644 --- a/server/lib/core/commands/remove_condition_command.dart +++ b/server/lib/core/commands/remove_condition_command.dart @@ -18,9 +18,9 @@ class RemoveConditionCommand extends Command { @override void execute() { - FigureState? figure = GameMethods.getFigure(ownerId, figureId); + final FigureState? figure = GameMethods.getFigure(ownerId, figureId); if (figure != null) { - List newList = []; + final List newList = []; newList.addAll(figure.conditions); newList.remove(condition); figure.setConditions(stateAccess, newList); diff --git a/server/lib/core/commands/remove_cs_party_card_command.dart b/server/lib/core/commands/remove_cs_party_card_command.dart index 64f03bf..fa1a896 100644 --- a/server/lib/core/commands/remove_cs_party_card_command.dart +++ b/server/lib/core/commands/remove_cs_party_card_command.dart @@ -11,7 +11,7 @@ class RemoveCSPartyCardCommand extends Command { @override void execute() { - ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(characterId, _gameState); deck.removeCSPartyCard(stateAccess); } diff --git a/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart b/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart index 3751097..4d9c246 100644 --- a/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart +++ b/server/lib/core/commands/remove_cs_sanctuary_donation_command.dart @@ -13,7 +13,7 @@ class RemoveCSSanctuaryDonationCommand extends Command { @override void execute() { - ModifierDeck? deck = GameMethods.getModifierDeck(characterId, _gameState); + final ModifierDeck deck = GameMethods.getModifierDeck(characterId, _gameState); deck.removeCSSanctuary(stateAccess); } diff --git a/server/lib/core/commands/shuffle_drawn_ability_card_command.dart b/server/lib/core/commands/shuffle_drawn_ability_card_command.dart index 795b9b4..e9b6f8c 100644 --- a/server/lib/core/commands/shuffle_drawn_ability_card_command.dart +++ b/server/lib/core/commands/shuffle_drawn_ability_card_command.dart @@ -10,11 +10,11 @@ class ShuffleDrawnAbilityCardCommand extends Command { @override void execute() { - Monster? monster = GameMethods.getCurrentMonsters().firstWhereOrNull( + final Monster? monster = GameMethods.getCurrentMonsters().firstWhereOrNull( (element) => element.type.deck == deck, ); if (monster != null) { - MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck); + final MonsterAbilityState? deck = GameMethods.getDeck(monster.type.deck); deck?.shuffleUnDrawn(stateAccess); } } diff --git a/server/lib/core/commands/use_fh_perks_command.dart b/server/lib/core/commands/use_fh_perks_command.dart index 8200ae7..b857e45 100644 --- a/server/lib/core/commands/use_fh_perks_command.dart +++ b/server/lib/core/commands/use_fh_perks_command.dart @@ -9,7 +9,7 @@ class UseFHPerksCommand extends Command { @override void execute() { - Character? character = GameMethods.getCharacterByName(characterId); + final Character? character = GameMethods.getCharacterByName(characterId); if (character != null) { character.flipUseFHPerks(stateAccess); } @@ -17,7 +17,7 @@ class UseFHPerksCommand extends Command { @override String describe() { - Character? character = GameMethods.getCharacterByName(characterId); + final Character? character = GameMethods.getCharacterByName(characterId); final charId = character?.id ?? characterId; final use = character?.characterState.useFHPerks ?? false; if (use) { diff --git a/server/lib/core/enums.dart b/server/lib/core/enums.dart index 590f825..997dbe0 100644 --- a/server/lib/core/enums.dart +++ b/server/lib/core/enums.dart @@ -48,7 +48,7 @@ enum Condition { static const int _kChar4Index = 3; String _getCharacterName(int index) { - List characters = GameMethods.getCurrentCharacters(); + final List characters = GameMethods.getCurrentCharacters(); characters.sortBy((element) => element.characterClass.name); if (characters.length > index) { return characters[index].characterClass.name; diff --git a/server/lib/core/game_data.dart b/server/lib/core/game_data.dart index 65b4c59..db0ad68 100644 --- a/server/lib/core/game_data.dart +++ b/server/lib/core/game_data.dart @@ -29,24 +29,24 @@ class GameData { if (data.containsKey('summons')) { final summons = data['summons'] as Map; - List summonModels = []; + final List summonModels = []; for (String key in summons.keys) { summonModels.add(SummonModel.fromJson(summons[key], key)); } itemSummonData = summonModels; } - Map map = {}; + final Map map = {}; final String editionsJson = File( p.join(root, 'editions', 'editions.json'), ).readAsStringSync(); final Map editionData = await json.decode(editionsJson); - List editionList = []; + final List editionList = []; for (String item in editionData["editions"]) { editionList.add(item); - List roomData = []; + final List roomData = []; final roomDataResult = await fetchRoomData(item, root); if (roomDataResult != null) roomData.addAll(roomDataResult.roomData); diff --git a/server/lib/core/game_methods.dart b/server/lib/core/game_methods.dart index cf43ab7..646a9f2 100644 --- a/server/lib/core/game_methods.dart +++ b/server/lib/core/game_methods.dart @@ -47,7 +47,7 @@ class GameMethods { static int getCoinValue({GameState? gameState}) { final gs = gameState ?? getIt(); - int level = gs.level; + final int level = gs.level; if (level == _kCoinMaxLevel) { return _kCoinMaxValue; } @@ -162,7 +162,7 @@ class GameMethods { } static List getCurrentCharactersForState(GameState state) { - List characters = []; + final List characters = []; for (ListItemData data in state.currentList) { if (data is Character && !GameMethods.isObjectiveOrEscort(data.characterClass)) { @@ -291,7 +291,7 @@ class GameMethods { } static List getCurrentMonsters({GameState? gameState}) { - List monsters = []; + final List monsters = []; final gs = gameState ?? getIt(); for (ListItemData data in gs.currentList) { if (data is Monster) { @@ -304,7 +304,7 @@ class GameMethods { static int getNextAvailableBnBStandee(Monster data, {GameState? gameState}) { final gs = gameState ?? getIt(); - int nrOfStandees = data.type.count; + final int nrOfStandees = data.type.count; for (int i = 0; i < nrOfStandees; i++) { bool isAvailable = true; for (final item in data.monsterInstances) { @@ -346,7 +346,7 @@ class GameMethods { nrOfStandees = _kPolarBearStandees; //for the special case where there are only 4 standees in first printing } - List available = []; + final List available = []; for (int i = 0; i < nrOfStandees; i++) { bool isAvailable = true; for (final item in data.monsterInstances) { @@ -400,7 +400,7 @@ class GameMethods { if (item.id == ownerId) { if (item is Monster) { for (final instance in item.monsterInstances) { - String id = + final String id = instance.name + instance.gfx + instance.standeeNr.toString(); if (id == figureId) { return instance; @@ -408,7 +408,7 @@ class GameMethods { } } else if (item is Character) { for (final instance in item.characterState.summonList) { - String id = + final String id = instance.name + instance.gfx + instance.standeeNr.toString(); if (id == figureId) { return instance; @@ -488,7 +488,7 @@ class GameMethods { GameState? gameState, }) { final gs = gameState ?? getIt(); - String scenario = gs.scenario; + final String scenario = gs.scenario; if (edition == "Solo") { if (scenario.contains("${"#19"} ")) { return false; //this is forgotten circles @@ -584,7 +584,7 @@ class GameMethods { } static List getFactionCards(String faction) { - List retVal = []; + final List retVal = []; if (faction == "Demons") { retVal.add(ModifierCard(CardType.add, "Demons-perks/plus1any")); retVal.add( diff --git a/server/lib/core/line_builder/stat_applier.dart b/server/lib/core/line_builder/stat_applier.dart index 436e7ef..e706a73 100644 --- a/server/lib/core/line_builder/stat_applier.dart +++ b/server/lib/core/line_builder/stat_applier.dart @@ -49,7 +49,7 @@ class StatApplier { final normalTokens = _getStatTokens(monster, false); final eliteTokens = _getStatTokens(monster, true); - RegExp regExpNumbers = RegExp(r'^[\d ()xCL/*+-]+$'); + final RegExp regExpNumbers = RegExp(r'^[\d ()xCL/*+-]+$'); //first pass fix values only String lastToken = ""; //turn this into move or attack or whatever, then apply correct monster stat @@ -81,11 +81,11 @@ class StatApplier { ' ') //supposing there is always a leading whitespace to any formula ) { String formula = line[i]; - int startIndex = i; + final int startIndex = i; int endIndex = i; for (int j = i + 1; j < lineInput.length; j++) { - String val = lineInput[j]; + final String val = lineInput[j]; if (val.contains(regExpNumbers) || val == "d") { if (val != ' ') formula += val; endIndex = j; @@ -172,7 +172,7 @@ class StatApplier { } for (String item in data.attributes) { //remove size modifiers (only used for immobilize since it's so long it overflows.) - String sizeMod = (item.substring(0, 1)); + final String sizeMod = (item.substring(0, 1)); if (sizeMod == "^" || sizeMod == "*" && item.length > 1) { item = item.substring(1); } @@ -181,14 +181,14 @@ class StatApplier { //parse item and then parse number; for (int i = 1; i < item.length; i++) { if (item[i] == '%') { - String token = item.substring(1, i); + final String token = item.substring(1, i); int number = 0; if (i != item.length - 1) { for (int j = i + _kTokenEndOffset; j < item.length; j++) { if (item[j] == ' ' || j == item.length - 1) { //need to find end of nr and ignore the rest - String nr = item.substring(i + 1, j + 1); - int? res = StatCalculator.calculateFormula(nr); + final String nr = item.substring(i + 1, j + 1); + final int? res = StatCalculator.calculateFormula(nr); if (res != null) { number = res; } else { @@ -233,15 +233,15 @@ class StatApplier { return [line]; } - List retVal = []; - List tokens = []; - List eTokens = []; + final List retVal = []; + final List tokens = []; + final List eTokens = []; int normalValue = 0; int eliteValue = 0; bool skipCalculation = false; //in case un-calculable final level = monster.type.levels[monster.level]; - MonsterStatsModel? normal = level.boss ?? level.normal; - MonsterStatsModel? elite = level.elite; + final MonsterStatsModel? normal = level.boss ?? level.normal; + final MonsterStatsModel? elite = level.elite; if (lastToken == "attack") { if (normal == null) return []; int? calc = StatCalculator.calculateFormula(normal.attack); @@ -257,7 +257,7 @@ class StatApplier { } } - RegExp regEx = RegExp( + final RegExp regEx = RegExp( r"(?=.*[a-z])", ); //not sure why I do this. only letters? for (final item in normalTokens.keys) { @@ -296,8 +296,8 @@ class StatApplier { eliteValue = StatCalculator.calculateFormula(elite.move) ?? 0; } } else if (lastToken == "shield") { - int? value = normalTokens["shield"]; - int? eValue = eliteTokens["shield"]; + final int? value = normalTokens["shield"]; + final int? eValue = eliteTokens["shield"]; if (elite != null && eValue != null) { eliteValue = eValue; } @@ -305,8 +305,8 @@ class StatApplier { normalValue = value; } } else if (lastToken == "retaliate") { - int? value = normalTokens["retaliate"]; - int? eValue = eliteTokens["retaliate"]; + final int? value = normalTokens["retaliate"]; + final int? eValue = eliteTokens["retaliate"]; if (elite != null && eValue != null) { eliteValue = eValue; } @@ -336,8 +336,8 @@ class StatApplier { for (final item in tokens) { newStartOfLine += "|$item"; //add nr if applicable - String key = item.substring(1, item.length - 1); - int value = normalTokens[key] ?? 0; + final String key = item.substring(1, item.length - 1); + final int value = normalTokens[key] ?? 0; if (value > 0) { newStartOfLine += "$value"; } @@ -366,8 +366,8 @@ class StatApplier { eliteString += "|$item"; //add nr if applicable - String key = item.substring(1, item.length - 1); - int value = eliteTokens[key]!; + final String key = item.substring(1, item.length - 1); + final int value = eliteTokens[key]!; if (value > 0) { eliteString += "$value"; } @@ -377,7 +377,7 @@ class StatApplier { retVal.add(newStartOfLine); } if (endIndex < line.length) { - String leftOver = + final String leftOver = "!$sizeModifier${line.substring(endIndex + 1, line.length)}"; retVal.add(leftOver); diff --git a/server/lib/core/methods/character_methods.dart b/server/lib/core/methods/character_methods.dart index 9c2705a..6cd6c10 100644 --- a/server/lib/core/methods/character_methods.dart +++ b/server/lib/core/methods/character_methods.dart @@ -193,7 +193,7 @@ class CharacterMethods { final list = character.characterState.summonList; if (list.isNotEmpty && list.first.name == name) { - int hp = health + character.characterState.level * multiplier; + final int hp = health + character.characterState.level * multiplier; list.first.setMaxHealth(s, hp); list.first.setHealth(s, hp); } @@ -261,7 +261,7 @@ class CharacterMethods { } if (name.isNotEmpty) { - MonsterInstance summon = MonsterInstance.summon( + final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, @@ -282,7 +282,7 @@ class CharacterMethods { List characters, { GameState? gameState, }) { - List newList = []; + final List newList = []; final gs = gameState ?? getIt(); for (final item in gs.currentList) { if (item is Character) { @@ -314,7 +314,7 @@ class CharacterMethods { GameData? gameData, }) { Character? character; - List characters = []; + final List characters = []; final gd = gameData ?? getIt(); final modelData = gd.modelData; for (String key in modelData.keys) { @@ -371,7 +371,7 @@ class CharacterMethods { } if (name.isNotEmpty) { - MonsterInstance summon = MonsterInstance.summon( + final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, diff --git a/server/lib/core/methods/deck_methods.dart b/server/lib/core/methods/deck_methods.dart index 535324f..a501d23 100644 --- a/server/lib/core/methods/deck_methods.dart +++ b/server/lib/core/methods/deck_methods.dart @@ -35,7 +35,7 @@ class DeckMethods { for (final item in gs.currentList) { if (item is Monster) { if (item.type.deck == deck.name) { - bool specialInactive = GameMethods.isInactiveForRule( + final bool specialInactive = GameMethods.isInactiveForRule( item.type.name, ); if ((item.monsterInstances.isNotEmpty && !specialInactive) || diff --git a/server/lib/core/methods/element_methods.dart b/server/lib/core/methods/element_methods.dart index 5da97a3..c65d53c 100644 --- a/server/lib/core/methods/element_methods.dart +++ b/server/lib/core/methods/element_methods.dart @@ -13,7 +13,7 @@ class ElementMethods { static void updateElements(_StateModifier _, {GameState? gameState}) { //elementalist special: bool elementalistPerk = false; - Character? elementalist = GameMethods.getCharacterByName("Elementalist"); + final Character? elementalist = GameMethods.getCharacterByName("Elementalist"); if (elementalist != null && elementalist.characterState.perkList[15]) { if (elementalist.characterClass.edition == "Gloomhaven 2nd Edition") { elementalistPerk = true; diff --git a/server/lib/core/methods/monster_methods.dart b/server/lib/core/methods/monster_methods.dart index c0743b3..5ba936e 100644 --- a/server/lib/core/methods/monster_methods.dart +++ b/server/lib/core/methods/monster_methods.dart @@ -29,7 +29,7 @@ class MonsterMethods { GameData? gameData, }) { final gd = gameData ?? getIt(); - Map monsters = {}; + final Map monsters = {}; final modelData = gd.modelData; for (String key in modelData.keys) { monsters.addAll(modelData[key]?.monsters ?? {}); @@ -43,8 +43,8 @@ class MonsterMethods { List items, { GameState? gameState, }) { - List deckIds = []; - List newList = []; + final List deckIds = []; + final List newList = []; final gs = gameState ?? getIt(); for (final item in gs.currentList) { if (item is Monster) { @@ -235,7 +235,7 @@ class MonsterMethods { GameState? gameState, }) { int levelAdjust = 0; - Set alliedMonsters = {}; + final Set alliedMonsters = {}; for (final rule in specialRules) { if (rule.name == monster || rule.name == "Enemies") { if (rule.type == "LevelAdjust") { @@ -285,7 +285,7 @@ class MonsterMethods { }) { final gs = gameState ?? getIt(); //handle room data - int characterIndex = + final int characterIndex = GameMethods.getCurrentCharacterAmount().clamp( _kMinCharacters, _kMaxCharacters, @@ -295,7 +295,7 @@ class MonsterMethods { final roomMonsters = roomMonsterData[i]; addMonster(stateModifier, roomMonsters.name, gs._scenarioSpecialRules); } - bool addSorted = gs.currentCampaign == "Buttons and Bugs"; + final bool addSorted = gs.currentCampaign == "Buttons and Bugs"; final s = settings ?? getIt(); if (!s.noStandees && s.autoAddStandees) { if (s.randomStandees || addSorted) { @@ -303,17 +303,17 @@ class MonsterMethods { initMessage += "\n"; } for (int i = 0; i < roomMonsterData.length; i++) { - List normals = []; - List elites = []; + final List normals = []; + final List elites = []; final roomMonsters = roomMonsterData[i]; - Monster data = + final Monster data = gs.currentList.firstWhereOrNull( (element) => element.id == roomMonsters.name, ) as Monster; - int eliteAmount = roomMonsters.elite[characterIndex]; - int normalAmount = roomMonsters.normal[characterIndex]; + final int eliteAmount = roomMonsters.elite[characterIndex]; + final int normalAmount = roomMonsters.normal[characterIndex]; bool isBoss = false; if (data.type.levels.first.boss != null) { @@ -321,7 +321,7 @@ class MonsterMethods { } for (int i = 0; i < eliteAmount; i++) { - int randomNr = GameMethods.getRandomStandee(data); + final int randomNr = GameMethods.getRandomStandee(data); if (randomNr != 0) { elites.add(randomNr); executeAddStandee( diff --git a/server/lib/core/methods/round_methods.dart b/server/lib/core/methods/round_methods.dart index 4ad146d..5102fb2 100644 --- a/server/lib/core/methods/round_methods.dart +++ b/server/lib/core/methods/round_methods.dart @@ -96,8 +96,8 @@ class RoundMethods { int init = 0; for (int i = 0; i < newList.length; i++) { - ListItemData currentItem = newList[i]; - int currentItemInitiative = GameMethods.getInitiative(currentItem); + final ListItemData currentItem = newList[i]; + final int currentItemInitiative = GameMethods.getInitiative(currentItem); if (currentItemInitiative > initiative && currentItemInitiative > init) { if (i > currentTurnItemIndex) { newList.insert(i, item); @@ -265,18 +265,18 @@ class RoundMethods { }) { final gs = gameState ?? getIt(); final gd = gameData ?? getIt(); - List? rules = + final List? rules = gd.modelData[gs.currentCampaign]?.scenarios[gs.scenario]?.specialRules; if (rules != null) { for (SpecialRule rule in rules) { if (rule.type == "Objective" || rule.type == "Escort") { - Character? character = + final Character? character = gs.currentList.firstWhereOrNull( (element) => element.id == rule.name, ) as Character?; if (character != null) { - int? newHealth = StatCalculator.calculateFormula( + final int? newHealth = StatCalculator.calculateFormula( rule.health.toString(), ); if (newHealth != character.characterState.maxHealth && @@ -286,14 +286,14 @@ class RoundMethods { } } } else if (rule.type == "LevelAdjust") { - Monster? monster = + final Monster? monster = gs.currentList.firstWhereOrNull( (element) => element.id == rule.name, ) as Monster?; if (monster != null) { if (gs.level == monster.level) { - int newLevel = (monster.level + rule.level).clamp( + final int newLevel = (monster.level + rule.level).clamp( _kMinLevel, _kMaxLevel, ); @@ -361,7 +361,7 @@ class RoundMethods { final conditions = figure._conditions; //handle chill separately - int nrOfChills = figure.conditions + final int nrOfChills = figure.conditions .where((a) => a == Condition.chill) .length; if (nrOfChills > 0) { @@ -380,7 +380,7 @@ class RoundMethods { .length; for (int i = conditions.length - 1; i >= 0; i--) { - Condition item = conditions[i]; + final Condition item = conditions[i]; if (GameMethods.canExpire(item)) { if (item != Condition.chill) { if (!figure.conditionsAddedThisTurn.contains(item)) { @@ -463,7 +463,7 @@ class RoundMethods { //get next active item and set to current for (; newIndex < gs.currentList.length; newIndex++) { - ListItemData data = gs.currentList[newIndex]; + final ListItemData data = gs.currentList[newIndex]; if (data is Monster) { if (data.isActive && !GameMethods.isInactiveForRule(data.type.name)) { if (data.turnState == TurnsState.done) { diff --git a/server/lib/core/methods/scenario_methods.dart b/server/lib/core/methods/scenario_methods.dart index 257d076..a75fc80 100644 --- a/server/lib/core/methods/scenario_methods.dart +++ b/server/lib/core/methods/scenario_methods.dart @@ -107,7 +107,7 @@ class ScenarioMethods { gs._scenario = scenario; gs._scenarioSectionsAdded = []; - List newList = []; + final List newList = []; for (final item in gs.currentList) { if (item is Character) { if (!GameMethods.isObjectiveOrEscort(item.characterClass)) { @@ -127,14 +127,14 @@ class ScenarioMethods { static void _initLootDeck(String scenario, GameState gs, GameData gd) { if (scenario != "custom") { final campaignModel = gd.modelData[gs.currentCampaign]; - LootDeckModel? lootDeckModel = + final LootDeckModel? lootDeckModel = campaignModel?.scenarios[scenario]?.lootDeck; lootDeckModel != null ? gs._lootDeck = LootDeck(lootDeckModel, gs.lootDeck) : gs._lootDeck = LootDeck.from(gs.lootDeck); } else { if (gs.currentCampaign == "Frosthaven") { - LootDeckModel? lootDeckModel = const LootDeckModel( + final LootDeckModel lootDeckModel = const LootDeckModel( 2, 2, 2, @@ -171,7 +171,7 @@ class ScenarioMethods { List monsters = []; List specialRules = []; List roomMonsterData = []; - List subSections = []; + final List subSections = []; String initMessage = ""; if (section) { @@ -256,7 +256,7 @@ class ScenarioMethods { if (item.type == "Objective") { if (item.condition == "" || StatCalculator.evaluateCondition(item.condition as Object)) { - Character? objective = CharacterMethods.createCharacter( + final Character? objective = CharacterMethods.createCharacter( s, "Objective", null, diff --git a/server/lib/core/models/campaign.dart b/server/lib/core/models/campaign.dart index 0a393d3..02a87d0 100644 --- a/server/lib/core/models/campaign.dart +++ b/server/lib/core/models/campaign.dart @@ -32,30 +32,30 @@ class CampaignModel { final edition = data['edition'] as String; final monsterAbilities = (data['monsterAbilities'] as List) .cast>(); - List deckDataList = []; + final List deckDataList = []; for (final item in monsterAbilities) { deckDataList.add(MonsterAbilityDeckModel.fromJson(item, edition)); } - Map monsterMap = HashMap(); + final Map monsterMap = HashMap(); final monsters = data['monsters'] as Map; for (String key in monsters.keys) { monsterMap[key] = MonsterModel.fromJson(monsters[key], key, edition); } - List characterDataList = []; + final List characterDataList = []; final classes = (data['classes'] as List) .cast>(); for (final item in classes) { characterDataList.add(CharacterClass.fromJson(item)); } - Map scenarioMap = HashMap(); + final Map scenarioMap = HashMap(); final scenarios = data['scenarios'] as Map; for (String key in scenarios.keys) { //find right room if exists - RoomsModel? rooms = roomsData.firstWhereOrNull( + final RoomsModel? rooms = roomsData.firstWhereOrNull( (element) => element.scenarioName == key.substring(1).split(" ").first, ); scenarioMap[key] = ScenarioModel.fromJson(key, scenarios[key], rooms); diff --git a/server/lib/core/models/character_class.dart b/server/lib/core/models/character_class.dart index 12f4285..def0354 100644 --- a/server/lib/core/models/character_class.dart +++ b/server/lib/core/models/character_class.dart @@ -39,9 +39,9 @@ class CharacterClass { } //TODO: color array + gradiantType support final healthByLevel = (data['health'] as List).cast(); - int radix = 16; + final int radix = 16; final colorValue = data['color']; - Color color = (colorValue is List) + final Color color = (colorValue is List) ? Color(int.parse(colorValue.first as String, radix: radix)) : Color(int.parse(colorValue as String, radix: radix)); @@ -54,7 +54,7 @@ class CharacterClass { : Color(int.parse(data['colorSecondary'], radix: radix)); } - List summonList = []; + final List summonList = []; if (data.containsKey('summons')) { final summons = data['summons'] as Map; for (String key in summons.keys) { @@ -62,7 +62,7 @@ class CharacterClass { } } - List perkList = []; + final List perkList = []; if (data.containsKey('perks')) { final perks = (data['perks'] as List) .cast>(); @@ -71,7 +71,7 @@ class CharacterClass { } } - List perkFHList = []; + final List perkFHList = []; if (data.containsKey('perks_fh')) { final perks = (data['perks_fh'] as List) .cast>(); @@ -107,7 +107,7 @@ class PerkModel { text = data['text']; } - List addList = []; + final List addList = []; if (data.containsKey('adds')) { final adds = (data['adds'] as List).cast(); for (String item in adds) { @@ -115,7 +115,7 @@ class PerkModel { } } - List removeList = []; + final List removeList = []; if (data.containsKey('removes')) { final removes = (data['removes'] as List).cast(); for (String item in removes) { diff --git a/server/lib/core/models/monster.dart b/server/lib/core/models/monster.dart index 77312cf..7e1232e 100644 --- a/server/lib/core/models/monster.dart +++ b/server/lib/core/models/monster.dart @@ -98,7 +98,7 @@ class MonsterModel { final levels = (data['levels'] as List) .cast>(); - List monsterLevelDataList = []; + final List monsterLevelDataList = []; for (final item in levels) { monsterLevelDataList.add(MonsterLevelModel.fromJson(item)); } diff --git a/server/lib/core/models/monster_ability.dart b/server/lib/core/models/monster_ability.dart index 3a90a52..f13ee3e 100644 --- a/server/lib/core/models/monster_ability.dart +++ b/server/lib/core/models/monster_ability.dart @@ -17,25 +17,25 @@ class MonsterAbilityDeckModel { as List< dynamic >; // ignore: avoid-dynamic, complex JSON cards array requires mutable dynamic list - List cards = []; + final List cards = []; for (final card in dynamicCards) { String title = name; if (card[0] is String) { title = card[0] as String; card.removeAt(0); } - int nr = card[0] as int; + final int nr = card[0] as int; ///duplication check if (cards.any((element) => element.nr == nr)) { print("duplicate monster ability card nr: $nr for $name"); } - bool shuffle = card[1] as bool; - int initiative = card[2] as int; - List graphicPositionals = []; + final bool shuffle = card[1] as bool; + final int initiative = card[2] as int; + final List graphicPositionals = []; if (card[3] is List) { //handle the graphic extras - List list = + final List list = card[3]; // ignore: avoid-dynamic, graphic extras are a dynamic JSON array for (final item in list) { @@ -47,7 +47,7 @@ class MonsterAbilityDeckModel { if (item.containsKey('scale')) { scale = item['scale']; } - GraphicPositional pos = GraphicPositional( + final GraphicPositional pos = GraphicPositional( item["gfx"], item["x"], item["y"], @@ -59,7 +59,7 @@ class MonsterAbilityDeckModel { card.removeAt(_kGraphicsIndex); } - List lines = []; + final List lines = []; for (int i = _kGraphicsIndex; i < card.length; i++) { lines.add(card[i] as String); } diff --git a/server/lib/core/models/room.dart b/server/lib/core/models/room.dart index 903dc47..036a385 100644 --- a/server/lib/core/models/room.dart +++ b/server/lib/core/models/room.dart @@ -6,11 +6,11 @@ class RoomMonsterData { const RoomMonsterData(this.name, this.normal, this.elite); factory RoomMonsterData.fromJson(Map data, String key) { - String name = key; - List normal = data.containsKey('normal') + final String name = key; + final List normal = data.containsKey('normal') ? data['normal'].cast() : [0, 0, 0]; - List elite = data.containsKey('elite') + final List elite = data.containsKey('elite') ? data['elite'].cast() : [0, 0, 0]; @@ -24,8 +24,8 @@ class RoomModel { const RoomModel(this.name, this.monsterData); factory RoomModel.fromJson(Map data) { - String name = data.keys.first; - List monsterList = []; + final String name = data.keys.first; + final List monsterList = []; data[name].forEach((key, value) { monsterList.add(RoomMonsterData.fromJson(value, key)); }); @@ -40,7 +40,7 @@ class RoomsModel { const RoomsModel(this.scenarioName, this.roomData); factory RoomsModel.fromJson(List sectionData, String scenarioName) { - List roomList = []; + final List roomList = []; for (final value in sectionData) { roomList.add(RoomModel.fromJson(value as Map)); } @@ -54,7 +54,7 @@ class EditionRoomsModel { const EditionRoomsModel(this.roomData); factory EditionRoomsModel.fromJson(Map data) { - List roomList = []; + final List roomList = []; for (final entry in data.entries) { roomList.add(RoomsModel.fromJson(entry.value, entry.key)); } diff --git a/server/lib/core/models/scenario.dart b/server/lib/core/models/scenario.dart index 18cd709..0e3d97e 100644 --- a/server/lib/core/models/scenario.dart +++ b/server/lib/core/models/scenario.dart @@ -164,14 +164,14 @@ class ScenarioModel { Map data, RoomsModel? rooms, ) { - List monsterList = []; + final List monsterList = []; if (data.containsKey('monsters')) { final monsters = (data['monsters'] as List).cast(); for (final monster in monsters) { monsterList.add(monster); } } - List rulesList = []; + final List rulesList = []; if (data.containsKey('special')) { final specialRules = (data['special'] as List) .cast>(); @@ -188,10 +188,10 @@ class ScenarioModel { initMessage = data['initialMessage']; } - List sectionList = []; + final List sectionList = []; if (rooms != null) { - List names = []; + final List names = []; for (final u in rooms.roomData) { if (names.contains(u.name)) { print("duplicate ${u.name} in ${rooms.scenarioName}"); @@ -218,14 +218,14 @@ class ScenarioModel { } else { //it might be a bit silly that room data and section data is separate //merge if has already - int splitIndex = 0; + final int splitIndex = 0; //would be nice to know which is solo scenario - ScenarioModel? section = sectionList.firstWhereOrNull( + final ScenarioModel? section = sectionList.firstWhereOrNull( (element) => element.name == key.split(" ")[splitIndex], ); if (section != null) { //merge - ScenarioModel model = ScenarioModel.sectionFromJson( + final ScenarioModel model = ScenarioModel.sectionFromJson( key, sections[key], rooms, @@ -261,14 +261,14 @@ class ScenarioModel { Map data, RoomsModel? rooms, ) { - List monsterList = []; + final List monsterList = []; if (data.containsKey('monsters')) { final monsters = (data['monsters'] as List).cast(); for (final monster in monsters) { monsterList.add(monster); } } - List rulesList = []; + final List rulesList = []; if (data.containsKey('special')) { final specialRules = (data['special'] as List) .cast>(); @@ -282,7 +282,7 @@ class ScenarioModel { } //find right room - List? standees = rooms?.roomData + final List? standees = rooms?.roomData .firstWhereOrNull( (element) => element.name == diff --git a/server/lib/core/models/summon_model.dart b/server/lib/core/models/summon_model.dart index 802f3f8..4beb176 100644 --- a/server/lib/core/models/summon_model.dart +++ b/server/lib/core/models/summon_model.dart @@ -21,7 +21,7 @@ class SummonModel { ); factory SummonModel.fromJson(Map data, String key) { - String name = key; + final String name = key; StatValue health = const IntStatValue(2); //default to 2 not to die if (data.containsKey('health')) { health = StatValue.fromJson(data['health']); diff --git a/server/lib/core/settings.dart b/server/lib/core/settings.dart index 3f25afe..31d3e79 100644 --- a/server/lib/core/settings.dart +++ b/server/lib/core/settings.dart @@ -52,7 +52,7 @@ class Settings { /// Loads the named save into the game state (an undoable command). void loadSave(String saveName, {GameState? gameState}) { - String? save = saves[saveName]; + final String? save = saves[saveName]; if (save != null) { final gs = gameState ?? getIt(); gs.action(LoadSaveCommand(saveName, save, gameState: gs)); @@ -72,7 +72,7 @@ class Settings { /// Loads the named character save (an undoable command). void loadCharacterSave(String saveId, {GameState? gameState}) { - String? save = characterSaves[saveId]; + final String? save = characterSaves[saveId]; if (save != null) { final gs = gameState ?? getIt(); final name = saveId.split('\n').first; diff --git a/server/lib/core/stat_calculator.dart b/server/lib/core/stat_calculator.dart index 2ffb297..7027644 100644 --- a/server/lib/core/stat_calculator.dart +++ b/server/lib/core/stat_calculator.dart @@ -26,7 +26,7 @@ class StatCalculator { if (C < minNrCharacters) { C = minNrCharacters; } - int L = gs.level; + final int L = gs.level; String formula = str.replaceAll("C", C.toString()); formula = formula.replaceAll("L", L.toString()); return eval(formula); @@ -66,7 +66,7 @@ class Parser { int? parse() { try { nextChar(); - int? result = parseCondition(); + final int? result = parseCondition(); if (pos < str.length) { // ignore: avoid_print print("Unexpected: $ch"); @@ -148,7 +148,7 @@ class Parser { if (eat('-')) return -parseFactor()!; // unary minus int? result; - int startPos = pos; + final int startPos = pos; int asciiValue = ch.codeUnits.first; if (eat('(')) { // parentheses diff --git a/server/lib/core/state/game_save_state.dart b/server/lib/core/state/game_save_state.dart index 331b3a8..57ddf30 100644 --- a/server/lib/core/state/game_save_state.dart +++ b/server/lib/core/state/game_save_state.dart @@ -27,7 +27,7 @@ class GameSaveState { } if (data.containsKey('scenarioSectionsAdded')) { - List scenarioSectionsAdded = + final List scenarioSectionsAdded = data['scenarioSectionsAdded'] as List; gameState._scenarioSectionsAdded.clear(); for (final item in scenarioSectionsAdded) { @@ -78,7 +78,7 @@ class GameSaveState { //main list — update existing objects in-place final list = data['currentList'] as List; - List newList = []; + final List newList = []; for (Map item in list) { if (item["noteRow"] == true) { final String itemId = item["id"] as String; @@ -133,10 +133,10 @@ class GameSaveState { // Prototype has the full initialized card set; used only for nr lookups. final proto = MonsterAbilityState(deckName); - List newDrawList = []; - List drawPile = item["drawPile"] as List; + final List newDrawList = []; + final List drawPile = item["drawPile"] as List; for (final cardItem in drawPile) { - int nr = cardItem["nr"]; + final int nr = cardItem["nr"]; for (final card in proto._drawPile.getList()) { if (card.nr == nr) { newDrawList.add(card); @@ -144,9 +144,9 @@ class GameSaveState { } } } - List newDiscardList = []; + final List newDiscardList = []; for (final cardItem in item["discardPile"] as List) { - int nr = cardItem["nr"]; + final int nr = cardItem["nr"]; for (final card in proto._drawPile.getList()) { if (card.nr == nr) { newDiscardList.add(card); @@ -192,7 +192,7 @@ class GameSaveState { } //////elements - Map elementData = data['elementState']; + final Map elementData = data['elementState']; for (final element in Elements.values) { final raw = elementData[element.index.toString()] as int?; final idx = @@ -218,7 +218,7 @@ class GameSaveState { void loadFromDisk(GameState gameState) { //have to call after init or element state overridden - String? data = getIt().read(); + final String? data = getIt().read(); if (data != null) { _savedState = data; load(gameState); diff --git a/server/lib/core/state/game_state.dart b/server/lib/core/state/game_state.dart index 23666fe..fc2521e 100644 --- a/server/lib/core/state/game_state.dart +++ b/server/lib/core/state/game_state.dart @@ -257,13 +257,13 @@ class GameState { String toString() => json.encode(toJson()); void save() { - GameSaveState state = GameSaveState(); + final GameSaveState state = GameSaveState(); state.saveToDisk(this); addSaveState(state); } void load() { - GameSaveState state = GameSaveState(); + final GameSaveState state = GameSaveState(); state.loadFromDisk(this); addSaveState( state, @@ -271,7 +271,7 @@ class GameState { } void loadFromData(String data) { - GameSaveState state = GameSaveState(); + final GameSaveState state = GameSaveState(); state.loadFromData(data, this); } diff --git a/server/lib/core/state/loot_deck_state.dart b/server/lib/core/state/loot_deck_state.dart index ccd1003..790e161 100644 --- a/server/lib/core/state/loot_deck_state.dart +++ b/server/lib/core/state/loot_deck_state.dart @@ -48,7 +48,7 @@ class LootCard { if (enhanced > 0) { value += enhanced; } - int characters = GameMethods.getCurrentCharacterAmount(); + final int characters = GameMethods.getCurrentCharacterAmount(); if (characters >= _kHighCharCount) { return value; } @@ -200,14 +200,14 @@ class LootDeck { )..owner = owner; } - List newDrawList = []; - List drawPile = lootDeckData["drawPile"] as List; + final List newDrawList = []; + final List drawPile = lootDeckData["drawPile"] as List; int id = 0; for (final item in drawPile) { if (item.containsKey('id')) id = item["id"] as int; newDrawList.add(cardFromJson(item as Map, id)); } - List newDiscardList = []; + final List newDiscardList = []; for (final item in lootDeckData["discardPile"] as List) { if (item.containsKey('id')) id = item["id"] as int; newDiscardList.add(cardFromJson(item as Map, id)); @@ -244,7 +244,7 @@ class LootDeck { } void _setDeck(LootDeckModel model) { - List cards = []; + final List cards = []; if (_hasCard1419) { _addOtherType(_kSpecialCard1419, cards, "special 1419"); @@ -434,7 +434,7 @@ class LootDeck { } List _getAvailableCards(List pool) { - List list = []; + final List list = []; for (final item in pool) { if (!_drawPile.getList().any((element) => element.id == item.id)) { list.add(item); @@ -525,8 +525,8 @@ class LootDeck { _initPools(); final gs = gameState ?? getIt(); final gd = gameData ?? getIt(); - String scenario = gs.scenario; - LootDeckModel? lootDeckModel = + final String scenario = gs.scenario; + final LootDeckModel? lootDeckModel = gd.modelData[gs.currentCampaign]?.scenarios[scenario]?.lootDeck; if (lootDeckModel != null) { _setDeck(lootDeckModel); @@ -535,7 +535,7 @@ class LootDeck { void _shuffle() { while (_discardPile.isNotEmpty) { - LootCard card = _discardPile.pop(); + final LootCard card = _discardPile.pop(); _drawPile.push(card); } _drawPile.shuffle(); @@ -543,7 +543,7 @@ class LootDeck { void draw(_StateModifier _, {GameState? gameState}) { //put top of draw pile on discard pile - LootCard card = _drawPile.pop(); + final LootCard card = _drawPile.pop(); //mark owner final gs = gameState ?? getIt(); diff --git a/server/lib/core/state/modifier_deck.dart b/server/lib/core/state/modifier_deck.dart index b7c00f1..d50131f 100644 --- a/server/lib/core/state/modifier_deck.dart +++ b/server/lib/core/state/modifier_deck.dart @@ -100,7 +100,7 @@ class ModifierDeck { _needsShuffle = false; for (final item in modifierDeckData["drawPile"] as List) { - String gfx = item["gfx"]; + final String gfx = item["gfx"]; if (gfx == "curse" || gfx.contains("empower") || gfx.contains("enfeeble") || @@ -109,7 +109,7 @@ class ModifierDeck { } } for (final item in modifierDeckData["discardPile"] as List) { - String gfx = item["gfx"]; + final String gfx = item["gfx"]; if (_isMultiplyType(gfx)) { _needsShuffle = true; } @@ -527,7 +527,7 @@ class ModifierDeck { } //put top of draw pile on discard pile if (_drawPile.isNotEmpty) { - ModifierCard card = _drawPile.pop(); + final ModifierCard card = _drawPile.pop(); if (card.type == CardType.multiply) { _needsShuffle = true; } @@ -540,7 +540,7 @@ class ModifierDeck { } void reorderCards(_StateModifier s, int newIndex, int oldIndex) { - List list = List.of(_drawPile.getList()); + final List list = List.of(_drawPile.getList()); final item = list.removeAt(oldIndex); list.insert(newIndex, item); _drawPile.setList(list); @@ -588,7 +588,7 @@ class ModifierDeck { Map modifierDeckData, String deckId, ) { - List newList = []; + final List newList = []; for (final item in modifierDeckData[deckId] as List) { String gfx = item["gfx"]; gfx = gfx.replaceAll("-allies", ""); @@ -614,7 +614,7 @@ class ModifierDeck { } void _initDeck() { - List cards = []; + final List cards = []; cards.add(ModifierCard(CardType.add, "minus2")); cards.add(ModifierCard(CardType.add, "plus2")); cards.add(ModifierCard(CardType.multiply, "doubleAttack")); @@ -688,7 +688,7 @@ class ModifierDeck { } } } else { - int toRemove = count - notifierValue; + final int toRemove = count - notifierValue; for (int i = 0; i < toRemove; i++) { _drawPile.removeFirstWhere((card) => card.gfx == gfx); } @@ -700,7 +700,7 @@ class ModifierDeck { void _shuffle() { while (_discardPile.isNotEmpty) { - ModifierCard card = _discardPile.pop(); + final ModifierCard card = _discardPile.pop(); //remove curse and bless if (card.type != CardType.remove) { _drawPile.push(card); @@ -714,7 +714,7 @@ class ModifierDeck { void _shuffleOnlyBelowRevealed() { final revealCount = _revealedCount; - List revealed = []; + final List revealed = []; for (int i = 0; i < _revealedCount; i++) { revealed.insert(0, _drawPile.pop()); } @@ -728,7 +728,7 @@ class ModifierDeck { void _shuffleDrawPileRespectCassandra() { if (_cassandraSpecial) { //dont shuffle the revealed cards - List revealed = []; + final List revealed = []; for (int i = 0; i < _revealedCount; i++) { revealed.insert(0, _drawPile.pop()); } diff --git a/server/lib/core/state/monster.dart b/server/lib/core/state/monster.dart index 6ed3f67..c936907 100644 --- a/server/lib/core/state/monster.dart +++ b/server/lib/core/state/monster.dart @@ -73,7 +73,7 @@ class Monster extends ListItemData { _isActive = json['isActive']; } - List instanceList = json["monsterInstances"] as List; + final List instanceList = json["monsterInstances"] as List; _monsterInstances.clear(); for (Map item diff --git a/server/lib/core/state/monster_ability_state.dart b/server/lib/core/state/monster_ability_state.dart index 161a063..f1d4403 100644 --- a/server/lib/core/state/monster_ability_state.dart +++ b/server/lib/core/state/monster_ability_state.dart @@ -31,7 +31,7 @@ class MonsterAbilityState { MonsterAbilityState(this.name, {GameData? gameData}) { final gd = gameData ?? getIt(); - List monsters = []; + final List monsters = []; for (String key in gd.modelData.keys) { monsters.addAll(gd.modelData[key]?.monsterAbilities ?? []); } diff --git a/server/lib/core/state/monster_instance.dart b/server/lib/core/state/monster_instance.dart index a3fde0c..f4c3c99 100644 --- a/server/lib/core/state/monster_instance.dart +++ b/server/lib/core/state/monster_instance.dart @@ -81,7 +81,7 @@ class MonsterInstance extends FigureState { newHealthValue = levels[levelIndex].normal?.health ?? newHealthValue; } } - int? value = StatCalculator.calculateFormula(newHealthValue); + final int? value = StatCalculator.calculateFormula(newHealthValue); if (value != null) { _maxHealth = value; } else { @@ -178,7 +178,7 @@ class MonsterInstance extends FigureState { } if (json.containsKey("conditionsAddedThisTurn")) { - List condis2 = json["conditionsAddedThisTurn"] as List; + final List condis2 = json["conditionsAddedThisTurn"] as List; for (int item in condis2.cast()) { if (item >= 0 && item < Condition.values.length) { _conditionsAddedThisTurn.add(Condition.values[item]); @@ -186,7 +186,7 @@ class MonsterInstance extends FigureState { } } if (json.containsKey("conditionsAddedPreviousTurn")) { - List condis3 = + final List condis3 = json["conditionsAddedPreviousTurn"] as List; for (int item in condis3.cast()) { if (item >= 0 && item < Condition.values.length) { diff --git a/server/lib/core/state/sanctuary_deck.dart b/server/lib/core/state/sanctuary_deck.dart index 8858fea..0221403 100644 --- a/server/lib/core/state/sanctuary_deck.dart +++ b/server/lib/core/state/sanctuary_deck.dart @@ -16,14 +16,14 @@ class SanctuaryDeck { SanctuaryDeck.fromJson(Map modifierDeckData) { _initDeck(); - List newMultList = []; - List newFlipList = []; + final List newMultList = []; + final List newFlipList = []; for (final item in modifierDeckData["multPile"] as List) { - String gfx = item["gfx"]; + final String gfx = item["gfx"]; newMultList.add(ModifierCard(CardType.remove, gfx)); } for (final item in modifierDeckData["flipPile"] as List) { - String gfx = item["gfx"]; + final String gfx = item["gfx"]; newFlipList.add(ModifierCard(CardType.remove, gfx)); } _multPile.setList(newMultList); @@ -67,8 +67,8 @@ class SanctuaryDeck { void _initDeck() { _multPile.clear(); _flipPile.clear(); - List flipCards = []; - List multCards = []; + final List flipCards = []; + final List multCards = []; final prefix = "sanctuary/"; for (int i = 1; i < _kCardTypeCount; i++) { //2 of each of 4 different cards -- cgit v1.3.1