Add Xu Province recruit sortie flow
This commit is contained in:
@@ -271,6 +271,60 @@ export function applyCampBondExp(dialogueId: string, bondId: string, amount: num
|
||||
return cloneReport(state.firstBattleReport);
|
||||
}
|
||||
|
||||
export function ensureCampaignRosterUnits(units: UnitData[], bonds: BattleBond[] = []) {
|
||||
const state = ensureCampaignState();
|
||||
let changed = false;
|
||||
const existingUnitIds = new Set(state.roster.map((unit) => unit.id));
|
||||
|
||||
units.forEach((unit) => {
|
||||
if (existingUnitIds.has(unit.id)) {
|
||||
return;
|
||||
}
|
||||
state.roster.push(cloneUnit(unit));
|
||||
existingUnitIds.add(unit.id);
|
||||
changed = true;
|
||||
});
|
||||
|
||||
const existingBondIds = new Set(state.bonds.map((bond) => bond.id));
|
||||
bonds.forEach((bond) => {
|
||||
if (existingBondIds.has(bond.id)) {
|
||||
return;
|
||||
}
|
||||
state.bonds.push(createCampBondSnapshot(bond));
|
||||
existingBondIds.add(bond.id);
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (state.firstBattleReport) {
|
||||
const reportUnitIds = new Set(state.firstBattleReport.units.map((unit) => unit.id));
|
||||
units.forEach((unit) => {
|
||||
if (reportUnitIds.has(unit.id)) {
|
||||
return;
|
||||
}
|
||||
state.firstBattleReport?.units.push(cloneUnit(unit));
|
||||
reportUnitIds.add(unit.id);
|
||||
changed = true;
|
||||
});
|
||||
|
||||
const reportBondIds = new Set(state.firstBattleReport.bonds.map((bond) => bond.id));
|
||||
bonds.forEach((bond) => {
|
||||
if (reportBondIds.has(bond.id)) {
|
||||
return;
|
||||
}
|
||||
state.firstBattleReport?.bonds.push(createCampBondSnapshot(bond));
|
||||
reportBondIds.add(bond.id);
|
||||
changed = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
state.updatedAt = new Date().toISOString();
|
||||
persistCampaignState(state);
|
||||
}
|
||||
|
||||
return cloneCampaignState(state);
|
||||
}
|
||||
|
||||
function ensureCampaignState() {
|
||||
if (!campaignState) {
|
||||
campaignState = readStoredCampaignState() ?? createInitialCampaignState();
|
||||
@@ -433,3 +487,11 @@ function cloneBondSnapshot(bond: CampBondSnapshot): CampBondSnapshot {
|
||||
unitIds: [...bond.unitIds] as [string, string]
|
||||
};
|
||||
}
|
||||
|
||||
function createCampBondSnapshot(bond: BattleBond): CampBondSnapshot {
|
||||
return {
|
||||
...bond,
|
||||
unitIds: [...bond.unitIds] as [string, string],
|
||||
battleExp: 0
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user