Add post-battle camp scene
This commit is contained in:
73
src/game/state/campaignState.ts
Normal file
73
src/game/state/campaignState.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user