This commit is contained in:
59
src/data/storyRecovery.ts
Normal file
59
src/data/storyRecovery.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type { CompanionState, GameState } from '../types';
|
||||
import {
|
||||
getCharacterById,
|
||||
getCharacterCombatStats,
|
||||
getCharacterMaxHp,
|
||||
} from './characterPresets';
|
||||
|
||||
function recoverCompanion(
|
||||
companion: CompanionState,
|
||||
state: Pick<GameState, 'worldType' | 'customWorldProfile'>,
|
||||
) {
|
||||
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)),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user