Spaces:
Running
Running
Update index.html
Browse files- index.html +531 -113
index.html
CHANGED
|
@@ -112,14 +112,11 @@
|
|
| 112 |
.choice-button:hover:not(:disabled) { background-color: #d4a017; color: #222; border-color: #b8860b; }
|
| 113 |
.choice-button:disabled { background-color: #444; color: #888; cursor: not-allowed; border-color: #666; opacity: 0.7; }
|
| 114 |
|
| 115 |
-
/* Optional Roll Result Styling */
|
| 116 |
.roll-success { color: #7f7; border-left: 3px solid #4a4; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
|
| 117 |
.roll-failure { color: #f77; border-left: 3px solid #a44; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
|
| 118 |
-
|
| 119 |
</style>
|
| 120 |
</head>
|
| 121 |
<body>
|
| 122 |
-
|
| 123 |
<div id="game-container">
|
| 124 |
<div id="scene-container"></div>
|
| 125 |
<div id="ui-container">
|
|
@@ -149,8 +146,6 @@
|
|
| 149 |
|
| 150 |
<script type="module">
|
| 151 |
import * as THREE from 'three';
|
| 152 |
-
// Optional: Add OrbitControls for debugging/viewing scene
|
| 153 |
-
// import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 154 |
|
| 155 |
const sceneContainer = document.getElementById('scene-container');
|
| 156 |
const storyTitleElement = document.getElementById('story-title');
|
|
@@ -162,6 +157,7 @@
|
|
| 162 |
let scene, camera, renderer;
|
| 163 |
let currentAssemblyGroup = null;
|
| 164 |
|
|
|
|
| 165 |
const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x888888, roughness: 0.8, metalness: 0.1 });
|
| 166 |
const woodMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513, roughness: 0.7, metalness: 0 });
|
| 167 |
const darkWoodMaterial = new THREE.MeshStandardMaterial({ color: 0x5C3D20, roughness: 0.7, metalness: 0 });
|
|
@@ -171,6 +167,12 @@
|
|
| 171 |
const templeMaterial = new THREE.MeshStandardMaterial({ color: 0xA99B78, roughness: 0.7, metalness: 0.1 });
|
| 172 |
const errorMaterial = new THREE.MeshStandardMaterial({ color: 0xffa500, roughness: 0.5 });
|
| 173 |
const gameOverMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000, roughness: 0.5 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
function initThreeJS() {
|
| 176 |
if (!sceneContainer) { console.error("Scene container not found!"); return; }
|
|
@@ -188,17 +190,6 @@
|
|
| 188 |
sceneContainer.appendChild(renderer.domElement);
|
| 189 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
| 190 |
scene.add(ambientLight);
|
| 191 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
|
| 192 |
-
directionalLight.position.set(8, 15, 10);
|
| 193 |
-
directionalLight.castShadow = true;
|
| 194 |
-
directionalLight.shadow.mapSize.width = 1024;
|
| 195 |
-
directionalLight.shadow.mapSize.height = 1024;
|
| 196 |
-
directionalLight.shadow.camera.near = 0.5;
|
| 197 |
-
directionalLight.shadow.camera.far = 50;
|
| 198 |
-
const shadowCamSize = 15;
|
| 199 |
-
directionalLight.shadow.camera.left = -shadowCamSize; directionalLight.shadow.camera.right = shadowCamSize;
|
| 200 |
-
directionalLight.shadow.camera.top = shadowCamSize; directionalLight.shadow.camera.bottom = -shadowCamSize;
|
| 201 |
-
scene.add(directionalLight);
|
| 202 |
window.addEventListener('resize', onWindowResize, false);
|
| 203 |
setTimeout(onWindowResize, 100);
|
| 204 |
animate();
|
|
@@ -217,7 +208,10 @@
|
|
| 217 |
|
| 218 |
function animate() {
|
| 219 |
requestAnimationFrame(animate);
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
| 221 |
if (renderer && scene && camera) {
|
| 222 |
renderer.render(scene, camera);
|
| 223 |
}
|
|
@@ -240,33 +234,355 @@
|
|
| 240 |
return ground;
|
| 241 |
}
|
| 242 |
|
| 243 |
-
//
|
| 244 |
-
function createDefaultAssembly() {
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
function
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
const gameData = {
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
"10": { title: "Goblin Ambush!", content: `<p>Two scraggly goblins leap out, brandishing crude spears!</p>`, options: [ { text: "Fight the goblins!", next: 12 }, { text: "Attempt to dodge past them (Dexterity Check)", check: { stat: 'dexterity', dc: 13, onFailure: 10 }, next: 13 } ], illustration: "two-goblins-ambush-forest-path-spears" },
|
| 268 |
"11": { title: "Hidden Evasion", content: `<p>You melt into the shadows as the goblins blunder past.</p><p>(+30 XP)</p>`, options: [ { text: "Continue cautiously", next: 14 } ], illustration: "forest-shadows-hiding-goblins-walking-past", reward: { xp: 30 } },
|
| 269 |
-
"12": { title: "Ambush Victory!", content: `<p>You defeat the goblins! Found a Crude Dagger.</p><p>(+50 XP)</p>`, options: [ { text: "Press onward", next: 14 } ], illustration: "defeated-goblins-forest-path-loot", reward: { xp: 50, addItem: "Crude Dagger" } },
|
| 270 |
"13": { title: "Daring Escape", content: `<p>With surprising agility, you tumble past the goblins!</p><p>(+25 XP)</p>`, options: [ { text: "Keep running!", next: 14 } ], illustration: "blurred-motion-running-past-goblins-forest", reward: { xp: 25 } },
|
| 271 |
"14": { title: "Forest Stream Crossing", content: `<p>The path leads to a clear, shallow stream...</p>`, options: [ { text: "Wade across the stream", next: 16 }, { text: "Look for a drier crossing point (fallen log?)", next: 15 } ], illustration: "forest-stream-crossing-dappled-sunlight-stones" },
|
| 272 |
"15": { title: "Log Bridge", content: `<p>Further upstream, a large, mossy log spans the stream.</p>`, options: [ { text: "Cross carefully on the log (Dexterity Check)", check: { stat: 'dexterity', dc: 9, onFailure: 151 }, next: 16 }, { text: "Go back and wade instead", next: 14 } ], illustration: "mossy-log-bridge-over-forest-stream" },
|
|
@@ -280,21 +596,19 @@
|
|
| 280 |
"31": { title: "Tumbled Down", content: `<p>You lose your footing... landing hard on the sandy cove floor. You lose 5 HP. A dark cave entrance beckons.</p>`, options: [ { text: "Gingerly explore the dark cave", next: 35 } ], illustration: "character-fallen-at-bottom-of-cliff-path-cove", hpLoss: 5 },
|
| 281 |
"32": { title: "No Easier Path", content: `<p>You scan the cliffs intently but find no obviously easier routes.</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 } ], illustration: "scanning-sea-cliffs-no-other-paths-visible" },
|
| 282 |
"33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot a series of barely visible handholds and steps carved into the rock...</p><p>(+15 XP)</p>`, options: [ { text: "Use the hidden steps (Easier Dex Check)", check: { stat: 'dexterity', dc: 8, onFailure: 31 }, next: 30 } ], illustration: "close-up-handholds-carved-in-cliff-face", reward: { xp: 15 } },
|
| 283 |
-
"35": { title: "Dark Cave", content: `<p>The cave smells of salt and decay. Water drips somewhere within.</p>`, options: [{ text: "Press deeper into the darkness", next: 99 } ], illustration: "dark-cave-entrance-dripping-water" },
|
| 284 |
"40": { title: "Overgrown Shrine", content: `<p>Wildflowers grow thick around a small stone shrine. It feels ancient and neglected.</p>`, options: [{ text: "Examine the carvings (Intelligence Check)", check:{stat:'intelligence', dc:11, onFailure: 401}, next: 400 } ], illustration: "overgrown-stone-shrine-wildflowers-close" },
|
| 285 |
-
"41": { title: "Rocky Badlands", content: `<p>The green hills give way to cracked earth and jagged rock formations under a harsh sun.</p>`, options: [{ text: "Scout ahead", next: 99 } ], illustration: "rocky-badlands-cracked-earth-harsh-sun" },
|
| 286 |
-
// Add pages 70-73, 80-82, 190-192, 21, 22, 400, 401 etc.
|
| 287 |
"190": { title: "Over the Rocks", content:"<p>With considerable effort, you manage to climb over the rockslide.</p><p>(+35 XP)</p>", options: [{text:"Continue up the path", next: 22}], illustration:"character-climbing-over-boulders", reward: {xp:35} },
|
| 288 |
"191": { title: "Climb Fails", content:"<p>The boulders are too unstable or sheer. You cannot climb them safely.</p>", options: [{text:"Search for another way around", next: 192}], illustration:"character-slipping-on-rockslide-boulders"},
|
| 289 |
"192": { title: "Detour Found", content:"<p>After some searching, you find a rough path leading around the rockslide, eventually rejoining the main trail.</p>", options: [{text:"Continue up the path", next: 22}], illustration:"rough-detour-path-around-rockslide"},
|
| 290 |
"21": { title: "Western Ridge", content:"<p>The ridge path is narrow and exposed, with strong winds threatening to push you off.</p>", options: [{text:"Proceed carefully (Dexterity Check)", check:{stat:'dexterity', dc: 14, onFailure: 211}, next: 22 } ], illustration:"narrow-windy-mountain-ridge-path" },
|
| 291 |
-
"22": { title: "Fortress Approach", content:"<p>You've navigated the treacherous paths and now stand near the outer walls of the dark fortress. Guards patrol the battlements.</p>", options: [{text:"Look for an unguarded entrance", next: 99}], illustration:"approaching-dark-fortress-walls-guards"},
|
| 292 |
"211": {title:"Lost Balance", content:"<p>A strong gust of wind catches you off guard, sending you tumbling down a steep slope! You lose 10 HP.</p>", options:[{text:"Climb back up and find another way", next: 17}], illustration:"character-falling-off-windy-ridge", hpLoss: 10},
|
| 293 |
-
|
| 294 |
"99": { title: "Game Over / To Be Continued...", content: "<p>Your adventure ends here (for now).</p>", options: [{ text: "Restart", next: 1 }], illustration: "game-over-generic", gameOver: true }
|
| 295 |
};
|
| 296 |
|
| 297 |
-
//
|
| 298 |
let gameState = {
|
| 299 |
currentPageId: 1,
|
| 300 |
character: {
|
|
@@ -305,12 +619,10 @@
|
|
| 305 |
}
|
| 306 |
};
|
| 307 |
|
| 308 |
-
//
|
| 309 |
function startGame() {
|
| 310 |
const defaultChar = { name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer", level: 1, xp: 0, xpToNextLevel: 100, stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 }, inventory: [] };
|
| 311 |
-
gameState = { currentPageId: 1, character: { ...defaultChar } };
|
| 312 |
-
// Potential load logic could go here later:
|
| 313 |
-
// if (loadCharacter()) { console.log("Loaded saved game."); }
|
| 314 |
renderPage(gameState.currentPageId);
|
| 315 |
}
|
| 316 |
|
|
@@ -319,7 +631,7 @@
|
|
| 319 |
const itemToAdd = choiceData.addItem;
|
| 320 |
let nextPageId = optionNextPageId;
|
| 321 |
let rollResultMessage = "";
|
| 322 |
-
const check = choiceData.check;
|
| 323 |
|
| 324 |
if (isNaN(optionNextPageId) && !check) { console.error("Invalid choice data:", choiceData); return; }
|
| 325 |
|
|
@@ -331,10 +643,10 @@
|
|
| 331 |
const dc = check.dc;
|
| 332 |
console.log(`Check: ${check.stat} (DC ${dc}) | Roll: ${roll} + Mod: ${modifier} = ${totalResult}`);
|
| 333 |
if (totalResult >= dc) {
|
| 334 |
-
nextPageId = optionNextPageId;
|
| 335 |
rollResultMessage = `<p class="roll-success"><em>Check Success! (${totalResult} vs DC ${dc})</em></p>`;
|
| 336 |
} else {
|
| 337 |
-
nextPageId = parseInt(check.onFailure);
|
| 338 |
rollResultMessage = `<p class="roll-failure"><em>Check Failed! (${totalResult} vs DC ${dc})</em></p>`;
|
| 339 |
if (isNaN(nextPageId)) { console.error("Invalid onFailure ID:", check.onFailure); nextPageId = 99; }
|
| 340 |
}
|
|
@@ -352,24 +664,30 @@
|
|
| 352 |
if (nextPageData.hpLoss) {
|
| 353 |
gameState.character.stats.hp -= nextPageData.hpLoss;
|
| 354 |
console.log(`Lost ${nextPageData.hpLoss} HP.`);
|
| 355 |
-
if (gameState.character.stats.hp <= 0) { gameState.character.stats.hp = 0; console.log("Player died!"); nextPageId = 99;
|
| 356 |
}
|
| 357 |
if (nextPageData.reward) {
|
| 358 |
if (nextPageData.reward.xp) { gameState.character.xp += nextPageData.reward.xp; console.log(`Gained ${nextPageData.reward.xp} XP! Total: ${gameState.character.xp}`); }
|
| 359 |
-
if (nextPageData.reward.statIncrease) {
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
}
|
| 362 |
-
// Recalculate max HP based on CON after potential stat changes
|
| 363 |
-
const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
| 364 |
-
// Example Max HP calculation: Base + CON modifier per level
|
| 365 |
-
gameState.character.stats.maxHp = 10 + (conModifier * gameState.character.level); // Adjust base 10 as needed
|
| 366 |
-
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp); // Clamp HP
|
| 367 |
-
|
| 368 |
-
// Handle forced game over from HP loss
|
| 369 |
-
if (nextPageId === 99 && gameState.character.stats.hp <= 0) {
|
| 370 |
-
renderPageInternal(99, gameData[99], rollResultMessage);
|
| 371 |
-
return;
|
| 372 |
-
}
|
| 373 |
} else {
|
| 374 |
console.error(`Data for page ${nextPageId} not found!`);
|
| 375 |
renderPageInternal(99, gameData[99], "<p><em>Error: Next page data missing!</em></p>");
|
|
@@ -379,29 +697,71 @@
|
|
| 379 |
}
|
| 380 |
|
| 381 |
function renderPageInternal(pageId, pageData, message = "") {
|
| 382 |
-
if (!pageData) { console.error(`Render Error: No data for page ${pageId}`); return; }
|
| 383 |
storyTitleElement.textContent = pageData.title || "Untitled Page";
|
| 384 |
storyContentElement.innerHTML = message + (pageData.content || "<p>...</p>");
|
| 385 |
-
updateStatsDisplay();
|
|
|
|
| 386 |
choicesElement.innerHTML = '';
|
| 387 |
if (pageData.options && pageData.options.length > 0) {
|
| 388 |
pageData.options.forEach(option => {
|
| 389 |
-
const button = document.createElement('button');
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
updateScene(pageData.illustration || 'default');
|
| 394 |
}
|
| 395 |
|
| 396 |
function renderPage(pageId) { renderPageInternal(pageId, gameData[pageId]); }
|
| 397 |
|
| 398 |
-
function updateStatsDisplay() {
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
function updateScene(illustrationKey) {
|
| 402 |
-
// console.log(`Updating scene to: ${illustrationKey}`); // Minimal log
|
| 403 |
if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); }
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
switch (illustrationKey) {
|
| 406 |
case 'city-gates': assemblyFunction = createCityGatesAssembly; break;
|
| 407 |
case 'weaponsmith': assemblyFunction = createWeaponsmithAssembly; break;
|
|
@@ -411,57 +771,115 @@
|
|
| 411 |
case 'road-ambush': assemblyFunction = createRoadAmbushAssembly; break;
|
| 412 |
case 'forest-edge': assemblyFunction = createForestEdgeAssembly; break;
|
| 413 |
case 'prisoner-cell': assemblyFunction = createPrisonerCellAssembly; break;
|
| 414 |
-
case 'game-over': case 'game-over-generic': assemblyFunction = createGameOverAssembly; break;
|
| 415 |
case 'error': assemblyFunction = createErrorAssembly; break;
|
| 416 |
-
case 'crossroads-signpost-sunny':
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
case 'rolling-green-hills-shepherd-distance':
|
|
|
|
|
|
|
|
|
|
| 418 |
case 'windy-sea-cliffs-crashing-waves-path-down':
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
| 420 |
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
|
|
|
|
|
|
|
|
|
| 421 |
case 'overgrown-forest-path-glowing-fungi-vines':
|
|
|
|
|
|
|
|
|
|
| 422 |
case 'forest-clearing-mossy-statue-weathered-stone':
|
| 423 |
-
|
|
|
|
|
|
|
| 424 |
case 'two-goblins-ambush-forest-path-spears':
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
case 'forest-stream-crossing-dappled-sunlight-stones':
|
| 429 |
-
case 'mossy-log-bridge-over-forest-stream':
|
| 430 |
-
case 'character-splashing-into-stream-from-log':
|
| 431 |
-
case 'forest-edge-view-rocky-foothills-distant-mountain-fortress':
|
| 432 |
-
case 'climbing-rocky-foothills-path-fortress-closer':
|
| 433 |
-
case 'zoomed-view-mountain-fortress-western-ridge':
|
| 434 |
-
case 'rockslide-blocking-mountain-path-boulders':
|
| 435 |
-
case 'narrow-goat-trail-mountainside-fortress-view':
|
| 436 |
case 'hidden-cove-beach-dark-cave-entrance':
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
|
|
|
| 440 |
case 'dark-cave-entrance-dripping-water':
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
case 'rough-detour-path-around-rockslide':
|
| 446 |
-
case 'narrow-windy-mountain-ridge-path':
|
| 447 |
-
case 'approaching-dark-fortress-walls-guards':
|
| 448 |
-
case 'character-falling-off-windy-ridge':
|
| 449 |
-
// Add specific assembly functions for these later or assign existing ones
|
| 450 |
-
console.warn(`Assembly function not yet defined for: "${illustrationKey}". Using default.`);
|
| 451 |
-
assemblyFunction = createDefaultAssembly; break;
|
| 452 |
default:
|
| 453 |
console.warn(`Unknown illustration key: "${illustrationKey}". Using default.`);
|
| 454 |
assemblyFunction = createDefaultAssembly; break;
|
| 455 |
}
|
| 456 |
-
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
}
|
| 458 |
|
| 459 |
document.addEventListener('DOMContentLoaded', () => {
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
});
|
| 463 |
-
|
| 464 |
</script>
|
| 465 |
-
|
| 466 |
</body>
|
| 467 |
</html>
|
|
|
|
| 112 |
.choice-button:hover:not(:disabled) { background-color: #d4a017; color: #222; border-color: #b8860b; }
|
| 113 |
.choice-button:disabled { background-color: #444; color: #888; cursor: not-allowed; border-color: #666; opacity: 0.7; }
|
| 114 |
|
|
|
|
| 115 |
.roll-success { color: #7f7; border-left: 3px solid #4a4; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
|
| 116 |
.roll-failure { color: #f77; border-left: 3px solid #a44; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
|
|
|
|
| 117 |
</style>
|
| 118 |
</head>
|
| 119 |
<body>
|
|
|
|
| 120 |
<div id="game-container">
|
| 121 |
<div id="scene-container"></div>
|
| 122 |
<div id="ui-container">
|
|
|
|
| 146 |
|
| 147 |
<script type="module">
|
| 148 |
import * as THREE from 'three';
|
|
|
|
|
|
|
| 149 |
|
| 150 |
const sceneContainer = document.getElementById('scene-container');
|
| 151 |
const storyTitleElement = document.getElementById('story-title');
|
|
|
|
| 157 |
let scene, camera, renderer;
|
| 158 |
let currentAssemblyGroup = null;
|
| 159 |
|
| 160 |
+
// Materials
|
| 161 |
const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x888888, roughness: 0.8, metalness: 0.1 });
|
| 162 |
const woodMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513, roughness: 0.7, metalness: 0 });
|
| 163 |
const darkWoodMaterial = new THREE.MeshStandardMaterial({ color: 0x5C3D20, roughness: 0.7, metalness: 0 });
|
|
|
|
| 167 |
const templeMaterial = new THREE.MeshStandardMaterial({ color: 0xA99B78, roughness: 0.7, metalness: 0.1 });
|
| 168 |
const errorMaterial = new THREE.MeshStandardMaterial({ color: 0xffa500, roughness: 0.5 });
|
| 169 |
const gameOverMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000, roughness: 0.5 });
|
| 170 |
+
const dirtMaterial = new THREE.MeshStandardMaterial({ color: 0x8B5E3C, roughness: 0.9 });
|
| 171 |
+
const grassMaterial = new THREE.MeshStandardMaterial({ color: 0x3CB371, roughness: 0.8 });
|
| 172 |
+
const oceanMaterial = new THREE.MeshStandardMaterial({ color: 0x1E90FF, roughness: 0.5, metalness: 0.2 });
|
| 173 |
+
const sandMaterial = new THREE.MeshStandardMaterial({ color: 0xF4A460, roughness: 0.9 });
|
| 174 |
+
const wetStoneMaterial = new THREE.MeshStandardMaterial({ color: 0x2F4F4F, roughness: 0.7 });
|
| 175 |
+
const glowMaterial = new THREE.MeshStandardMaterial({ color: 0x00FFAA, emissive: 0x00FFAA, emissiveIntensity: 0.5 });
|
| 176 |
|
| 177 |
function initThreeJS() {
|
| 178 |
if (!sceneContainer) { console.error("Scene container not found!"); return; }
|
|
|
|
| 190 |
sceneContainer.appendChild(renderer.domElement);
|
| 191 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
| 192 |
scene.add(ambientLight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
window.addEventListener('resize', onWindowResize, false);
|
| 194 |
setTimeout(onWindowResize, 100);
|
| 195 |
animate();
|
|
|
|
| 208 |
|
| 209 |
function animate() {
|
| 210 |
requestAnimationFrame(animate);
|
| 211 |
+
const time = performance.now() * 0.001;
|
| 212 |
+
scene.traverse(obj => {
|
| 213 |
+
if (obj.userData.update) obj.userData.update(time);
|
| 214 |
+
});
|
| 215 |
if (renderer && scene && camera) {
|
| 216 |
renderer.render(scene, camera);
|
| 217 |
}
|
|
|
|
| 234 |
return ground;
|
| 235 |
}
|
| 236 |
|
| 237 |
+
// Procedural Generation Functions
|
| 238 |
+
function createDefaultAssembly() {
|
| 239 |
+
const group = new THREE.Group();
|
| 240 |
+
const sphereGeo = new THREE.SphereGeometry(0.5, 16, 16);
|
| 241 |
+
group.add(createMesh(sphereGeo, stoneMaterial, { x: 0, y: 0.5, z: 0 }));
|
| 242 |
+
group.add(createGroundPlane());
|
| 243 |
+
return group;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
function createCityGatesAssembly() {
|
| 247 |
+
const group = new THREE.Group();
|
| 248 |
+
const gh=4, gw=1.5, gd=0.8, ah=1, aw=3;
|
| 249 |
+
const tlGeo = new THREE.BoxGeometry(gw, gh, gd);
|
| 250 |
+
group.add(createMesh(tlGeo, stoneMaterial, { x:-(aw/2+gw/2), y:gh/2, z:0 }));
|
| 251 |
+
const trGeo = new THREE.BoxGeometry(gw, gh, gd);
|
| 252 |
+
group.add(createMesh(trGeo, stoneMaterial, { x:(aw/2+gw/2), y:gh/2, z:0 }));
|
| 253 |
+
const aGeo = new THREE.BoxGeometry(aw, ah, gd);
|
| 254 |
+
group.add(createMesh(aGeo, stoneMaterial, { x:0, y:gh-ah/2, z:0 }));
|
| 255 |
+
const cs=0.4;
|
| 256 |
+
const cg = new THREE.BoxGeometry(cs, cs, gd*1.1);
|
| 257 |
+
for(let i=-1; i<=1; i+=2){
|
| 258 |
+
group.add(createMesh(cg.clone(), stoneMaterial, { x:-(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
|
| 259 |
+
group.add(createMesh(cg.clone(), stoneMaterial, { x:(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
|
| 260 |
+
}
|
| 261 |
+
group.add(createMesh(cg.clone(), stoneMaterial, { x:0, y:gh+ah-cs/2, z:0 }));
|
| 262 |
+
group.add(createGroundPlane(stoneMaterial));
|
| 263 |
+
return group;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
function createWeaponsmithAssembly() {
|
| 267 |
+
const group = new THREE.Group();
|
| 268 |
+
const bw=3, bh=2.5, bd=3.5;
|
| 269 |
+
const bGeo = new THREE.BoxGeometry(bw, bh, bd);
|
| 270 |
+
group.add(createMesh(bGeo, darkWoodMaterial, { x:0, y:bh/2, z:0 }));
|
| 271 |
+
const ch=3.5;
|
| 272 |
+
const cGeo = new THREE.CylinderGeometry(0.3, 0.4, ch, 8);
|
| 273 |
+
group.add(createMesh(cGeo, stoneMaterial, { x:bw*0.3, y:ch/2, z:-bd*0.3 }));
|
| 274 |
+
group.add(createGroundPlane());
|
| 275 |
+
return group;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
function createTempleAssembly() {
|
| 279 |
+
const group = new THREE.Group();
|
| 280 |
+
const bs=5, bsh=0.5, ch=3, cr=0.25, rh=0.5;
|
| 281 |
+
const bGeo = new THREE.BoxGeometry(bs, bsh, bs);
|
| 282 |
+
group.add(createMesh(bGeo, templeMaterial, { x:0, y:bsh/2, z:0 }));
|
| 283 |
+
const cGeo = new THREE.CylinderGeometry(cr, cr, ch, 12);
|
| 284 |
+
const cPos = [{x:-bs/3, z:-bs/3}, {x:bs/3, z:-bs/3}, {x:-bs/3, z:bs/3}, {x:bs/3, z:bs/3}];
|
| 285 |
+
cPos.forEach(p=>group.add(createMesh(cGeo.clone(), templeMaterial, { x:p.x, y:bsh+ch/2, z:p.z })));
|
| 286 |
+
const rGeo = new THREE.BoxGeometry(bs*0.9, rh, bs*0.9);
|
| 287 |
+
group.add(createMesh(rGeo, templeMaterial, { x:0, y:bsh+ch+rh/2, z:0 }));
|
| 288 |
+
group.add(createGroundPlane());
|
| 289 |
+
return group;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
function createResistanceMeetingAssembly() {
|
| 293 |
+
const group = new THREE.Group();
|
| 294 |
+
const tw=2, th=0.8, td=1, tt=0.1;
|
| 295 |
+
const ttg = new THREE.BoxGeometry(tw, tt, td);
|
| 296 |
+
group.add(createMesh(ttg, woodMaterial, { x:0, y:th-tt/2, z:0 }));
|
| 297 |
+
const lh=th-tt, ls=0.1;
|
| 298 |
+
const lg=new THREE.BoxGeometry(ls, lh, ls);
|
| 299 |
+
const lofW=tw/2-ls*1.5;
|
| 300 |
+
const lofD=td/2-ls*1.5;
|
| 301 |
+
group.add(createMesh(lg, woodMaterial, { x:-lofW, y:lh/2, z:-lofD }));
|
| 302 |
+
group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:-lofD }));
|
| 303 |
+
group.add(createMesh(lg.clone(), woodMaterial, { x:-lofW, y:lh/2, z:lofD }));
|
| 304 |
+
group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:lofD }));
|
| 305 |
+
const ss=0.4;
|
| 306 |
+
const sg=new THREE.BoxGeometry(ss, ss*0.8, ss);
|
| 307 |
+
group.add(createMesh(sg, darkWoodMaterial, { x:-tw*0.6, y:ss*0.4, z:0 }));
|
| 308 |
+
group.add(createMesh(sg.clone(), darkWoodMaterial, { x:tw*0.6, y:ss*0.4, z:0 }));
|
| 309 |
+
group.add(createGroundPlane(stoneMaterial));
|
| 310 |
+
return group;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
function createForestAssembly(tc=10, a=10) {
|
| 314 |
+
const group = new THREE.Group();
|
| 315 |
+
const cT=(x,z)=>{
|
| 316 |
+
const tg=new THREE.Group();
|
| 317 |
+
const th=Math.random()*1.5+2;
|
| 318 |
+
const tr=Math.random()*0.1+0.1;
|
| 319 |
+
const tGeo = new THREE.CylinderGeometry(tr*0.7, tr, th, 8);
|
| 320 |
+
tg.add(createMesh(tGeo, woodMaterial, {x:0, y:th/2, z:0}));
|
| 321 |
+
const fr=th*0.4+0.2;
|
| 322 |
+
const fGeo=new THREE.SphereGeometry(fr, 8, 6);
|
| 323 |
+
tg.add(createMesh(fGeo, leafMaterial, {x:0, y:th*0.9, z:0}));
|
| 324 |
+
tg.position.set(x,0,z);
|
| 325 |
+
return tg;
|
| 326 |
+
};
|
| 327 |
+
for(let i=0; i<tc; i++){
|
| 328 |
+
const x=(Math.random()-0.5)*a;
|
| 329 |
+
const z=(Math.random()-0.5)*a;
|
| 330 |
+
if(Math.sqrt(x*x+z*z)>1.0) group.add(cT(x,z));
|
| 331 |
+
}
|
| 332 |
+
group.add(createGroundPlane(groundMaterial, a*1.1));
|
| 333 |
+
return group;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
function createRoadAmbushAssembly() {
|
| 337 |
+
const group = new THREE.Group();
|
| 338 |
+
const a=12;
|
| 339 |
+
const fg = createForestAssembly(8, a);
|
| 340 |
+
group.add(fg);
|
| 341 |
+
const rw=3, rl=a*1.2;
|
| 342 |
+
const rGeo=new THREE.PlaneGeometry(rw, rl);
|
| 343 |
+
const rMat=new THREE.MeshStandardMaterial({color:0x966F33, roughness:0.9});
|
| 344 |
+
const r=createMesh(rGeo, rMat, {x:0, y:0.01, z:0}, {x:-Math.PI/2});
|
| 345 |
+
r.receiveShadow=true;
|
| 346 |
+
group.add(r);
|
| 347 |
+
const rkGeo=new THREE.SphereGeometry(0.5, 5, 4);
|
| 348 |
+
const rkMat=new THREE.MeshStandardMaterial({color:0x666666, roughness:0.8});
|
| 349 |
+
group.add(createMesh(rkGeo, rkMat, {x:rw*0.7, y:0.25, z:1}, {y:Math.random()*Math.PI}));
|
| 350 |
+
group.add(createMesh(rkGeo.clone().scale(0.8,0.8,0.8), rkMat, {x:-rw*0.8, y:0.2, z:-2}, {y:Math.random()*Math.PI}));
|
| 351 |
+
return group;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
function createForestEdgeAssembly() {
|
| 355 |
+
const group = new THREE.Group();
|
| 356 |
+
const a=15;
|
| 357 |
+
const fg = createForestAssembly(15, a);
|
| 358 |
+
const ttr=[];
|
| 359 |
+
fg.children.forEach(c => {
|
| 360 |
+
if(c.type === 'Group' && c.position.x > 0) ttr.push(c);
|
| 361 |
+
});
|
| 362 |
+
ttr.forEach(t => fg.remove(t));
|
| 363 |
+
group.add(fg);
|
| 364 |
+
return group;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
function createPrisonerCellAssembly() {
|
| 368 |
+
const group = new THREE.Group();
|
| 369 |
+
const cs=3, wh=2.5, wt=0.2, br=0.05, bsp=0.25;
|
| 370 |
+
const cfMat=stoneMaterial.clone();
|
| 371 |
+
cfMat.color.setHex(0x555555);
|
| 372 |
+
group.add(createGroundPlane(cfMat, cs));
|
| 373 |
+
const wbGeo=new THREE.BoxGeometry(cs, wh, wt);
|
| 374 |
+
group.add(createMesh(wbGeo, stoneMaterial, {x:0, y:wh/2, z:-cs/2}));
|
| 375 |
+
const wsGeo=new THREE.BoxGeometry(wt, wh, cs);
|
| 376 |
+
group.add(createMesh(wsGeo, stoneMaterial, {x:-cs/2, y:wh/2, z:0}));
|
| 377 |
+
group.add(createMesh(wsGeo.clone(), stoneMaterial, {x:cs/2, y:wh/2, z:0}));
|
| 378 |
+
const bGeo=new THREE.CylinderGeometry(br, br, wh, 8);
|
| 379 |
+
const nb=Math.floor(cs/bsp);
|
| 380 |
+
for(let i=0; i<nb; i++){
|
| 381 |
+
const xp=-cs/2+(i+0.5)*bsp;
|
| 382 |
+
group.add(createMesh(bGeo.clone(), metalMaterial, {x:xp, y:wh/2, z:cs/2}));
|
| 383 |
+
}
|
| 384 |
+
return group;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
function createGameOverAssembly() {
|
| 388 |
+
const group = new THREE.Group();
|
| 389 |
+
const boxGeo = new THREE.BoxGeometry(2, 2, 2);
|
| 390 |
+
group.add(createMesh(boxGeo, gameOverMaterial, { x: 0, y: 1, z: 0 }));
|
| 391 |
+
group.add(createGroundPlane(stoneMaterial.clone().set({color: 0x333333})));
|
| 392 |
+
return group;
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
function createErrorAssembly() {
|
| 396 |
+
const group = new THREE.Group();
|
| 397 |
+
const coneGeo = new THREE.ConeGeometry(0.8, 1.5, 8);
|
| 398 |
+
group.add(createMesh(coneGeo, errorMaterial, { x: 0, y: 0.75, z: 0 }));
|
| 399 |
+
group.add(createGroundPlane());
|
| 400 |
+
return group;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
function createCrossroadsAssembly() {
|
| 404 |
+
const group = new THREE.Group();
|
| 405 |
+
group.add(createGroundPlane(dirtMaterial, 30));
|
| 406 |
+
const poleGeo = new THREE.CylinderGeometry(0.1, 0.1, 3, 8);
|
| 407 |
+
group.add(createMesh(poleGeo, woodMaterial, { y: 1.5 }));
|
| 408 |
+
const signGeo = new THREE.BoxGeometry(1.5, 0.3, 0.05);
|
| 409 |
+
group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: 0.2 }, { y: Math.PI / 4 }));
|
| 410 |
+
group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: -0.2 }, { y: -Math.PI / 4 }));
|
| 411 |
+
const grassGeo = new THREE.ConeGeometry(0.2, 0.5, 6);
|
| 412 |
+
for (let i = 0; i < 20; i++) {
|
| 413 |
+
const x = (Math.random() - 0.5) * 15;
|
| 414 |
+
const z = (Math.random() - 0.5) * 15;
|
| 415 |
+
if (Math.abs(x) > 2 || Math.abs(z) > 2) {
|
| 416 |
+
group.add(createMesh(grassGeo, grassMaterial, { x, y: 0.25, z }, { y: Math.random() * Math.PI }));
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
const rockGeo = new THREE.SphereGeometry(0.3, 6, 6);
|
| 420 |
+
for (let i = 0; i < 10; i++) {
|
| 421 |
+
group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.15, z: (Math.random() - 0.5) * 10 }, { y: Math.random() * Math.PI }));
|
| 422 |
+
}
|
| 423 |
+
return group;
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
function createRollingHillsAssembly() {
|
| 427 |
+
const group = new THREE.Group();
|
| 428 |
+
const hillGeo = new THREE.PlaneGeometry(50, 50, 10, 10);
|
| 429 |
+
const hillMat = grassMaterial.clone();
|
| 430 |
+
const hill = new THREE.Mesh(hillGeo, hillMat);
|
| 431 |
+
hill.rotation.x = -Math.PI / 2;
|
| 432 |
+
hill.receiveShadow = true;
|
| 433 |
+
for (let i = 0; i < hillGeo.attributes.position.count; i++) {
|
| 434 |
+
const x = hillGeo.attributes.position.getX(i);
|
| 435 |
+
const z = hillGeo.attributes.position.getZ(i);
|
| 436 |
+
hillGeo.attributes.position.setY(i, Math.sin(x * 0.2 + z * 0.2) * 2);
|
| 437 |
+
}
|
| 438 |
+
hillGeo.computeVertexNormals();
|
| 439 |
+
group.add(hill);
|
| 440 |
+
const shepherdGeo = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
|
| 441 |
+
group.add(createMesh(shepherdGeo, darkWoodMaterial, { x: 10, y: 2, z: -15 }));
|
| 442 |
+
const grassGeo = new THREE.ConeGeometry(0.3, 0.7, 6);
|
| 443 |
+
for (let i = 0; i < 50; i++) {
|
| 444 |
+
group.add(createMesh(grassGeo, grassMaterial, { x: (Math.random() - 0.5) * 40, y: 0.35, z: (Math.random() - 0.5) * 40 }, { y: Math.random() * Math.PI }));
|
| 445 |
+
}
|
| 446 |
+
return group;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
function createCoastalCliffsAssembly() {
|
| 450 |
+
const group = new THREE.Group();
|
| 451 |
+
const cliffGeo = new THREE.BoxGeometry(10, 5, 10);
|
| 452 |
+
group.add(createMesh(cliffGeo, stoneMaterial, { y: 2.5 }));
|
| 453 |
+
const pathGeo = new THREE.PlaneGeometry(1, 10);
|
| 454 |
+
const path = createMesh(pathGeo, dirtMaterial, { x: -2, y: 2, z: 0 }, { x: -Math.PI / 2, z: -Math.PI / 4 });
|
| 455 |
+
group.add(path);
|
| 456 |
+
const oceanGeo = new THREE.PlaneGeometry(100, 100);
|
| 457 |
+
const ocean = createMesh(oceanGeo, oceanMaterial, { y: -2 }, { x: -Math.PI / 2 });
|
| 458 |
+
ocean.receiveShadow = false;
|
| 459 |
+
ocean.userData.update = (time) => {
|
| 460 |
+
ocean.position.y = -2 + Math.sin(time * 0.5) * 0.1;
|
| 461 |
+
};
|
| 462 |
+
group.add(ocean);
|
| 463 |
+
return group;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
function createForestEntranceAssembly() {
|
| 467 |
+
const group = createForestAssembly(20, 12);
|
| 468 |
+
const rootGeo = new THREE.TorusGeometry(0.5, 0.1, 8, 16);
|
| 469 |
+
for (let i = 0; i < 10; i++) {
|
| 470 |
+
group.add(createMesh(rootGeo, woodMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }, { x: Math.PI / 2 }));
|
| 471 |
+
}
|
| 472 |
+
return group;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
function createOvergrownPathAssembly() {
|
| 476 |
+
const group = new THREE.Group();
|
| 477 |
+
group.add(createGroundPlane(dirtMaterial, 15));
|
| 478 |
+
const forest = createForestAssembly(15, 10);
|
| 479 |
+
group.add(forest);
|
| 480 |
+
const fungiGeo = new THREE.SphereGeometry(0.1, 8, 8);
|
| 481 |
+
for (let i = 0; i < 30; i++) {
|
| 482 |
+
group.add(createMesh(fungiGeo, glowMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }));
|
| 483 |
+
}
|
| 484 |
+
const vineGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
|
| 485 |
+
for (let i = 0; i < 10; i++) {
|
| 486 |
+
group.add(createMesh(vineGeo, leafMaterial, { x: (Math.random() - 0.5) * 6, y: 2, z: (Math.random() - 0.5) * 6 }, { z: Math.random() * Math.PI }));
|
| 487 |
+
}
|
| 488 |
+
return group;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
function createClearingStatueAssembly() {
|
| 492 |
+
const group = new THREE.Group();
|
| 493 |
+
group.add(createGroundPlane(grassMaterial, 10));
|
| 494 |
+
const statueGeo = new THREE.BoxGeometry(0.8, 2, 0.8);
|
| 495 |
+
group.add(createMesh(statueGeo, stoneMaterial, { y: 1 }));
|
| 496 |
+
const mossGeo = new THREE.SphereGeometry(0.2, 8, 8);
|
| 497 |
+
for (let i = 0; i < 10; i++) {
|
| 498 |
+
group.add(createMesh(mossGeo, grassMaterial, { x: (Math.random() - 0.5) * 0.8, y: 0.5 + Math.random(), z: (Math.random() - 0.5) * 0.8 }));
|
| 499 |
+
}
|
| 500 |
+
const leafGeo = new THREE.PlaneGeometry(0.1, 0.1);
|
| 501 |
+
for (let i = 0; i < 20; i++) {
|
| 502 |
+
group.add(createMesh(leafGeo, leafMaterial, { x: (Math.random() - 0.5) * 5, y: 0.05, z: (Math.random() - 0.5) * 5 }, { y: Math.random() * Math.PI }));
|
| 503 |
+
}
|
| 504 |
+
return group;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
function createGoblinAmbushAssembly() {
|
| 508 |
+
const group = createOvergrownPathAssembly();
|
| 509 |
+
const bodyGeo = new THREE.CylinderGeometry(0.3, 0.3, 1, 8);
|
| 510 |
+
const headGeo = new THREE.SphereGeometry(0.2, 8, 8);
|
| 511 |
+
const goblinMat = new THREE.MeshStandardMaterial({ color: 0x556B2F });
|
| 512 |
+
for (let i = -1; i <= 1; i += 2) {
|
| 513 |
+
const goblin = new THREE.Group();
|
| 514 |
+
goblin.add(createMesh(bodyGeo, goblinMat, { y: 0.5 }));
|
| 515 |
+
goblin.add(createMesh(headGeo, goblinMat, { y: 1.2 }));
|
| 516 |
+
const spearGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
|
| 517 |
+
goblin.add(createMesh(spearGeo, woodMaterial, { x: 0.3, y: 1, z: 0 }, { z: Math.PI / 4 }));
|
| 518 |
+
goblin.position.set(i * 2, 0, 2);
|
| 519 |
+
group.add(goblin);
|
| 520 |
+
}
|
| 521 |
+
return group;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
function createHiddenCoveAssembly() {
|
| 525 |
+
const group = new THREE.Group();
|
| 526 |
+
group.add(createGroundPlane(sandMaterial, 15));
|
| 527 |
+
const caveGeo = new THREE.BoxGeometry(3, 2, 3);
|
| 528 |
+
group.add(createMesh(caveGeo, stoneMaterial, { z: -5, y: 1 }));
|
| 529 |
+
const rockGeo = new THREE.SphereGeometry(0.5, 6, 6);
|
| 530 |
+
for (let i = 0; i < 15; i++) {
|
| 531 |
+
group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.25, z: (Math.random() - 0.5) * 10 }));
|
| 532 |
+
}
|
| 533 |
+
const seaweedGeo = new THREE.ConeGeometry(0.2, 1, 6);
|
| 534 |
+
for (let i = 0; i < 10; i++) {
|
| 535 |
+
group.add(createMesh(seaweedGeo, leafMaterial, { x: (Math.random() - 0.5) * 8, y: 0.5, z: (Math.random() - 0.5) * 8 }));
|
| 536 |
+
}
|
| 537 |
+
return group;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
function createDarkCaveAssembly() {
|
| 541 |
+
const group = new THREE.Group();
|
| 542 |
+
group.add(createGroundPlane(wetStoneMaterial, 10));
|
| 543 |
+
const wallGeo = new THREE.CylinderGeometry(3, 3, 5, 12, 1, true);
|
| 544 |
+
const wall = createMesh(wallGeo, stoneMaterial, { y: 2.5 }, { x: Math.PI / 2 });
|
| 545 |
+
wall.scale.set(1, 1, -1);
|
| 546 |
+
group.add(wall);
|
| 547 |
+
const dripGeo = new THREE.SphereGeometry(0.05, 8, 8);
|
| 548 |
+
for (let i = 0; i < 5; i++) {
|
| 549 |
+
const drip = createMesh(dripGeo, oceanMaterial, { x: (Math.random() - 0.5) * 2, y: 4, z: (Math.random() - 0.5) * 2 });
|
| 550 |
+
drip.userData.update = (time) => {
|
| 551 |
+
drip.position.y -= 0.1;
|
| 552 |
+
if (drip.position.y < 0) drip.position.y = 4;
|
| 553 |
+
};
|
| 554 |
+
group.add(drip);
|
| 555 |
+
}
|
| 556 |
+
return group;
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
// Game Data
|
| 560 |
+
const itemsData = {
|
| 561 |
+
"Flaming Sword":{type:"weapon", description:"A fiery blade"},
|
| 562 |
+
"Whispering Bow":{type:"weapon", description:"A silent bow"},
|
| 563 |
+
"Guardian Shield":{type:"armor", description:"A protective shield"},
|
| 564 |
+
"Healing Light Spell":{type:"spell", description:"Mends minor wounds"},
|
| 565 |
+
"Shield of Faith Spell":{type:"spell", description:"Temporary shield"},
|
| 566 |
+
"Binding Runes Scroll":{type:"spell", description:"Binds an enemy"},
|
| 567 |
+
"Secret Tunnel Map":{type:"quest", description:"Shows a hidden path"},
|
| 568 |
+
"Poison Daggers":{type:"weapon", description:"Daggers with poison"},
|
| 569 |
+
"Master Key":{type:"quest", description:"Unlocks many doors"},
|
| 570 |
+
"Crude Dagger":{type:"weapon", description:"A roughly made dagger."},
|
| 571 |
+
"Scout's Pouch":{type:"quest", description:"Contains odds and ends."}
|
| 572 |
+
};
|
| 573 |
+
|
| 574 |
const gameData = {
|
| 575 |
+
"1": { title: "The Crossroads", content: `<p>Dust swirls... Which path calls to you?</p>`, options: [ { text: "Enter the Shadowwood Forest (North)", next: 5 }, { text: "Head towards the Rolling Hills (East)", next: 2 }, { text: "Investigate the Coastal Cliffs (West)", next: 3 } ], illustration: "crossroads-signpost-sunny" },
|
| 576 |
+
"2": { title: "Rolling Hills", content: `<p>Verdant hills stretch before you... It feels peaceful...</p>`, options: [ { text: "Follow the narrow path", next: 4 }, { text: "Try to hail the distant shepherd (Charisma Check?)", next: 99 } ], illustration: "rolling-green-hills-shepherd-distance" },
|
| 577 |
+
"3": { title: "Coastal Cliffs Edge", content: `<p>You stand atop windswept cliffs... A precarious-looking path descends...</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 }, { text: "Scan the cliff face for easier routes (Wisdom Check)", check: { stat: 'wisdom', dc: 11, onFailure: 32 }, next: 33 } ], illustration: "windy-sea-cliffs-crashing-waves-path-down" },
|
| 578 |
+
"4": { title: "Hill Path Overlook", content: `<p>The path crests a hill... you see a small, overgrown shrine...</p>`, options: [ { text: "Investigate the overgrown shrine", next: 40 }, { text: "Continue towards the badlands", next: 41 } ], illustration: "hilltop-view-overgrown-shrine-wildflowers" },
|
| 579 |
+
"5": { title: "Shadowwood Entrance", content: `<p>Sunlight struggles to pierce the dense canopy... How do you proceed?</p>`, options: [ { text: "Follow the main, albeit overgrown, path", next: 6 }, { text: "Try to navigate through the lighter undergrowth", next: 7 }, { text: "Look for animal trails or signs of passage (Wisdom Check)", check: { stat: 'wisdom', dc: 10, onFailure: 6 }, next: 8 } ], illustration: "dark-forest-entrance-gnarled-roots-filtered-light" },
|
| 580 |
+
"6": { title: "Overgrown Forest Path", content: `<p>The path is barely visible... You hear a twig snap nearby!</p>`, options: [ { text: "Ready your weapon and investigate", next: 10 }, { text: "Attempt to hide quietly (Dexterity Check)", check: { stat: 'dexterity', dc: 11, onFailure: 10 }, next: 11 }, { text: "Call out cautiously", next: 10 } ], illustration: "overgrown-forest-path-glowing-fungi-vines" },
|
| 581 |
+
"7": { title: "Tangled Undergrowth", content: `<p>Pushing through ferns... You stumble upon a small clearing containing a moss-covered, weathered stone statue...</p>`, options: [ { text: "Examine the statue closely (Intelligence Check)", check: { stat: 'intelligence', dc: 13, onFailure: 71 }, next: 70 }, { text: "Ignore the statue and press on", next: 72 }, { text: "Leave a small offering (if possible)", next: 73 } ], illustration: "forest-clearing-mossy-statue-weathered-stone" },
|
| 582 |
+
"8": { title: "Hidden Game Trail", content: `<p>Your sharp eyes spot a faint trail... It leads towards a ravine spanned by a rickety rope bridge.</p><p>(+20 XP)</p>`, options: [ { text: "Risk crossing the rope bridge (Dexterity Check)", check: { stat: 'dexterity', dc: 10, onFailure: 81 }, next: 80 }, { text: "Search for another way across the ravine", next: 82 } ], illustration: "narrow-game-trail-forest-rope-bridge-ravine", reward: { xp: 20 } },
|
| 583 |
+
"10": { title: "Goblin Ambush!", content: `<p>Two scraggly goblins leap out, brandishing crude spears!</p>`, options: [ { text: "Fight the goblins!", next: 12 }, { text: "Attempt to dodge past them (Dexterity Check)", check: { stat: 'dexterity', dc: 13, onFailure: 10 }, next: 13 } ], illustration: "two-goblins-ambush-forest-path-spears" },
|
| 584 |
"11": { title: "Hidden Evasion", content: `<p>You melt into the shadows as the goblins blunder past.</p><p>(+30 XP)</p>`, options: [ { text: "Continue cautiously", next: 14 } ], illustration: "forest-shadows-hiding-goblins-walking-past", reward: { xp: 30 } },
|
| 585 |
+
"12": { title: "Ambush Victory!", content: `<p>You defeat the goblins! Found a Crude Dagger.</p><p>(+50 XP)</p>`, options: [ { text: "Press onward", next: 14 } ], illustration: "defeated-goblins-forest-path-loot", reward: { xp: 50, addItem: "Crude Dagger" } },
|
| 586 |
"13": { title: "Daring Escape", content: `<p>With surprising agility, you tumble past the goblins!</p><p>(+25 XP)</p>`, options: [ { text: "Keep running!", next: 14 } ], illustration: "blurred-motion-running-past-goblins-forest", reward: { xp: 25 } },
|
| 587 |
"14": { title: "Forest Stream Crossing", content: `<p>The path leads to a clear, shallow stream...</p>`, options: [ { text: "Wade across the stream", next: 16 }, { text: "Look for a drier crossing point (fallen log?)", next: 15 } ], illustration: "forest-stream-crossing-dappled-sunlight-stones" },
|
| 588 |
"15": { title: "Log Bridge", content: `<p>Further upstream, a large, mossy log spans the stream.</p>`, options: [ { text: "Cross carefully on the log (Dexterity Check)", check: { stat: 'dexterity', dc: 9, onFailure: 151 }, next: 16 }, { text: "Go back and wade instead", next: 14 } ], illustration: "mossy-log-bridge-over-forest-stream" },
|
|
|
|
| 596 |
"31": { title: "Tumbled Down", content: `<p>You lose your footing... landing hard on the sandy cove floor. You lose 5 HP. A dark cave entrance beckons.</p>`, options: [ { text: "Gingerly explore the dark cave", next: 35 } ], illustration: "character-fallen-at-bottom-of-cliff-path-cove", hpLoss: 5 },
|
| 597 |
"32": { title: "No Easier Path", content: `<p>You scan the cliffs intently but find no obviously easier routes.</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 } ], illustration: "scanning-sea-cliffs-no-other-paths-visible" },
|
| 598 |
"33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot a series of barely visible handholds and steps carved into the rock...</p><p>(+15 XP)</p>`, options: [ { text: "Use the hidden steps (Easier Dex Check)", check: { stat: 'dexterity', dc: 8, onFailure: 31 }, next: 30 } ], illustration: "close-up-handholds-carved-in-cliff-face", reward: { xp: 15 } },
|
| 599 |
+
"35": { title: "Dark Cave", content: `<p>The cave smells of salt and decay. Water drips somewhere within.</p>`, options: [{ text: "Press deeper into the darkness", next: 99 } ], illustration: "dark-cave-entrance-dripping-water" },
|
| 600 |
"40": { title: "Overgrown Shrine", content: `<p>Wildflowers grow thick around a small stone shrine. It feels ancient and neglected.</p>`, options: [{ text: "Examine the carvings (Intelligence Check)", check:{stat:'intelligence', dc:11, onFailure: 401}, next: 400 } ], illustration: "overgrown-stone-shrine-wildflowers-close" },
|
| 601 |
+
"41": { title: "Rocky Badlands", content: `<p>The green hills give way to cracked earth and jagged rock formations under a harsh sun.</p>`, options: [{ text: "Scout ahead", next: 99 } ], illustration: "rocky-badlands-cracked-earth-harsh-sun" },
|
|
|
|
| 602 |
"190": { title: "Over the Rocks", content:"<p>With considerable effort, you manage to climb over the rockslide.</p><p>(+35 XP)</p>", options: [{text:"Continue up the path", next: 22}], illustration:"character-climbing-over-boulders", reward: {xp:35} },
|
| 603 |
"191": { title: "Climb Fails", content:"<p>The boulders are too unstable or sheer. You cannot climb them safely.</p>", options: [{text:"Search for another way around", next: 192}], illustration:"character-slipping-on-rockslide-boulders"},
|
| 604 |
"192": { title: "Detour Found", content:"<p>After some searching, you find a rough path leading around the rockslide, eventually rejoining the main trail.</p>", options: [{text:"Continue up the path", next: 22}], illustration:"rough-detour-path-around-rockslide"},
|
| 605 |
"21": { title: "Western Ridge", content:"<p>The ridge path is narrow and exposed, with strong winds threatening to push you off.</p>", options: [{text:"Proceed carefully (Dexterity Check)", check:{stat:'dexterity', dc: 14, onFailure: 211}, next: 22 } ], illustration:"narrow-windy-mountain-ridge-path" },
|
| 606 |
+
"22": { title: "Fortress Approach", content:"<p>You've navigated the treacherous paths and now stand near the outer walls of the dark fortress. Guards patrol the battlements.</p>", options: [{text:"Look for an unguarded entrance", next: 99}], illustration:"approaching-dark-fortress-walls-guards"},
|
| 607 |
"211": {title:"Lost Balance", content:"<p>A strong gust of wind catches you off guard, sending you tumbling down a steep slope! You lose 10 HP.</p>", options:[{text:"Climb back up and find another way", next: 17}], illustration:"character-falling-off-windy-ridge", hpLoss: 10},
|
|
|
|
| 608 |
"99": { title: "Game Over / To Be Continued...", content: "<p>Your adventure ends here (for now).</p>", options: [{ text: "Restart", next: 1 }], illustration: "game-over-generic", gameOver: true }
|
| 609 |
};
|
| 610 |
|
| 611 |
+
// Game State
|
| 612 |
let gameState = {
|
| 613 |
currentPageId: 1,
|
| 614 |
character: {
|
|
|
|
| 619 |
}
|
| 620 |
};
|
| 621 |
|
| 622 |
+
// Game Logic Functions
|
| 623 |
function startGame() {
|
| 624 |
const defaultChar = { name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer", level: 1, xp: 0, xpToNextLevel: 100, stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 }, inventory: [] };
|
| 625 |
+
gameState = { currentPageId: 1, character: { ...defaultChar } };
|
|
|
|
|
|
|
| 626 |
renderPage(gameState.currentPageId);
|
| 627 |
}
|
| 628 |
|
|
|
|
| 631 |
const itemToAdd = choiceData.addItem;
|
| 632 |
let nextPageId = optionNextPageId;
|
| 633 |
let rollResultMessage = "";
|
| 634 |
+
const check = choiceData.check;
|
| 635 |
|
| 636 |
if (isNaN(optionNextPageId) && !check) { console.error("Invalid choice data:", choiceData); return; }
|
| 637 |
|
|
|
|
| 643 |
const dc = check.dc;
|
| 644 |
console.log(`Check: ${check.stat} (DC ${dc}) | Roll: ${roll} + Mod: ${modifier} = ${totalResult}`);
|
| 645 |
if (totalResult >= dc) {
|
| 646 |
+
nextPageId = optionNextPageId;
|
| 647 |
rollResultMessage = `<p class="roll-success"><em>Check Success! (${totalResult} vs DC ${dc})</em></p>`;
|
| 648 |
} else {
|
| 649 |
+
nextPageId = parseInt(check.onFailure);
|
| 650 |
rollResultMessage = `<p class="roll-failure"><em>Check Failed! (${totalResult} vs DC ${dc})</em></p>`;
|
| 651 |
if (isNaN(nextPageId)) { console.error("Invalid onFailure ID:", check.onFailure); nextPageId = 99; }
|
| 652 |
}
|
|
|
|
| 664 |
if (nextPageData.hpLoss) {
|
| 665 |
gameState.character.stats.hp -= nextPageData.hpLoss;
|
| 666 |
console.log(`Lost ${nextPageData.hpLoss} HP.`);
|
| 667 |
+
if (gameState.character.stats.hp <= 0) { gameState.character.stats.hp = 0; console.log("Player died!"); nextPageId = 99; }
|
| 668 |
}
|
| 669 |
if (nextPageData.reward) {
|
| 670 |
if (nextPageData.reward.xp) { gameState.character.xp += nextPageData.reward.xp; console.log(`Gained ${nextPageData.reward.xp} XP! Total: ${gameState.character.xp}`); }
|
| 671 |
+
if (nextPageData.reward.statIncrease) {
|
| 672 |
+
const stat = nextPageData.reward.statIncrease.stat;
|
| 673 |
+
const amount = nextPageData.reward.statIncrease.amount;
|
| 674 |
+
if (gameState.character.stats.hasOwnProperty(stat)) {
|
| 675 |
+
gameState.character.stats[stat] += amount;
|
| 676 |
+
console.log(`Stat ${stat} increased by ${amount}.`);
|
| 677 |
+
}
|
| 678 |
+
}
|
| 679 |
+
if(nextPageData.reward.addItem && !gameState.character.inventory.includes(nextPageData.reward.addItem)){
|
| 680 |
+
gameState.character.inventory.push(nextPageData.reward.addItem);
|
| 681 |
+
console.log(`Found item: ${nextPageData.reward.addItem}`);
|
| 682 |
+
}
|
| 683 |
+
}
|
| 684 |
+
const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
| 685 |
+
gameState.character.stats.maxHp = 10 + (conModifier * gameState.character.level);
|
| 686 |
+
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp);
|
| 687 |
+
if (nextPageId === 99 && gameState.character.stats.hp <= 0) {
|
| 688 |
+
renderPageInternal(99, gameData[99], rollResultMessage);
|
| 689 |
+
return;
|
| 690 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
} else {
|
| 692 |
console.error(`Data for page ${nextPageId} not found!`);
|
| 693 |
renderPageInternal(99, gameData[99], "<p><em>Error: Next page data missing!</em></p>");
|
|
|
|
| 697 |
}
|
| 698 |
|
| 699 |
function renderPageInternal(pageId, pageData, message = "") {
|
| 700 |
+
if (!pageData) { console.error(`Render Error: No data for page ${pageId}`); return; }
|
| 701 |
storyTitleElement.textContent = pageData.title || "Untitled Page";
|
| 702 |
storyContentElement.innerHTML = message + (pageData.content || "<p>...</p>");
|
| 703 |
+
updateStatsDisplay();
|
| 704 |
+
updateInventoryDisplay();
|
| 705 |
choicesElement.innerHTML = '';
|
| 706 |
if (pageData.options && pageData.options.length > 0) {
|
| 707 |
pageData.options.forEach(option => {
|
| 708 |
+
const button = document.createElement('button');
|
| 709 |
+
button.classList.add('choice-button');
|
| 710 |
+
button.textContent = option.text;
|
| 711 |
+
let requirementMet = true;
|
| 712 |
+
if (option.requireItem && !gameState.character.inventory.includes(option.requireItem)) {
|
| 713 |
+
requirementMet = false;
|
| 714 |
+
button.title = `Requires: ${option.requireItem}`;
|
| 715 |
+
button.disabled = true;
|
| 716 |
+
}
|
| 717 |
+
if (requirementMet) {
|
| 718 |
+
const choiceData = { nextPage: option.next, addItem: option.addItem, check: option.check };
|
| 719 |
+
button.onclick = () => handleChoiceClick(choiceData);
|
| 720 |
+
} else {
|
| 721 |
+
button.classList.add('disabled');
|
| 722 |
+
}
|
| 723 |
+
choicesElement.appendChild(button);
|
| 724 |
+
});
|
| 725 |
+
} else {
|
| 726 |
+
const button = document.createElement('button');
|
| 727 |
+
button.classList.add('choice-button');
|
| 728 |
+
button.textContent = pageData.gameOver ? "Restart Adventure" : "The End";
|
| 729 |
+
button.onclick = () => handleChoiceClick({ nextPage: pageData.gameOver ? 1 : 99 });
|
| 730 |
+
choicesElement.appendChild(button);
|
| 731 |
+
if (!pageData.gameOver) choicesElement.insertAdjacentHTML('afterbegin', '<p><i>The path ends here.</i></p>');
|
| 732 |
+
}
|
| 733 |
updateScene(pageData.illustration || 'default');
|
| 734 |
}
|
| 735 |
|
| 736 |
function renderPage(pageId) { renderPageInternal(pageId, gameData[pageId]); }
|
| 737 |
|
| 738 |
+
function updateStatsDisplay() {
|
| 739 |
+
const char=gameState.character;
|
| 740 |
+
statsElement.innerHTML = `<strong>Stats:</strong> <span>Lvl: ${char.level}</span> <span>XP: ${char.xp}/${char.xpToNextLevel}</span> <span>HP: ${char.stats.hp}/${char.stats.maxHp}</span> <span>Str: ${char.stats.strength}</span> <span>Int: ${char.stats.intelligence}</span> <span>Wis: ${char.stats.wisdom}</span> <span>Dex: ${char.stats.dexterity}</span> <span>Con: ${char.stats.constitution}</span> <span>Cha: ${char.stats.charisma}</span>`;
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
function updateInventoryDisplay() {
|
| 744 |
+
let h='<strong>Inventory:</strong> ';
|
| 745 |
+
if(gameState.character.inventory.length === 0){
|
| 746 |
+
h+='<em>Empty</em>';
|
| 747 |
+
} else {
|
| 748 |
+
gameState.character.inventory.forEach(i=>{
|
| 749 |
+
const d=itemsData[i]||{type:'unknown',description:'???'};
|
| 750 |
+
const c=`item-${d.type||'unknown'}`;
|
| 751 |
+
h+=`<span class="${c}" title="${d.description}">${i}</span>`;
|
| 752 |
+
});
|
| 753 |
+
}
|
| 754 |
+
inventoryElement.innerHTML = h;
|
| 755 |
+
}
|
| 756 |
|
| 757 |
function updateScene(illustrationKey) {
|
|
|
|
| 758 |
if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); }
|
| 759 |
+
scene.fog = null;
|
| 760 |
+
scene.background = new THREE.Color(0x222222);
|
| 761 |
+
camera.position.set(0, 2.5, 7);
|
| 762 |
+
camera.lookAt(0, 0.5, 0);
|
| 763 |
+
|
| 764 |
+
let assemblyFunction;
|
| 765 |
switch (illustrationKey) {
|
| 766 |
case 'city-gates': assemblyFunction = createCityGatesAssembly; break;
|
| 767 |
case 'weaponsmith': assemblyFunction = createWeaponsmithAssembly; break;
|
|
|
|
| 771 |
case 'road-ambush': assemblyFunction = createRoadAmbushAssembly; break;
|
| 772 |
case 'forest-edge': assemblyFunction = createForestEdgeAssembly; break;
|
| 773 |
case 'prisoner-cell': assemblyFunction = createPrisonerCellAssembly; break;
|
| 774 |
+
case 'game-over': case 'game-over-generic': assemblyFunction = createGameOverAssembly; break;
|
| 775 |
case 'error': assemblyFunction = createErrorAssembly; break;
|
| 776 |
+
case 'crossroads-signpost-sunny':
|
| 777 |
+
scene.fog = new THREE.Fog(0x87CEEB, 10, 30);
|
| 778 |
+
scene.background = new THREE.Color(0x87CEEB);
|
| 779 |
+
camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0);
|
| 780 |
+
assemblyFunction = createCrossroadsAssembly; break;
|
| 781 |
case 'rolling-green-hills-shepherd-distance':
|
| 782 |
+
scene.fog = new THREE.Fog(0xA8E4A0, 15, 50);
|
| 783 |
+
camera.position.set(0, 5, 15); camera.lookAt(0, 2, -5);
|
| 784 |
+
assemblyFunction = createRollingHillsAssembly; break;
|
| 785 |
case 'windy-sea-cliffs-crashing-waves-path-down':
|
| 786 |
+
scene.fog = new THREE.Fog(0x6699CC, 10, 40);
|
| 787 |
+
scene.background = new THREE.Color(0x6699CC);
|
| 788 |
+
camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5);
|
| 789 |
+
assemblyFunction = createCoastalCliffsAssembly; break;
|
| 790 |
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
| 791 |
+
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
| 792 |
+
camera.position.set(0, 2, 8); camera.lookAt(0, 1, 0);
|
| 793 |
+
assemblyFunction = createForestEntranceAssembly; break;
|
| 794 |
case 'overgrown-forest-path-glowing-fungi-vines':
|
| 795 |
+
scene.fog = new THREE.Fog(0x1A2F2A, 3, 15);
|
| 796 |
+
camera.position.set(0, 1.5, 6); camera.lookAt(0, 0.5, 0);
|
| 797 |
+
assemblyFunction = createOvergrownPathAssembly; break;
|
| 798 |
case 'forest-clearing-mossy-statue-weathered-stone':
|
| 799 |
+
scene.fog = new THREE.Fog(0x2E4F3A, 5, 25);
|
| 800 |
+
camera.position.set(0, 2, 5); camera.lookAt(0, 1, 0);
|
| 801 |
+
assemblyFunction = createClearingStatueAssembly; break;
|
| 802 |
case 'two-goblins-ambush-forest-path-spears':
|
| 803 |
+
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
| 804 |
+
camera.position.set(0, 2, 7); camera.lookAt(0, 1, 0);
|
| 805 |
+
assemblyFunction = createGoblinAmbushAssembly; break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 806 |
case 'hidden-cove-beach-dark-cave-entrance':
|
| 807 |
+
scene.fog = new THREE.Fog(0x336699, 5, 30);
|
| 808 |
+
scene.background = new THREE.Color(0x336699);
|
| 809 |
+
camera.position.set(0, 2, 8); camera.lookAt(0, 1, -2);
|
| 810 |
+
assemblyFunction = createHiddenCoveAssembly; break;
|
| 811 |
case 'dark-cave-entrance-dripping-water':
|
| 812 |
+
scene.fog = new THREE.Fog(0x1A1A1A, 2, 10);
|
| 813 |
+
scene.background = new THREE.Color(0x1A1A1A);
|
| 814 |
+
camera.position.set(0, 1.5, 4); camera.lookAt(0, 1, 0);
|
| 815 |
+
assemblyFunction = createDarkCaveAssembly; break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
default:
|
| 817 |
console.warn(`Unknown illustration key: "${illustrationKey}". Using default.`);
|
| 818 |
assemblyFunction = createDefaultAssembly; break;
|
| 819 |
}
|
| 820 |
+
try {
|
| 821 |
+
currentAssemblyGroup = assemblyFunction();
|
| 822 |
+
scene.add(currentAssemblyGroup);
|
| 823 |
+
adjustLighting(illustrationKey);
|
| 824 |
+
} catch (error) {
|
| 825 |
+
console.error(`Error creating assembly for ${illustrationKey}:`, error);
|
| 826 |
+
currentAssemblyGroup = createErrorAssembly();
|
| 827 |
+
scene.add(currentAssemblyGroup);
|
| 828 |
+
}
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
function adjustLighting(illustrationKey) {
|
| 832 |
+
scene.children.forEach(child => {
|
| 833 |
+
if (child.isLight && child !== scene.children.find(c => c.isAmbientLight)) {
|
| 834 |
+
scene.remove(child);
|
| 835 |
+
}
|
| 836 |
+
});
|
| 837 |
+
const ambient = scene.children.find(c => c.isAmbientLight);
|
| 838 |
+
let directionalLight;
|
| 839 |
+
switch (illustrationKey) {
|
| 840 |
+
case 'crossroads-signpost-sunny':
|
| 841 |
+
ambient.intensity = 0.8;
|
| 842 |
+
directionalLight = new THREE.DirectionalLight(0xFFF8E1, 1.5);
|
| 843 |
+
directionalLight.position.set(10, 15, 10);
|
| 844 |
+
break;
|
| 845 |
+
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
| 846 |
+
case 'overgrown-forest-path-glowing-fungi-vines':
|
| 847 |
+
ambient.intensity = 0.3;
|
| 848 |
+
directionalLight = new THREE.DirectionalLight(0xA8E4A0, 0.6);
|
| 849 |
+
directionalLight.position.set(5, 10, 5);
|
| 850 |
+
break;
|
| 851 |
+
case 'dark-cave-entrance-dripping-water':
|
| 852 |
+
ambient.intensity = 0.1;
|
| 853 |
+
directionalLight = new THREE.DirectionalLight(0x666666, 0.2);
|
| 854 |
+
directionalLight.position.set(2, 5, 2);
|
| 855 |
+
break;
|
| 856 |
+
default:
|
| 857 |
+
ambient.intensity = 0.5;
|
| 858 |
+
directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
|
| 859 |
+
directionalLight.position.set(8, 15, 10);
|
| 860 |
+
}
|
| 861 |
+
directionalLight.castShadow = true;
|
| 862 |
+
directionalLight.shadow.mapSize.set(1024, 1024);
|
| 863 |
+
directionalLight.shadow.camera.near = 0.5;
|
| 864 |
+
directionalLight.shadow.camera.far = 50;
|
| 865 |
+
directionalLight.shadow.camera.left = -15;
|
| 866 |
+
directionalLight.shadow.camera.right = 15;
|
| 867 |
+
directionalLight.shadow.camera.top = 15;
|
| 868 |
+
directionalLight.shadow.camera.bottom = -15;
|
| 869 |
+
scene.add(directionalLight);
|
| 870 |
}
|
| 871 |
|
| 872 |
document.addEventListener('DOMContentLoaded', () => {
|
| 873 |
+
console.log("DOM Ready.");
|
| 874 |
+
try {
|
| 875 |
+
initThreeJS();
|
| 876 |
+
startGame();
|
| 877 |
+
} catch (error) {
|
| 878 |
+
console.error("Init failed:", error);
|
| 879 |
+
storyTitleElement.textContent = "Error";
|
| 880 |
+
storyContentElement.innerHTML = `<p>Init Error. Check console.</p><pre>${error}</pre>`;
|
| 881 |
+
}
|
| 882 |
});
|
|
|
|
| 883 |
</script>
|
|
|
|
| 884 |
</body>
|
| 885 |
</html>
|