feat: port NPC possession through turn daemon

This commit is contained in:
2026-07-31 03:46:02 +00:00
parent d82e493109
commit 2de8f64da4
30 changed files with 3271 additions and 319 deletions
+21
View File
@@ -226,6 +226,16 @@ export type TurnDaemonCommand =
inheritCity?: number;
inheritBonusStat?: [number, number, number];
}
| {
type: 'npcPossessGeneral';
requestId?: string;
userId: string;
ownerDisplayName: string;
profileId: string;
ownerLegacyPenalty?: Record<string, unknown>;
generalId: number;
tokenNonce: number;
}
| {
type: 'selectPoolCreate';
requestId?: string;
@@ -509,6 +519,17 @@ export type TurnDaemonCommandResult =
code: 'BAD_REQUEST' | 'FORBIDDEN' | 'PRECONDITION_FAILED' | 'CONFLICT' | 'INTERNAL_SERVER_ERROR';
reason: string;
}
| {
type: 'npcPossessGeneral';
ok: true;
generalId: number;
}
| {
type: 'npcPossessGeneral';
ok: false;
code: 'BAD_REQUEST' | 'NOT_FOUND' | 'PRECONDITION_FAILED' | 'CONFLICT' | 'INTERNAL_SERVER_ERROR';
reason: string;
}
| {
type: 'selectPoolCreate';
ok: true;
+14 -1
View File
@@ -154,7 +154,7 @@ model City {
model General {
id Int @id
userId String? @map("user_id")
userId String? @unique(map: "general_user_id_key") @map("user_id")
name String
nationId Int @default(0) @map("nation_id")
cityId Int @default(0) @map("city_id")
@@ -211,6 +211,19 @@ model SelectPoolEntry {
@@map("select_pool")
}
model NpcSelectionToken {
ownerUserId String @id @map("owner_user_id")
validUntil DateTime @map("valid_until")
pickMoreFrom DateTime @map("pick_more_from")
pickResult Json @map("pick_result")
nonce Int
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@index([validUntil])
@@map("select_npc_token")
}
model GeneralAccessLog {
id Int @id @default(autoincrement())
generalId Int @unique @map("general_id")
@@ -0,0 +1,51 @@
BEGIN;
-- Core의 한 사용자당 한 장수 invariant를 DB에서도 보장한다. 기존 중복 owner가
-- 있으면 어떤 DDL도 적용하기 전에 owner와 장수 ID를 식별해 실패한다.
DO $$
DECLARE
duplicate_owners TEXT;
BEGIN
SELECT string_agg(
format('%s(count=%s, general_ids=%s)', "user_id", owner_count, general_ids),
', '
)
INTO duplicate_owners
FROM (
SELECT
"user_id",
count(*) AS owner_count,
string_agg("id"::TEXT, ',' ORDER BY "id") AS general_ids
FROM "general"
WHERE "user_id" IS NOT NULL
GROUP BY "user_id"
HAVING count(*) > 1
ORDER BY "user_id"
LIMIT 20
) AS duplicate_rows;
IF duplicate_owners IS NOT NULL THEN
RAISE EXCEPTION
'general.user_id duplicate owners must be reviewed before migration: %',
duplicate_owners;
END IF;
END
$$;
CREATE TABLE "select_npc_token" (
"owner_user_id" TEXT NOT NULL,
"valid_until" TIMESTAMP(3) NOT NULL,
"pick_more_from" TIMESTAMP(3) NOT NULL,
"pick_result" JSONB NOT NULL,
"nonce" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "select_npc_token_pkey" PRIMARY KEY ("owner_user_id")
);
CREATE INDEX "select_npc_token_valid_until_idx" ON "select_npc_token"("valid_until");
CREATE UNIQUE INDEX "general_user_id_key" ON "general"("user_id");
COMMIT;
+1
View File
@@ -7,6 +7,7 @@ export interface DatabaseClient {
worldState: GamePrisma.WorldStateDelegate;
general: GamePrisma.GeneralDelegate;
selectPoolEntry: GamePrisma.SelectPoolEntryDelegate;
npcSelectionToken: GamePrisma.NpcSelectionTokenDelegate;
generalAccessLog: GamePrisma.GeneralAccessLogDelegate;
trafficPeriod: GamePrisma.TrafficPeriodDelegate;
trafficPeriodGeneral: GamePrisma.TrafficPeriodGeneralDelegate;