Add post-battle camp scene

This commit is contained in:
2026-06-22 16:48:54 +09:00
parent 7135ac8e55
commit 797051ac9f
5 changed files with 651 additions and 4 deletions

View File

@@ -0,0 +1,73 @@
import type { BattleBond, UnitData } from '../data/scenario';
export type BattleObjectiveSnapshot = {
id: string;
label: string;
achieved: boolean;
detail: string;
rewardGold: number;
};
export type CampBondSnapshot = BattleBond & {
battleExp: number;
};
export type CampMvpSnapshot = {
unitId: string;
name: string;
damageDealt: number;
defeats: number;
};
export type FirstBattleReport = {
outcome: 'victory' | 'defeat';
turnNumber: number;
rewardGold: number;
defeatedEnemies: number;
totalEnemies: number;
objectives: BattleObjectiveSnapshot[];
units: UnitData[];
bonds: CampBondSnapshot[];
mvp?: CampMvpSnapshot;
itemRewards: string[];
completedCampDialogues: string[];
createdAt: string;
};
let firstBattleReport: FirstBattleReport | undefined;
export function setFirstBattleReport(report: FirstBattleReport) {
firstBattleReport = cloneReport(report);
}
export function getFirstBattleReport() {
return firstBattleReport ? cloneReport(firstBattleReport) : undefined;
}
export function applyCampBondExp(dialogueId: string, bondId: string, amount: number) {
if (!firstBattleReport) {
return undefined;
}
const bond = firstBattleReport.bonds.find((candidate) => candidate.id === bondId);
if (!bond) {
return undefined;
}
if (!firstBattleReport.completedCampDialogues.includes(dialogueId)) {
firstBattleReport.completedCampDialogues.push(dialogueId);
}
bond.battleExp += amount;
bond.exp += amount;
while (bond.exp >= 100) {
bond.exp -= 100;
bond.level = Math.min(100, bond.level + 1);
}
return cloneReport(firstBattleReport);
}
function cloneReport(report: FirstBattleReport): FirstBattleReport {
return JSON.parse(JSON.stringify(report)) as FirstBattleReport;
}