|
|
|
|
@@ -12,10 +12,27 @@ function cleanText(str) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseList(raw) {
|
|
|
|
|
return raw
|
|
|
|
|
.split(/\n?\d+[).]\s+/)
|
|
|
|
|
.map(line => cleanText(line))
|
|
|
|
|
if (!raw) return [];
|
|
|
|
|
|
|
|
|
|
// Match all numbered items using a regex that captures the content
|
|
|
|
|
// This handles both "1. Title" and "1) Title" formats, and works even if multiple titles are on one line
|
|
|
|
|
// The regex captures everything after the number until the next number pattern or end of string
|
|
|
|
|
// Using [\s\S] to match any character including newlines, but stop at the next number pattern
|
|
|
|
|
const NUMBERED_ITEM_REGEX = /\d+[).]\s+([\s\S]+?)(?=\s*\d+[).]\s+|$)/g;
|
|
|
|
|
|
|
|
|
|
const items = Array.from(raw.matchAll(NUMBERED_ITEM_REGEX))
|
|
|
|
|
.map(match => match[1].trim())
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.map(cleanText)
|
|
|
|
|
.filter(Boolean);
|
|
|
|
|
|
|
|
|
|
// Fallback: if regex didn't work, try the old method
|
|
|
|
|
return items.length > 0
|
|
|
|
|
? items
|
|
|
|
|
: raw
|
|
|
|
|
.split(/\n?\d+[).]\s+/)
|
|
|
|
|
.map(line => cleanText(line))
|
|
|
|
|
.filter(Boolean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseObjects(raw, type = "rooms") {
|
|
|
|
|
@@ -431,6 +448,207 @@ function validateNarrativeCoherence(dungeonData) {
|
|
|
|
|
return issues;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixStructureIssues(dungeonData) {
|
|
|
|
|
const fixes = [];
|
|
|
|
|
|
|
|
|
|
// Fix missing or invalid room names
|
|
|
|
|
if (dungeonData.rooms) {
|
|
|
|
|
dungeonData.rooms.forEach((room, i) => {
|
|
|
|
|
if (!room.name || !room.name.trim()) {
|
|
|
|
|
// Extract name from description if possible
|
|
|
|
|
const desc = room.description || '';
|
|
|
|
|
const nameMatch = desc.match(/^([A-Z][^.!?]{5,30}?)(?:\s|\.|:)/);
|
|
|
|
|
if (nameMatch) {
|
|
|
|
|
room.name = nameMatch[1].trim();
|
|
|
|
|
fixes.push(`Extracted room name from description: "${room.name}"`);
|
|
|
|
|
} else {
|
|
|
|
|
room.name = `Room ${i + 1}`;
|
|
|
|
|
fixes.push(`Added default name for room ${i + 1}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Truncate overly long room names
|
|
|
|
|
const words = room.name.split(/\s+/);
|
|
|
|
|
if (words.length > 6) {
|
|
|
|
|
const original = room.name;
|
|
|
|
|
room.name = words.slice(0, 6).join(' ');
|
|
|
|
|
fixes.push(`Truncated room name: "${original}" -> "${room.name}"`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fix missing or invalid encounter names
|
|
|
|
|
if (dungeonData.encounters) {
|
|
|
|
|
dungeonData.encounters.forEach((encounter, i) => {
|
|
|
|
|
if (!encounter.name || !encounter.name.trim()) {
|
|
|
|
|
// Extract name from details if possible
|
|
|
|
|
const details = encounter.details || '';
|
|
|
|
|
const nameMatch = details.match(/^([^:]+):\s*(.+)$/);
|
|
|
|
|
if (nameMatch) {
|
|
|
|
|
encounter.name = nameMatch[1].trim();
|
|
|
|
|
encounter.details = nameMatch[2].trim();
|
|
|
|
|
fixes.push(`Extracted encounter name from details: "${encounter.name}"`);
|
|
|
|
|
} else {
|
|
|
|
|
encounter.name = `Encounter ${i + 1}`;
|
|
|
|
|
fixes.push(`Added default name for encounter ${i + 1}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Truncate overly long encounter names
|
|
|
|
|
const words = encounter.name.split(/\s+/);
|
|
|
|
|
if (words.length > 6) {
|
|
|
|
|
const original = encounter.name;
|
|
|
|
|
encounter.name = words.slice(0, 6).join(' ');
|
|
|
|
|
fixes.push(`Truncated encounter name: "${original}" -> "${encounter.name}"`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fix missing or invalid NPC names
|
|
|
|
|
if (dungeonData.npcs) {
|
|
|
|
|
dungeonData.npcs.forEach((npc, i) => {
|
|
|
|
|
if (!npc.name || !npc.name.trim()) {
|
|
|
|
|
// Extract name from trait if possible
|
|
|
|
|
const trait = npc.trait || '';
|
|
|
|
|
const nameMatch = trait.match(/^([A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,2})(?:\s|:)/);
|
|
|
|
|
if (nameMatch) {
|
|
|
|
|
npc.name = nameMatch[1].trim();
|
|
|
|
|
fixes.push(`Extracted NPC name from trait: "${npc.name}"`);
|
|
|
|
|
} else {
|
|
|
|
|
npc.name = `NPC ${i + 1}`;
|
|
|
|
|
fixes.push(`Added default name for NPC ${i + 1}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Truncate overly long NPC names
|
|
|
|
|
const words = npc.name.split(/\s+/);
|
|
|
|
|
if (words.length > 4) {
|
|
|
|
|
const original = npc.name;
|
|
|
|
|
npc.name = words.slice(0, 4).join(' ');
|
|
|
|
|
fixes.push(`Truncated NPC name: "${original}" -> "${npc.name}"`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fixes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixMissingContent(dungeonData) {
|
|
|
|
|
const fixes = [];
|
|
|
|
|
|
|
|
|
|
// Pad NPCs if needed
|
|
|
|
|
if (!dungeonData.npcs || dungeonData.npcs.length < 4) {
|
|
|
|
|
if (!dungeonData.npcs) dungeonData.npcs = [];
|
|
|
|
|
const factionName = dungeonData.coreConcepts?.match(/Primary Faction[:\s]+([^.]+)/i)?.[1]?.trim() || 'the primary faction';
|
|
|
|
|
while (dungeonData.npcs.length < 4) {
|
|
|
|
|
dungeonData.npcs.push({
|
|
|
|
|
name: `NPC ${dungeonData.npcs.length + 1}`,
|
|
|
|
|
trait: `A member of ${factionName.toLowerCase()} with unknown motives.`
|
|
|
|
|
});
|
|
|
|
|
fixes.push(`Added fallback NPC ${dungeonData.npcs.length}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pad encounters if needed
|
|
|
|
|
if (!dungeonData.encounters || dungeonData.encounters.length < 6) {
|
|
|
|
|
if (!dungeonData.encounters) dungeonData.encounters = [];
|
|
|
|
|
if (dungeonData.encounters.length > 0 && dungeonData.rooms && dungeonData.rooms.length > 0) {
|
|
|
|
|
const dynamicElement = dungeonData.coreConcepts?.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences';
|
|
|
|
|
const conflict = dungeonData.coreConcepts?.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a threat';
|
|
|
|
|
while (dungeonData.encounters.length < 6) {
|
|
|
|
|
const roomIndex = dungeonData.encounters.length % dungeonData.rooms.length;
|
|
|
|
|
const roomName = dungeonData.rooms[roomIndex]?.name || 'Unknown Location';
|
|
|
|
|
const fallbackNames = [
|
|
|
|
|
`${roomName} Guardian`,
|
|
|
|
|
`${roomName} Threat`,
|
|
|
|
|
`${roomName} Challenge`,
|
|
|
|
|
`${dynamicElement.split(' ')[0]} Manifestation`,
|
|
|
|
|
`${conflict.split(' ')[0]} Encounter`,
|
|
|
|
|
`${roomName} Hazard`
|
|
|
|
|
];
|
|
|
|
|
dungeonData.encounters.push({
|
|
|
|
|
name: fallbackNames[dungeonData.encounters.length % fallbackNames.length],
|
|
|
|
|
details: `${roomName}: An encounter related to ${dynamicElement.toLowerCase()} occurs here.`
|
|
|
|
|
});
|
|
|
|
|
fixes.push(`Added fallback encounter: "${dungeonData.encounters[dungeonData.encounters.length - 1].name}"`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pad treasure if needed
|
|
|
|
|
if (!dungeonData.treasure || dungeonData.treasure.length < 4) {
|
|
|
|
|
if (!dungeonData.treasure) dungeonData.treasure = [];
|
|
|
|
|
while (dungeonData.treasure.length < 4) {
|
|
|
|
|
dungeonData.treasure.push({
|
|
|
|
|
name: `Treasure ${dungeonData.treasure.length + 1}`,
|
|
|
|
|
description: `A mysterious item found in the dungeon.`
|
|
|
|
|
});
|
|
|
|
|
fixes.push(`Added fallback treasure ${dungeonData.treasure.length}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pad random events if needed
|
|
|
|
|
if (!dungeonData.randomEvents || dungeonData.randomEvents.length < 6) {
|
|
|
|
|
if (!dungeonData.randomEvents) dungeonData.randomEvents = [];
|
|
|
|
|
if (dungeonData.randomEvents.length > 0 && dungeonData.coreConcepts) {
|
|
|
|
|
const dynamicElement = dungeonData.coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences';
|
|
|
|
|
const conflict = dungeonData.coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat';
|
|
|
|
|
const fallbackEvents = [
|
|
|
|
|
{ name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` },
|
|
|
|
|
{ name: 'Conflict Manifestation', description: `A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.` },
|
|
|
|
|
{ name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` },
|
|
|
|
|
{ name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` },
|
|
|
|
|
{ name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` },
|
|
|
|
|
{ name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` }
|
|
|
|
|
];
|
|
|
|
|
while (dungeonData.randomEvents.length < 6) {
|
|
|
|
|
dungeonData.randomEvents.push(fallbackEvents[dungeonData.randomEvents.length % fallbackEvents.length]);
|
|
|
|
|
fixes.push(`Added fallback random event: "${dungeonData.randomEvents[dungeonData.randomEvents.length - 1].name}"`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pad plot resolutions if needed
|
|
|
|
|
if (!dungeonData.plotResolutions || dungeonData.plotResolutions.length < 4) {
|
|
|
|
|
if (!dungeonData.plotResolutions) dungeonData.plotResolutions = [];
|
|
|
|
|
while (dungeonData.plotResolutions.length < 4) {
|
|
|
|
|
dungeonData.plotResolutions.push(`The adventurers could resolve the central conflict through decisive action.`);
|
|
|
|
|
fixes.push(`Added fallback plot resolution ${dungeonData.plotResolutions.length}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fixes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixNarrativeCoherence(dungeonData) {
|
|
|
|
|
const fixes = [];
|
|
|
|
|
|
|
|
|
|
// Fix encounters referencing unknown locations
|
|
|
|
|
if (dungeonData.encounters && dungeonData.rooms) {
|
|
|
|
|
const roomNames = dungeonData.rooms.map(r => r.name.trim().toLowerCase());
|
|
|
|
|
dungeonData.encounters.forEach(encounter => {
|
|
|
|
|
if (!encounter.details) return;
|
|
|
|
|
const locationMatch = encounter.details.match(/^([^:]+):/);
|
|
|
|
|
if (locationMatch) {
|
|
|
|
|
const locName = locationMatch[1].trim().toLowerCase();
|
|
|
|
|
// Check if location matches any room name (fuzzy match)
|
|
|
|
|
const matches = roomNames.some(rn =>
|
|
|
|
|
locName === rn ||
|
|
|
|
|
locName.includes(rn) ||
|
|
|
|
|
rn.includes(locName) ||
|
|
|
|
|
locName.split(/\s+/).some(word => rn.includes(word))
|
|
|
|
|
);
|
|
|
|
|
if (!matches && roomNames.length > 0) {
|
|
|
|
|
// Assign to a random room
|
|
|
|
|
const roomIdx = Math.floor(Math.random() * roomNames.length);
|
|
|
|
|
const roomName = dungeonData.rooms[roomIdx].name;
|
|
|
|
|
encounter.details = encounter.details.replace(/^[^:]+:\s*/, `${roomName}: `);
|
|
|
|
|
fixes.push(`Fixed unknown location in encounter "${encounter.name}" to "${roomName}"`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fixes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function validateAndFixContent(dungeonData) {
|
|
|
|
|
const allFixes = [];
|
|
|
|
|
const allIssues = [];
|
|
|
|
|
@@ -439,6 +657,10 @@ function validateAndFixContent(dungeonData) {
|
|
|
|
|
const nameFixes = validateNameConsistency(dungeonData);
|
|
|
|
|
allFixes.push(...nameFixes);
|
|
|
|
|
|
|
|
|
|
// Fix structure issues (missing names, too long names)
|
|
|
|
|
const structureFixes = fixStructureIssues(dungeonData);
|
|
|
|
|
allFixes.push(...structureFixes);
|
|
|
|
|
|
|
|
|
|
// Standardize encounter locations and add missing ones
|
|
|
|
|
if (dungeonData.encounters && dungeonData.rooms) {
|
|
|
|
|
const roomNames = dungeonData.rooms.map(r => r.name.trim());
|
|
|
|
|
@@ -458,7 +680,15 @@ function validateAndFixContent(dungeonData) {
|
|
|
|
|
allFixes.push(...locationResult.fixes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run content validation
|
|
|
|
|
// Fix narrative coherence issues
|
|
|
|
|
const coherenceFixes = fixNarrativeCoherence(dungeonData);
|
|
|
|
|
allFixes.push(...coherenceFixes);
|
|
|
|
|
|
|
|
|
|
// Fix missing content (pad arrays)
|
|
|
|
|
const contentFixes = fixMissingContent(dungeonData);
|
|
|
|
|
allFixes.push(...contentFixes);
|
|
|
|
|
|
|
|
|
|
// Run content validation (for reporting remaining issues)
|
|
|
|
|
const completenessIssues = validateContentCompleteness(dungeonData);
|
|
|
|
|
const qualityIssues = validateContentQuality(dungeonData);
|
|
|
|
|
const structureIssues = validateContentStructure(dungeonData);
|
|
|
|
|
@@ -472,7 +702,7 @@ function validateAndFixContent(dungeonData) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (allIssues.length > 0) {
|
|
|
|
|
console.log("\n[Validation] Content quality issues found:");
|
|
|
|
|
console.log("\n[Validation] Content quality issues found (not auto-fixable):");
|
|
|
|
|
allIssues.forEach(issue => console.warn(` ⚠ ${issue}`));
|
|
|
|
|
} else {
|
|
|
|
|
console.log("\n[Validation] Content quality checks passed");
|
|
|
|
|
@@ -483,31 +713,24 @@ function validateAndFixContent(dungeonData) {
|
|
|
|
|
|
|
|
|
|
export async function generateDungeon() {
|
|
|
|
|
// Step 1: Titles
|
|
|
|
|
const generatedTitlesRaw = await callOllama(
|
|
|
|
|
`Generate 50 different and unique short, punchy dungeon titles (2-4 words maximum, single evocative name, no colons), numbered as a plain text list.
|
|
|
|
|
Each title should come from a different style or theme. Make the set varied and evocative. For example:
|
|
|
|
|
|
|
|
|
|
- OSR / classic tabletop: gritty, mysterious, old-school
|
|
|
|
|
- Mörk Borg: dark, apocalyptic, foreboding
|
|
|
|
|
- Pulpy fantasy: adventurous, dramatic, larger-than-life
|
|
|
|
|
- Mildly sci-fi: alien, technological, strange
|
|
|
|
|
- Weird fantasy: uncanny, surreal, unsettling
|
|
|
|
|
- Whimsical: fun, quirky, playful
|
|
|
|
|
|
|
|
|
|
CRITICAL: Ensure all spelling is correct. Double-check all words before outputting.
|
|
|
|
|
Avoid repeating materials or adjectives. Absolutely do not use the words "Obsidian" or "Clockwork" in any title. Do not include explanations, markdown, or preambles. Do not include the style or theme in parenthesis. Only the 50 numbered titles.`,
|
|
|
|
|
const generatedTitles = await callOllama(
|
|
|
|
|
`Generate 50 short, punchy dungeon titles (max 5 words each), numbered as a plain text list.
|
|
|
|
|
Each title should come from a different style or theme. Make the set varied and evocative. For example:
|
|
|
|
|
|
|
|
|
|
- OSR / classic tabletop: gritty, mysterious, old-school
|
|
|
|
|
- Mörk Borg: dark, apocalyptic, foreboding
|
|
|
|
|
- Pulpy fantasy: adventurous, dramatic, larger-than-life
|
|
|
|
|
- Mildly sci-fi: alien, technological, strange
|
|
|
|
|
- Weird fantasy: uncanny, surreal, unsettling
|
|
|
|
|
- Whimsical: fun, quirky, playful
|
|
|
|
|
|
|
|
|
|
CRITICAL: Ensure all spelling is correct. Double-check all words before outputting.
|
|
|
|
|
Avoid repeating materials or adjectives. Absolutely do not use the words "Obsidian" or "Clockwork" in any title. Do not include explanations, markdown, or preambles. Do not include the style or theme in parenthesis. Only the 50 numbered titles.`,
|
|
|
|
|
undefined, 5, "Step 1: Titles"
|
|
|
|
|
);
|
|
|
|
|
const generatedTitles = parseList(generatedTitlesRaw);
|
|
|
|
|
console.log("Generated Titles:", generatedTitles);
|
|
|
|
|
let title = generatedTitles[Math.floor(Math.random() * generatedTitles.length)];
|
|
|
|
|
// Remove colons, dashes, and other separators, but keep the full title
|
|
|
|
|
title = title.split(/[:—–-]/)[0].trim();
|
|
|
|
|
// Only limit to 4 words if it's clearly too long (more than 6 words)
|
|
|
|
|
const titleWords = title.split(/\s+/);
|
|
|
|
|
if (titleWords.length > 6) {
|
|
|
|
|
title = titleWords.slice(0, 4).join(' ');
|
|
|
|
|
}
|
|
|
|
|
const titlesList = parseList(generatedTitles);
|
|
|
|
|
const title = titlesList[Math.floor(Math.random() * titlesList.length)];
|
|
|
|
|
console.log("Selected title:", title);
|
|
|
|
|
|
|
|
|
|
// Step 2: Core Concepts
|
|
|
|
|
@@ -669,13 +892,14 @@ EXAMPLE TREASURE:
|
|
|
|
|
"Whispering Blade — This dagger amplifies the wielder's voice to a deafening roar when drawn. Found in the Guardian Golem's chamber, it was used to command the construct. The blade is cursed: each use permanently reduces the wielder's hearing. Can be used to shatter glass or stun enemies, but the curse cannot be removed."
|
|
|
|
|
|
|
|
|
|
- **Strictly 1 Random Events Table:** A d6 table (EXACTLY 6 entries, no more, no less) with random events/wandering encounters. Each entry MUST:
|
|
|
|
|
- Have a short, evocative event name (max 4 words)
|
|
|
|
|
- Provide interesting complications or opportunities (not just combat)
|
|
|
|
|
- Tie to the core concepts and dynamic element
|
|
|
|
|
- Add replayability and surprise
|
|
|
|
|
- Be 15-20 words maximum
|
|
|
|
|
- Description should be 15-20 words maximum
|
|
|
|
|
- Be UNIQUE and DIFFERENT from each other (no duplicates or generic placeholders)
|
|
|
|
|
- Be SPECIFIC to this dungeon's theme, conflict, and dynamic element
|
|
|
|
|
Format as numbered 1-6 list under "Random Events:" label. Each event must be a complete, interesting sentence describing what happens.
|
|
|
|
|
Format as numbered 1-6 list under "Random Events:" label. Each event must be formatted as "Event Name: Description text" using colons, NOT em-dashes.
|
|
|
|
|
|
|
|
|
|
CRITICAL: Each item must be on its own numbered line. DO NOT combine multiple items into a single numbered entry.
|
|
|
|
|
|
|
|
|
|
@@ -706,16 +930,23 @@ Treasures:
|
|
|
|
|
4. Actual Item Name — Description text.
|
|
|
|
|
|
|
|
|
|
Random Events:
|
|
|
|
|
1. Event description.
|
|
|
|
|
2. Event description.
|
|
|
|
|
3. Event description.
|
|
|
|
|
4. Event description.
|
|
|
|
|
5. Event description.
|
|
|
|
|
6. Event description.
|
|
|
|
|
1. Event Name: Event description.
|
|
|
|
|
2. Event Name: Event description.
|
|
|
|
|
3. Event Name: Event description.
|
|
|
|
|
4. Event Name: Event description.
|
|
|
|
|
5. Event Name: Event description.
|
|
|
|
|
6. Event Name: Event description.
|
|
|
|
|
|
|
|
|
|
CRITICAL: Every name must be unique and creative. Never use generic placeholders like "Location Name", "NPC Name", "Encounter Name", or "Treasure Name". Use actual descriptive names that fit the dungeon's theme.
|
|
|
|
|
|
|
|
|
|
CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns, character names, and location names. Verify consistency of names across all sections.
|
|
|
|
|
|
|
|
|
|
CRITICAL: Location name matching - When writing encounters, the location name in the encounter details MUST exactly match one of the room names you've created (Entrance Room, Climax Room, or one of the 3 Locations). Double-check that every encounter location matches an actual room name.
|
|
|
|
|
|
|
|
|
|
CRITICAL: Avoid vague language - Do not use words like "some", "various", "several", "many", "few", "things", "stuff", "items", or "objects" without specific details. Be concrete and specific in all descriptions.
|
|
|
|
|
|
|
|
|
|
CRITICAL: All names required - Every room, encounter, NPC, and treasure MUST have a name. Do not leave names blank or use placeholders. If you cannot think of a name, create one based on the dungeon's theme.
|
|
|
|
|
|
|
|
|
|
CRITICAL: You MUST output exactly five separate sections with these exact labels on their own lines:
|
|
|
|
|
"Locations:"
|
|
|
|
|
"Encounters:"
|
|
|
|
|
@@ -773,7 +1004,20 @@ Each section must start with its label on its own line, followed by numbered ite
|
|
|
|
|
if (intermediateRooms.length > 3) {
|
|
|
|
|
console.warn(`Expected exactly 3 intermediate locations but got ${intermediateRooms.length}, limiting to first 3`);
|
|
|
|
|
}
|
|
|
|
|
const rooms = [entranceRoom, ...limitedIntermediateRooms, climaxRoom];
|
|
|
|
|
|
|
|
|
|
// Deduplicate rooms by name (case-insensitive), keeping first occurrence
|
|
|
|
|
const allRooms = [entranceRoom, ...limitedIntermediateRooms, climaxRoom].filter(Boolean);
|
|
|
|
|
const seenNames = new Set();
|
|
|
|
|
const rooms = allRooms.filter(room => {
|
|
|
|
|
if (!room || !room.name) return false;
|
|
|
|
|
const nameLower = room.name.toLowerCase().trim();
|
|
|
|
|
if (seenNames.has(nameLower)) {
|
|
|
|
|
console.warn(`Duplicate room name detected: "${room.name}", skipping duplicate`);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
seenNames.add(nameLower);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
let encounters = splitCombinedEncounters(parseObjects(encountersSection || "", "encounters"));
|
|
|
|
|
let npcs = parseObjects(npcsSection || "", "npcs");
|
|
|
|
|
const treasure = parseObjects(treasureSection || "", "treasure");
|
|
|
|
|
@@ -823,7 +1067,7 @@ Each section must start with its label on its own line, followed by numbered ite
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let randomEvents = parseList(randomEventsSection || "");
|
|
|
|
|
// Filter out placeholder events and strip any title prefixes
|
|
|
|
|
// Parse events into objects with name and description
|
|
|
|
|
randomEvents = randomEvents
|
|
|
|
|
.filter(e =>
|
|
|
|
|
e &&
|
|
|
|
|
@@ -832,28 +1076,35 @@ Each section must start with its label on its own line, followed by numbered ite
|
|
|
|
|
!e.toLowerCase().includes('placeholder') &&
|
|
|
|
|
e.length > 10
|
|
|
|
|
)
|
|
|
|
|
.map(e => {
|
|
|
|
|
// Strip title prefixes like "Event 1:", "Random Event:", "Guardian Golem:", "Location Name:", etc.
|
|
|
|
|
// Remove numbered prefixes, random event labels, and location/encounter name prefixes
|
|
|
|
|
.map((e, index) => {
|
|
|
|
|
// Strip numbered prefixes like "Event 1:", "Random Event:", etc.
|
|
|
|
|
let cleaned = e.replace(/^(Event\s+\d+[:\s]+|Random\s+Event[:\s]+|Random\s+Events?[:\s]+)/i, '').trim();
|
|
|
|
|
// Remove location/encounter name prefixes (format: "Name: Location: description" or "Name: description")
|
|
|
|
|
// If it starts with a capitalized phrase followed by colon, it might be a title
|
|
|
|
|
const titleMatch = cleaned.match(/^([A-Z][^:]{3,40}):\s*(.+)$/);
|
|
|
|
|
if (titleMatch) {
|
|
|
|
|
const potentialTitle = titleMatch[1];
|
|
|
|
|
const rest = titleMatch[2];
|
|
|
|
|
// If the rest also has a colon, the first part is likely a title to remove
|
|
|
|
|
if (rest.includes(':')) {
|
|
|
|
|
cleaned = rest;
|
|
|
|
|
} else {
|
|
|
|
|
// Check if it looks like a location name (common patterns)
|
|
|
|
|
if (potentialTitle.match(/\b(Chamber|Room|Tower|Hall|Temple|Shrine|Crypt|Tomb|Vault|Gate|Bridge|Path|Corridor|Labyrinth|Dungeon|Cavern|Cave|Grotto|Sanctum|Shrine|Altar|Pit|Well|Pool|Fountain|Garden|Courtyard|Plaza|Square|Arena|Colosseum|Theater|Library|Laboratory|Workshop|Forge|Smithy|Barracks|Armory|Treasury|Storehouse|Warehouse|Cellar|Basement|Attic|Loft|Garret|Turret|Spire|Keep|Fortress|Castle|Palace|Manor|Mansion|Estate|Villa|Cottage|Hut|Shack|Tent|Pavilion|Gazebo|Pergola|Arbor|Bower|Grotto|Grot|Den|Lair|Nest|Burrow|Hollow|Recess|Niche|Alcove|Cubby|Cubbyhole|Closet|Wardrobe|Cupboard|Cabinet|Drawer|Shelf|Rack|Peg|Hook|Nail|Screw|Bolt|Rivet|Pin|Clip|Clamp|Brace|Bracket|Support|Prop|Pillar|Column|Post|Pole|Rod|Stick|Staff|Wand|Scepter|Mace|Club|Hammer|Axe|Sword|Dagger|Knife|Blade|Edge|Point|Tip|End|Top|Bottom|Side|Front|Back|Left|Right|Center|Middle|Core|Heart|Soul|Spirit|Mind|Body|Head|Neck|Chest|Torso|Waist|Hip|Thigh|Knee|Leg|Foot|Toe|Heel|Ankle|Shin|Calf|Thigh|Buttock|Backside|Rear|Behind|Aft|Stern|Bow|Port|Starboard|Fore|Aft|Midship|Amidship|Amidships|Amidship|Amidships)\b/i)) {
|
|
|
|
|
cleaned = rest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse "Event Name: Description" format
|
|
|
|
|
const colonMatch = cleaned.match(/^([^:]+):\s*(.+)$/);
|
|
|
|
|
if (colonMatch) {
|
|
|
|
|
const name = colonMatch[1].trim();
|
|
|
|
|
const description = colonMatch[2].trim();
|
|
|
|
|
// Skip if name looks like a placeholder
|
|
|
|
|
if (name.toLowerCase().includes('event name') || name.toLowerCase().includes('placeholder')) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return { name, description };
|
|
|
|
|
}
|
|
|
|
|
return cleaned.trim();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Fallback: if no colon, use first few words as name
|
|
|
|
|
const words = cleaned.split(/\s+/);
|
|
|
|
|
if (words.length > 3) {
|
|
|
|
|
return {
|
|
|
|
|
name: words.slice(0, 2).join(' '),
|
|
|
|
|
description: words.slice(2).join(' ')
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last resort: use as description with generic name
|
|
|
|
|
return { name: `Event ${index + 1}`, description: cleaned };
|
|
|
|
|
})
|
|
|
|
|
.filter(Boolean); // Remove null entries
|
|
|
|
|
randomEvents = randomEvents.slice(0, 6);
|
|
|
|
|
|
|
|
|
|
// Generate context-aware fallbacks if needed (only if we have some events already)
|
|
|
|
|
@@ -861,12 +1112,12 @@ Each section must start with its label on its own line, followed by numbered ite
|
|
|
|
|
const dynamicElement = coreConcepts.match(/Dynamic Element[:\s]+([^.]+)/i)?.[1]?.trim() || 'strange occurrences';
|
|
|
|
|
const conflict = coreConcepts.match(/Central Conflict[:\s]+([^.]+)/i)?.[1]?.trim() || 'a mysterious threat';
|
|
|
|
|
const fallbackEvents = [
|
|
|
|
|
`The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.`,
|
|
|
|
|
`A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.`,
|
|
|
|
|
`The dungeon shifts, revealing a previously hidden passage or danger.`,
|
|
|
|
|
`An NPC from the primary faction appears with urgent information.`,
|
|
|
|
|
`The power source fluctuates, creating temporary hazards or opportunities.`,
|
|
|
|
|
`Echoes of past events manifest, providing clues or complications.`
|
|
|
|
|
{ name: 'Environmental Shift', description: `The ${dynamicElement.toLowerCase()} causes unexpected changes in the environment.` },
|
|
|
|
|
{ name: 'Conflict Manifestation', description: `A sign of ${conflict.toLowerCase()} appears, requiring immediate attention.` },
|
|
|
|
|
{ name: 'Dungeon Shift', description: `The dungeon shifts, revealing a previously hidden passage or danger.` },
|
|
|
|
|
{ name: 'Faction Messenger', description: `An NPC from the primary faction appears with urgent information.` },
|
|
|
|
|
{ name: 'Power Fluctuation', description: `The power source fluctuates, creating temporary hazards or opportunities.` },
|
|
|
|
|
{ name: 'Echoes of the Past', description: `Echoes of past events manifest, providing clues or complications.` }
|
|
|
|
|
];
|
|
|
|
|
while (randomEvents.length < 6) {
|
|
|
|
|
randomEvents.push(fallbackEvents[randomEvents.length % fallbackEvents.length]);
|
|
|
|
|
|