feat(npc): add weighted activity, level, and dialogue conversations
- GameNpcs: Narrative Activity group (weighted options, forced flag, configurable reshuffle interval), level + richText levelDescription, canMessage toggle - New npc-dialogues collection with a purpose-built React Flow dialogue editor (dialogue/choice/event/end nodes) in the admin panel - Frontend: Currently-activity line and level description on the contact profile page; NpcConversation messaging surface with a documented (disabled) LLM extension seam - Permissions: npc-dialogues CRUD + admin manage in a new NPC Dialogue group; event types for dialogue triggers - Migration 20261006_000000 (applied to dev DB) with full schema snapshot sidecar
This commit is contained in:
parent
76ca0e1d72
commit
2a3ad57bce
24 changed files with 39047 additions and 13 deletions
118
src/app/(frontend)/personnel/contacts/[id]/actions.ts
Normal file
118
src/app/(frontend)/personnel/contacts/[id]/actions.ts
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
"use server";
|
||||||
|
|
||||||
|
import config from "@payload-config";
|
||||||
|
import { isPayloadUser } from "@/utils/access-control/isPayloadUser";
|
||||||
|
import { getPayload } from "payload";
|
||||||
|
import type { User } from "@/payload-types";
|
||||||
|
import { emitGameEvent } from "@/utils/event-log/emit";
|
||||||
|
import { EventTypes } from "@/utils/event-log/eventTypes";
|
||||||
|
import { notifyUser } from "@/lib/notifications";
|
||||||
|
import type { FlowData, NpcDialogueEffect } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
|
||||||
|
interface ActionResult<T = undefined> {
|
||||||
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
data?: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function authenticate() {
|
||||||
|
const payloadConfig = await config;
|
||||||
|
const payload = await getPayload({ config: payloadConfig });
|
||||||
|
const { headers } = await import("next/headers");
|
||||||
|
const hdrs = await headers();
|
||||||
|
const { user } = await payload.auth({
|
||||||
|
headers: hdrs,
|
||||||
|
canSetHeaders: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isPayloadUser(user)) {
|
||||||
|
throw new Error("Unauthorized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return { payload, user };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the effect configured on a dialogue `event` node and run it. The
|
||||||
|
* node is looked up server-side from the stored flowchart, so the client can
|
||||||
|
* only trigger effects an admin has authored for this conversation.
|
||||||
|
*/
|
||||||
|
export async function triggerNpcDialogueEvent(
|
||||||
|
npcId: number,
|
||||||
|
nodeId: string,
|
||||||
|
): Promise<ActionResult> {
|
||||||
|
try {
|
||||||
|
const { payload, user } = await authenticate();
|
||||||
|
|
||||||
|
const res = await payload.find({
|
||||||
|
collection: "npc-dialogues",
|
||||||
|
where: { npc: { equals: npcId } },
|
||||||
|
limit: 1,
|
||||||
|
depth: 0,
|
||||||
|
overrideAccess: true,
|
||||||
|
});
|
||||||
|
const flowData = res.docs[0]?.flowData as unknown as FlowData | undefined;
|
||||||
|
if (!flowData || !Array.isArray(flowData.nodes)) {
|
||||||
|
return { success: false, error: "This contact has no conversation configured." };
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = flowData.nodes.find((n) => n.id === nodeId);
|
||||||
|
if (!node || node.type !== "event" || !node.data.effect) {
|
||||||
|
// Nothing to trigger (or the node isn't an event): treated as a no-op.
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
const effect: NpcDialogueEffect = node.data.effect;
|
||||||
|
await runEffect(payload, user.id as number, npcId, effect);
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (message === "Unauthorized") {
|
||||||
|
return { success: false, error: "You must be logged in." };
|
||||||
|
}
|
||||||
|
return { success: false, error: message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runEffect(
|
||||||
|
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||||
|
userId: number,
|
||||||
|
npcId: number,
|
||||||
|
effect: NpcDialogueEffect,
|
||||||
|
): Promise<void> {
|
||||||
|
switch (effect.type) {
|
||||||
|
case "notify": {
|
||||||
|
await notifyUser(payload, {
|
||||||
|
userId,
|
||||||
|
type: "npc:dialogue",
|
||||||
|
title: effect.title ?? "Conversation",
|
||||||
|
message: effect.message,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "emit": {
|
||||||
|
await emitGameEvent(payload, {
|
||||||
|
type: EventTypes.NpcDialogue,
|
||||||
|
message: effect.message ?? "NPC dialogue event",
|
||||||
|
actor: userId,
|
||||||
|
targetCollection: "game-npcs",
|
||||||
|
targetId: npcId,
|
||||||
|
data: { effect: "emit" },
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reward": {
|
||||||
|
// LLM/reward seam intentionally left unconfigured (see Phase 5).
|
||||||
|
await emitGameEvent(payload, {
|
||||||
|
type: EventTypes.NpcDialogue,
|
||||||
|
message: effect.message ?? "NPC dialogue reward (unconfigured)",
|
||||||
|
actor: userId,
|
||||||
|
targetCollection: "game-npcs",
|
||||||
|
targetId: npcId,
|
||||||
|
data: { effect: "reward", unconfigured: true },
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,9 @@ import { getPayload } from "payload";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { headers as nextHeaders } from "next/headers";
|
import { headers as nextHeaders } from "next/headers";
|
||||||
import type { GameNpc, MarketListing, NpcStaffing } from "@/payload-types";
|
import type { GameNpc, MarketListing, NpcStaffing } from "@/payload-types";
|
||||||
|
import type { FlowData } from "@/lib/npc-dialogue/dialogue";
|
||||||
import { NpcProfile } from "@/components/frontend/personnel/NpcProfile";
|
import { NpcProfile } from "@/components/frontend/personnel/NpcProfile";
|
||||||
|
import { NpcConversation } from "@/components/frontend/personnel/NpcConversation";
|
||||||
import { EmploymentCard } from "@/components/frontend/baseManagement/EmploymentCard";
|
import { EmploymentCard } from "@/components/frontend/baseManagement/EmploymentCard";
|
||||||
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
|
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
|
||||||
import type { LaborClassificationOption, StructureStaffingOption } from "@/lib/base";
|
import type { LaborClassificationOption, StructureStaffingOption } from "@/lib/base";
|
||||||
|
|
@ -149,8 +151,13 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
});
|
});
|
||||||
const listings = listingsRes.docs as unknown as MarketListing[];
|
const listings = listingsRes.docs as unknown as MarketListing[];
|
||||||
|
|
||||||
|
const dialogue =
|
||||||
|
npc.canMessage === true
|
||||||
|
? await firstDialogue(payload, id)
|
||||||
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-5">
|
<div className="p-5 flex flex-col gap-6">
|
||||||
<NpcProfile
|
<NpcProfile
|
||||||
npc={npc}
|
npc={npc}
|
||||||
listings={listings}
|
listings={listings}
|
||||||
|
|
@ -168,6 +175,22 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<NpcConversation npc={npc} dialogue={dialogue} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fetches the single dialogue flowchart for an NPC, if one exists. */
|
||||||
|
async function firstDialogue(
|
||||||
|
payload: Awaited<ReturnType<typeof getPayload>>,
|
||||||
|
npcId: number,
|
||||||
|
) {
|
||||||
|
const res = await payload.find({
|
||||||
|
collection: "npc-dialogues",
|
||||||
|
where: { npc: { equals: npcId } },
|
||||||
|
limit: 1,
|
||||||
|
depth: 0,
|
||||||
|
});
|
||||||
|
return res.docs[0] as unknown as { id: number; flowData?: FlowData } | null;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import { UnderlineFeatureClient as UnderlineFeatureClient_e70f5e05f09f93e00b997e
|
||||||
import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||||
import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from '@payloadcms/richtext-lexical/client'
|
||||||
import { ComposeField as ComposeField_4490b89d4413c1ffaecdacfe72efaf73 } from '@ai-stack/payloadcms/client'
|
import { ComposeField as ComposeField_4490b89d4413c1ffaecdacfe72efaf73 } from '@ai-stack/payloadcms/client'
|
||||||
|
import { default as default_163cd5fa19b83af73532cccaf34704fb } from '@/components/admin/npc-dialogue/NpcDialogueEditor'
|
||||||
import { default as default_513af5ed43d616d133e530d8c94232f8 } from '@/components/admin/groups/CollapsibleGroupField'
|
import { default as default_513af5ed43d616d133e530d8c94232f8 } from '@/components/admin/groups/CollapsibleGroupField'
|
||||||
import { default as default_d9c22b951ac6762f436db59b889da382 } from '@/components/admin/awards/CommendationColorField'
|
import { default as default_d9c22b951ac6762f436db59b889da382 } from '@/components/admin/awards/CommendationColorField'
|
||||||
import { default as default_c3ea68702b5e5f8f2f98055e01c43c8d } from '@/components/admin/awards/RibbonDesigner'
|
import { default as default_c3ea68702b5e5f8f2f98055e01c43c8d } from '@/components/admin/awards/RibbonDesigner'
|
||||||
|
|
@ -74,6 +75,7 @@ export const importMap = {
|
||||||
"@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
"@payloadcms/richtext-lexical/client#BoldFeatureClient": BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||||
"@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
"@payloadcms/richtext-lexical/client#ItalicFeatureClient": ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
||||||
"@ai-stack/payloadcms/client#ComposeField": ComposeField_4490b89d4413c1ffaecdacfe72efaf73,
|
"@ai-stack/payloadcms/client#ComposeField": ComposeField_4490b89d4413c1ffaecdacfe72efaf73,
|
||||||
|
"@/components/admin/npc-dialogue/NpcDialogueEditor#default": default_163cd5fa19b83af73532cccaf34704fb,
|
||||||
"@/components/admin/groups/CollapsibleGroupField#default": default_513af5ed43d616d133e530d8c94232f8,
|
"@/components/admin/groups/CollapsibleGroupField#default": default_513af5ed43d616d133e530d8c94232f8,
|
||||||
"@/components/admin/awards/CommendationColorField#default": default_d9c22b951ac6762f436db59b889da382,
|
"@/components/admin/awards/CommendationColorField#default": default_d9c22b951ac6762f436db59b889da382,
|
||||||
"@/components/admin/awards/RibbonDesigner#default": default_c3ea68702b5e5f8f2f98055e01c43c8d,
|
"@/components/admin/awards/RibbonDesigner#default": default_c3ea68702b5e5f8f2f98055e01c43c8d,
|
||||||
|
|
|
||||||
|
|
@ -119,5 +119,83 @@ export const GameNpcs: CollectionConfig = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "activity",
|
||||||
|
label: "Narrative Activity",
|
||||||
|
type: "group",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "intervalMinutes",
|
||||||
|
type: "number",
|
||||||
|
min: 1,
|
||||||
|
defaultValue: 30,
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"How often (in minutes) the current activity reshuffles automatically. Ignored while a forced activity is active.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "activityOptions",
|
||||||
|
type: "array",
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"Possible activities this contact can be doing. 'Forced' activities stay active until turned off; otherwise the most likely option (by 'Chance') is picked on each interval.",
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "label",
|
||||||
|
type: "text",
|
||||||
|
required: true,
|
||||||
|
admin: {
|
||||||
|
description: "What the contact is doing (e.g. 'Coordinating combat androids').",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "weight",
|
||||||
|
type: "number",
|
||||||
|
min: 1,
|
||||||
|
defaultValue: 1,
|
||||||
|
admin: {
|
||||||
|
description: "Relative chance this activity is picked when reshuffling.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "forced",
|
||||||
|
type: "checkbox",
|
||||||
|
defaultValue: false,
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"Keep this activity active until turned off (overrides the interval reshuffle).",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "level",
|
||||||
|
type: "number",
|
||||||
|
min: 1,
|
||||||
|
admin: {
|
||||||
|
description: "This contact's level. Shown on their profile alongside its description.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "levelDescription",
|
||||||
|
type: "richText",
|
||||||
|
admin: {
|
||||||
|
description: "Capabilities / notes for this contact's level (e.g. a bullet list).",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "canMessage",
|
||||||
|
label: "Messaging",
|
||||||
|
type: "checkbox",
|
||||||
|
defaultValue: false,
|
||||||
|
admin: {
|
||||||
|
description:
|
||||||
|
"Enable conversing with this contact on their profile page. Requires a configured NPC Dialogue flow.",
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
68
src/collections/game/NpcDialogues.ts
Normal file
68
src/collections/game/NpcDialogues.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
import { CollectionConfig } from "payload";
|
||||||
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
||||||
|
|
||||||
|
export const NpcDialogues: CollectionConfig = {
|
||||||
|
slug: "npc-dialogues",
|
||||||
|
admin: {
|
||||||
|
group: "Game",
|
||||||
|
useAsTitle: "name",
|
||||||
|
listSearchableFields: ["name"],
|
||||||
|
defaultColumns: ["name", "npc"],
|
||||||
|
pagination: { defaultLimit: 50 },
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
read: requirePermission("npc-dialogues:read"),
|
||||||
|
create: requirePermission("npc-dialogues:create"),
|
||||||
|
update: requirePermission("npc-dialogues:update"),
|
||||||
|
delete: requirePermission("npc-dialogues:delete"),
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
type: "text",
|
||||||
|
required: true,
|
||||||
|
admin: {
|
||||||
|
description: "A short label for this conversation (e.g. 'Merchant greeting').",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "npc",
|
||||||
|
type: "relationship",
|
||||||
|
relationTo: "game-npcs",
|
||||||
|
required: true,
|
||||||
|
hasMany: false,
|
||||||
|
admin: {
|
||||||
|
description: "The contact this conversation belongs to.",
|
||||||
|
},
|
||||||
|
filterOptions: {
|
||||||
|
canMessage: { equals: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "tabs",
|
||||||
|
tabs: [
|
||||||
|
{
|
||||||
|
label: "Flow Editor",
|
||||||
|
description:
|
||||||
|
"Build the conversation: dialogue lines, branching choices, and trigger events. Mark one node as the start.",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "flowData",
|
||||||
|
type: "json",
|
||||||
|
required: true,
|
||||||
|
defaultValue: () => ({
|
||||||
|
nodes: [],
|
||||||
|
edges: [],
|
||||||
|
}),
|
||||||
|
admin: {
|
||||||
|
components: {
|
||||||
|
Field: "@/components/admin/npc-dialogue/NpcDialogueEditor",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
306
src/components/admin/npc-dialogue/NodeEditDialog.tsx
Normal file
306
src/components/admin/npc-dialogue/NodeEditDialog.tsx
Normal file
|
|
@ -0,0 +1,306 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { XIcon } from "lucide-react";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
|
||||||
|
import type {
|
||||||
|
DialogueNext,
|
||||||
|
DialogueNode,
|
||||||
|
DialogueNodeData,
|
||||||
|
NpcDialogueEffect,
|
||||||
|
NpcDialogueNodeType,
|
||||||
|
} from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { EFFECT_TYPES } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
|
||||||
|
interface NodeEditDialogProps {
|
||||||
|
readonly node: DialogueNode | null;
|
||||||
|
/** Every node in the flow, used to build the "goes to" target lists. */
|
||||||
|
readonly allNodes: DialogueNode[];
|
||||||
|
readonly open: boolean;
|
||||||
|
readonly onOpenChange: (open: boolean) => void;
|
||||||
|
readonly onSave: (nodeId: string, data: DialogueNodeData) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EFFECT_LABELS: Record<NpcDialogueEffect["type"], string> = {
|
||||||
|
notify: "Notify user (in-app)",
|
||||||
|
emit: "Log game event",
|
||||||
|
reward: "Reward (unconfigured)",
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Short readable label for a node in the target pickers. */
|
||||||
|
function nodeLabel(node: DialogueNode): string {
|
||||||
|
const preview =
|
||||||
|
node.data.speaker ||
|
||||||
|
node.data.body ||
|
||||||
|
node.data.leadIn ||
|
||||||
|
node.data.closing ||
|
||||||
|
node.id.slice(0, 8);
|
||||||
|
const trimmed = preview.length > 28 ? `${preview.slice(0, 28)}…` : preview;
|
||||||
|
return `${node.type} · ${trimmed}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Inline editor for a single dialogue node's data. */
|
||||||
|
export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: NodeEditDialogProps) {
|
||||||
|
const [draft, setDraft] = useState<DialogueNodeData | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setDraft(node?.data ?? null);
|
||||||
|
}, [node?.id, open]);
|
||||||
|
|
||||||
|
if (!node || !draft) return null;
|
||||||
|
|
||||||
|
const patch = (partial: Partial<DialogueNodeData>) =>
|
||||||
|
setDraft((prev) => (prev ? { ...prev, ...partial } : prev));
|
||||||
|
|
||||||
|
const patchEffect = (partial: Partial<NpcDialogueEffect>) =>
|
||||||
|
patch({ effect: { type: "notify", ...draft.effect, ...partial } });
|
||||||
|
|
||||||
|
const setChoice = (index: number, next: DialogueNext) =>
|
||||||
|
patch({ choices: (draft.choices ?? []).map((choice, i) => (i === index ? next : choice)) });
|
||||||
|
|
||||||
|
const addChoice = () =>
|
||||||
|
patch({ choices: [...(draft.choices ?? []), { label: "", target: "" }] });
|
||||||
|
|
||||||
|
const removeChoice = (index: number) =>
|
||||||
|
patch({ choices: (draft.choices ?? []).filter((_, i) => i !== index) });
|
||||||
|
|
||||||
|
const targetOptions = allNodes.filter((n) => n.id !== node.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent
|
||||||
|
className="max-w-lg max-h-[80vh] overflow-y-auto dark:bg-zinc-900 dark:text-zinc-100 dark:border-zinc-700 bg-white text-zinc-900"
|
||||||
|
showCloseButton={false}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="flex items-center justify-between">
|
||||||
|
<span>Edit {node.type}</span>
|
||||||
|
<span
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
className="p-2 -m-2 hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-zinc-400 rounded-full"
|
||||||
|
aria-label="Close"
|
||||||
|
>
|
||||||
|
<XIcon className="size-4 text-zinc-500" />
|
||||||
|
</span>
|
||||||
|
</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-4 pt-2">
|
||||||
|
{(node.type === "dialogue" || node.type === "event") && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Speaker</Label>
|
||||||
|
<Input
|
||||||
|
value={draft.speaker ?? ""}
|
||||||
|
onChange={(e) => patch({ speaker: e.target.value || undefined })}
|
||||||
|
placeholder="NPC"
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "dialogue" && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Line</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.body ?? ""}
|
||||||
|
onChange={(e) => patch({ body: e.target.value || undefined })}
|
||||||
|
placeholder="The NPC says…"
|
||||||
|
rows={4}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "choice" && (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Lead-in</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.leadIn ?? ""}
|
||||||
|
onChange={(e) => patch({ leadIn: e.target.value || undefined })}
|
||||||
|
placeholder="Optional line before the choices."
|
||||||
|
rows={2}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Choices
|
||||||
|
</Label>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={addChoice}
|
||||||
|
className="h-6 border-white/20 text-xs text-white"
|
||||||
|
>
|
||||||
|
Add choice
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{(draft.choices ?? []).map((choice, index) => (
|
||||||
|
<div key={index} className="flex flex-col gap-1.5 border-t border-white/10 pt-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[9px] uppercase tracking-wider text-white/40">Button text</Label>
|
||||||
|
<Input
|
||||||
|
value={choice.label ?? ""}
|
||||||
|
onChange={(e) => setChoice(index, { ...choice, label: e.target.value })}
|
||||||
|
placeholder="How do you respond?"
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[9px] uppercase tracking-wider text-white/40">Goes to</Label>
|
||||||
|
<select
|
||||||
|
value={choice.target ?? ""}
|
||||||
|
onChange={(e) => setChoice(index, { ...choice, target: e.target.value })}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
<option value="">None</option>
|
||||||
|
{targetOptions.map((target) => (
|
||||||
|
<option key={target.id} value={target.id}>
|
||||||
|
{nodeLabel(target)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => removeChoice(index)}
|
||||||
|
className="h-6 self-end border-red-900/50 text-red-400 hover:bg-red-950/40"
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{(draft.choices?.length ?? 0) === 0 && (
|
||||||
|
<p className="text-xs text-white/30">No choices yet. Add one above.</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "event" && (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Effect</Label>
|
||||||
|
<select
|
||||||
|
value={draft.effect?.type ?? "notify"}
|
||||||
|
onChange={(e) => patchEffect({ type: e.target.value as NpcDialogueEffect["type"] })}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
{EFFECT_TYPES.map((type) => (
|
||||||
|
<option key={type} value={type}>
|
||||||
|
{EFFECT_LABELS[type]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{draft.effect?.type === "notify" && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Title</Label>
|
||||||
|
<Input
|
||||||
|
value={draft.effect.title ?? ""}
|
||||||
|
onChange={(e) => patchEffect({ title: e.target.value || undefined })}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Message</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.effect?.message ?? ""}
|
||||||
|
onChange={(e) => patchEffect({ message: e.target.value || undefined })}
|
||||||
|
placeholder="What happens when the player reaches this node?"
|
||||||
|
rows={3}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{node.type === "end" && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">Closing line</Label>
|
||||||
|
<Textarea
|
||||||
|
value={draft.closing ?? ""}
|
||||||
|
onChange={(e) => patch({ closing: e.target.value || undefined })}
|
||||||
|
placeholder="The conversation ends."
|
||||||
|
rows={3}
|
||||||
|
className="bg-zinc-800 border-white/20 text-white placeholder:text-white/30"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{(node.type === "dialogue" || node.type === "event") && (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label className="text-[10px] uppercase tracking-wider text-white/50">
|
||||||
|
Continues to
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
value={draft.next?.target ?? ""}
|
||||||
|
onChange={(e) => {
|
||||||
|
const target = e.target.value;
|
||||||
|
patch({
|
||||||
|
next: target ? { ...(draft.next ?? { target: "" }), target } : undefined,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
className="bg-zinc-800 border border-white/20 rounded px-2 py-1 text-sm text-white"
|
||||||
|
>
|
||||||
|
<option value="">Ends the conversation</option>
|
||||||
|
{targetOptions.map((target) => (
|
||||||
|
<option key={target.id} value={target.id}>
|
||||||
|
{nodeLabel(target)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<label className="flex items-center gap-2 pt-2 text-sm text-white/70 cursor-pointer">
|
||||||
|
<Checkbox
|
||||||
|
checked={draft.isStart === true}
|
||||||
|
onCheckedChange={(checked) => patch({ isStart: checked === true })}
|
||||||
|
/>
|
||||||
|
Mark as conversation start
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<DialogFooter className="gap-2 -mt-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
className="border-white/20 text-white"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => onSave(node.id, draft)}
|
||||||
|
className="bg-cyan-600 text-white hover:bg-cyan-500"
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
265
src/components/admin/npc-dialogue/NpcDialogueEditor.tsx
Normal file
265
src/components/admin/npc-dialogue/NpcDialogueEditor.tsx
Normal file
|
|
@ -0,0 +1,265 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent as ReactMouseEvent } from "react";
|
||||||
|
import {
|
||||||
|
Background,
|
||||||
|
type Connection,
|
||||||
|
type Edge,
|
||||||
|
type Node,
|
||||||
|
ReactFlow,
|
||||||
|
useNodesState,
|
||||||
|
} from "@xyflow/react";
|
||||||
|
import "@xyflow/react/dist/style.css";
|
||||||
|
|
||||||
|
import { useField } from "@payloadcms/ui";
|
||||||
|
|
||||||
|
import type {
|
||||||
|
DialogueEdge,
|
||||||
|
DialogueNode,
|
||||||
|
DialogueNodeData,
|
||||||
|
FlowData,
|
||||||
|
NpcDialogueNodeType,
|
||||||
|
} from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { deriveEdges, validateGraph } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { NpcDialogueNode } from "./NpcDialogueNode";
|
||||||
|
import { NodeEditDialog } from "./NodeEditDialog";
|
||||||
|
|
||||||
|
const nodeTypes = {
|
||||||
|
dialogue: NpcDialogueNode,
|
||||||
|
choice: NpcDialogueNode,
|
||||||
|
event: NpcDialogueNode,
|
||||||
|
end: NpcDialogueNode,
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultFlow: FlowData = { nodes: [], edges: [] };
|
||||||
|
|
||||||
|
type ContextMenu = { x: number; y: number; nodeId: string } | null;
|
||||||
|
|
||||||
|
const NODE_LABELS: Record<NpcDialogueNodeType, string> = {
|
||||||
|
dialogue: "Dialogue",
|
||||||
|
choice: "Choice",
|
||||||
|
event: "Event",
|
||||||
|
end: "End",
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_DATA: Record<string, DialogueNodeData> = {
|
||||||
|
dialogue: { speaker: "NPC", body: "" },
|
||||||
|
choice: { choices: [] },
|
||||||
|
event: { effect: { type: "notify", message: "" } },
|
||||||
|
end: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function NpcDialogueEditor() {
|
||||||
|
const { value, setValue } = useField<FlowData>();
|
||||||
|
|
||||||
|
const initial: FlowData =
|
||||||
|
value && typeof value === "object" && Array.isArray((value as FlowData).nodes)
|
||||||
|
? (value as FlowData)
|
||||||
|
: defaultFlow;
|
||||||
|
|
||||||
|
const [nodes, setNodes, onNodesChange] = useNodesState(initial.nodes as Node[]);
|
||||||
|
const [editingNodeId, setEditingNodeId] = useState<string | null>(null);
|
||||||
|
const [contextMenu, setContextMenu] = useState<ContextMenu>(null);
|
||||||
|
|
||||||
|
const lastSerialized = useRef<string>("");
|
||||||
|
|
||||||
|
// Edges are a derived projection of the node data, never edited directly.
|
||||||
|
const syncedEdges = useMemo<Edge[]>(
|
||||||
|
() => deriveEdges(nodes as DialogueNode[]),
|
||||||
|
[nodes],
|
||||||
|
);
|
||||||
|
|
||||||
|
const serialize = useCallback((nds: Node[]) => {
|
||||||
|
const payload: FlowData = {
|
||||||
|
nodes: nds as DialogueNode[],
|
||||||
|
edges: deriveEdges(nds as DialogueNode[]),
|
||||||
|
};
|
||||||
|
const serialized = JSON.stringify(payload);
|
||||||
|
if (serialized !== lastSerialized.current) {
|
||||||
|
lastSerialized.current = serialized;
|
||||||
|
setValue(payload);
|
||||||
|
}
|
||||||
|
}, [setValue]);
|
||||||
|
|
||||||
|
const addNode = useCallback(
|
||||||
|
(type: NpcDialogueNodeType) => {
|
||||||
|
const count = nodes.length;
|
||||||
|
const node: DialogueNode = {
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
type,
|
||||||
|
position: {
|
||||||
|
x: 120 + (count % 4) * 240,
|
||||||
|
y: 80 + Math.floor(count / 4) * 140,
|
||||||
|
},
|
||||||
|
data: { ...DEFAULT_DATA[type] },
|
||||||
|
};
|
||||||
|
const next = [...nodes, node];
|
||||||
|
setNodes(next);
|
||||||
|
serialize(next);
|
||||||
|
setEditingNodeId(node.id);
|
||||||
|
},
|
||||||
|
[nodes, setNodes, serialize],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleNodeSave = useCallback(
|
||||||
|
(nodeId: string, data: DialogueNodeData) => {
|
||||||
|
const next = nodes.map((n) => (n.id === nodeId ? { ...n, data } : n));
|
||||||
|
setNodes(next);
|
||||||
|
serialize(next);
|
||||||
|
setEditingNodeId(null);
|
||||||
|
},
|
||||||
|
[nodes, setNodes, serialize],
|
||||||
|
);
|
||||||
|
|
||||||
|
const deleteNode = useCallback(
|
||||||
|
(nodeId: string) => {
|
||||||
|
const next = (nodes as DialogueNode[])
|
||||||
|
.filter((n) => n.id !== nodeId)
|
||||||
|
.map((n) => ({
|
||||||
|
...n,
|
||||||
|
data: {
|
||||||
|
...n.data,
|
||||||
|
next: n.data.next && n.data.next.target !== nodeId ? n.data.next : undefined,
|
||||||
|
choices: (n.data.choices ?? []).filter((c) => c.target !== nodeId),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
setNodes(next);
|
||||||
|
serialize(next);
|
||||||
|
setContextMenu(null);
|
||||||
|
if (editingNodeId === nodeId) setEditingNodeId(null);
|
||||||
|
},
|
||||||
|
[nodes, setNodes, serialize, editingNodeId],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onNodeContextMenu = useCallback(
|
||||||
|
(e: ReactMouseEvent, node: Node) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setContextMenu({ x: e.clientX, y: e.clientY, nodeId: node.id });
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onPaneClick = useCallback(() => setContextMenu(null), []);
|
||||||
|
|
||||||
|
const validation = useMemo(() => validateGraph(nodes as DialogueNode[]), [nodes]);
|
||||||
|
|
||||||
|
// Close the context menu on escape / pointer outside.
|
||||||
|
const closeMenu = useCallback(() => setContextMenu(null), []);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!contextMenu) return;
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") closeMenu();
|
||||||
|
};
|
||||||
|
const onPtr = () => closeMenu();
|
||||||
|
window.addEventListener("keydown", onKey);
|
||||||
|
document.addEventListener("pointerdown", onPtr);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", onKey);
|
||||||
|
document.removeEventListener("pointerdown", onPtr);
|
||||||
|
};
|
||||||
|
}, [contextMenu, closeMenu]);
|
||||||
|
|
||||||
|
const buttonClass =
|
||||||
|
"px-2 py-1 text-[10px] font-medium rounded border transition-colors cursor-pointer";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-2 w-full">
|
||||||
|
<div className="flex flex-wrap items-center gap-1 px-2 py-1.5 bg-zinc-900 rounded-t-md border border-zinc-700">
|
||||||
|
<span className="text-[9px] uppercase tracking-wider text-zinc-500 font-semibold mr-1">
|
||||||
|
Nodes
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-blue-950 border-blue-700 text-blue-200 hover:bg-blue-900`}
|
||||||
|
onClick={() => addNode("dialogue")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.dialogue}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-amber-950 border-amber-700 text-amber-200 hover:bg-amber-900`}
|
||||||
|
onClick={() => addNode("choice")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.choice}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-emerald-950 border-emerald-700 text-emerald-200 hover:bg-emerald-900`}
|
||||||
|
onClick={() => addNode("event")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.event}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${buttonClass} bg-slate-950 border-slate-700 text-slate-200 hover:bg-slate-900`}
|
||||||
|
onClick={() => addNode("end")}
|
||||||
|
>
|
||||||
|
{NODE_LABELS.end}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<span className="ml-auto text-[10px] text-zinc-500">
|
||||||
|
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!validation.valid && (
|
||||||
|
<div className="px-2 py-1 bg-red-950/60 border-b border-red-900/50 text-xs text-red-300">
|
||||||
|
{validation.errors.slice(0, 3).join(" ")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="h-96 border border-zinc-700 rounded-b-md overflow-hidden bg-zinc-950">
|
||||||
|
<ReactFlow
|
||||||
|
nodes={nodes}
|
||||||
|
edges={syncedEdges}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onConnect={(c: Connection) => void c}
|
||||||
|
onNodeClick={(_e, node) => setEditingNodeId(node.id)}
|
||||||
|
onNodeContextMenu={onNodeContextMenu}
|
||||||
|
onPaneClick={onPaneClick}
|
||||||
|
nodeTypes={nodeTypes}
|
||||||
|
fitView
|
||||||
|
colorMode="dark"
|
||||||
|
nodesConnectable={false}
|
||||||
|
defaultEdgeOptions={{ animated: true }}
|
||||||
|
proOptions={{ hideAttribution: true }}
|
||||||
|
>
|
||||||
|
<Background color="#27272a" gap={20} />
|
||||||
|
{nodes.length === 0 && (
|
||||||
|
<div className="absolute inset-0 pointer-events-none flex items-center justify-center text-zinc-600 text-sm">
|
||||||
|
Add a node to start building the conversation.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</ReactFlow>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="text-[10px] text-zinc-500">
|
||||||
|
Click a node to edit. Right-click to delete. Connect nodes by pointing a choice / continuation
|
||||||
|
at the target node in the editor.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{contextMenu && (
|
||||||
|
<div
|
||||||
|
className="fixed z-50 min-w-[7rem] overflow-hidden rounded-md border border-zinc-700 bg-zinc-900 p-1 shadow-lg"
|
||||||
|
style={{ left: contextMenu.x, top: contextMenu.y }}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => deleteNode(contextMenu.nodeId)}
|
||||||
|
className="flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm text-red-400 outline-none select-none hover:bg-red-950/40"
|
||||||
|
>
|
||||||
|
Delete node
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<NodeEditDialog
|
||||||
|
node={(nodes as DialogueNode[]).find((n) => n.id === editingNodeId) ?? null}
|
||||||
|
allNodes={nodes as DialogueNode[]}
|
||||||
|
open={editingNodeId !== null}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) setEditingNodeId(null);
|
||||||
|
}}
|
||||||
|
onSave={handleNodeSave}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NpcDialogueEditor;
|
||||||
116
src/components/admin/npc-dialogue/NpcDialogueNode.tsx
Normal file
116
src/components/admin/npc-dialogue/NpcDialogueNode.tsx
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Handle, NodeProps, Position } from "@xyflow/react";
|
||||||
|
import { FileTextIcon, GitBranchIcon, SparklesIcon, CircleStopIcon } from "lucide-react";
|
||||||
|
|
||||||
|
import type { DialogueNodeData, NpcDialogueNodeType } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { DIALOGUE_NODES } from "./types";
|
||||||
|
|
||||||
|
const position: Position = Position.Right;
|
||||||
|
const inputPosition: Position = Position.Left;
|
||||||
|
|
||||||
|
/** Single reusable canvas node for every dialogue node type. */
|
||||||
|
export function NpcDialogueNode({ data, type }: NodeProps) {
|
||||||
|
const d = data as DialogueNodeData;
|
||||||
|
const nodeType = type as NpcDialogueNodeType;
|
||||||
|
const meta = DIALOGUE_NODES[nodeType];
|
||||||
|
const terminal = nodeType === "end" || (nodeType === "choice" && !(d.choices?.length ?? 0));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`min-w-[15rem] rounded border bg-zinc-900 shadow-lg ${meta.border}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2 border-b border-white/10 px-3 py-1.5">
|
||||||
|
<NodeIcon type={nodeType} />
|
||||||
|
<span className="font-mono text-[10px] uppercase tracking-widest text-white/70">
|
||||||
|
{meta.label}
|
||||||
|
</span>
|
||||||
|
{d.isStart && (
|
||||||
|
<span className="ml-auto font-mono text-[8px] uppercase tracking-widest text-emerald-400">
|
||||||
|
start
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="max-h-32 min-h-20 overflow-y-auto px-3 py-2">
|
||||||
|
{nodeType === "dialogue" && (
|
||||||
|
<div>
|
||||||
|
{d.speaker && (
|
||||||
|
<p className="text-[10px] uppercase tracking-wider text-white/40">{d.speaker}</p>
|
||||||
|
)}
|
||||||
|
<p className="line-clamp-3 text-sm text-white/90">
|
||||||
|
{d.body || <span className="italic text-white/30">Empty line</span>}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nodeType === "choice" && (
|
||||||
|
<div>
|
||||||
|
{d.leadIn && (
|
||||||
|
<p className="mb-1.5 line-clamp-2 text-sm text-white/70">{d.leadIn}</p>
|
||||||
|
)}
|
||||||
|
<ul className="flex flex-col gap-1">
|
||||||
|
{(d.choices ?? []).map((choice, index) => (
|
||||||
|
<li key={index} className="flex items-center gap-1.5 text-xs text-white/70">
|
||||||
|
<span className="size-3 shrink-0 rounded border border-amber-500/50" />
|
||||||
|
<span className="truncate">{choice.label || "Unlabeled choice"}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
{(d.choices?.length ?? 0) === 0 && (
|
||||||
|
<li className="text-white/30">Add a choice below.</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nodeType === "event" && (
|
||||||
|
<div className="text-sm">
|
||||||
|
{d.effect ? (
|
||||||
|
<span className="text-white/80">
|
||||||
|
{d.effect.type === "notify"
|
||||||
|
? "Notify user"
|
||||||
|
: d.effect.type === "emit"
|
||||||
|
? "Log game event"
|
||||||
|
: "Reward (unconfigured)"}
|
||||||
|
{d.effect.message ? `: "${d.effect.message}"` : ""}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="italic text-white/30">No effect configured</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nodeType === "end" && (
|
||||||
|
<div className="text-sm text-white/70">
|
||||||
|
{d.closing ? (
|
||||||
|
<span className="line-clamp-3">{d.closing}</span>
|
||||||
|
) : (
|
||||||
|
<span className="italic text-white/30">No closing line</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!terminal && (
|
||||||
|
<Handle type="source" position={position} className="!size-2 !bg-white/60" />
|
||||||
|
)}
|
||||||
|
{!d.isStart && (
|
||||||
|
<Handle type="target" position={inputPosition} className="!size-2 !bg-white/60" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function NodeIcon({ type }: { type: NpcDialogueNodeType }) {
|
||||||
|
const className = "size-3.5 text-white/50";
|
||||||
|
switch (type) {
|
||||||
|
case "choice":
|
||||||
|
return <GitBranchIcon className={className} />;
|
||||||
|
case "event":
|
||||||
|
return <SparklesIcon className={className} />;
|
||||||
|
case "end":
|
||||||
|
return <CircleStopIcon className={className} />;
|
||||||
|
default:
|
||||||
|
return <FileTextIcon className={className} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/components/admin/npc-dialogue/types.ts
Normal file
43
src/components/admin/npc-dialogue/types.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import type { NpcDialogueNodeType } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
|
||||||
|
export interface NodeMeta {
|
||||||
|
type: NpcDialogueNodeType;
|
||||||
|
label: string;
|
||||||
|
/** Tailwind border accent class. */
|
||||||
|
border: string;
|
||||||
|
/** Canvas / minimap node color. */
|
||||||
|
node: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Authoring metadata for each dialogue node type. */
|
||||||
|
export const DIALOGUE_NODES: Record<NpcDialogueNodeType, NodeMeta> = {
|
||||||
|
dialogue: {
|
||||||
|
type: "dialogue",
|
||||||
|
label: "Dialogue",
|
||||||
|
border: "border-blue-500/60",
|
||||||
|
node: "#3b82f6",
|
||||||
|
description: "The NPC speaks a line.",
|
||||||
|
},
|
||||||
|
choice: {
|
||||||
|
type: "choice",
|
||||||
|
label: "Choice",
|
||||||
|
border: "border-amber-500/60",
|
||||||
|
node: "#d97706",
|
||||||
|
description: "Player branches the conversation.",
|
||||||
|
},
|
||||||
|
event: {
|
||||||
|
type: "event",
|
||||||
|
label: "Event",
|
||||||
|
border: "border-emerald-500/60",
|
||||||
|
node: "#10b981",
|
||||||
|
description: "Trigger a notification or game event.",
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
type: "end",
|
||||||
|
label: "End",
|
||||||
|
border: "border-slate-500/60",
|
||||||
|
node: "#64748b",
|
||||||
|
description: "End the conversation.",
|
||||||
|
},
|
||||||
|
};
|
||||||
40
src/components/frontend/personnel/NpcActivityLine.tsx
Normal file
40
src/components/frontend/personnel/NpcActivityLine.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { DOSSIER } from "@/components/frontend/operations";
|
||||||
|
import {
|
||||||
|
formatActivityLine,
|
||||||
|
resolveCurrentActivity,
|
||||||
|
type NpcActivityOption,
|
||||||
|
} from "@/lib/npcs/activity";
|
||||||
|
|
||||||
|
interface NpcActivityLineProps {
|
||||||
|
/** How often (minutes) the activity reshuffles when nothing is forced. */
|
||||||
|
readonly intervalMinutes: number;
|
||||||
|
/** The contact's possible activities. */
|
||||||
|
readonly activityOptions: NpcActivityOption[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the contact's "current activity" and reshuffles it on the configured
|
||||||
|
* interval. A forced activity stays put until the flag is turned off.
|
||||||
|
*/
|
||||||
|
export function NpcActivityLine({ intervalMinutes, activityOptions }: NpcActivityLineProps) {
|
||||||
|
const [tick, setTick] = useState(0);
|
||||||
|
const reshuffle = intervalMinutes > 0 && activityOptions.length > 0;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!reshuffle) return;
|
||||||
|
const interval = setInterval(() => setTick((prev) => prev + 1), intervalMinutes * 60_000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [intervalMinutes, reshuffle]);
|
||||||
|
|
||||||
|
const activity = resolveCurrentActivity(activityOptions, reshuffle ? `tick-${tick}` : undefined);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span className={DOSSIER.readoutLabel}>Activity</span>
|
||||||
|
<span className={DOSSIER.chip}>{formatActivityLine(activity)}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ export function NpcCard({ npc }: NpcCardProps) {
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="relative z-10 flex h-full items-center justify-center px-3 text-center">
|
<div className="relative z-10 flex h-full items-center justify-center px-3 text-center">
|
||||||
<div className="flex max-w-full flex-col items-center gap-1.5">
|
<div className="flex max-w-full flex-col items-center gap-1">
|
||||||
<h2
|
<h2
|
||||||
data-text={npc.name}
|
data-text={npc.name}
|
||||||
className="glitch-hover text-balance text-center text-sm font-bold leading-tight text-white drop-shadow-lg"
|
className="glitch-hover text-balance text-center text-sm font-bold leading-tight text-white drop-shadow-lg"
|
||||||
|
|
@ -80,7 +80,7 @@ export function NpcCard({ npc }: NpcCardProps) {
|
||||||
<p className="glitch-soft line-clamp-1 max-w-full text-pretty text-[10px] text-white/60 drop-shadow">
|
<p className="glitch-soft line-clamp-1 max-w-full text-pretty text-[10px] text-white/60 drop-shadow">
|
||||||
{npc.occupation ?? "Occupation not recorded"}
|
{npc.occupation ?? "Occupation not recorded"}
|
||||||
</p>
|
</p>
|
||||||
<NpcStatusChips npc={npc} size="compact" className="mt-0.5 justify-center" />
|
<NpcStatusChips npc={npc} size="compact" className="justify-center" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
196
src/components/frontend/personnel/NpcConversation.tsx
Normal file
196
src/components/frontend/personnel/NpcConversation.tsx
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { CircleIcon, XIcon } from "lucide-react";
|
||||||
|
|
||||||
|
import type { GameNpc } from "@/payload-types";
|
||||||
|
import type { DialogueNode, FlowData } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { findStartNode } from "@/lib/npc-dialogue/dialogue";
|
||||||
|
import { DOSSIER } from "@/components/frontend/operations";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { triggerNpcDialogueEvent } from "@/app/(frontend)/personnel/contacts/[id]/actions";
|
||||||
|
|
||||||
|
interface NpcConversationProps {
|
||||||
|
readonly npc: GameNpc;
|
||||||
|
readonly dialogue: { id: number; flowData?: FlowData } | null | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ResolvedFlow {
|
||||||
|
nodes: DialogueNode[];
|
||||||
|
startId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LogEntry {
|
||||||
|
node: DialogueNode;
|
||||||
|
triggered: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves the authored flowchart into a shape the runtime can walk. */
|
||||||
|
function resolveFlow(dialogue: NpcConversationProps["dialogue"]): ResolvedFlow | null {
|
||||||
|
if (!dialogue?.flowData || !Array.isArray(dialogue.flowData.nodes)) return null;
|
||||||
|
const nodes = dialogue.flowData.nodes as DialogueNode[];
|
||||||
|
return { nodes, startId: findStartNode(nodes)?.id ?? null };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function NpcConversation({ npc, dialogue }: NpcConversationProps) {
|
||||||
|
const flow = useMemo(() => resolveFlow(dialogue), [dialogue]);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [log, setLog] = useState<LogEntry[]>([]);
|
||||||
|
|
||||||
|
if (npc.canMessage !== true || !flow || flow.nodes.length === 0) return null;
|
||||||
|
|
||||||
|
const enterNode = (node: DialogueNode) => {
|
||||||
|
setLog((prev) => [...prev, { node, triggered: false }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const begin = () => {
|
||||||
|
setLog([]);
|
||||||
|
if (flow.startId) {
|
||||||
|
const start = flow.nodes.find((n) => n.id === flow.startId);
|
||||||
|
if (start) {
|
||||||
|
enterNode(start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = () => setOpen(false);
|
||||||
|
|
||||||
|
const last = log[log.length - 1];
|
||||||
|
|
||||||
|
// Trigger an event node's effect exactly once when it first arrives.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!last || last.node.type !== "event" || !last.node.data.effect || last.triggered) return;
|
||||||
|
void triggerNpcDialogueEvent(Number(npc.id), last.node.id).catch(() => undefined);
|
||||||
|
setLog((prev) =>
|
||||||
|
prev.map((entry) =>
|
||||||
|
entry.node.id === last.node.id ? { ...entry, triggered: true } : entry,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}, [last?.node.id, last?.triggered, last, npc.id]);
|
||||||
|
|
||||||
|
const nextNode = (): DialogueNode | null => {
|
||||||
|
if (!last) return null;
|
||||||
|
const target = last.node.data.next?.target;
|
||||||
|
if (!target) return null;
|
||||||
|
return flow.nodes.find((n) => n.id === target) ?? null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const choiceHops = last?.node.type === "choice" ? last.node.data.choices ?? [] : [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="flex flex-col gap-4">
|
||||||
|
{!open ? (
|
||||||
|
<Button
|
||||||
|
onClick={begin}
|
||||||
|
className="group relative overflow-hidden rounded-none border border-white/20 bg-black/40 hover:border-white/40"
|
||||||
|
>
|
||||||
|
<span className="absolute -left-8 h-full w-8 bg-cyan-500/20 transition-transform group-hover:translate-x-8" />
|
||||||
|
<CircleIcon className="relative z-10 size-3.5 text-cyan-400" />
|
||||||
|
<span className="relative z-10 ml-2 text-xs uppercase tracking-widest">Converse</span>
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<div className="relative flex max-h-[70vh] flex-col overflow-hidden rounded-none border border-white/20 bg-black/40">
|
||||||
|
<div className="flex items-center justify-between border-b border-white/15 bg-black/50 px-4 py-2">
|
||||||
|
<span className="font-mono text-[10px] uppercase tracking-widest text-white/50">
|
||||||
|
Conversation // {npc.name}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={close}
|
||||||
|
aria-label="Close conversation"
|
||||||
|
className="text-white/40 transition-colors hover:text-white/90"
|
||||||
|
>
|
||||||
|
<XIcon className="size-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{flow.startId === null ? (
|
||||||
|
<div className="p-4 text-sm text-white/50">
|
||||||
|
This conversation has no start node. Ask staff to configure it.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="flex-1 space-y-3 overflow-y-auto p-4">
|
||||||
|
{log.map((entry) => (
|
||||||
|
<Bubble key={entry.node.id} entry={entry} />
|
||||||
|
))}
|
||||||
|
{log.length === 0 && <div className="text-sm text-white/40">Loading…</div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{last && (
|
||||||
|
<div className="border-t border-white/15 bg-black/50 p-3 flex flex-col gap-2">
|
||||||
|
{last.node.type === "choice" ? (
|
||||||
|
choiceHops.length > 0 ? (
|
||||||
|
choiceHops.map((hop, index) => (
|
||||||
|
<button
|
||||||
|
key={index}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
const target = flow.nodes.find((n) => n.id === hop.target);
|
||||||
|
if (target) enterNode(target);
|
||||||
|
}}
|
||||||
|
className="w-full text-left rounded-none border border-white/20 bg-black/40 px-3 py-2 text-sm text-white/80 transition-colors hover:border-cyan-500/60 hover:text-white"
|
||||||
|
>
|
||||||
|
{hop.label || "…"}
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<span className="text-xs text-white/40">No choices configured.</span>
|
||||||
|
)
|
||||||
|
) : last.node.type === "end" ? (
|
||||||
|
<Button onClick={close} className="bg-cyan-600 hover:bg-cyan-500 text-white">
|
||||||
|
End conversation
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
nextNode() ? (
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
const target = nextNode();
|
||||||
|
if (target) enterNode(target);
|
||||||
|
}}
|
||||||
|
className="bg-cyan-600 hover:bg-cyan-500 text-white"
|
||||||
|
>
|
||||||
|
Continue
|
||||||
|
</Button>
|
||||||
|
) : null
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Bubble({ entry }: { entry: LogEntry }) {
|
||||||
|
const { node } = entry;
|
||||||
|
const speaker = node.data.speaker ?? "Contact";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className={DOSSIER.readoutLabel}>{speaker}</span>
|
||||||
|
{node.type === "dialogue" && (
|
||||||
|
<p className="text-sm text-white/90">
|
||||||
|
{node.data.body || <span className="italic text-white/30">…</span>}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{node.type === "event" && (
|
||||||
|
<p className="text-sm text-emerald-300">
|
||||||
|
{node.data.effect?.message || "An event unfolds…"}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{node.type === "end" && (
|
||||||
|
<p className="text-sm text-white/80">{node.data.closing || "The conversation ends."}</p>
|
||||||
|
)}
|
||||||
|
{node.type === "choice" &&
|
||||||
|
(node.data.leadIn ? (
|
||||||
|
<p className="text-sm italic text-white/60">{node.data.leadIn}</p>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-white/40">Choose a response.</p>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,8 @@ import {
|
||||||
type ReadoutCell,
|
type ReadoutCell,
|
||||||
} from "@/components/frontend/operations";
|
} from "@/components/frontend/operations";
|
||||||
import { CurrencyAmount } from "@/components/frontend/banking/CurrencyAmount";
|
import { CurrencyAmount } from "@/components/frontend/banking/CurrencyAmount";
|
||||||
|
import { NpcActivityLine } from "@/components/frontend/personnel/NpcActivityLine";
|
||||||
|
import type { NpcActivityOption } from "@/lib/npcs/activity";
|
||||||
import { NpcStatusChips } from "@/components/frontend/personnel/NpcStatusChips";
|
import { NpcStatusChips } from "@/components/frontend/personnel/NpcStatusChips";
|
||||||
import { initialsOf } from "@/components/frontend/personnel/initials";
|
import { initialsOf } from "@/components/frontend/personnel/initials";
|
||||||
|
|
||||||
|
|
@ -65,6 +67,16 @@ function NpcBio({ bio }: { bio: GameNpc["bio"] }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Renders an NPC's level description (Lexical richText), falling back when empty. */
|
||||||
|
function LevelDescription({ data }: { data: GameNpc["levelDescription"] }) {
|
||||||
|
const children = (data as { root?: { children?: unknown[] } } | null | undefined)?.root
|
||||||
|
?.children;
|
||||||
|
if (!data || !Array.isArray(children) || children.length === 0) {
|
||||||
|
return <p className="text-sm text-white/60">No capabilities on file.</p>;
|
||||||
|
}
|
||||||
|
return <div className="lexical-content"><RichText data={data as LexicalData} /></div>;
|
||||||
|
}
|
||||||
|
|
||||||
export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
const faction = typeof npc.faction === "object" && npc.faction !== null ? npc.faction : null;
|
const faction = typeof npc.faction === "object" && npc.faction !== null ? npc.faction : null;
|
||||||
const location =
|
const location =
|
||||||
|
|
@ -79,6 +91,15 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
|
|
||||||
const refCode = String(npc.id).padStart(3, "0");
|
const refCode = String(npc.id).padStart(3, "0");
|
||||||
const monogram = initialsOf(npc.name);
|
const monogram = initialsOf(npc.name);
|
||||||
|
const activityInterval = npc.activity?.intervalMinutes ?? 30;
|
||||||
|
const activityOptions: NpcActivityOption[] = (npc.activity?.activityOptions ?? []).map(
|
||||||
|
(option) => ({
|
||||||
|
label: option.label,
|
||||||
|
weight: option.weight ?? 1,
|
||||||
|
forced: option.forced ?? false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const hasLevel = typeof npc.level === "number";
|
||||||
|
|
||||||
const heroCells: ReadoutCell[] = [
|
const heroCells: ReadoutCell[] = [
|
||||||
{ label: "Faction", value: faction?.name ?? "Unaffiliated" },
|
{ label: "Faction", value: faction?.name ?? "Unaffiliated" },
|
||||||
|
|
@ -178,6 +199,20 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</StrategicSummary>
|
</StrategicSummary>
|
||||||
|
|
||||||
|
<NpcActivityLine
|
||||||
|
intervalMinutes={activityInterval}
|
||||||
|
activityOptions={activityOptions}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{hasLevel && (
|
||||||
|
<StrategicSummary
|
||||||
|
classificationLeft="Capabilities"
|
||||||
|
classificationRight={`Level ${npc.level}`}
|
||||||
|
>
|
||||||
|
<LevelDescription data={npc.levelDescription} />
|
||||||
|
</StrategicSummary>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
|
|
@ -215,15 +250,20 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
classificationLeft="Active Market Stock"
|
classificationLeft="Active Market Stock"
|
||||||
classificationRight={`${listings.length} Listing(s)`}
|
classificationRight={`${listings.length} Listing(s)`}
|
||||||
>
|
>
|
||||||
|
{listings.length === 0 ? (
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<p className="text-sm italic text-white/50">No active stock.</p>
|
||||||
|
<Button asChild variant="outline" size="sm">
|
||||||
|
<Link href="/logistics/market">View market</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Button asChild variant="outline" size="sm">
|
<Button asChild variant="outline" size="sm">
|
||||||
<Link href="/logistics/market">View market</Link>
|
<Link href="/logistics/market">View market</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{listings.length === 0 ? (
|
|
||||||
<p className="text-sm italic text-white/50">No active stock.</p>
|
|
||||||
) : (
|
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{listings.map((listing, index) => (
|
{listings.map((listing, index) => (
|
||||||
<Fragment key={listing.id}>
|
<Fragment key={listing.id}>
|
||||||
|
|
@ -244,8 +284,8 @@ export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</StrategicSummary>
|
</StrategicSummary>
|
||||||
|
|
||||||
{employmentSlot ? (
|
{employmentSlot ? (
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,13 @@ function Chip({
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex items-center border font-mono uppercase leading-none tracking-widest",
|
"inline-flex items-center border font-mono uppercase tracking-widest",
|
||||||
size === "compact" ? "px-1 py-px text-[8px]" : "px-1.5 py-0.5 text-[9px]",
|
// Keep `leading-none` AFTER the font-size: tailwind-merge drops it when a
|
||||||
|
// later `text-[Npx]` is in the same class list, which leaves the chip at
|
||||||
|
// the inherited line-height (very tall).
|
||||||
|
size === "compact"
|
||||||
|
? "px-1 py-px text-[8px] leading-none"
|
||||||
|
: "px-1.5 py-0.5 text-[9px] leading-none",
|
||||||
STATUS_CHIP[tone],
|
STATUS_CHIP[tone],
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
141
src/lib/npc-dialogue/dialogue.ts
Normal file
141
src/lib/npc-dialogue/dialogue.ts
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
/**
|
||||||
|
* Canonical model + pure helpers for NPC conversation flowcharts.
|
||||||
|
*
|
||||||
|
* The graph is authoritative in node data: every node lists where the
|
||||||
|
* conversation can go next (`next` for a single continuation, `choices` for
|
||||||
|
* branching). Edges are a derived projection of that data, so the admin
|
||||||
|
* canvas and the runtime walker always agree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type NpcDialogueNodeType = "dialogue" | "choice" | "event" | "end";
|
||||||
|
|
||||||
|
/** A directed hop to another node. `label` is the choice button text. */
|
||||||
|
export interface DialogueNext {
|
||||||
|
/** Button text shown to the player (required on choice hops). */
|
||||||
|
label?: string;
|
||||||
|
/** Target node id. */
|
||||||
|
target: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configured effect for an `event` node. */
|
||||||
|
export interface NpcDialogueEffect {
|
||||||
|
type: "notify" | "emit" | "reward";
|
||||||
|
/** In-app notification title (notify). */
|
||||||
|
title?: string;
|
||||||
|
/** Notification / event-log body (notify, emit). */
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DialogueNodeData = {
|
||||||
|
/** Speaker label shown above the line. */
|
||||||
|
speaker?: string;
|
||||||
|
/** The spoken line. */
|
||||||
|
body?: string;
|
||||||
|
/** Branching options (choice nodes). */
|
||||||
|
choices?: DialogueNext[];
|
||||||
|
/** Optional lead-in text before the choices. */
|
||||||
|
leadIn?: string;
|
||||||
|
/** Triggered when the conversation arrives at this node. */
|
||||||
|
effect?: NpcDialogueEffect;
|
||||||
|
/** Closing text shown when the conversation ends. */
|
||||||
|
closing?: string;
|
||||||
|
/** Marks this node as the conversation start. */
|
||||||
|
isStart?: boolean;
|
||||||
|
/** Single continuation (dialogue / event / end nodes). */
|
||||||
|
next?: DialogueNext;
|
||||||
|
} & Record<string, unknown>;
|
||||||
|
|
||||||
|
export interface DialogueNode {
|
||||||
|
id: string;
|
||||||
|
type: NpcDialogueNodeType;
|
||||||
|
position: { x: number; y: number };
|
||||||
|
data: DialogueNodeData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DialogueEdge {
|
||||||
|
id: string;
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FlowData {
|
||||||
|
nodes: DialogueNode[];
|
||||||
|
edges: DialogueEdge[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** All effect types the runtime can actually trigger. */
|
||||||
|
export const EFFECT_TYPES: NpcDialogueEffect["type"][] = ["notify", "emit", "reward"];
|
||||||
|
|
||||||
|
/** True when a node has no outgoing hops (conversation ends here). */
|
||||||
|
export function isTerminalNode(node: DialogueNode): boolean {
|
||||||
|
if (node.type === "choice") return (node.data.choices?.length ?? 0) === 0;
|
||||||
|
return !node.data.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves the node the conversation should start at. */
|
||||||
|
export function findStartNode(nodes: DialogueNode[]): DialogueNode | null {
|
||||||
|
if (nodes.length === 0) return null;
|
||||||
|
const marked = nodes.find((node) => node.data.isStart === true);
|
||||||
|
if (marked) return marked;
|
||||||
|
// Fall back to the first node with no incoming edges.
|
||||||
|
const targets = new Set(nodes.flatMap((n) => (n.data.choices ?? []).map((c) => c.target).concat(n.data.next ? [n.data.next.target] : [])));
|
||||||
|
const roots = nodes.filter((n) => !targets.has(n.id));
|
||||||
|
return (roots.length ? roots[0] : nodes[0]) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Builds the edge projection that mirrors the node graph. */
|
||||||
|
export function deriveEdges(nodes: DialogueNode[]): DialogueEdge[] {
|
||||||
|
const edges: DialogueEdge[] = [];
|
||||||
|
for (const node of nodes) {
|
||||||
|
const hops =
|
||||||
|
node.type === "choice" ? node.data.choices ?? [] : node.data.next ? [node.data.next] : [];
|
||||||
|
hops.forEach((hop, index) => {
|
||||||
|
if (!hop || !hop.target) return;
|
||||||
|
edges.push({
|
||||||
|
id: `${node.id}->${index}`,
|
||||||
|
source: node.id,
|
||||||
|
target: hop.target,
|
||||||
|
label: hop.label,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GraphValidation {
|
||||||
|
valid: boolean;
|
||||||
|
errors: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a flowchart: a start node exists, every hop target resolves, and
|
||||||
|
* choice hops carry a label. Does not hard-fail on cycles (branching can be
|
||||||
|
* intentionally re-entrant) but reports them.
|
||||||
|
*/
|
||||||
|
export function validateGraph(nodes: DialogueNode[]): GraphValidation {
|
||||||
|
const errors: string[] = [];
|
||||||
|
const ids = new Set(nodes.map((n) => n.id));
|
||||||
|
|
||||||
|
if (nodes.length === 0) {
|
||||||
|
return { valid: false, errors: ["Add at least one node to start building the conversation."] };
|
||||||
|
}
|
||||||
|
if (!findStartNode(nodes)) {
|
||||||
|
errors.push("Mark a node as the conversation start.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const node of nodes) {
|
||||||
|
const hops = node.type === "choice" ? node.data.choices ?? [] : node.data.next ? [node.data.next] : [];
|
||||||
|
for (const hop of hops) {
|
||||||
|
if (!hop) continue;
|
||||||
|
if (hop.target && !ids.has(hop.target)) {
|
||||||
|
errors.push(`"${node.id}" points to missing node "${hop.target}".`);
|
||||||
|
}
|
||||||
|
if (node.type === "choice" && !hop.label?.trim()) {
|
||||||
|
errors.push(`A choice on "${node.id}" needs button text.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { valid: errors.length === 0, errors };
|
||||||
|
}
|
||||||
85
src/lib/npcs/activity.ts
Normal file
85
src/lib/npcs/activity.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
/**
|
||||||
|
* Pure, client-safe helpers for an NPC's "current activity" flavor.
|
||||||
|
*
|
||||||
|
* An NPC has a list of possible activities, each with a relative "chance"
|
||||||
|
* (weight) and an optional "forced" flag. If any activity is forced, it is
|
||||||
|
* shown stably (it ignores the reshuffle interval). Otherwise the most likely
|
||||||
|
* activity is picked at random, weighted by each option's chance.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface NpcActivityOption {
|
||||||
|
label: string;
|
||||||
|
/** Relative chance this activity is picked when reshuffling (min 1). */
|
||||||
|
weight: number;
|
||||||
|
/** When true, this activity stays active until the flag is turned off. */
|
||||||
|
forced?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Deterministic 32-bit PRNG (mulberry32) so reshuffles are reproducible in tests. */
|
||||||
|
export function seededRng(seed: number | string): () => number {
|
||||||
|
let a = typeof seed === "string" ? stringToSeed(seed) : seed;
|
||||||
|
return function next(): number {
|
||||||
|
a |= 0;
|
||||||
|
a = (a + 0x6d2b79f5) | 0;
|
||||||
|
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
||||||
|
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||||
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringToSeed(input: string): number {
|
||||||
|
let hash = 0;
|
||||||
|
for (let i = 0; i < input.length; i++) {
|
||||||
|
hash = (mathHash(hash + input.charCodeAt(i), 0x1000193) + mathHash(hash, 0x287c47fd)) | 0;
|
||||||
|
}
|
||||||
|
return hash >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mathHash(value: number, prime: number): number {
|
||||||
|
return (Math.imul(value ^ (value >>> 16), prime) >>> 0) | 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true when at least one activity is flagged forced. */
|
||||||
|
export function hasForcedActivity(options: NpcActivityOption[]): boolean {
|
||||||
|
return options.some((option) => option.forced === true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the activity an NPC is "currently" doing.
|
||||||
|
*
|
||||||
|
* - If any activity is forced, the first forced option is returned (stable,
|
||||||
|
* ignores the reshuffle interval).
|
||||||
|
* - Otherwise a weighted-random pick is made. Pass `seed`/`rng` to reshuffle
|
||||||
|
* deterministically (e.g. a new seed each interval tick on the frontend).
|
||||||
|
*/
|
||||||
|
export function resolveCurrentActivity(
|
||||||
|
options: NpcActivityOption[],
|
||||||
|
seed?: number | string,
|
||||||
|
rng: () => number = Math.random,
|
||||||
|
): string | null {
|
||||||
|
const forced = options.filter((option) => option.forced === true);
|
||||||
|
if (forced.length > 0) {
|
||||||
|
return forced[0].label;
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalWeight = options.reduce((sum, option) => sum + Math.max(0, option.weight ?? 1), 0);
|
||||||
|
if (totalWeight <= 0) {
|
||||||
|
return options.length > 0 ? options[0].label : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pickRng = seed !== undefined ? seededRng(seed) : rng;
|
||||||
|
let roll = pickRng() * totalWeight;
|
||||||
|
for (const option of options) {
|
||||||
|
const weight = Math.max(0, option.weight ?? 1);
|
||||||
|
if (roll < weight) {
|
||||||
|
return option.label;
|
||||||
|
}
|
||||||
|
roll -= weight;
|
||||||
|
}
|
||||||
|
return options[options.length - 1]?.label ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Formats an activity for the "Currently: …" readout. */
|
||||||
|
export function formatActivityLine(activity: string | null | undefined): string {
|
||||||
|
return activity ? `Currently: ${activity}` : "Currently: undetermined";
|
||||||
|
}
|
||||||
37156
src/migrations/20261006_000000_add_npc_dialogue_and_activity_fields.json
Normal file
37156
src/migrations/20261006_000000_add_npc_dialogue_and_activity_fields.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NPC contacts: the "Narrative Activity" group + `level`/`levelDescription`/
|
||||||
|
* `canMessage` fields on `game_npcs`, the `npc-dialogues` collection (branching
|
||||||
|
* conversation flowcharts), and the collection's RBAC permission values.
|
||||||
|
* Hand-written in the add_mission_role_signups / add_mission_map_markers style
|
||||||
|
* (isolated to this feature's footprint).
|
||||||
|
*/
|
||||||
|
export async function up({ db }: MigrateUpArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
ALTER TYPE "public"."enum_roles_permissions" ADD VALUE IF NOT EXISTS 'npc-dialogues:create' BEFORE 'campaigns:create';
|
||||||
|
ALTER TYPE "public"."enum_roles_permissions" ADD VALUE IF NOT EXISTS 'npc-dialogues:read' BEFORE 'campaigns:create';
|
||||||
|
ALTER TYPE "public"."enum_roles_permissions" ADD VALUE IF NOT EXISTS 'npc-dialogues:update' BEFORE 'campaigns:create';
|
||||||
|
ALTER TYPE "public"."enum_roles_permissions" ADD VALUE IF NOT EXISTS 'npc-dialogues:delete' BEFORE 'campaigns:create';
|
||||||
|
ALTER TYPE "public"."enum_roles_permissions" ADD VALUE IF NOT EXISTS 'admin:npc-dialogues:manage' BEFORE 'campaigns:create';
|
||||||
|
CREATE TABLE "npc_dialogues" (
|
||||||
|
"id" serial PRIMARY KEY NOT NULL,
|
||||||
|
"name" varchar NOT NULL,
|
||||||
|
"npc_id" integer NOT NULL,
|
||||||
|
"flow_data" jsonb DEFAULT '{"nodes":[],"edges":[]}' NOT NULL,
|
||||||
|
"created_at" timestamp(3) with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp(3) with time zone DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
-- game_npcs: narrative activity group. intervalMinutes is a direct column
|
||||||
|
-- (default 30); activityOptions is an array, which Payload stores in its own
|
||||||
|
-- sub-table rather than as a jsonb column on the parent.
|
||||||
|
ALTER TABLE "game_npcs" ADD COLUMN "activity_interval_minutes" numeric DEFAULT 30;
|
||||||
|
ALTER TABLE "game_npcs" ADD COLUMN "level" numeric;
|
||||||
|
ALTER TABLE "game_npcs" ADD COLUMN "level_description" jsonb;
|
||||||
|
ALTER TABLE "game_npcs" ADD COLUMN "can_message" boolean DEFAULT false;
|
||||||
|
|
||||||
|
-- array sub-table for activity.activityOptions (Payload-managed _order/_parent_id/id)
|
||||||
|
CREATE TABLE "game_npcs_activity_activity_options" (
|
||||||
|
"id" varchar PRIMARY KEY NOT NULL,
|
||||||
|
"_order" integer NOT NULL,
|
||||||
|
"_parent_id" integer NOT NULL,
|
||||||
|
"label" varchar NOT NULL,
|
||||||
|
"weight" numeric DEFAULT 1,
|
||||||
|
"forced" boolean DEFAULT false
|
||||||
|
);
|
||||||
|
CREATE INDEX "game_npcs_activity_activity_options_order_idx" ON "game_npcs_activity_activity_options" USING btree ("_order");
|
||||||
|
CREATE INDEX "game_npcs_activity_activity_options_parent_id_idx" ON "game_npcs_activity_activity_options" USING btree ("_parent_id");
|
||||||
|
ALTER TABLE "game_npcs_activity_activity_options" ADD CONSTRAINT "game_npcs_activity_activity_options_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."game_npcs"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
|
|
||||||
|
-- MCP exposure (the mcp plugin is enabled for every scoped collection)
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "npc_dialogues_find" boolean DEFAULT false;
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "npc_dialogues_create" boolean DEFAULT false;
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "npc_dialogues_update" boolean DEFAULT false;
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" ADD COLUMN "npc_dialogues_delete" boolean DEFAULT false;
|
||||||
|
|
||||||
|
-- document locking bookkeeping for the new collection
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" ADD COLUMN "npc_dialogues_id" integer;
|
||||||
|
ALTER TABLE "npc_dialogues" ADD CONSTRAINT "npc_dialogues_npc_id_game_npcs_id_fk" FOREIGN KEY ("npc_id") REFERENCES "public"."game_npcs"("id") ON DELETE set null ON UPDATE no action;
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_npc_dialogues_fk" FOREIGN KEY ("npc_dialogues_id") REFERENCES "public"."npc_dialogues"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
|
CREATE INDEX "npc_dialogues_npc_idx" ON "npc_dialogues" USING btree ("npc_id");
|
||||||
|
CREATE INDEX "npc_dialogues_updated_at_idx" ON "npc_dialogues" USING btree ("updated_at");
|
||||||
|
CREATE INDEX "npc_dialogues_created_at_idx" ON "npc_dialogues" USING btree ("created_at");
|
||||||
|
CREATE INDEX "payload_locked_documents_rels_npc_dialogues_id_idx" ON "payload_locked_documents_rels" USING btree ("npc_dialogues_id");`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drops the table, columns and FKs. The enum values are left in place (Postgres
|
||||||
|
* cannot drop enum values without rebuilding the type, and an unused value is
|
||||||
|
* harmless); role rows holding them are removed.
|
||||||
|
*/
|
||||||
|
export async function down({ db }: MigrateDownArgs): Promise<void> {
|
||||||
|
await db.execute(sql`
|
||||||
|
DELETE FROM "roles_permissions" WHERE "value"::text LIKE '%npc-dialogues%';
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT IF EXISTS "payload_locked_documents_rels_npc_dialogues_fk";
|
||||||
|
DROP INDEX IF EXISTS "payload_locked_documents_rels_npc_dialogues_id_idx";
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" DROP COLUMN IF EXISTS "npc_dialogues_id";
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN IF EXISTS "npc_dialogues_find";
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN IF EXISTS "npc_dialogues_create";
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN IF EXISTS "npc_dialogues_update";
|
||||||
|
ALTER TABLE "payload_mcp_api_keys" DROP COLUMN IF EXISTS "npc_dialogues_delete";
|
||||||
|
ALTER TABLE "game_npcs_activity_activity_options" DROP CONSTRAINT IF EXISTS "game_npcs_activity_activity_options_parent_id_fk";
|
||||||
|
DROP INDEX IF EXISTS "game_npcs_activity_activity_options_order_idx";
|
||||||
|
DROP INDEX IF EXISTS "game_npcs_activity_activity_options_parent_id_idx";
|
||||||
|
DROP TABLE IF EXISTS "game_npcs_activity_activity_options" CASCADE;
|
||||||
|
DROP INDEX IF EXISTS "npc_dialogues_npc_idx";
|
||||||
|
DROP INDEX IF EXISTS "npc_dialogues_updated_at_idx";
|
||||||
|
DROP INDEX IF EXISTS "npc_dialogues_created_at_idx";
|
||||||
|
ALTER TABLE "npc_dialogues" DROP CONSTRAINT IF EXISTS "npc_dialogues_npc_id_game_npcs_id_fk";
|
||||||
|
DROP TABLE IF EXISTS "npc_dialogues" CASCADE;
|
||||||
|
ALTER TABLE "game_npcs" DROP COLUMN IF EXISTS "activity_interval_minutes";
|
||||||
|
ALTER TABLE "game_npcs" DROP COLUMN IF EXISTS "level";
|
||||||
|
ALTER TABLE "game_npcs" DROP COLUMN IF EXISTS "level_description";
|
||||||
|
ALTER TABLE "game_npcs" DROP COLUMN IF EXISTS "can_message";`)
|
||||||
|
}
|
||||||
|
|
@ -106,6 +106,7 @@ import * as migration_20261005_001212_add_map_grid_config from './20261005_00121
|
||||||
import * as migration_20261005_051452_add_game_structure_item_storage from './20261005_051452_add_game_structure_item_storage';
|
import * as migration_20261005_051452_add_game_structure_item_storage from './20261005_051452_add_game_structure_item_storage';
|
||||||
import * as migration_20261005_054132_add_game_npc_bio_richtext from './20261005_054132_add_game_npc_bio_richtext';
|
import * as migration_20261005_054132_add_game_npc_bio_richtext from './20261005_054132_add_game_npc_bio_richtext';
|
||||||
import * as migration_20261005_063613_add_game_npc_image from './20261005_063613_add_game_npc_image';
|
import * as migration_20261005_063613_add_game_npc_image from './20261005_063613_add_game_npc_image';
|
||||||
|
import * as migration_20261006_000000_add_npc_dialogue_and_activity_fields from './20261006_000000_add_npc_dialogue_and_activity_fields';
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
{
|
{
|
||||||
|
|
@ -646,6 +647,11 @@ export const migrations = [
|
||||||
{
|
{
|
||||||
up: migration_20261005_063613_add_game_npc_image.up,
|
up: migration_20261005_063613_add_game_npc_image.up,
|
||||||
down: migration_20261005_063613_add_game_npc_image.down,
|
down: migration_20261005_063613_add_game_npc_image.down,
|
||||||
name: '20261005_063613_add_game_npc_image'
|
name: '20261005_063613_add_game_npc_image',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
up: migration_20261006_000000_add_npc_dialogue_and_activity_fields.up,
|
||||||
|
down: migration_20261006_000000_add_npc_dialogue_and_activity_fields.down,
|
||||||
|
name: '20261006_000000_add_npc_dialogue_and_activity_fields'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -439,6 +439,11 @@ export const enum_roles_permissions = pgEnum("enum_roles_permissions", [
|
||||||
"narrative-events:update",
|
"narrative-events:update",
|
||||||
"narrative-events:delete",
|
"narrative-events:delete",
|
||||||
"admin:narrative-events:manage",
|
"admin:narrative-events:manage",
|
||||||
|
"npc-dialogues:create",
|
||||||
|
"npc-dialogues:read",
|
||||||
|
"npc-dialogues:update",
|
||||||
|
"npc-dialogues:delete",
|
||||||
|
"admin:npc-dialogues:manage",
|
||||||
"mission-files:create",
|
"mission-files:create",
|
||||||
"mission-files:read",
|
"mission-files:read",
|
||||||
"mission-files:update",
|
"mission-files:update",
|
||||||
|
|
@ -1668,6 +1673,27 @@ export const game_vehicles = pgTable(
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const game_npcs_activity_activity_options = pgTable(
|
||||||
|
"game_npcs_activity_activity_options",
|
||||||
|
{
|
||||||
|
_order: integer("_order").notNull(),
|
||||||
|
_parentID: integer("_parent_id").notNull(),
|
||||||
|
id: varchar("id").primaryKey(),
|
||||||
|
label: varchar("label").notNull(),
|
||||||
|
weight: numeric("weight", { mode: "number" }).default(1),
|
||||||
|
forced: boolean("forced").default(false),
|
||||||
|
},
|
||||||
|
(columns) => [
|
||||||
|
index("game_npcs_activity_activity_options_order_idx").on(columns._order),
|
||||||
|
index("game_npcs_activity_activity_options_parent_id_idx").on(columns._parentID),
|
||||||
|
foreignKey({
|
||||||
|
columns: [columns["_parentID"]],
|
||||||
|
foreignColumns: [game_npcs.id],
|
||||||
|
name: "game_npcs_activity_activity_options_parent_id_fk",
|
||||||
|
}).onDelete("cascade"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
export const game_npcs = pgTable(
|
export const game_npcs = pgTable(
|
||||||
"game_npcs",
|
"game_npcs",
|
||||||
{
|
{
|
||||||
|
|
@ -1688,6 +1714,10 @@ export const game_npcs = pgTable(
|
||||||
isInGame: boolean("is_in_game").default(true),
|
isInGame: boolean("is_in_game").default(true),
|
||||||
vendor_enabled: boolean("vendor_enabled").default(false),
|
vendor_enabled: boolean("vendor_enabled").default(false),
|
||||||
vendor_priceModifier: numeric("vendor_price_modifier", { mode: "number" }).default(1),
|
vendor_priceModifier: numeric("vendor_price_modifier", { mode: "number" }).default(1),
|
||||||
|
activity_intervalMinutes: numeric("activity_interval_minutes", { mode: "number" }).default(30),
|
||||||
|
level: numeric("level", { mode: "number" }),
|
||||||
|
levelDescription: jsonb("level_description"),
|
||||||
|
canMessage: boolean("can_message").default(false),
|
||||||
updatedAt: timestamp("updated_at", { mode: "string", withTimezone: true, precision: 3 })
|
updatedAt: timestamp("updated_at", { mode: "string", withTimezone: true, precision: 3 })
|
||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.notNull(),
|
||||||
|
|
@ -1773,6 +1803,31 @@ export const npc_staffing = pgTable(
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const npc_dialogues = pgTable(
|
||||||
|
"npc_dialogues",
|
||||||
|
{
|
||||||
|
id: serial("id").primaryKey(),
|
||||||
|
name: varchar("name").notNull(),
|
||||||
|
npc: integer("npc_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => game_npcs.id, {
|
||||||
|
onDelete: "set null",
|
||||||
|
}),
|
||||||
|
flowData: jsonb("flow_data").notNull(),
|
||||||
|
updatedAt: timestamp("updated_at", { mode: "string", withTimezone: true, precision: 3 })
|
||||||
|
.defaultNow()
|
||||||
|
.notNull(),
|
||||||
|
createdAt: timestamp("created_at", { mode: "string", withTimezone: true, precision: 3 })
|
||||||
|
.defaultNow()
|
||||||
|
.notNull(),
|
||||||
|
},
|
||||||
|
(columns) => [
|
||||||
|
index("npc_dialogues_npc_idx").on(columns.npc),
|
||||||
|
index("npc_dialogues_updated_at_idx").on(columns.updatedAt),
|
||||||
|
index("npc_dialogues_created_at_idx").on(columns.createdAt),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
export const labor_classifications = pgTable(
|
export const labor_classifications = pgTable(
|
||||||
"labor_classifications",
|
"labor_classifications",
|
||||||
{
|
{
|
||||||
|
|
@ -7092,6 +7147,10 @@ export const payload_mcp_api_keys = pgTable(
|
||||||
npcStaffing_create: boolean("npc_staffing_create").default(false),
|
npcStaffing_create: boolean("npc_staffing_create").default(false),
|
||||||
npcStaffing_update: boolean("npc_staffing_update").default(false),
|
npcStaffing_update: boolean("npc_staffing_update").default(false),
|
||||||
npcStaffing_delete: boolean("npc_staffing_delete").default(false),
|
npcStaffing_delete: boolean("npc_staffing_delete").default(false),
|
||||||
|
npcDialogues_find: boolean("npc_dialogues_find").default(false),
|
||||||
|
npcDialogues_create: boolean("npc_dialogues_create").default(false),
|
||||||
|
npcDialogues_update: boolean("npc_dialogues_update").default(false),
|
||||||
|
npcDialogues_delete: boolean("npc_dialogues_delete").default(false),
|
||||||
laborClassifications_find: boolean("labor_classifications_find").default(false),
|
laborClassifications_find: boolean("labor_classifications_find").default(false),
|
||||||
laborClassifications_create: boolean("labor_classifications_create").default(false),
|
laborClassifications_create: boolean("labor_classifications_create").default(false),
|
||||||
laborClassifications_update: boolean("labor_classifications_update").default(false),
|
laborClassifications_update: boolean("labor_classifications_update").default(false),
|
||||||
|
|
@ -7440,6 +7499,7 @@ export const payload_locked_documents_rels = pgTable(
|
||||||
"game-vehiclesID": integer("game_vehicles_id"),
|
"game-vehiclesID": integer("game_vehicles_id"),
|
||||||
"game-npcsID": integer("game_npcs_id"),
|
"game-npcsID": integer("game_npcs_id"),
|
||||||
"npc-staffingID": integer("npc_staffing_id"),
|
"npc-staffingID": integer("npc_staffing_id"),
|
||||||
|
"npc-dialoguesID": integer("npc_dialogues_id"),
|
||||||
"labor-classificationsID": integer("labor_classifications_id"),
|
"labor-classificationsID": integer("labor_classifications_id"),
|
||||||
"game-event-logsID": integer("game_event_logs_id"),
|
"game-event-logsID": integer("game_event_logs_id"),
|
||||||
usersID: integer("users_id"),
|
usersID: integer("users_id"),
|
||||||
|
|
@ -7530,6 +7590,7 @@ export const payload_locked_documents_rels = pgTable(
|
||||||
index("payload_locked_documents_rels_game_vehicles_id_idx").on(columns["game-vehiclesID"]),
|
index("payload_locked_documents_rels_game_vehicles_id_idx").on(columns["game-vehiclesID"]),
|
||||||
index("payload_locked_documents_rels_game_npcs_id_idx").on(columns["game-npcsID"]),
|
index("payload_locked_documents_rels_game_npcs_id_idx").on(columns["game-npcsID"]),
|
||||||
index("payload_locked_documents_rels_npc_staffing_id_idx").on(columns["npc-staffingID"]),
|
index("payload_locked_documents_rels_npc_staffing_id_idx").on(columns["npc-staffingID"]),
|
||||||
|
index("payload_locked_documents_rels_npc_dialogues_id_idx").on(columns["npc-dialoguesID"]),
|
||||||
index("payload_locked_documents_rels_labor_classifications_id_idx").on(
|
index("payload_locked_documents_rels_labor_classifications_id_idx").on(
|
||||||
columns["labor-classificationsID"],
|
columns["labor-classificationsID"],
|
||||||
),
|
),
|
||||||
|
|
@ -7700,6 +7761,11 @@ export const payload_locked_documents_rels = pgTable(
|
||||||
foreignColumns: [npc_staffing.id],
|
foreignColumns: [npc_staffing.id],
|
||||||
name: "payload_locked_documents_rels_npc_staffing_fk",
|
name: "payload_locked_documents_rels_npc_staffing_fk",
|
||||||
}).onDelete("cascade"),
|
}).onDelete("cascade"),
|
||||||
|
foreignKey({
|
||||||
|
columns: [columns["npc-dialoguesID"]],
|
||||||
|
foreignColumns: [npc_dialogues.id],
|
||||||
|
name: "payload_locked_documents_rels_npc_dialogues_fk",
|
||||||
|
}).onDelete("cascade"),
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [columns["labor-classificationsID"]],
|
columns: [columns["labor-classificationsID"]],
|
||||||
foreignColumns: [labor_classifications.id],
|
foreignColumns: [labor_classifications.id],
|
||||||
|
|
@ -8636,6 +8702,16 @@ export const relations_game_vehicles = relations(game_vehicles, ({ one, many })
|
||||||
relationName: "voidStorage",
|
relationName: "voidStorage",
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
export const relations_game_npcs_activity_activity_options = relations(
|
||||||
|
game_npcs_activity_activity_options,
|
||||||
|
({ one }) => ({
|
||||||
|
_parentID: one(game_npcs, {
|
||||||
|
fields: [game_npcs_activity_activity_options._parentID],
|
||||||
|
references: [game_npcs.id],
|
||||||
|
relationName: "activity_activityOptions",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
export const relations_game_npcs_rels = relations(game_npcs_rels, ({ one }) => ({
|
export const relations_game_npcs_rels = relations(game_npcs_rels, ({ one }) => ({
|
||||||
parent: one(game_npcs, {
|
parent: one(game_npcs, {
|
||||||
fields: [game_npcs_rels.parent],
|
fields: [game_npcs_rels.parent],
|
||||||
|
|
@ -8664,6 +8740,9 @@ export const relations_game_npcs = relations(game_npcs, ({ one, many }) => ({
|
||||||
references: [factions.id],
|
references: [factions.id],
|
||||||
relationName: "faction",
|
relationName: "faction",
|
||||||
}),
|
}),
|
||||||
|
activity_activityOptions: many(game_npcs_activity_activity_options, {
|
||||||
|
relationName: "activity_activityOptions",
|
||||||
|
}),
|
||||||
_rels: many(game_npcs_rels, {
|
_rels: many(game_npcs_rels, {
|
||||||
relationName: "_rels",
|
relationName: "_rels",
|
||||||
}),
|
}),
|
||||||
|
|
@ -8685,6 +8764,13 @@ export const relations_npc_staffing = relations(npc_staffing, ({ one }) => ({
|
||||||
relationName: "laborClassification",
|
relationName: "laborClassification",
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
export const relations_npc_dialogues = relations(npc_dialogues, ({ one }) => ({
|
||||||
|
npc: one(game_npcs, {
|
||||||
|
fields: [npc_dialogues.npc],
|
||||||
|
references: [game_npcs.id],
|
||||||
|
relationName: "npc",
|
||||||
|
}),
|
||||||
|
}));
|
||||||
export const relations_labor_classifications = relations(labor_classifications, () => ({}));
|
export const relations_labor_classifications = relations(labor_classifications, () => ({}));
|
||||||
export const relations_game_event_logs = relations(game_event_logs, ({ one }) => ({
|
export const relations_game_event_logs = relations(game_event_logs, ({ one }) => ({
|
||||||
actor: one(users, {
|
actor: one(users, {
|
||||||
|
|
@ -10919,6 +11005,11 @@ export const relations_payload_locked_documents_rels = relations(
|
||||||
references: [npc_staffing.id],
|
references: [npc_staffing.id],
|
||||||
relationName: "npc-staffing",
|
relationName: "npc-staffing",
|
||||||
}),
|
}),
|
||||||
|
"npc-dialoguesID": one(npc_dialogues, {
|
||||||
|
fields: [payload_locked_documents_rels["npc-dialoguesID"]],
|
||||||
|
references: [npc_dialogues.id],
|
||||||
|
relationName: "npc-dialogues",
|
||||||
|
}),
|
||||||
"labor-classificationsID": one(labor_classifications, {
|
"labor-classificationsID": one(labor_classifications, {
|
||||||
fields: [payload_locked_documents_rels["labor-classificationsID"]],
|
fields: [payload_locked_documents_rels["labor-classificationsID"]],
|
||||||
references: [labor_classifications.id],
|
references: [labor_classifications.id],
|
||||||
|
|
@ -11561,9 +11652,11 @@ type DatabaseSchema = {
|
||||||
game_vehicles_stored_resources: typeof game_vehicles_stored_resources;
|
game_vehicles_stored_resources: typeof game_vehicles_stored_resources;
|
||||||
game_vehicles_void_storage: typeof game_vehicles_void_storage;
|
game_vehicles_void_storage: typeof game_vehicles_void_storage;
|
||||||
game_vehicles: typeof game_vehicles;
|
game_vehicles: typeof game_vehicles;
|
||||||
|
game_npcs_activity_activity_options: typeof game_npcs_activity_activity_options;
|
||||||
game_npcs: typeof game_npcs;
|
game_npcs: typeof game_npcs;
|
||||||
game_npcs_rels: typeof game_npcs_rels;
|
game_npcs_rels: typeof game_npcs_rels;
|
||||||
npc_staffing: typeof npc_staffing;
|
npc_staffing: typeof npc_staffing;
|
||||||
|
npc_dialogues: typeof npc_dialogues;
|
||||||
labor_classifications: typeof labor_classifications;
|
labor_classifications: typeof labor_classifications;
|
||||||
game_event_logs: typeof game_event_logs;
|
game_event_logs: typeof game_event_logs;
|
||||||
users_roles: typeof users_roles;
|
users_roles: typeof users_roles;
|
||||||
|
|
@ -11757,9 +11850,11 @@ type DatabaseSchema = {
|
||||||
relations_game_vehicles_stored_resources: typeof relations_game_vehicles_stored_resources;
|
relations_game_vehicles_stored_resources: typeof relations_game_vehicles_stored_resources;
|
||||||
relations_game_vehicles_void_storage: typeof relations_game_vehicles_void_storage;
|
relations_game_vehicles_void_storage: typeof relations_game_vehicles_void_storage;
|
||||||
relations_game_vehicles: typeof relations_game_vehicles;
|
relations_game_vehicles: typeof relations_game_vehicles;
|
||||||
|
relations_game_npcs_activity_activity_options: typeof relations_game_npcs_activity_activity_options;
|
||||||
relations_game_npcs_rels: typeof relations_game_npcs_rels;
|
relations_game_npcs_rels: typeof relations_game_npcs_rels;
|
||||||
relations_game_npcs: typeof relations_game_npcs;
|
relations_game_npcs: typeof relations_game_npcs;
|
||||||
relations_npc_staffing: typeof relations_npc_staffing;
|
relations_npc_staffing: typeof relations_npc_staffing;
|
||||||
|
relations_npc_dialogues: typeof relations_npc_dialogues;
|
||||||
relations_labor_classifications: typeof relations_labor_classifications;
|
relations_labor_classifications: typeof relations_labor_classifications;
|
||||||
relations_game_event_logs: typeof relations_game_event_logs;
|
relations_game_event_logs: typeof relations_game_event_logs;
|
||||||
relations_users_roles: typeof relations_users_roles;
|
relations_users_roles: typeof relations_users_roles;
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ export interface Config {
|
||||||
'game-vehicles': GameVehicle;
|
'game-vehicles': GameVehicle;
|
||||||
'game-npcs': GameNpc;
|
'game-npcs': GameNpc;
|
||||||
'npc-staffing': NpcStaffing;
|
'npc-staffing': NpcStaffing;
|
||||||
|
'npc-dialogues': NpcDialogue;
|
||||||
'labor-classifications': LaborClassification;
|
'labor-classifications': LaborClassification;
|
||||||
'game-event-logs': GameEventLog;
|
'game-event-logs': GameEventLog;
|
||||||
users: User;
|
users: User;
|
||||||
|
|
@ -172,6 +173,7 @@ export interface Config {
|
||||||
'game-vehicles': GameVehiclesSelect<false> | GameVehiclesSelect<true>;
|
'game-vehicles': GameVehiclesSelect<false> | GameVehiclesSelect<true>;
|
||||||
'game-npcs': GameNpcsSelect<false> | GameNpcsSelect<true>;
|
'game-npcs': GameNpcsSelect<false> | GameNpcsSelect<true>;
|
||||||
'npc-staffing': NpcStaffingSelect<false> | NpcStaffingSelect<true>;
|
'npc-staffing': NpcStaffingSelect<false> | NpcStaffingSelect<true>;
|
||||||
|
'npc-dialogues': NpcDialoguesSelect<false> | NpcDialoguesSelect<true>;
|
||||||
'labor-classifications': LaborClassificationsSelect<false> | LaborClassificationsSelect<true>;
|
'labor-classifications': LaborClassificationsSelect<false> | LaborClassificationsSelect<true>;
|
||||||
'game-event-logs': GameEventLogsSelect<false> | GameEventLogsSelect<true>;
|
'game-event-logs': GameEventLogsSelect<false> | GameEventLogsSelect<true>;
|
||||||
users: UsersSelect<false> | UsersSelect<true>;
|
users: UsersSelect<false> | UsersSelect<true>;
|
||||||
|
|
@ -814,6 +816,11 @@ export interface Role {
|
||||||
| 'narrative-events:update'
|
| 'narrative-events:update'
|
||||||
| 'narrative-events:delete'
|
| 'narrative-events:delete'
|
||||||
| 'admin:narrative-events:manage'
|
| 'admin:narrative-events:manage'
|
||||||
|
| 'npc-dialogues:create'
|
||||||
|
| 'npc-dialogues:read'
|
||||||
|
| 'npc-dialogues:update'
|
||||||
|
| 'npc-dialogues:delete'
|
||||||
|
| 'admin:npc-dialogues:manage'
|
||||||
| 'mission-files:create'
|
| 'mission-files:create'
|
||||||
| 'mission-files:read'
|
| 'mission-files:read'
|
||||||
| 'mission-files:update'
|
| 'mission-files:update'
|
||||||
|
|
@ -2420,6 +2427,58 @@ export interface GameNpc {
|
||||||
*/
|
*/
|
||||||
sells?: (number | Asset)[] | null;
|
sells?: (number | Asset)[] | null;
|
||||||
};
|
};
|
||||||
|
activity?: {
|
||||||
|
/**
|
||||||
|
* How often (in minutes) the current activity reshuffles automatically. Ignored while a forced activity is active.
|
||||||
|
*/
|
||||||
|
intervalMinutes?: number | null;
|
||||||
|
/**
|
||||||
|
* Possible activities this contact can be doing. 'Forced' activities stay active until turned off; otherwise the most likely option (by 'Chance') is picked on each interval.
|
||||||
|
*/
|
||||||
|
activityOptions?:
|
||||||
|
| {
|
||||||
|
/**
|
||||||
|
* What the contact is doing (e.g. 'Coordinating combat androids').
|
||||||
|
*/
|
||||||
|
label: string;
|
||||||
|
/**
|
||||||
|
* Relative chance this activity is picked when reshuffling.
|
||||||
|
*/
|
||||||
|
weight?: number | null;
|
||||||
|
/**
|
||||||
|
* Keep this activity active until turned off (overrides the interval reshuffle).
|
||||||
|
*/
|
||||||
|
forced?: boolean | null;
|
||||||
|
id?: string | null;
|
||||||
|
}[]
|
||||||
|
| null;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* This contact's level. Shown on their profile alongside its description.
|
||||||
|
*/
|
||||||
|
level?: number | null;
|
||||||
|
/**
|
||||||
|
* Capabilities / notes for this contact's level (e.g. a bullet list).
|
||||||
|
*/
|
||||||
|
levelDescription?: {
|
||||||
|
root: {
|
||||||
|
type: string;
|
||||||
|
children: {
|
||||||
|
type: any;
|
||||||
|
version: number;
|
||||||
|
[k: string]: unknown;
|
||||||
|
}[];
|
||||||
|
direction: ('ltr' | 'rtl') | null;
|
||||||
|
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
||||||
|
indent: number;
|
||||||
|
version: number;
|
||||||
|
};
|
||||||
|
[k: string]: unknown;
|
||||||
|
} | null;
|
||||||
|
/**
|
||||||
|
* Enable conversing with this contact on their profile page. Requires a configured NPC Dialogue flow.
|
||||||
|
*/
|
||||||
|
canMessage?: boolean | null;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
@ -2446,6 +2505,32 @@ export interface NpcStaffing {
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "npc-dialogues".
|
||||||
|
*/
|
||||||
|
export interface NpcDialogue {
|
||||||
|
id: number;
|
||||||
|
/**
|
||||||
|
* A short label for this conversation (e.g. 'Merchant greeting').
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
/**
|
||||||
|
* The contact this conversation belongs to.
|
||||||
|
*/
|
||||||
|
npc: number | GameNpc;
|
||||||
|
flowData:
|
||||||
|
| {
|
||||||
|
[k: string]: unknown;
|
||||||
|
}
|
||||||
|
| unknown[]
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| null;
|
||||||
|
updatedAt: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "game-event-logs".
|
* via the `definition` "game-event-logs".
|
||||||
|
|
@ -5677,6 +5762,24 @@ export interface PayloadMcpApiKey {
|
||||||
*/
|
*/
|
||||||
delete?: boolean | null;
|
delete?: boolean | null;
|
||||||
};
|
};
|
||||||
|
npcDialogues?: {
|
||||||
|
/**
|
||||||
|
* Allow clients to find npc-dialogues.
|
||||||
|
*/
|
||||||
|
find?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to create npc-dialogues.
|
||||||
|
*/
|
||||||
|
create?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to update npc-dialogues.
|
||||||
|
*/
|
||||||
|
update?: boolean | null;
|
||||||
|
/**
|
||||||
|
* Allow clients to delete npc-dialogues.
|
||||||
|
*/
|
||||||
|
delete?: boolean | null;
|
||||||
|
};
|
||||||
laborClassifications?: {
|
laborClassifications?: {
|
||||||
/**
|
/**
|
||||||
* Allow clients to find labor-classifications.
|
* Allow clients to find labor-classifications.
|
||||||
|
|
@ -7032,6 +7135,10 @@ export interface PayloadLockedDocument {
|
||||||
relationTo: 'npc-staffing';
|
relationTo: 'npc-staffing';
|
||||||
value: number | NpcStaffing;
|
value: number | NpcStaffing;
|
||||||
} | null)
|
} | null)
|
||||||
|
| ({
|
||||||
|
relationTo: 'npc-dialogues';
|
||||||
|
value: number | NpcDialogue;
|
||||||
|
} | null)
|
||||||
| ({
|
| ({
|
||||||
relationTo: 'labor-classifications';
|
relationTo: 'labor-classifications';
|
||||||
value: number | LaborClassification;
|
value: number | LaborClassification;
|
||||||
|
|
@ -7622,6 +7729,22 @@ export interface GameNpcsSelect<T extends boolean = true> {
|
||||||
priceModifier?: T;
|
priceModifier?: T;
|
||||||
sells?: T;
|
sells?: T;
|
||||||
};
|
};
|
||||||
|
activity?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
intervalMinutes?: T;
|
||||||
|
activityOptions?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
label?: T;
|
||||||
|
weight?: T;
|
||||||
|
forced?: T;
|
||||||
|
id?: T;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
level?: T;
|
||||||
|
levelDescription?: T;
|
||||||
|
canMessage?: T;
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
}
|
}
|
||||||
|
|
@ -7644,6 +7767,17 @@ export interface NpcStaffingSelect<T extends boolean = true> {
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "npc-dialogues_select".
|
||||||
|
*/
|
||||||
|
export interface NpcDialoguesSelect<T extends boolean = true> {
|
||||||
|
name?: T;
|
||||||
|
npc?: T;
|
||||||
|
flowData?: T;
|
||||||
|
updatedAt?: T;
|
||||||
|
createdAt?: T;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "labor-classifications_select".
|
* via the `definition` "labor-classifications_select".
|
||||||
|
|
@ -9862,6 +9996,14 @@ export interface PayloadMcpApiKeysSelect<T extends boolean = true> {
|
||||||
update?: T;
|
update?: T;
|
||||||
delete?: T;
|
delete?: T;
|
||||||
};
|
};
|
||||||
|
npcDialogues?:
|
||||||
|
| T
|
||||||
|
| {
|
||||||
|
find?: T;
|
||||||
|
create?: T;
|
||||||
|
update?: T;
|
||||||
|
delete?: T;
|
||||||
|
};
|
||||||
laborClassifications?:
|
laborClassifications?:
|
||||||
| T
|
| T
|
||||||
| {
|
| {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ import { GameEventLogs } from "@/collections/game/GameEventLogs";
|
||||||
import { GameVehicles } from "@/collections/game/GameVehicles";
|
import { GameVehicles } from "@/collections/game/GameVehicles";
|
||||||
import { GameNpcs } from "@/collections/game/GameNpcs";
|
import { GameNpcs } from "@/collections/game/GameNpcs";
|
||||||
import { NpcStaffing } from "@/collections/game/NpcStaffing";
|
import { NpcStaffing } from "@/collections/game/NpcStaffing";
|
||||||
|
import { NpcDialogues } from "@/collections/game/NpcDialogues";
|
||||||
import { LaborClassifications } from "@/collections/game/LaborClassifications";
|
import { LaborClassifications } from "@/collections/game/LaborClassifications";
|
||||||
import { Experience } from "@/collections/users/Experience";
|
import { Experience } from "@/collections/users/Experience";
|
||||||
import { BankAccounts } from "@/collections/banking/BankAccounts";
|
import { BankAccounts } from "@/collections/banking/BankAccounts";
|
||||||
|
|
@ -268,6 +269,7 @@ const collections = [
|
||||||
GameVehicles,
|
GameVehicles,
|
||||||
GameNpcs,
|
GameNpcs,
|
||||||
NpcStaffing,
|
NpcStaffing,
|
||||||
|
NpcDialogues,
|
||||||
LaborClassifications,
|
LaborClassifications,
|
||||||
GameEventLogs,
|
GameEventLogs,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,16 @@ export const PERMISSION_GROUPS: PermissionGroup[] = [
|
||||||
{ value: "admin:narrative-events:manage", label: "Manage Admin Page" },
|
{ value: "admin:narrative-events:manage", label: "Manage Admin Page" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
group: "NPC Dialogue",
|
||||||
|
permissions: [
|
||||||
|
{ value: "npc-dialogues:create", label: "Create" },
|
||||||
|
{ value: "npc-dialogues:read", label: "Read" },
|
||||||
|
{ value: "npc-dialogues:update", label: "Update" },
|
||||||
|
{ value: "npc-dialogues:delete", label: "Delete" },
|
||||||
|
{ value: "admin:npc-dialogues:manage", label: "Manage Admin Page" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
// ---- Server --------------------------------------------------------------
|
// ---- Server --------------------------------------------------------------
|
||||||
{
|
{
|
||||||
|
|
@ -984,6 +994,11 @@ export const ALL_PERMISSION_VALUES = PERMISSION_GROUPS.flatMap((g) =>
|
||||||
"narrative-events:update",
|
"narrative-events:update",
|
||||||
"narrative-events:delete",
|
"narrative-events:delete",
|
||||||
"admin:narrative-events:manage",
|
"admin:narrative-events:manage",
|
||||||
|
"npc-dialogues:create",
|
||||||
|
"npc-dialogues:read",
|
||||||
|
"npc-dialogues:update",
|
||||||
|
"npc-dialogues:delete",
|
||||||
|
"admin:npc-dialogues:manage",
|
||||||
"mission-files:create",
|
"mission-files:create",
|
||||||
"mission-files:read",
|
"mission-files:read",
|
||||||
"mission-files:update",
|
"mission-files:update",
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ export const EventTypes = {
|
||||||
|
|
||||||
// NPCs
|
// NPCs
|
||||||
NpcGenerate: "npc:generate",
|
NpcGenerate: "npc:generate",
|
||||||
|
NpcDialogue: "npc:dialogue",
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
AccountPasswordChange: "account:password-change",
|
AccountPasswordChange: "account:password-change",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue