import type { CompanionState, GameState } from '../types'; import { getCharacterById, getCharacterCombatStats, getCharacterMaxHp, } from './characterPresets'; function recoverCompanion( companion: CompanionState, state: Pick, ) { if (companion.hp <= 0) { return companion; } const character = getCharacterById(companion.characterId); if (!character) { return companion; } const recovery = getCharacterCombatStats( character, state.worldType, state.customWorldProfile, ).storyRecovery; const maxHp = Math.max( companion.maxHp, getCharacterMaxHp(character, state.worldType, state.customWorldProfile), ); return { ...companion, maxHp, hp: Math.min(maxHp, companion.hp + recovery), }; } export function applyStoryReasoningRecovery(state: GameState) { if (!state.playerCharacter) { return state; } const playerRecovery = state.playerHp > 0 ? getCharacterCombatStats( state.playerCharacter, state.worldType, state.customWorldProfile, ).storyRecovery : 0; return { ...state, playerHp: state.playerHp > 0 ? Math.min(state.playerMaxHp, state.playerHp + playerRecovery) : state.playerHp, companions: state.companions.map(companion => recoverCompanion(companion, state)), roster: state.roster.map(companion => recoverCompanion(companion, state)), }; }