feat: implement diplomacy system with state management and processing logic

This commit is contained in:
2026-01-02 17:48:44 +00:00
parent f137c5be65
commit cb86a47f94
13 changed files with 606 additions and 45 deletions
+38 -5
View File
@@ -260,13 +260,46 @@ export const seedScenarioToDatabase = async (
});
}
if (seed.diplomacy.length > 0) {
const diplomacyMap = new Map<
string,
{ srcNationId: number; destNationId: number; state: number; term: number }
>();
const nationIds = seed.nations.map((nation) => nation.id);
for (const srcNationId of nationIds) {
for (const destNationId of nationIds) {
if (srcNationId === destNationId) {
continue;
}
diplomacyMap.set(`${srcNationId}:${destNationId}`, {
srcNationId,
destNationId,
state: 2,
term: 0,
});
}
}
for (const row of seed.diplomacy) {
diplomacyMap.set(`${row.fromNationId}:${row.toNationId}`, {
srcNationId: row.fromNationId,
destNationId: row.toNationId,
state: row.state,
term: row.durationMonths,
});
diplomacyMap.set(`${row.toNationId}:${row.fromNationId}`, {
srcNationId: row.toNationId,
destNationId: row.fromNationId,
state: row.state,
term: row.durationMonths,
});
}
const diplomacyRows = Array.from(diplomacyMap.values());
if (diplomacyRows.length > 0) {
await prisma.diplomacy.createMany({
data: seed.diplomacy.map((row) => ({
srcNationId: row.fromNationId,
destNationId: row.toNationId,
data: diplomacyRows.map((row) => ({
srcNationId: row.srcNationId,
destNationId: row.destNationId,
stateCode: row.state,
term: row.durationMonths,
term: row.term,
meta: asJson({}),
})),
});