Spaces:
Running
Running
Update index.html
Browse files- index.html +148 -757
index.html
CHANGED
@@ -234,389 +234,17 @@
|
|
234 |
return ground;
|
235 |
}
|
236 |
|
237 |
-
// Procedural
|
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); // Make inside visible
|
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; // Reset drip
|
553 |
-
};
|
554 |
-
group.add(drip);
|
555 |
-
}
|
556 |
-
return group;
|
557 |
-
}
|
558 |
-
|
559 |
|
560 |
// Game Data
|
561 |
const itemsData = {
|
562 |
"Flaming Sword":{type:"weapon", description:"A fiery blade"},
|
563 |
-
|
564 |
-
"Guardian Shield":{type:"armor", description:"A protective shield"},
|
565 |
-
"Healing Light Spell":{type:"spell", description:"Mends minor wounds"},
|
566 |
-
"Shield of Faith Spell":{type:"spell", description:"Temporary shield"},
|
567 |
-
"Binding Runes Scroll":{type:"spell", description:"Binds an enemy"},
|
568 |
-
"Secret Tunnel Map":{type:"quest", description:"Shows a hidden path"},
|
569 |
-
"Poison Daggers":{type:"weapon", description:"Daggers with poison"},
|
570 |
-
"Master Key":{type:"quest", description:"Unlocks many doors"},
|
571 |
-
"Crude Dagger":{type:"weapon", description:"A roughly made dagger."},
|
572 |
-
"Scout's Pouch":{type:"quest", description:"Contains odds and ends."}
|
573 |
};
|
574 |
|
575 |
const gameData = {
|
576 |
-
"1": { title: "The Crossroads", content: `<p
|
577 |
-
|
578 |
-
"3": { title: "Coastal Cliffs Edge", content: `<p>You stand atop windswept cliffs, the roar of crashing waves filling the air below. Seabirds circle overhead. A precarious-looking path, seemingly carved by desperate hands, descends the cliff face towards a hidden cove.</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" },
|
579 |
-
"4": { title: "Hill Path Overlook", content: `<p>The path crests a hill, offering a panoramic view. To the east, the hills gradually give way to rugged, barren badlands. Nearby, nestled amongst wildflowers, you spot a small, ancient-looking shrine, heavily overgrown with vines.</p>`, options: [ { text: "Investigate the overgrown shrine", next: 40 }, { text: "Continue towards the badlands", next: 41 } ], illustration: "hilltop-view-overgrown-shrine-wildflowers" },
|
580 |
-
"5": { title: "Shadowwood Entrance", content: `<p>The air grows cool and damp as you step beneath the dense canopy of the Shadowwood. Sunlight struggles to pierce the gloom, illuminating gnarled roots that writhe across the forest floor. A narrow, overgrown path leads deeper into the woods.</p>`, options: [ { text: "Follow the main, albeit overgrown, path", next: 6 }, { text: "Try to navigate through the lighter undergrowth beside the path", 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" },
|
581 |
-
"6": { title: "Overgrown Forest Path", content: `<p>The path is barely visible beneath a thick layer of fallen leaves and creeping vines. Strange, faintly glowing fungi cling to rotting logs. You push deeper into the oppressive silence when suddenly, you hear a twig snap nearby!</p>`, options: [ { text: "Ready your weapon and investigate the sound", next: 10 }, { text: "Attempt to hide quietly amongst the ferns (Dexterity Check)", check: { stat: 'dexterity', dc: 11, onFailure: 10 }, next: 11 }, { text: "Call out cautiously, 'Who's there?'", next: 10 } ], illustration: "overgrown-forest-path-glowing-fungi-vines" },
|
582 |
-
"7": { title: "Tangled Undergrowth", content: `<p>Pushing through thick ferns and thorny bushes proves difficult. You stumble into a small, unexpected clearing. In the center stands a weathered stone statue, its features eroded by time and covered in thick moss. It depicts a forgotten deity or hero.</p>`, options: [ { text: "Examine the statue closely for clues or markings (Intelligence Check)", check: { stat: 'intelligence', dc: 13, onFailure: 71 }, next: 70 }, { text: "Ignore the statue and try to find the main path again", next: 72 }, { text: "Leave a small offering (if you have something suitable)", next: 73 } ], illustration: "forest-clearing-mossy-statue-weathered-stone" },
|
583 |
-
"8": { title: "Hidden Game Trail", content: `<p>Your sharp eyes spot a faint trail, almost invisible to the untrained observer, diverging from the main path. It looks like a route used by deer or other forest creatures. Following it, you soon arrive at the edge of a deep ravine spanned by a single, 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 along the ravine edge for another way across", next: 82 } ], illustration: "narrow-game-trail-forest-rope-bridge-ravine", reward: { xp: 20 } },
|
584 |
-
"10": { title: "Goblin Ambush!", content: `<p>Suddenly, two scraggly goblins, clad in mismatched leather scraps and wielding crude, sharp spears, leap out from behind large toadstools! Their beady eyes fix on you with malicious intent.</p>`, options: [ { text: "Fight the goblins!", next: 12 }, { text: "Attempt to dodge past them and flee down the path (Dexterity Check)", check: { stat: 'dexterity', dc: 13, onFailure: 10 }, next: 13 } ], illustration: "two-goblins-ambush-forest-path-spears" },
|
585 |
-
"11": { title: "Hidden Evasion", content: `<p>Quickly and silently, you melt into the deep shadows beneath a large, ancient tree. The two goblins blunder past, bickering in their guttural tongue, completely oblivious to your presence.</p><p>(+30 XP)</p>`, options: [ { text: "Continue cautiously down the path once they are gone", next: 14 } ], illustration: "forest-shadows-hiding-goblins-walking-past", reward: { xp: 30 } },
|
586 |
-
"12": { title: "Ambush Victory!", content: `<p>Though caught by surprise, you react swiftly. After a brief, vicious skirmish, the goblins lie defeated at your feet. Searching their meagre belongings, you find a single, Crude Dagger.</p><p>(+50 XP)</p>`, options: [ { text: "Wipe your blade clean and press onward", next: 14 } ], illustration: "defeated-goblins-forest-path-loot", reward: { xp: 50, addItem: "Crude Dagger" } },
|
587 |
-
"13": { title: "Daring Escape", content: `<p>With surprising agility, you feint left, then dive right, tumbling past the goblins' clumsy spear thrusts! You scramble to your feet and sprint down the path, leaving the surprised goblins behind.</p><p>(+25 XP)</p>`, options: [ { text: "Keep running!", next: 14 } ], illustration: "blurred-motion-running-past-goblins-forest", reward: { xp: 25 } },
|
588 |
-
"14": { title: "Forest Stream Crossing", content: `<p>The overgrown path eventually leads to the bank of a clear, shallow stream. Smooth, mossy stones line the streambed, and dappled sunlight filters through the leaves overhead, sparkling on the water's surface.</p>`, options: [ { text: "Wade across the stream", next: 16 }, { text: "Look for a drier crossing point (fallen log?) upstream", next: 15 } ], illustration: "forest-stream-crossing-dappled-sunlight-stones" },
|
589 |
-
"15": { title: "Log Bridge", content: `<p>A short walk upstream reveals a large, fallen tree spanning the stream. It's covered in slick, green moss, making it look like a potentially treacherous crossing.</p>`, options: [ { text: "Cross carefully on the mossy log (Dexterity Check)", check: { stat: 'dexterity', dc: 9, onFailure: 151 }, next: 16 }, { text: "Decide it's too risky and go back to wade across", next: 14 } ], illustration: "mossy-log-bridge-over-forest-stream" },
|
590 |
-
"151": { title: "Splash!", content: `<p>You place a foot carefully on the log, but the moss is slicker than it looks! Your feet shoot out from under you, and you tumble into the cold stream with a loud splash! You're soaked and slightly embarrassed, but otherwise unharmed.</p>`, options: [ { text: "Shake yourself off and continue on the other side", next: 16 } ], illustration: "character-splashing-into-stream-from-log" },
|
591 |
-
"16": { title: "Edge of the Woods", content: `<p>Finally, the trees begin to thin, and you emerge from the oppressive gloom of the Shadowwood. Before you lie steep, rocky foothills leading up towards a formidable-looking mountain fortress perched high above.</p>`, options: [ { text: "Begin the ascent into the foothills towards the fortress", next: 17 }, { text: "Scan the fortress and surrounding terrain from afar (Wisdom Check)", check: { stat: 'wisdom', dc: 14, onFailure: 17 }, next: 18 } ], illustration: "forest-edge-view-rocky-foothills-distant-mountain-fortress" },
|
592 |
-
"17": { title: "Rocky Foothills Path", content: `<p>The climb is arduous, the path winding steeply upwards over loose scree and jagged rocks. The air thins slightly. The dark stone walls of the mountain fortress loom much larger now, seeming to watch your approach.</p>`, options: [ { text: "Continue the direct ascent", next: 19 }, { text: "Look for signs of a hidden trail or less obvious route (Wisdom Check)", check: { stat: 'wisdom', dc: 15, onFailure: 19 }, next: 20 } ], illustration: "climbing-rocky-foothills-path-fortress-closer" },
|
593 |
-
"18": { title: "Distant Observation", content: `<p>Taking a moment to study the fortress from this distance, your keen eyes notice something interesting. The main approach looks heavily guarded, but along the western ridge, the terrain seems slightly less sheer, potentially offering a less-guarded, albeit more treacherous, approach.</p><p>(+30 XP)</p>`, options: [ { text: "Decide against the risk and take the main path into the foothills", next: 17 }, { text: "Attempt the western ridge approach", next: 21 } ], illustration: "zoomed-view-mountain-fortress-western-ridge", reward: { xp: 30 } },
|
594 |
-
"19": { title: "Blocked Pass", content: `<p>As you round a sharp bend, your way is completely blocked by a recent rockslide! Huge boulders and debris choke the path, making further progress impossible along this route.</p>`, options: [ { text: "Try to climb over the unstable rockslide (Strength Check)", check: { stat: 'strength', dc: 14, onFailure: 191 }, next: 190 }, { text: "Search the surrounding cliffs for another way around", next: 192 } ], illustration: "rockslide-blocking-mountain-path-boulders" },
|
595 |
-
"20": { title: "Goat Trail", content: `<p>Your thorough search pays off! Partially hidden behind a cluster of hardy mountain shrubs, you discover a narrow trail, barely wide enough for a single person (or perhaps a mountain goat). It seems to bypass the main path, heading upwards towards the fortress.</p><p>(+40 XP)</p>`, options: [ { text: "Follow the precarious goat trail", next: 22 } ], illustration: "narrow-goat-trail-mountainside-fortress-view", reward: { xp: 40 } },
|
596 |
-
"30": { title: "Hidden Cove", content: `<p>Your careful descent, whether via the main path or hidden steps, brings you safely to a secluded, sandy cove sheltered by the towering cliffs. The air smells strongly of salt and seaweed. Half-hidden in the shadows at the back of the cove is the dark, foreboding entrance to a sea cave.</p><p>(+25 XP)</p>`, options: [ { text: "Explore the dark cave", next: 35 } ], illustration: "hidden-cove-beach-dark-cave-entrance", reward: { xp: 25 } },
|
597 |
-
"31": { title: "Tumbled Down", content: `<p>You lose your footing on the steep, treacherous path! You tumble and slide the last few feet, landing hard on the sandy cove floor. You take 5 points of damage from the fall. Shaking your head to clear it, you see the dark entrance to a sea cave nearby.</p>`, options: [ { text: "Gingerly get up and explore the dark cave", next: 35 } ], illustration: "character-fallen-at-bottom-of-cliff-path-cove", hpLoss: 5 },
|
598 |
-
"32": { title: "No Easier Path", content: `<p>You scan the towering cliffs intently, searching for any alternative routes down. Despite your efforts, you find no obviously easier or safer paths than the precarious one directly before you.</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" },
|
599 |
-
"33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot what others might miss: a series of barely visible handholds and footholds carved into the rock face, slightly hidden by an overhang. They look old but might offer a slightly less treacherous descent.</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 } },
|
600 |
-
"35": { title: "Dark Cave", content: `<p>You cautiously enter the sea cave. The air inside is heavy with the smell of salt, damp rock, and something else... decay. Water drips rhythmically from unseen stalactites somewhere deeper within the oppressive darkness.</p>`, options: [{ text: "Press deeper into the darkness (Requires Light Source?)", next: 99 } ], illustration: "dark-cave-entrance-dripping-water" }, // TODO: Add light source requirement?
|
601 |
-
"40": { title: "Overgrown Shrine", content: `<p>Pushing aside thick vines reveals a small stone shrine dedicated to a forgotten nature deity. Intricate carvings, though worn, are still visible beneath the moss and grime. A sense of ancient peace emanates from the stones. Wildflowers grow in profusion around its base.</p>`, options: [{ text: "Examine the carvings for meaning (Intelligence Check)", check:{stat:'intelligence', dc:11, onFailure: 401}, next: 400 }, {text: "Leave the shrine undisturbed", next: 4}, {text: "Say a quiet prayer for guidance", next: 402}], illustration: "overgrown-stone-shrine-wildflowers-close" },
|
602 |
-
"400": { title: "Shrine Insights", content:"<p>The carvings depict cycles of growth and renewal. You feel a sense of calm wash over you, slightly restoring your vitality. (+1 HP)</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close", reward: {hpGain: 1}}, // TODO: Implement hpGain
|
603 |
-
"401": { title: "Mysterious Carvings", content:"<p>The carvings are too worn and abstract to decipher their specific meaning, though you sense they are very old.</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close"},
|
604 |
-
"402": { title: "Moment of Peace", content:"<p>You spend a quiet moment in reflection. While no divine voice answers, the tranquility of the place settles your nerves.</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close"},
|
605 |
-
"41": { title: "Rocky Badlands", content: `<p>The gentle green hills give way abruptly to cracked, sun-baked earth and jagged rock formations. The air is hot and still under a harsh, unforgiving sun. This land looks hostile and sparsely populated.</p>`, options: [{ text: "Scout ahead cautiously", next: 99 } ], illustration: "rocky-badlands-cracked-earth-harsh-sun" },
|
606 |
-
"70": { title: "Statue's Secret", content:"<p>Running your fingers over the mossy stone, you find a small, almost invisible seam near the base. Applying pressure, a hidden compartment clicks open! Inside is a Scout's Pouch.</p><p>(+40 XP)</p>", options: [{text:"Take the pouch and press on", next: 72}], illustration: "forest-clearing-mossy-statue-hidden-compartment", reward:{xp: 40, addItem: "Scout's Pouch"}},
|
607 |
-
"71": { title: "Just an Old Statue", content:"<p>Despite a careful examination, the statue appears to be just that – an old, weathered stone figure of no special significance that you can discern.</p>", options: [{text:"Ignore the statue and press on", next: 72}], illustration: "forest-clearing-mossy-statue-weathered-stone"},
|
608 |
-
"72": { title: "Back to the Thicket", content:"<p>Leaving the clearing and the statue behind, you push back into the dense undergrowth, eventually relocating the main forest path.</p>", options: [{text:"Continue along the main path", next: 6}], illustration:"pushing-through-forest-undergrowth"},
|
609 |
-
"73": { title: "A Small Offering", content:"<p>You place a small, simple offering at the statue's base (a ration, a coin, or perhaps just a moment of respect). You feel a subtle sense of approval or peace before turning to leave.</p>", options: [{text:"Try to find the main path again", next: 72}], illustration:"forest-clearing-mossy-statue-offering"}, // TODO: Check inventory for offering?
|
610 |
-
"80": { title: "Across the Ravine", content:"<p>Taking a deep breath, you step onto the swaying rope bridge. With careful, deliberate steps, testing each plank before putting your weight on it, you make your way across the chasm to the other side.</p><p>(+25 XP)</p>", options: [{text:"Continue following the game trail", next: 14}], illustration:"character-crossing-rope-bridge-safely", reward:{xp:25}}, // Leads back to stream eventually? Maybe a different path?
|
611 |
-
"81": { title: "Bridge Collapse!", content:"<p>Halfway across, a frayed rope snaps! The bridge lurches violently, sending you plunging into the ravine below! You lose 10 HP. Luckily, the bottom is covered in soft moss and mud, cushioning your fall.</p>", options: [{text:"Climb out and find another way", next: 82}], illustration:"rope-bridge-snapping-character-falling", hpLoss: 10},
|
612 |
-
"82": { title: "Ravine Detour", content:"<p>Searching along the ravine's edge, you eventually find a place where the chasm narrows, and a fallen log provides a much safer, if longer, way across.</p>", options: [{text:"Cross the log bridge and continue", next: 14}], illustration:"fallen-log-crossing-ravine"}, // Leads back to stream eventually?
|
613 |
-
"190": { title: "Over the Rocks", content:"<p>Summoning your strength, you find handholds and footholds, scrambling and pulling yourself up and over the precarious rockslide. It's exhausting work, but you make it past the blockage.</p><p>(+35 XP)</p>", options: [{text:"Continue up the now clear path", next: 22}], illustration:"character-climbing-over-boulders", reward: {xp:35} },
|
614 |
-
"191": { title: "Climb Fails", content:"<p>The boulders are too large, too smooth, or too unstable. You try several approaches, but cannot safely climb over the rockslide. This way is blocked.</p>", options: [{text:"Search the surrounding cliffs for another way around", next: 192}], illustration:"character-slipping-on-rockslide-boulders"},
|
615 |
-
"192": { title: "Detour Found", content:"<p>After considerable searching along the cliff face, you find a rough, overgrown path leading steeply up and around the rockslide area. It eventually rejoins the main trail further up the mountain.</p>", options: [{text:"Follow the detour path", next: 22}], illustration:"rough-detour-path-around-rockslide"},
|
616 |
-
"21": { title: "Western Ridge", content:"<p>The path along the western ridge is dangerously narrow and exposed. Loose gravel shifts underfoot, and strong gusts of wind whip around you, threatening to push you off the edge into the dizzying drop below.</p>", options: [{text:"Proceed carefully along the ridge (Dexterity Check)", check:{stat:'dexterity', dc: 14, onFailure: 211}, next: 22 } ], illustration:"narrow-windy-mountain-ridge-path" },
|
617 |
-
"211": {title:"Lost Balance", content:"<p>A particularly strong gust of wind catches you at a bad moment! You lose your balance and stumble, tumbling down a steep, rocky slope before managing to arrest your fall. You lose 10 HP.</p>", options:[{text:"Climb back up and reconsider the main path", next: 17}], illustration:"character-falling-off-windy-ridge", hpLoss: 10},
|
618 |
-
"22": { title: "Fortress Approach", content:"<p>You've navigated the treacherous paths and finally stand near the imposing outer walls of the dark mountain fortress. Stern-faced guards patrol the battlements, their eyes scanning the approaches. The main gate looks heavily fortified.</p>", options: [{text:"Look for an unguarded entrance or weak point (Wisdom/Intelligence Check?)", next: 99}, {text:"Attempt to bluff or sneak past the gate guards (Charisma/Dexterity Check?)", next: 99}], illustration:"approaching-dark-fortress-walls-guards"}, // TODO: Add specific checks
|
619 |
-
"99": { title: "Game Over / To Be Continued...", content: "<p>Your adventure ends here (for now). Thanks for playing!</p>", options: [{ text: "Restart Adventure", next: 1 }], illustration: "game-over-generic", gameOver: true }
|
620 |
};
|
621 |
|
622 |
// Game State
|
@@ -632,31 +260,34 @@
|
|
632 |
|
633 |
// Game Logic Functions
|
634 |
function startGame() {
|
635 |
-
|
636 |
-
|
637 |
-
|
|
|
|
|
|
|
638 |
gameState = { currentPageId: 1, character: JSON.parse(JSON.stringify(defaultChar)) };
|
639 |
renderPage(gameState.currentPageId);
|
640 |
}
|
641 |
|
642 |
function handleChoiceClick(choiceData) {
|
643 |
-
|
|
|
644 |
const itemToAdd = choiceData.addItem;
|
645 |
let nextPageId = optionNextPageId;
|
646 |
let rollResultMessage = "";
|
647 |
const check = choiceData.check;
|
648 |
|
649 |
-
if (isNaN(optionNextPageId) && !check && choiceData.next !== 1) {
|
650 |
console.error("Invalid choice data:", choiceData);
|
651 |
renderPageInternal(99, gameData[99] || { title: "Error", content: "<p>Invalid Choice Data!</p>", illustration: "error", gameOver: true }, "<p><em>Error: Invalid choice data encountered!</em></p>");
|
652 |
return;
|
653 |
}
|
654 |
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
}
|
660 |
|
661 |
if (check) {
|
662 |
const statValue = gameState.character.stats[check.stat] || 10;
|
@@ -669,101 +300,76 @@
|
|
669 |
nextPageId = optionNextPageId;
|
670 |
rollResultMessage = `<p class="roll-success"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Success! (Rolled ${roll} + ${modifier} = ${totalResult} vs DC ${dc})</em></p>`;
|
671 |
} else {
|
672 |
-
nextPageId = parseInt(check.onFailure);
|
673 |
rollResultMessage = `<p class="roll-failure"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Failed! (Rolled ${roll} + ${modifier} = ${totalResult} vs DC ${dc})</em></p>`;
|
674 |
if (isNaN(nextPageId)) {
|
675 |
console.error("Invalid onFailure ID:", check.onFailure);
|
676 |
-
nextPageId = 99;
|
677 |
rollResultMessage += "<p><em>Error: Invalid failure path!</em></p>";
|
678 |
}
|
679 |
}
|
680 |
}
|
681 |
|
682 |
-
// Handle rewards/consequences *before* checking game over from HP loss
|
683 |
const targetPageData = gameData[nextPageId];
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
}
|
721 |
-
}
|
722 |
-
if (targetPageData.reward.addItem && !gameState.character.inventory.includes(targetPageData.reward.addItem)) {
|
723 |
-
gameState.character.inventory.push(targetPageData.reward.addItem);
|
724 |
-
console.log(`Found item: ${targetPageData.reward.addItem}`);
|
725 |
-
}
|
726 |
-
}
|
727 |
-
// Add item from direct choice property (used in original example)
|
728 |
-
if (itemToAdd && !gameState.character.inventory.includes(itemToAdd)) {
|
729 |
-
gameState.character.inventory.push(itemToAdd);
|
730 |
-
console.log("Added item:", itemToAdd);
|
731 |
-
}
|
732 |
-
|
733 |
-
} else {
|
734 |
-
console.error(`Data for page ${nextPageId} not found!`);
|
735 |
-
renderPageInternal(99, gameData[99] || { title: "Error", content: "<p>Page Data Missing!</p>", illustration: "error", gameOver: true }, "<p><em>Error: Next page data missing!</em></p>");
|
736 |
-
return;
|
737 |
-
}
|
738 |
|
739 |
-
// Update current page ID *after* processing consequences
|
740 |
gameState.currentPageId = nextPageId;
|
741 |
-
// Recalculate max HP (in case level or con changed) - simple version assumes level 1
|
742 |
const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
743 |
-
gameState.character.stats.maxHp = 10 + conModifier;
|
744 |
-
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp);
|
745 |
|
746 |
-
// Render the determined next page
|
747 |
renderPageInternal(nextPageId, gameData[nextPageId], rollResultMessage);
|
748 |
}
|
749 |
|
750 |
-
|
751 |
function renderPageInternal(pageId, pageData, message = "") {
|
752 |
if (!pageData) {
|
753 |
-
|
754 |
-
pageData = gameData[99] || { title: "Error", content: "<p>Render Error!</p>", illustration: "error", gameOver: true }; // Fallback to game over
|
755 |
message += "<p><em>Render Error: Page data missing!</em></p>";
|
756 |
-
pageId = 99;
|
757 |
-
|
758 |
|
759 |
-
storyTitleElement.textContent = pageData.title
|
760 |
-
storyContentElement.innerHTML = message +
|
761 |
|
762 |
updateStatsDisplay();
|
763 |
updateInventoryDisplay();
|
764 |
|
765 |
-
choicesElement.innerHTML = '';
|
766 |
-
|
767 |
const options = pageData.options || [];
|
768 |
const isGameOverOrEnd = pageData.gameOver || options.length === 0;
|
769 |
|
@@ -775,39 +381,31 @@
|
|
775 |
let requirementMet = true;
|
776 |
let requirementText = "";
|
777 |
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
requirementMet = false;
|
782 |
-
requirementText = `Requires: ${option.requireItem}`;
|
783 |
-
}
|
784 |
}
|
785 |
-
// TODO: Add checks for stats (e.g., option.requireStat = {stat: 'strength', value: 12})
|
786 |
-
// TODO: Add checks for light source etc.
|
787 |
|
788 |
button.disabled = !requirementMet;
|
789 |
-
if (!requirementMet) {
|
790 |
-
button.title = requirementText;
|
791 |
-
button.classList.add('disabled'); // Ensure disabled style applies
|
792 |
-
}
|
793 |
-
|
794 |
-
// Attach click handler only if requirements met
|
795 |
if (requirementMet) {
|
796 |
const choiceData = {
|
797 |
next: option.next,
|
798 |
-
addItem: option.addItem,
|
799 |
check: option.check
|
800 |
};
|
801 |
button.onclick = () => handleChoiceClick(choiceData);
|
|
|
|
|
|
|
802 |
}
|
|
|
803 |
choicesElement.appendChild(button);
|
804 |
});
|
805 |
} else {
|
806 |
-
// Handle Game Over / End of Branch
|
807 |
const button = document.createElement('button');
|
808 |
button.classList.add('choice-button');
|
809 |
button.textContent = pageData.gameOver ? "Restart Adventure" : "The Path Ends Here (Restart?)";
|
810 |
-
button.onclick = () => handleChoiceClick({ next: 1 });
|
811 |
choicesElement.appendChild(button);
|
812 |
if (!pageData.gameOver) {
|
813 |
choicesElement.insertAdjacentHTML('afterbegin', '<p><i>There are no further paths from here.</i></p>');
|
@@ -820,327 +418,120 @@
|
|
820 |
function renderPage(pageId) { renderPageInternal(pageId, gameData[pageId]); }
|
821 |
|
822 |
function updateStatsDisplay() {
|
823 |
-
const
|
824 |
-
statsElement.innerHTML =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
}
|
826 |
|
827 |
function updateInventoryDisplay() {
|
828 |
-
let
|
829 |
-
if(gameState.character.inventory.length === 0){
|
830 |
-
|
831 |
} else {
|
832 |
-
gameState.character.inventory.forEach(itemName=>{
|
833 |
-
const item = itemsData[itemName] || {type:'unknown',description:'An unknown item.'};
|
834 |
-
const
|
835 |
-
|
836 |
});
|
837 |
}
|
838 |
-
inventoryElement.innerHTML =
|
839 |
}
|
840 |
|
841 |
function updateScene(illustrationKey) {
|
842 |
-
if (!scene) return;
|
843 |
-
|
844 |
-
|
845 |
-
scene.
|
846 |
-
|
847 |
-
camera.
|
848 |
-
camera.lookAt(0, 0.5, 0); // Reset camera lookAt
|
849 |
|
850 |
let assemblyFunction;
|
851 |
switch (illustrationKey) {
|
852 |
-
// Existing cases...
|
853 |
-
case 'city-gates': assemblyFunction = createCityGatesAssembly; break;
|
854 |
-
case 'weaponsmith': assemblyFunction = createWeaponsmithAssembly; break;
|
855 |
-
case 'temple': assemblyFunction = createTempleAssembly; break;
|
856 |
-
case 'resistance-meeting': assemblyFunction = createResistanceMeetingAssembly; break;
|
857 |
-
case 'shadowwood-forest': assemblyFunction = createForestAssembly; break; // Generic forest
|
858 |
-
case 'road-ambush': assemblyFunction = createRoadAmbushAssembly; break;
|
859 |
-
case 'forest-edge': assemblyFunction = createForestEdgeAssembly; break;
|
860 |
-
case 'prisoner-cell': assemblyFunction = createPrisonerCellAssembly; break;
|
861 |
-
case 'game-over': case 'game-over-generic': assemblyFunction = createGameOverAssembly; break;
|
862 |
-
case 'error': assemblyFunction = createErrorAssembly; break;
|
863 |
-
|
864 |
-
// Page-specific illustrations from gameData
|
865 |
case 'crossroads-signpost-sunny':
|
866 |
-
scene.fog = new THREE.Fog(0x87CEEB, 10, 30);
|
867 |
-
scene.background = new THREE.Color(0x87CEEB);
|
868 |
camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0);
|
869 |
-
assemblyFunction = createCrossroadsAssembly;
|
870 |
-
|
871 |
-
|
872 |
-
scene.background = new THREE.Color(0x90EE90); // Light green background
|
873 |
-
camera.position.set(0, 5, 15); camera.lookAt(0, 2, -5);
|
874 |
-
assemblyFunction = createRollingHillsAssembly; break;
|
875 |
-
case 'windy-sea-cliffs-crashing-waves-path-down':
|
876 |
-
scene.fog = new THREE.Fog(0x6699CC, 10, 40); // Grey-blue fog
|
877 |
-
scene.background = new THREE.Color(0x6699CC); // Steel blue background
|
878 |
-
camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5);
|
879 |
-
assemblyFunction = createCoastalCliffsAssembly; break;
|
880 |
-
case 'hilltop-view-overgrown-shrine-wildflowers': // Reuse rolling hills for base
|
881 |
-
scene.fog = new THREE.Fog(0xA8E4A0, 15, 50);
|
882 |
-
scene.background = new THREE.Color(0x90EE90);
|
883 |
-
camera.position.set(3, 4, 8); camera.lookAt(0, 1, 0); // Closer view towards shrine area
|
884 |
-
assemblyFunction = createRollingHillsAssembly; break; // Add shrine element here? Or separate assembly?
|
885 |
-
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
886 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); // Dark fog
|
887 |
-
scene.background = new THREE.Color(0x1A1A1A); // Very dark background
|
888 |
-
camera.position.set(0, 2, 8); camera.lookAt(0, 1, 0);
|
889 |
-
assemblyFunction = createForestEntranceAssembly; break;
|
890 |
-
case 'overgrown-forest-path-glowing-fungi-vines':
|
891 |
-
scene.fog = new THREE.Fog(0x1A2F2A, 3, 15); // Dark green fog, close visibility
|
892 |
-
scene.background = new THREE.Color(0x112211); // Dark green background
|
893 |
-
camera.position.set(0, 1.5, 6); camera.lookAt(0, 0.5, 0);
|
894 |
-
assemblyFunction = createOvergrownPathAssembly; break;
|
895 |
-
case 'forest-clearing-mossy-statue-weathered-stone':
|
896 |
-
case 'forest-clearing-mossy-statue-hidden-compartment': // Reuse visual
|
897 |
-
case 'forest-clearing-mossy-statue-offering': // Reuse visual
|
898 |
-
scene.fog = new THREE.Fog(0x2E4F3A, 5, 25); // Medium green fog
|
899 |
-
scene.background = new THREE.Color(0x223322); // Medium dark green
|
900 |
-
camera.position.set(0, 2, 5); camera.lookAt(0, 1, 0);
|
901 |
-
assemblyFunction = createClearingStatueAssembly; break;
|
902 |
-
case 'narrow-game-trail-forest-rope-bridge-ravine': // Can reuse basic forest
|
903 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
904 |
-
scene.background = new THREE.Color(0x1A1A1A);
|
905 |
-
camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2); // Look towards a simulated bridge/ravine
|
906 |
-
assemblyFunction = createForestAssembly; break; // Add bridge/ravine elements?
|
907 |
-
case 'two-goblins-ambush-forest-path-spears':
|
908 |
-
scene.fog = new THREE.Fog(0x1A2F2A, 3, 15);
|
909 |
-
scene.background = new THREE.Color(0x112211);
|
910 |
-
camera.position.set(0, 2, 7); camera.lookAt(0, 1, 0);
|
911 |
-
assemblyFunction = createGoblinAmbushAssembly; break;
|
912 |
-
case 'forest-shadows-hiding-goblins-walking-past': // Reuse ambush scene, player is just "observing"
|
913 |
-
case 'defeated-goblins-forest-path-loot': // Reuse ambush scene, maybe remove goblins?
|
914 |
-
case 'blurred-motion-running-past-goblins-forest': // Reuse ambush scene
|
915 |
-
scene.fog = new THREE.Fog(0x1A2F2A, 3, 15);
|
916 |
-
scene.background = new THREE.Color(0x112211);
|
917 |
-
camera.position.set(0, 2, 7); camera.lookAt(0, 1, 0);
|
918 |
-
assemblyFunction = createGoblinAmbushAssembly; break; // Needs refinement for different states
|
919 |
-
case 'forest-stream-crossing-dappled-sunlight-stones':
|
920 |
-
scene.fog = new THREE.Fog(0x668866, 8, 25); // Lighter green fog
|
921 |
-
scene.background = new THREE.Color(0x446644); // Lighter green background
|
922 |
-
camera.position.set(0, 2, 6); camera.lookAt(0, 0.5, 0);
|
923 |
-
assemblyFunction = createForestAssembly; break; // Add stream element?
|
924 |
-
case 'mossy-log-bridge-over-forest-stream':
|
925 |
-
scene.fog = new THREE.Fog(0x668866, 8, 25);
|
926 |
-
scene.background = new THREE.Color(0x446644);
|
927 |
-
camera.position.set(1, 2, 5); camera.lookAt(-1, 0.5, 0); // Look across log
|
928 |
-
assemblyFunction = createForestAssembly; break; // Add log/stream elements?
|
929 |
-
case 'character-splashing-into-stream-from-log': // Reuse stream scene
|
930 |
-
scene.fog = new THREE.Fog(0x668866, 8, 25);
|
931 |
-
scene.background = new THREE.Color(0x446644);
|
932 |
-
camera.position.set(0, 2, 6); camera.lookAt(0, 0.5, 0);
|
933 |
-
assemblyFunction = createForestAssembly; break;
|
934 |
-
case 'forest-edge-view-rocky-foothills-distant-mountain-fortress':
|
935 |
-
case 'forest-edge': // Reuse explicit key
|
936 |
-
scene.fog = new THREE.Fog(0xAAAAAA, 10, 40); // Grey fog
|
937 |
-
scene.background = new THREE.Color(0x888888); // Grey background
|
938 |
-
camera.position.set(0, 3, 10); camera.lookAt(0, 1, -5); // Look towards foothills
|
939 |
-
assemblyFunction = createForestEdgeAssembly; break;
|
940 |
-
case 'climbing-rocky-foothills-path-fortress-closer':
|
941 |
-
case 'rockslide-blocking-mountain-path-boulders':
|
942 |
-
case 'character-climbing-over-boulders':
|
943 |
-
case 'character-slipping-on-rockslide-boulders':
|
944 |
-
case 'rough-detour-path-around-rockslide':
|
945 |
-
scene.fog = new THREE.Fog(0x778899, 8, 35); // Light slate gray fog
|
946 |
-
scene.background = new THREE.Color(0x708090); // Slate gray
|
947 |
-
camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0);
|
948 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder - Needs rocky foothills assembly
|
949 |
-
case 'zoomed-view-mountain-fortress-western-ridge': // Reuse foothills view
|
950 |
-
scene.fog = new THREE.Fog(0x778899, 8, 35);
|
951 |
-
scene.background = new THREE.Color(0x708090);
|
952 |
-
camera.position.set(5, 6, 12); camera.lookAt(-2, 3, -5); // Zoomed/angled view
|
953 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder
|
954 |
-
case 'narrow-goat-trail-mountainside-fortress-view':
|
955 |
-
scene.fog = new THREE.Fog(0x778899, 5, 30); // Closer fog
|
956 |
-
scene.background = new THREE.Color(0x708090);
|
957 |
-
camera.position.set(1, 3, 6); camera.lookAt(0, 2, -2); // View along narrow trail
|
958 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder
|
959 |
-
case 'narrow-windy-mountain-ridge-path':
|
960 |
-
case 'character-falling-off-windy-ridge':
|
961 |
-
scene.fog = new THREE.Fog(0x8899AA, 6, 25); // Windy grey-blue fog
|
962 |
-
scene.background = new THREE.Color(0x778899); // Lighter slate gray
|
963 |
-
camera.position.set(2, 5, 7); camera.lookAt(0, 3, -3);
|
964 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder
|
965 |
-
case 'approaching-dark-fortress-walls-guards':
|
966 |
-
scene.fog = new THREE.Fog(0x444455, 5, 20); // Dark imposing fog
|
967 |
-
scene.background = new THREE.Color(0x333344); // Dark stone/shadow
|
968 |
-
camera.position.set(0, 3, 8); camera.lookAt(0, 2, 0);
|
969 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder - Needs fortress walls assembly
|
970 |
-
|
971 |
-
case 'hidden-cove-beach-dark-cave-entrance':
|
972 |
-
case 'character-fallen-at-bottom-of-cliff-path-cove': // Reuse cove scene
|
973 |
-
scene.fog = new THREE.Fog(0x336699, 5, 30); // Cove fog
|
974 |
-
scene.background = new THREE.Color(0x336699); // Cove blue/grey
|
975 |
-
camera.position.set(0, 2, 8); camera.lookAt(0, 1, -2); // Look towards cave
|
976 |
-
assemblyFunction = createHiddenCoveAssembly; break;
|
977 |
-
case 'scanning-sea-cliffs-no-other-paths-visible': // Reuse cliff scene
|
978 |
-
case 'close-up-handholds-carved-in-cliff-face': // Reuse cliff scene
|
979 |
-
scene.fog = new THREE.Fog(0x6699CC, 10, 40);
|
980 |
-
scene.background = new THREE.Color(0x6699CC);
|
981 |
-
camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5);
|
982 |
-
assemblyFunction = createCoastalCliffsAssembly; break;
|
983 |
-
case 'dark-cave-entrance-dripping-water':
|
984 |
-
scene.fog = new THREE.Fog(0x1A1A1A, 2, 10); // Very dark, close fog
|
985 |
-
scene.background = new THREE.Color(0x111111); // Near black
|
986 |
-
camera.position.set(0, 1.5, 4); camera.lookAt(0, 1, 0);
|
987 |
-
assemblyFunction = createDarkCaveAssembly; break;
|
988 |
-
case 'overgrown-stone-shrine-wildflowers-close': // Reuse hill scene, adjust camera
|
989 |
-
scene.fog = new THREE.Fog(0xA8E4A0, 15, 50);
|
990 |
-
scene.background = new THREE.Color(0x90EE90);
|
991 |
-
camera.position.set(1, 2, 4); camera.lookAt(0, 0.5, 0); // Close up on shrine area
|
992 |
-
assemblyFunction = createRollingHillsAssembly; break; // Needs shrine element
|
993 |
-
case 'rocky-badlands-cracked-earth-harsh-sun':
|
994 |
-
scene.fog = new THREE.Fog(0xD2B48C, 15, 40); // Tan/Dusty fog
|
995 |
-
scene.background = new THREE.Color(0xCD853F); // Peru/Brown background
|
996 |
-
camera.position.set(0, 3, 12); camera.lookAt(0, 1, 0);
|
997 |
-
assemblyFunction = createDefaultAssembly; break; // Placeholder - Needs badlands assembly
|
998 |
-
case 'pushing-through-forest-undergrowth': // Reuse generic forest
|
999 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
1000 |
-
scene.background = new THREE.Color(0x1A1A1A);
|
1001 |
-
camera.position.set(0, 1.5, 5); camera.lookAt(0, 1, 0);
|
1002 |
-
assemblyFunction = createForestAssembly; break;
|
1003 |
-
case 'character-crossing-rope-bridge-safely': // Reuse ravine/bridge scene
|
1004 |
-
case 'rope-bridge-snapping-character-falling': // Reuse ravine/bridge scene
|
1005 |
-
case 'fallen-log-crossing-ravine': // Reuse ravine scene
|
1006 |
-
scene.fog = new THREE.Fog(0x2E2E2E, 5, 20);
|
1007 |
-
scene.background = new THREE.Color(0x1A1A1A);
|
1008 |
-
camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2);
|
1009 |
-
assemblyFunction = createForestAssembly; break; // Needs bridge/ravine elements
|
1010 |
-
|
1011 |
-
|
1012 |
default:
|
1013 |
-
|
1014 |
-
|
1015 |
-
}
|
1016 |
try {
|
1017 |
currentAssemblyGroup = assemblyFunction();
|
1018 |
-
if (currentAssemblyGroup) {
|
1019 |
-
scene.add(currentAssemblyGroup);
|
1020 |
-
adjustLighting(illustrationKey); // Adjust lighting based on the specific scene key
|
1021 |
-
} else {
|
1022 |
-
throw new Error("Assembly function returned undefined or null.");
|
1023 |
-
}
|
1024 |
-
} catch (error) {
|
1025 |
-
console.error(`Error creating assembly for ${illustrationKey}:`, error);
|
1026 |
-
if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); } // Clean up potential partial assembly
|
1027 |
-
currentAssemblyGroup = createErrorAssembly(); // Display error cone
|
1028 |
scene.add(currentAssemblyGroup);
|
1029 |
-
adjustLighting(
|
|
|
|
|
|
|
|
|
|
|
1030 |
}
|
1031 |
-
onWindowResize();
|
1032 |
}
|
1033 |
|
1034 |
function adjustLighting(illustrationKey) {
|
1035 |
if (!scene) return;
|
1036 |
-
|
1037 |
-
|
1038 |
-
lightsToRemove.forEach(light => scene.remove(light));
|
1039 |
-
|
1040 |
const ambient = scene.children.find(c => c.isAmbientLight);
|
1041 |
-
if (!ambient)
|
1042 |
-
console.warn("No ambient light found in scene, adding default.");
|
1043 |
-
scene.add(new THREE.AmbientLight(0xffffff, 0.5)); // Add default if missing
|
1044 |
-
}
|
1045 |
|
1046 |
-
let
|
1047 |
-
let lightIntensity = 1.2;
|
1048 |
-
let ambientIntensity = 0.5;
|
1049 |
-
let lightColor = 0xffffff;
|
1050 |
-
let lightPosition = {x: 8, y: 15, z: 10};
|
1051 |
-
|
1052 |
-
// Adjust lighting based on scene type
|
1053 |
switch (illustrationKey) {
|
1054 |
case 'crossroads-signpost-sunny':
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
case '
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
case 'dark-cave-entrance-dripping-water':
|
1064 |
-
ambientIntensity = 0.1; lightIntensity = 0.2; lightColor = 0x666699; lightPosition = {x: 0, y: 5, z: 2}; break; // Very dim, bluish cave light from entrance?
|
1065 |
-
case 'windy-sea-cliffs-crashing-waves-path-down':
|
1066 |
-
case 'hidden-cove-beach-dark-cave-entrance':
|
1067 |
-
ambientIntensity = 0.6; lightIntensity = 1.0; lightColor = 0xCCDDFF; lightPosition = {x: -10, y: 12, z: 8}; break; // Overcast/Coastal light
|
1068 |
-
case 'rocky-badlands-cracked-earth-harsh-sun':
|
1069 |
-
ambientIntensity = 0.7; lightIntensity = 1.8; lightColor = 0xFFFFDD; lightPosition = {x: 5, y: 20, z: 5}; break; // Harsh sunlight
|
1070 |
-
case 'approaching-dark-fortress-walls-guards':
|
1071 |
-
case 'prisoner-cell':
|
1072 |
-
ambientIntensity = 0.2; lightIntensity = 0.5; lightColor = 0x7777AA; lightPosition = {x: 0, y: 10, z: 5}; break; // Gloomy, cold light
|
1073 |
-
case 'game-over': case 'game-over-generic':
|
1074 |
-
ambientIntensity = 0.1; lightIntensity = 0.8; lightColor = 0xFF6666; lightPosition = {x: 0, y: 5, z: 5}; break; // Reddish tint
|
1075 |
-
case 'error':
|
1076 |
-
ambientIntensity = 0.4; lightIntensity = 1.0; lightColor = 0xFFCC00; lightPosition = {x: 0, y: 5, z: 5}; break; // Orange tint
|
1077 |
-
default: // Default lighting
|
1078 |
-
ambientIntensity = 0.5; lightIntensity = 1.2; lightColor = 0xffffff; lightPosition = {x: 8, y: 15, z: 10}; break;
|
1079 |
-
}
|
1080 |
-
|
1081 |
-
// Update ambient light
|
1082 |
-
const currentAmbient = scene.children.find(c => c.isAmbientLight);
|
1083 |
-
if (currentAmbient) {
|
1084 |
-
currentAmbient.intensity = ambientIntensity;
|
1085 |
}
|
1086 |
|
1087 |
-
|
1088 |
-
|
1089 |
-
directionalLight.position.set(lightPosition.x, lightPosition.y, lightPosition.z);
|
1090 |
-
directionalLight.castShadow = true;
|
1091 |
-
// Configure shadow properties
|
1092 |
-
directionalLight.shadow.mapSize.set(1024, 1024);
|
1093 |
-
directionalLight.shadow.camera.near = 0.5;
|
1094 |
-
directionalLight.shadow.camera.far = 50; // Adjust based on scene scale
|
1095 |
-
directionalLight.shadow.camera.left = -15; // Adjust based on scene scale
|
1096 |
-
directionalLight.shadow.camera.right = 15;
|
1097 |
-
directionalLight.shadow.camera.top = 15;
|
1098 |
-
directionalLight.shadow.camera.bottom = -15;
|
1099 |
-
scene.add(directionalLight);
|
1100 |
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1104 |
}
|
1105 |
|
1106 |
-
/*
|
1107 |
-
Potential Areas for Expansion/Improvement:
|
1108 |
-
|
1109 |
-
* More Scene Variety: Add more create...Assembly functions and corresponding illustration keys for greater visual diversity.
|
1110 |
-
* More Complex Scenes: The current scenes are quite abstract. More detail could be added, potentially involving more complex geometry or even simple pre-made models loaded for key elements.
|
1111 |
-
* Interaction: Add interaction with the 3D scene (e.g., clicking on objects using raycasting).
|
1112 |
-
* Combat System: Implement a more detailed combat mechanic instead of abstract resolution (e.g., turn-based, HP tracking for enemies).
|
1113 |
-
* Character Progression: Implement a level-up system based on XP (increase stats, HP, unlock abilities). Check for level up after gaining XP.
|
1114 |
-
* Save/Load: Add functionality to save and load game progress (perhaps using `localStorage` to store `gameState`).
|
1115 |
-
* Data Management: For a larger game, storing `gameData` and `itemsData` in external JSON files and fetching them would be more manageable.
|
1116 |
-
* Error Handling: Add more robust checks for missing data (items, pages) or potential errors during scene generation and game logic. Improve feedback on errors.
|
1117 |
-
* Code Organization: Split the JavaScript into modules (e.g., `three-setup.js`, `game-logic.js`, `ui-manager.js`, `scene-generator.js`, `data.js`) for better maintainability using ES6 modules.
|
1118 |
-
* Refine Scene Logic: Improve how scene elements correspond to game state (e.g., remove defeated goblins from the scene, add visual representation of items found).
|
1119 |
-
* Add More Mechanics: Implement status effects, equipment slots, spells with costs, currency, shops, more complex skill checks (e.g., opposed checks, checks with advantage/disadvantage).
|
1120 |
-
* Accessibility: Review and improve accessibility (ARIA attributes, keyboard navigation).
|
1121 |
-
* Performance: For very complex scenes or many objects, consider optimizing geometry (instancing) and rendering.
|
1122 |
-
*/
|
1123 |
-
|
1124 |
-
// Initialization
|
1125 |
document.addEventListener('DOMContentLoaded', () => {
|
1126 |
-
console.log("DOM Ready. Initializing game...");
|
1127 |
try {
|
1128 |
initThreeJS();
|
1129 |
if (scene && camera && renderer) {
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
console.error("Initialization failed:", error);
|
1137 |
storyTitleElement.textContent = "Initialization Error";
|
1138 |
-
storyContentElement.innerHTML = `<p>
|
1139 |
-
|
1140 |
-
|
1141 |
-
if (sceneContainer) sceneContainer.innerHTML = '<p style="color:red; padding: 10px;">3D Scene Failed to Load</p>';
|
1142 |
}
|
1143 |
});
|
1144 |
</script>
|
1145 |
</body>
|
1146 |
-
</html>
|
|
|
234 |
return ground;
|
235 |
}
|
236 |
|
237 |
+
// [Procedural generation functions here: createDefaultAssembly, createCityGatesAssembly, etc.]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
|
239 |
// Game Data
|
240 |
const itemsData = {
|
241 |
"Flaming Sword":{type:"weapon", description:"A fiery blade"},
|
242 |
+
// … [other items]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
};
|
244 |
|
245 |
const gameData = {
|
246 |
+
"1": { title: "The Crossroads", content: `<p>…</p>`, options: [ { text: "Enter the Shadowwood Forest (North)", next: 5 }, /* … */ ], illustration: "crossroads-signpost-sunny" },
|
247 |
+
// … [all other pages]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
};
|
249 |
|
250 |
// Game State
|
|
|
260 |
|
261 |
// Game Logic Functions
|
262 |
function startGame() {
|
263 |
+
const defaultChar = {
|
264 |
+
name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer",
|
265 |
+
level: 1, xp: 0, xpToNextLevel: 100,
|
266 |
+
stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 },
|
267 |
+
inventory: []
|
268 |
+
};
|
269 |
gameState = { currentPageId: 1, character: JSON.parse(JSON.stringify(defaultChar)) };
|
270 |
renderPage(gameState.currentPageId);
|
271 |
}
|
272 |
|
273 |
function handleChoiceClick(choiceData) {
|
274 |
+
// FIXED: use `choiceData.next` (which we actually pass) instead of undefined `choiceData.nextPage`
|
275 |
+
const optionNextPageId = Number(choiceData.next);
|
276 |
const itemToAdd = choiceData.addItem;
|
277 |
let nextPageId = optionNextPageId;
|
278 |
let rollResultMessage = "";
|
279 |
const check = choiceData.check;
|
280 |
|
281 |
+
if (isNaN(optionNextPageId) && !check && choiceData.next !== 1) {
|
282 |
console.error("Invalid choice data:", choiceData);
|
283 |
renderPageInternal(99, gameData[99] || { title: "Error", content: "<p>Invalid Choice Data!</p>", illustration: "error", gameOver: true }, "<p><em>Error: Invalid choice data encountered!</em></p>");
|
284 |
return;
|
285 |
}
|
286 |
|
287 |
+
if (choiceData.next === 1 && gameState.currentPageId === 99) {
|
288 |
+
startGame();
|
289 |
+
return;
|
290 |
+
}
|
|
|
291 |
|
292 |
if (check) {
|
293 |
const statValue = gameState.character.stats[check.stat] || 10;
|
|
|
300 |
nextPageId = optionNextPageId;
|
301 |
rollResultMessage = `<p class="roll-success"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Success! (Rolled ${roll} + ${modifier} = ${totalResult} vs DC ${dc})</em></p>`;
|
302 |
} else {
|
303 |
+
nextPageId = parseInt(check.onFailure, 10);
|
304 |
rollResultMessage = `<p class="roll-failure"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Failed! (Rolled ${roll} + ${modifier} = ${totalResult} vs DC ${dc})</em></p>`;
|
305 |
if (isNaN(nextPageId)) {
|
306 |
console.error("Invalid onFailure ID:", check.onFailure);
|
307 |
+
nextPageId = 99;
|
308 |
rollResultMessage += "<p><em>Error: Invalid failure path!</em></p>";
|
309 |
}
|
310 |
}
|
311 |
}
|
312 |
|
|
|
313 |
const targetPageData = gameData[nextPageId];
|
314 |
+
if (targetPageData) {
|
315 |
+
if (targetPageData.hpLoss) {
|
316 |
+
gameState.character.stats.hp -= targetPageData.hpLoss;
|
317 |
+
if (gameState.character.stats.hp <= 0) {
|
318 |
+
gameState.character.stats.hp = 0;
|
319 |
+
nextPageId = 99;
|
320 |
+
rollResultMessage += "<p><em>You have succumbed to your injuries!</em></p>";
|
321 |
+
}
|
322 |
+
}
|
323 |
+
if (targetPageData.reward) {
|
324 |
+
if (targetPageData.reward.xp) {
|
325 |
+
gameState.character.xp += targetPageData.reward.xp;
|
326 |
+
}
|
327 |
+
if (targetPageData.reward.statIncrease) {
|
328 |
+
const { stat, amount } = targetPageData.reward.statIncrease;
|
329 |
+
if (gameState.character.stats.hasOwnProperty(stat)) {
|
330 |
+
gameState.character.stats[stat] += amount;
|
331 |
+
if (stat === 'constitution') {
|
332 |
+
const conMod = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
333 |
+
gameState.character.stats.maxHp = 10 + (conMod * gameState.character.level);
|
334 |
+
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp);
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
if (targetPageData.reward.addItem && !gameState.character.inventory.includes(targetPageData.reward.addItem)) {
|
339 |
+
gameState.character.inventory.push(targetPageData.reward.addItem);
|
340 |
+
}
|
341 |
+
}
|
342 |
+
if (itemToAdd && !gameState.character.inventory.includes(itemToAdd)) {
|
343 |
+
gameState.character.inventory.push(itemToAdd);
|
344 |
+
}
|
345 |
+
} else {
|
346 |
+
console.error(`Data for page ${nextPageId} not found!`);
|
347 |
+
renderPageInternal(99, gameData[99], "<p><em>Error: Next page data missing!</em></p>");
|
348 |
+
return;
|
349 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
|
|
|
351 |
gameState.currentPageId = nextPageId;
|
|
|
352 |
const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
353 |
+
gameState.character.stats.maxHp = 10 + conModifier;
|
354 |
+
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp);
|
355 |
|
|
|
356 |
renderPageInternal(nextPageId, gameData[nextPageId], rollResultMessage);
|
357 |
}
|
358 |
|
|
|
359 |
function renderPageInternal(pageId, pageData, message = "") {
|
360 |
if (!pageData) {
|
361 |
+
pageData = gameData[99];
|
|
|
362 |
message += "<p><em>Render Error: Page data missing!</em></p>";
|
363 |
+
pageId = 99;
|
364 |
+
}
|
365 |
|
366 |
+
storyTitleElement.textContent = pageData.title;
|
367 |
+
storyContentElement.innerHTML = message + pageData.content;
|
368 |
|
369 |
updateStatsDisplay();
|
370 |
updateInventoryDisplay();
|
371 |
|
372 |
+
choicesElement.innerHTML = '';
|
|
|
373 |
const options = pageData.options || [];
|
374 |
const isGameOverOrEnd = pageData.gameOver || options.length === 0;
|
375 |
|
|
|
381 |
let requirementMet = true;
|
382 |
let requirementText = "";
|
383 |
|
384 |
+
if (option.requireItem && !gameState.character.inventory.includes(option.requireItem)) {
|
385 |
+
requirementMet = false;
|
386 |
+
requirementText = `Requires: ${option.requireItem}`;
|
|
|
|
|
|
|
387 |
}
|
|
|
|
|
388 |
|
389 |
button.disabled = !requirementMet;
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
if (requirementMet) {
|
391 |
const choiceData = {
|
392 |
next: option.next,
|
393 |
+
addItem: option.addItem,
|
394 |
check: option.check
|
395 |
};
|
396 |
button.onclick = () => handleChoiceClick(choiceData);
|
397 |
+
} else {
|
398 |
+
button.title = requirementText;
|
399 |
+
button.classList.add('disabled');
|
400 |
}
|
401 |
+
|
402 |
choicesElement.appendChild(button);
|
403 |
});
|
404 |
} else {
|
|
|
405 |
const button = document.createElement('button');
|
406 |
button.classList.add('choice-button');
|
407 |
button.textContent = pageData.gameOver ? "Restart Adventure" : "The Path Ends Here (Restart?)";
|
408 |
+
button.onclick = () => handleChoiceClick({ next: 1 });
|
409 |
choicesElement.appendChild(button);
|
410 |
if (!pageData.gameOver) {
|
411 |
choicesElement.insertAdjacentHTML('afterbegin', '<p><i>There are no further paths from here.</i></p>');
|
|
|
418 |
function renderPage(pageId) { renderPageInternal(pageId, gameData[pageId]); }
|
419 |
|
420 |
function updateStatsDisplay() {
|
421 |
+
const c = gameState.character;
|
422 |
+
statsElement.innerHTML =
|
423 |
+
`<strong>Stats:</strong>
|
424 |
+
<span>Lvl: ${c.level}</span>
|
425 |
+
<span>XP: ${c.xp}/${c.xpToNextLevel}</span>
|
426 |
+
<span>HP: ${c.stats.hp}/${c.stats.maxHp}</span>
|
427 |
+
<span>Str: ${c.stats.strength}</span>
|
428 |
+
<span>Int: ${c.stats.intelligence}</span>
|
429 |
+
<span>Wis: ${c.stats.wisdom}</span>
|
430 |
+
<span>Dex: ${c.stats.dexterity}</span>
|
431 |
+
<span>Con: ${c.stats.constitution}</span>
|
432 |
+
<span>Cha: ${c.stats.charisma}</span>`;
|
433 |
}
|
434 |
|
435 |
function updateInventoryDisplay() {
|
436 |
+
let html = '<strong>Inventory:</strong> ';
|
437 |
+
if (gameState.character.inventory.length === 0) {
|
438 |
+
html += '<em>Empty</em>';
|
439 |
} else {
|
440 |
+
gameState.character.inventory.forEach(itemName => {
|
441 |
+
const item = itemsData[itemName] || { type: 'unknown', description: 'An unknown item.' };
|
442 |
+
const cls = `item-${item.type || 'unknown'}`;
|
443 |
+
html += `<span class="${cls}" title="${item.description}">${itemName}</span>`;
|
444 |
});
|
445 |
}
|
446 |
+
inventoryElement.innerHTML = html;
|
447 |
}
|
448 |
|
449 |
function updateScene(illustrationKey) {
|
450 |
+
if (!scene) return;
|
451 |
+
if (currentAssemblyGroup) scene.remove(currentAssemblyGroup);
|
452 |
+
scene.fog = null;
|
453 |
+
scene.background = new THREE.Color(0x222222);
|
454 |
+
camera.position.set(0, 2.5, 7);
|
455 |
+
camera.lookAt(0, 0.5, 0);
|
|
|
456 |
|
457 |
let assemblyFunction;
|
458 |
switch (illustrationKey) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
case 'crossroads-signpost-sunny':
|
460 |
+
scene.fog = new THREE.Fog(0x87CEEB, 10, 30);
|
461 |
+
scene.background = new THREE.Color(0x87CEEB);
|
462 |
camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0);
|
463 |
+
assemblyFunction = createCrossroadsAssembly;
|
464 |
+
break;
|
465 |
+
// … [all other cases]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
default:
|
467 |
+
assemblyFunction = createDefaultAssembly;
|
468 |
+
break;
|
469 |
+
}
|
470 |
try {
|
471 |
currentAssemblyGroup = assemblyFunction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
scene.add(currentAssemblyGroup);
|
473 |
+
adjustLighting(illustrationKey);
|
474 |
+
} catch (e) {
|
475 |
+
console.error(`Error building scene "${illustrationKey}":`, e);
|
476 |
+
currentAssemblyGroup = createErrorAssembly();
|
477 |
+
scene.add(currentAssemblyGroup);
|
478 |
+
adjustLighting('error');
|
479 |
}
|
480 |
+
onWindowResize();
|
481 |
}
|
482 |
|
483 |
function adjustLighting(illustrationKey) {
|
484 |
if (!scene) return;
|
485 |
+
const toRemove = scene.children.filter(c => c.isLight && !c.isAmbientLight);
|
486 |
+
toRemove.forEach(l => scene.remove(l));
|
|
|
|
|
487 |
const ambient = scene.children.find(c => c.isAmbientLight);
|
488 |
+
if (!ambient) scene.add(new THREE.AmbientLight(0xffffff, 0.5));
|
|
|
|
|
|
|
489 |
|
490 |
+
let intensity = 1.2, amb = 0.5, color = 0xffffff, pos = { x: 8, y: 15, z: 10 };
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
switch (illustrationKey) {
|
492 |
case 'crossroads-signpost-sunny':
|
493 |
+
amb = 0.8; intensity = 1.5; color = 0xFFF8E1; pos = { x: 10, y: 15, z: 10 };
|
494 |
+
break;
|
495 |
+
// … [lighting cases]
|
496 |
+
case 'error':
|
497 |
+
amb = 0.4; intensity = 1.0; color = 0xFFCC00; pos = { x: 0, y: 5, z: 5 };
|
498 |
+
break;
|
499 |
+
default:
|
500 |
+
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
}
|
502 |
|
503 |
+
const ambLight = scene.children.find(c => c.isAmbientLight);
|
504 |
+
if (ambLight) ambLight.intensity = amb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
505 |
|
506 |
+
const dir = new THREE.DirectionalLight(color, intensity);
|
507 |
+
dir.position.set(pos.x, pos.y, pos.z);
|
508 |
+
dir.castShadow = true;
|
509 |
+
dir.shadow.mapSize.set(1024, 1024);
|
510 |
+
dir.shadow.camera.near = 0.5;
|
511 |
+
dir.shadow.camera.far = 50;
|
512 |
+
dir.shadow.camera.left = -15;
|
513 |
+
dir.shadow.camera.right = 15;
|
514 |
+
dir.shadow.camera.top = 15;
|
515 |
+
dir.shadow.camera.bottom = -15;
|
516 |
+
scene.add(dir);
|
517 |
}
|
518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
520 |
try {
|
521 |
initThreeJS();
|
522 |
if (scene && camera && renderer) {
|
523 |
+
startGame();
|
524 |
+
} else {
|
525 |
+
throw new Error("Three.js failed to initialize.");
|
526 |
+
}
|
527 |
+
} catch (err) {
|
528 |
+
console.error("Initialization error:", err);
|
|
|
529 |
storyTitleElement.textContent = "Initialization Error";
|
530 |
+
storyContentElement.innerHTML = `<p>Unable to start the game. Check console for details.</p><pre>${err.stack}</pre>`;
|
531 |
+
choicesElement.innerHTML = '<p>Cannot proceed.</p>';
|
532 |
+
if (sceneContainer) sceneContainer.innerHTML = '<p style="color:red; padding:10px;">3D Scene Failed</p>';
|
|
|
533 |
}
|
534 |
});
|
535 |
</script>
|
536 |
</body>
|
537 |
+
</html>
|