Merge branch 'main' into feature/nation-personnel-finance-parity
# Conflicts: # app/game-frontend/e2e/playwright.config.mjs # app/game-frontend/package.json # docs/frontend-legacy-parity.md
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
evaluateConstraints,
|
||||
resolveGeneralAction,
|
||||
ITEM_KEYS,
|
||||
addOccupiedUniqueItemKeys,
|
||||
buildGenericUniqueSeed,
|
||||
countOccupiedUniqueItems,
|
||||
createItemModuleRegistry,
|
||||
@@ -382,6 +383,7 @@ const buildUniqueLotteryRunner = (options: {
|
||||
seedBase: string;
|
||||
itemRegistry: Map<string, ItemModule>;
|
||||
uniqueConfig: ReturnType<typeof resolveUniqueConfig>;
|
||||
getAdditionalOccupiedUniqueItemKeys?: () => Iterable<string | null | undefined>;
|
||||
}): UniqueLotteryRunner => {
|
||||
if (!options.worldView) {
|
||||
return () => null;
|
||||
@@ -408,6 +410,11 @@ const buildUniqueLotteryRunner = (options: {
|
||||
entry.id === general.id ? general.role.items : entry.role.items
|
||||
);
|
||||
const occupiedUniqueCounts = countOccupiedUniqueItems(generalItemsList, options.itemRegistry);
|
||||
addOccupiedUniqueItemKeys(
|
||||
occupiedUniqueCounts,
|
||||
options.getAdditionalOccupiedUniqueItemKeys?.() ?? [],
|
||||
options.itemRegistry
|
||||
);
|
||||
const rngSeed = buildGenericUniqueSeed(
|
||||
options.seedBase,
|
||||
world.currentYear,
|
||||
@@ -723,6 +730,7 @@ export const createReservedTurnHandler = async (options: {
|
||||
commandProfile?: TurnCommandProfile;
|
||||
commandEnv?: TurnCommandEnv;
|
||||
commandRngFactory?: (input: { kind: 'nation' | 'general'; actionKey: string; seed: string }) => RandUtil;
|
||||
getAdditionalOccupiedUniqueItemKeys?: () => Iterable<string | null | undefined>;
|
||||
onActionResolved?: (payload: {
|
||||
kind: 'nation' | 'general';
|
||||
generalId: number;
|
||||
@@ -944,6 +952,7 @@ export const createReservedTurnHandler = async (options: {
|
||||
seedBase,
|
||||
itemRegistry,
|
||||
uniqueConfig,
|
||||
getAdditionalOccupiedUniqueItemKeys: options.getAdditionalOccupiedUniqueItemKeys,
|
||||
});
|
||||
let baseContext: ActionContextBase = {
|
||||
general: currentGeneral,
|
||||
|
||||
@@ -473,6 +473,8 @@ const createTurnDaemonRuntimeWithLease = async (
|
||||
neutralAuctionRegistrar.handler,
|
||||
frontStateHandler
|
||||
);
|
||||
let occupiedAuctionUniqueItemKeys: string[] = [];
|
||||
let refreshOccupiedAuctionUniqueItemKeys = async (): Promise<void> => {};
|
||||
const worldOptions: InMemoryTurnWorldOptions = {
|
||||
schedule,
|
||||
generalTurnHandler:
|
||||
@@ -486,6 +488,7 @@ const createTurnDaemonRuntimeWithLease = async (
|
||||
getWorld: () => worldRef,
|
||||
commandProfile,
|
||||
commandEnv: monthlyCommandEnv,
|
||||
getAdditionalOccupiedUniqueItemKeys: () => occupiedAuctionUniqueItemKeys,
|
||||
})),
|
||||
calendarHandler: calendarHandler ?? undefined,
|
||||
autoAdvanceDiplomacyMonth: false,
|
||||
@@ -501,6 +504,7 @@ const createTurnDaemonRuntimeWithLease = async (
|
||||
? async (general) => {
|
||||
const promises: Promise<unknown>[] = [];
|
||||
promises.push(reservedTurnStoreHandle.store.refreshGeneralTurns(general.id));
|
||||
promises.push(refreshOccupiedAuctionUniqueItemKeys());
|
||||
if (general.nationId > 0 && general.officerLevel >= 5) {
|
||||
promises.push(
|
||||
reservedTurnStoreHandle.store.refreshNationTurns(general.nationId, general.officerLevel)
|
||||
@@ -648,6 +652,17 @@ const createTurnDaemonRuntimeWithLease = async (
|
||||
if (commandConnector && databaseCommandQueue) {
|
||||
await commandConnector.connect();
|
||||
await databaseCommandQueue.initialize();
|
||||
refreshOccupiedAuctionUniqueItemKeys = async () => {
|
||||
const rows = await commandConnector.prisma.auction.findMany({
|
||||
where: {
|
||||
type: 'UNIQUE_ITEM',
|
||||
status: { in: ['OPEN', 'FINALIZING'] },
|
||||
targetCode: { not: null },
|
||||
},
|
||||
select: { targetCode: true },
|
||||
});
|
||||
occupiedAuctionUniqueItemKeys = rows.flatMap((row) => (row.targetCode ? [row.targetCode] : []));
|
||||
};
|
||||
}
|
||||
|
||||
const baseClose = close;
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
LogFormat,
|
||||
LogScope,
|
||||
ITEM_KEYS,
|
||||
addOccupiedUniqueItemKeys,
|
||||
buildVoteUniqueSeed,
|
||||
countOccupiedUniqueItems,
|
||||
createItemModuleRegistry,
|
||||
@@ -1481,6 +1482,21 @@ async function handleVoteReward(
|
||||
generals.map((entry) => entry.role.items),
|
||||
itemRegistry
|
||||
);
|
||||
if (ctx.commandDb) {
|
||||
const reservedUniqueRows = await ctx.commandDb.auction.findMany({
|
||||
where: {
|
||||
type: 'UNIQUE_ITEM',
|
||||
status: { in: ['OPEN', 'FINALIZING'] },
|
||||
targetCode: { not: null },
|
||||
},
|
||||
select: { targetCode: true },
|
||||
});
|
||||
addOccupiedUniqueItemKeys(
|
||||
occupiedUniqueCounts,
|
||||
reservedUniqueRows.map((row) => row.targetCode),
|
||||
itemRegistry
|
||||
);
|
||||
}
|
||||
const userCount = generals.filter((entry) => entry.npcState < 2).length;
|
||||
const rngSeed = buildVoteUniqueSeed(
|
||||
typeof hiddenSeed === 'string' || typeof hiddenSeed === 'number' ? hiddenSeed : String(hiddenSeed),
|
||||
|
||||
@@ -173,4 +173,138 @@ describe('unique lottery on general commands', () => {
|
||||
const logTexts = (result.logs ?? []).map((entry) => entry.text);
|
||||
expect(logTexts.some((text) => text.includes('【아이템】'))).toBe(true);
|
||||
});
|
||||
|
||||
it('does not award a unique item reserved by an active auction', async () => {
|
||||
const schedule: TurnSchedule = { entries: [{ startMinute: 0, tickMinutes: 10 }] };
|
||||
const generals = [buildGeneral(1)];
|
||||
const snapshot: TurnWorldSnapshot = {
|
||||
generals: generals as any,
|
||||
cities: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'City_1',
|
||||
nationId: 1,
|
||||
viewName: 'City_1',
|
||||
agriculture: 100,
|
||||
agricultureMax: 2000,
|
||||
commerce: 100,
|
||||
commerceMax: 2000,
|
||||
security: 100,
|
||||
securityMax: 100,
|
||||
def: 100,
|
||||
defMax: 100,
|
||||
wall: 100,
|
||||
wallMax: 100,
|
||||
pop: 10000,
|
||||
popMax: 50000,
|
||||
trust: 50,
|
||||
supplyState: 1,
|
||||
frontState: 0,
|
||||
tradepoint: 0,
|
||||
level: 1,
|
||||
meta: {},
|
||||
},
|
||||
] as any,
|
||||
nations: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'TestNation',
|
||||
color: '#FF0000',
|
||||
capitalCityId: 1,
|
||||
chiefGeneralId: 1,
|
||||
gold: 10000,
|
||||
rice: 10000,
|
||||
power: 0,
|
||||
level: 1,
|
||||
typeCode: 'che_def',
|
||||
meta: {},
|
||||
},
|
||||
] as any,
|
||||
troops: [],
|
||||
diplomacy: [],
|
||||
events: [],
|
||||
initialEvents: [],
|
||||
map: {
|
||||
id: 'test_map',
|
||||
name: 'TestMap',
|
||||
cities: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'City_1',
|
||||
level: 1,
|
||||
region: 1,
|
||||
position: { x: 0, y: 0 },
|
||||
connections: [],
|
||||
max: {} as any,
|
||||
initial: {} as any,
|
||||
},
|
||||
],
|
||||
defaults: { trust: 50, trade: 100, supplyState: 1, frontState: 0 },
|
||||
} as any,
|
||||
scenarioConfig: {
|
||||
stat: { total: 300, min: 10, max: 100, npcTotal: 150, npcMax: 50, npcMin: 10, chiefMin: 70 },
|
||||
iconPath: '',
|
||||
map: {},
|
||||
const: {
|
||||
allItems: {
|
||||
weapon: {
|
||||
che_무기_12_칠성검: 1,
|
||||
},
|
||||
},
|
||||
maxUniqueItemLimit: [[-1, 1]],
|
||||
uniqueTrialCoef: 10,
|
||||
maxUniqueTrialProb: 10,
|
||||
minMonthToAllowInheritItem: 0,
|
||||
},
|
||||
environment: { mapName: 'test_map', unitSet: 'default' },
|
||||
},
|
||||
scenarioMeta: {
|
||||
startYear: 180,
|
||||
} as any,
|
||||
unitSet: {} as any,
|
||||
};
|
||||
const state: TurnWorldState = {
|
||||
id: 1,
|
||||
currentYear: 180,
|
||||
currentMonth: 1,
|
||||
tickSeconds: 3600,
|
||||
lastTurnTime: new Date('0180-01-01T00:00:00Z'),
|
||||
meta: {
|
||||
hiddenSeed: 'seed',
|
||||
scenarioId: 200,
|
||||
initYear: 180,
|
||||
initMonth: 1,
|
||||
scenarioMeta: { startYear: 180 },
|
||||
},
|
||||
};
|
||||
const world = new InMemoryTurnWorld(state, snapshot, { schedule });
|
||||
const reservedTurns = new InMemoryReservedTurnStore(
|
||||
{
|
||||
generalTurn: { findMany: async () => [] },
|
||||
nationTurn: { findMany: async () => [] },
|
||||
} as any,
|
||||
{ maxGeneralTurns: 30, maxNationTurns: 12 }
|
||||
);
|
||||
reservedTurns.getGeneralTurns(1)[0] = { action: 'che_훈련', args: {} };
|
||||
const handler = await createReservedTurnHandler({
|
||||
reservedTurns,
|
||||
scenarioConfig: snapshot.scenarioConfig,
|
||||
scenarioMeta: snapshot.scenarioMeta,
|
||||
map: snapshot.map,
|
||||
unitSet: snapshot.unitSet,
|
||||
getWorld: () => world,
|
||||
getAdditionalOccupiedUniqueItemKeys: () => ['che_무기_12_칠성검'],
|
||||
});
|
||||
|
||||
const result = handler.execute({
|
||||
general: world.getGeneralById(1)!,
|
||||
city: world.getCityById(1)!,
|
||||
nation: world.getNationById(1)!,
|
||||
world: world.getState(),
|
||||
schedule,
|
||||
});
|
||||
|
||||
expect(result.general?.role.items.weapon).toBeNull();
|
||||
expect((result.logs ?? []).some((entry) => entry.text.includes('【아이템】'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,4 +223,80 @@ describe('voteReward command', () => {
|
||||
const afterSecond = world.getGeneralById(1);
|
||||
expect(afterSecond?.gold).toBe(1500);
|
||||
});
|
||||
|
||||
it('treats an active unique auction as occupied when revalidating the lottery', async () => {
|
||||
const general = buildGeneral(1);
|
||||
const snapshot: TurnWorldSnapshot = {
|
||||
generals: [general] as any,
|
||||
cities: [] as any,
|
||||
nations: [] as any,
|
||||
troops: [],
|
||||
diplomacy: [],
|
||||
events: [],
|
||||
initialEvents: [],
|
||||
map: {
|
||||
id: 'test_map',
|
||||
name: 'TestMap',
|
||||
cities: [],
|
||||
defaults: { trust: 50, trade: 100, supplyState: 1, frontState: 0 },
|
||||
} as any,
|
||||
scenarioConfig: {
|
||||
stat: { total: 300, min: 10, max: 100, npcTotal: 150, npcMax: 50, npcMin: 10, chiefMin: 70 },
|
||||
iconPath: '',
|
||||
map: {},
|
||||
const: {
|
||||
allItems: { weapon: { che_무기_12_칠성검: 1 } },
|
||||
maxUniqueItemLimit: [[-1, 1]],
|
||||
uniqueTrialCoef: 10,
|
||||
maxUniqueTrialProb: 10,
|
||||
minMonthToAllowInheritItem: 0,
|
||||
},
|
||||
environment: { mapName: 'test_map', unitSet: 'default' },
|
||||
},
|
||||
scenarioMeta: { startYear: 180 } as any,
|
||||
unitSet: {} as any,
|
||||
};
|
||||
const state: TurnWorldState = {
|
||||
id: 1,
|
||||
currentYear: 180,
|
||||
currentMonth: 1,
|
||||
tickSeconds: 3600,
|
||||
lastTurnTime: new Date('0180-01-01T00:00:00Z'),
|
||||
meta: {
|
||||
hiddenSeed: 'seed',
|
||||
scenarioId: 200,
|
||||
initYear: 180,
|
||||
initMonth: 1,
|
||||
scenarioMeta: { startYear: 180 },
|
||||
},
|
||||
};
|
||||
const world = new InMemoryTurnWorld(state, snapshot, {
|
||||
schedule: { entries: [{ startMinute: 0, tickMinutes: 10 }] },
|
||||
});
|
||||
const handler = createTurnDaemonCommandHandler({ world });
|
||||
const commandDb = {
|
||||
auction: {
|
||||
findMany: async () => [{ targetCode: 'che_무기_12_칠성검' }],
|
||||
},
|
||||
};
|
||||
|
||||
const result = await handler.handle(
|
||||
{
|
||||
type: 'voteReward',
|
||||
voteId: 1,
|
||||
generalId: 1,
|
||||
goldReward: 500,
|
||||
unique: { expected: false, itemKey: null },
|
||||
},
|
||||
{ db: commandDb as any }
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
type: 'voteReward',
|
||||
ok: true,
|
||||
awardedUnique: false,
|
||||
});
|
||||
expect(world.getGeneralById(1)?.gold).toBe(1500);
|
||||
expect(world.getGeneralById(1)?.role.items.weapon).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user