part of '../state/game_state.dart'; // ignore_for_file: library_private_types_in_public_api class CharacterMethods { static const int _kHailPerkIndex = 17; static const int _kPainConduitPerkIndex = 16; static const int _kPainConduitHealthBonus = 5; static const int _kObjectiveInitiative = 99; // Special summon base stats static const int _kBeastHealth = 8; static const int _kBeastMultiplier = 2; static const int _kDomeHealth = 3; static const int _kGlacierHealth = 7; static const int _kJesterHealth = 5; static const int _kSpecialSummonMove = 3; static const int _kSpecialSummonAttack = 2; static const int _kSpecialSummonRange = 0; static const int _kSpecialSummonStandeeNr = 0; static const int _kSpecialSummonInitiative = -1; static void addPerk( _StateModifier s, Character character, int index, { GameState? gameState, }) { final gs = gameState ?? getIt(); final deck = character.characterState.modifierDeck; final perksFH = character.characterClass.perksFH; final useFHPerks = character.characterState.useFHPerks && perksFH.isNotEmpty; final perks = useFHPerks ? perksFH : character.characterClass.perks; final perk = perks[index]; for (final item in perk.remove) { final amount = deck.drawPileSize; deck.removeCard(s, item); if (deck.drawPileSize == amount) { //must be a perk card //find missing card from perk list for (int i = 0; i < perks.length; i++) { //check if other perk added the card previously final adds = perks[i].add; if (adds.contains(item)) { //remove that perk card String second = ""; if (adds.first != adds.last && item == adds.last) { second = "-2"; //in case perk adds 2 different cards } deck.removeCard(s, "P$i$second"); if (deck.drawPileSize != amount) { //found and removed break; } } } } } for (final item in perk.add) { CardType type = CardType.add; if (item.endsWith("/ns2")) { //nightshroud hack type = CardType.multiply; } final id = GameMethods.perkGfxIdToCardId(item, perk, index); deck.addCard(s, id, type); } final className = character.characterClass.name; if (index == _kHailPerkIndex && className == "Hail") { gs.modifierDeck.addHailSpecial(s); } if (index == _kPainConduitPerkIndex && className == "Pain Conduit") { final level = character.characterState.level; final healthByLevel = character.characterClass.healthByLevel; if (level >= 1 && level <= healthByLevel.length) { character.characterState._health = healthByLevel[level - 1] + _kPainConduitHealthBonus; character.characterState.setMaxHealth( s, character.characterState._health, ); } } } static void removePerk( _StateModifier s, Character character, int index, { GameState? gameState, }) { final gs = gameState ?? getIt(); final deck = character.characterState.modifierDeck; final perksFH = character.characterClass.perksFH; final useFHPerks = character.characterState.useFHPerks && perksFH.isNotEmpty; final perks = useFHPerks ? perksFH : character.characterClass.perks; final perk = perks[index]; for (final item in perk.remove) { if (item.startsWith("perks/")) { //find id of perk: bull: could be several... for (int i = 0; i < perks.length; i++) { if (character.characterState.perkList[i] && perks[i].add.contains(item)) { final id = GameMethods.perkGfxIdToCardId(item, perks[i], i); deck.addCard(s, id, CardType.add); break; } } } else { deck.addCard(s, item, CardType.add); } } for (final item in perk.add) { final id = GameMethods.perkGfxIdToCardId(item, perk, index); deck.removeCard(s, id); } final className = character.characterClass.name; if (index == _kHailPerkIndex && className == "Hail") { gs.modifierDeck.removeHailSpecial(s); } if (index == _kPainConduitPerkIndex && className == "Pain Conduit") { final state = character.characterState; final characterClass = character.characterClass; final level = state.level; if (level >= 1 && level <= characterClass.healthByLevel.length) { final int health = characterClass.healthByLevel[level - 1]; state.setMaxHealth(s, health); state.setHealth(s, health); } } } static void setCharacterLevel( _StateModifier s, int level, String characterId, { GameState? gameState, }) { final gs = gameState ?? getIt(); Character? character; for (final item in gs.currentList) { if (item.id == characterId && item is Character) { character = item; break; } } if (character != null) { final healthByLevel = character.characterClass.healthByLevel; if (healthByLevel.length < level) { level = healthByLevel.length; } character.characterState.setFigureLevel(s, level); character.characterState.setHealth(s, healthByLevel[level - 1]); if (character.id == "Pain Conduit" && character.characterState.perkList[_kPainConduitPerkIndex]) { character.characterState.setHealth( s, healthByLevel[level - 1] + _kPainConduitHealthBonus, ); } character.characterState.setMaxHealth(s, character.characterState.health); //handle special summons int health = 0; int multiplier = 1; String name = ""; if (character.id == "Beast Tyrant" || character.id == "Wildfury") { //create the bear summon health = _kBeastHealth; multiplier = _kBeastMultiplier; name = "Beast"; } if (character.id == "D.O.M.E.") { health = _kDomeHealth; name = "Barrier"; } if (character.id == "Glacial Torrent") { health = _kGlacierHealth; name = "Glacier"; } if (character.id == "Jester Twins") { //create the barrier as a summon health = _kJesterHealth; name = "Jester Twin"; } final list = character.characterState.summonList; if (list.isNotEmpty && list.first.name == name) { final int hp = health + character.characterState.level * multiplier; list.first.setMaxHealth(s, hp); list.first.setHealth(s, hp); } } ScenarioMethods.applyDifficulty(s); } static void resetCharacter(_StateModifier s, Character item) { item.characterState._initiative = 0; final level = item.characterState.level; item.characterState._health = item.characterClass.healthByLevel[level - 1]; if (item.characterClass.name == "Pain Conduit") { if (item.characterState.perkList[_kPainConduitPerkIndex]) { item.characterState._health += _kPainConduitHealthBonus; } } item.characterState._maxHealth = item.characterState.health; item.characterState._xp = 0; item.characterState._conditions.clear(); item.characterState._chill = 0; item.characterState._plague = 0; item.characterState.modifierDeck._initDeck(); //reapply perks final perksSetList = item.characterState.perkList; final perks = item.characterState.useFHPerks ? item.characterClass.perksFH : item.characterClass.perks; for (int i = 0; i < perks.length; i++) { if (perksSetList[i]) { addPerk(s, item, i); } } //handle special summons final summonList = item.characterState._summonList; summonList.clear(); int health = 0; int multiplier = 1; String gfx = ""; String name = ""; if (item.id == "Beast Tyrant" || item.id == "Wildfury") { //create the bear summon health = _kBeastHealth; multiplier = _kBeastMultiplier; gfx = item.id == "Beast Tyrant" ? "beast" : "Beast v2"; name = "Beast"; } if (item.id == "D.O.M.E.") { health = _kDomeHealth; gfx = "DOM barrier"; name = "Barrier"; } if (item.id == "Glacial Torrent") { health = _kGlacierHealth; gfx = "GLA glacier"; name = "Glacier"; } if (item.id == "Jester Twins") { //create the barrier as a summon health = _kJesterHealth; gfx = "JES twin"; name = "Jester Twin"; } if (name.isNotEmpty) { final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, health + level * multiplier, _kSpecialSummonMove, _kSpecialSummonAttack, _kSpecialSummonRange, gfx, _kSpecialSummonInitiative, ); summonList.add(summon); } item.characterState._notifySummonList(); } static void removeCharacters( _StateModifier s, List characters, { GameState? gameState, }) { final List newList = []; final gs = gameState ?? getIt(); for (final item in gs.currentList) { if (item is Character) { bool remove = false; for (final name in characters) { if (item.characterState.display == name.characterState.display) { remove = true; break; } } if (!remove) { newList.add(item); } } else { newList.add(item); } } gs._currentList = newList; RoundMethods.updateForSpecialRules(s); gs._notifyCurrentList(); } static Character? createCharacter( _StateModifier _, String id, String? edition, String? display, int level, { GameData? gameData, }) { Character? character; final List characters = []; final gd = gameData ?? getIt(); final modelData = gd.modelData; for (String key in modelData.keys) { characters.addAll(modelData[key]?.characters ?? []); } for (CharacterClass characterClass in characters) { if (characterClass.id == id && (edition == null || edition == characterClass.edition)) { final characterState = CharacterState(id); characterState._level = level; if (GameMethods.isObjectiveOrEscort(characterClass)) { characterState._initiative = _kObjectiveInitiative; } characterState._health = characterClass.healthByLevel[level - 1]; characterState._maxHealth = characterState.health; if (display != null) { characterState._display = display; } else { characterState._display = characterClass.name; } character = Character(characterState, characterClass); //handle special summons final summonList = character.characterState._summonList; summonList.clear(); int health = 0; int multiplier = 1; String gfx = ""; String name = ""; if (character.id == "Beast Tyrant" || character.id == "Wildfury") { //create the bear summon health = _kBeastHealth; multiplier = _kBeastMultiplier; gfx = character.id == "Beast Tyrant" ? "beast" : "Beast v2"; name = "Beast"; } if (character.id == "D.O.M.E.") { health = _kDomeHealth; gfx = "DOM barrier"; name = "Barrier"; } if (character.id == "Glacial Torrent") { health = _kGlacierHealth; gfx = "GLA glacier"; name = "Glacier"; } if (character.id == "Jester Twins") { //create the barrier as a summon health = _kJesterHealth; gfx = "JES twin"; name = "Jester Twin"; } if (name.isNotEmpty) { final MonsterInstance summon = MonsterInstance.summon( _kSpecialSummonStandeeNr, MonsterType.summon, name, health + level * multiplier, _kSpecialSummonMove, _kSpecialSummonAttack, _kSpecialSummonRange, gfx, _kSpecialSummonInitiative, ); summonList.add(summon); } break; } } return character; } }