Implement monthly nation level updates

This commit is contained in:
2026-07-25 17:19:44 +00:00
parent 7afb2ac63f
commit 41d70a475c
8 changed files with 1089 additions and 17 deletions
+21
View File
@@ -384,6 +384,7 @@ export const createDatabaseTurnHooks = async (
deletedEvents,
lifecycleEvents,
pendingNeutralAuctions,
inheritancePointAdjustments,
} = changes;
const reservedTurnChanges = options?.reservedTurns?.peekDirtyState();
@@ -435,6 +436,26 @@ export const createDatabaseTurnHooks = async (
asRecord(world.getScenarioConfig().const)
);
if (inheritancePointAdjustments.length > 0) {
const grouped = new Map<string, { userId: string; key: string; amount: number }>();
for (const entry of inheritancePointAdjustments) {
const groupKey = `${entry.userId}\u0000${entry.key}`;
const current = grouped.get(groupKey);
if (current) {
current.amount += entry.amount;
} else {
grouped.set(groupKey, { ...entry });
}
}
for (const entry of grouped.values()) {
await prisma.inheritancePoint.upsert({
where: { userId_key: { userId: entry.userId, key: entry.key } },
update: { value: { increment: entry.amount } },
create: { userId: entry.userId, key: entry.key, value: entry.amount },
});
}
}
if (deletedNationSnapshots.length > 0) {
const nationIds = deletedNationSnapshots.map((snapshot) => snapshot.nation.id);
const historyRows = await prisma.logEntry.findMany({