Spaces:
Running
Running
Update index.html
Browse files- index.html +431 -170
index.html
CHANGED
@@ -125,12 +125,12 @@
|
|
125 |
<p>Please wait while the adventure loads.</p>
|
126 |
</div>
|
127 |
<div id="stats-inventory-container">
|
128 |
-
|
129 |
-
|
130 |
</div>
|
131 |
<div id="choices-container">
|
132 |
-
|
133 |
-
|
134 |
</div>
|
135 |
</div>
|
136 |
</div>
|
@@ -542,20 +542,21 @@
|
|
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"},
|
@@ -572,40 +573,50 @@
|
|
572 |
};
|
573 |
|
574 |
const gameData = {
|
575 |
-
"1": { title: "The Crossroads", content: `<p>Dust swirls
|
576 |
-
"2": { title: "Rolling Hills", content: `<p>Verdant hills stretch before you
|
577 |
-
"3": { title: "Coastal Cliffs Edge", content: `<p>You stand atop windswept cliffs
|
578 |
-
"4": { title: "Hill Path Overlook", content: `<p>The path crests a hill
|
579 |
-
"5": { title: "Shadowwood Entrance", content: `<p>Sunlight struggles to pierce the
|
580 |
-
"6": { title: "Overgrown Forest Path", content: `<p>The path is barely visible
|
581 |
-
"7": { title: "Tangled Undergrowth", content: `<p>Pushing through ferns
|
582 |
-
"8": { title: "Hidden Game Trail", content: `<p>Your sharp eyes spot a faint trail
|
583 |
-
"10": { title: "Goblin Ambush!", content: `<p>
|
584 |
-
"11": { title: "Hidden Evasion", content: `<p>
|
585 |
-
"12": { title: "Ambush Victory!", content: `<p>
|
586 |
-
"13": { title: "Daring Escape", content: `<p>With surprising agility, you
|
587 |
-
"14": { title: "Forest Stream Crossing", content: `<p>The path leads to a clear, shallow stream
|
588 |
-
"15": { title: "Log Bridge", content: `<p>
|
589 |
-
"151": { title: "Splash!", content: `<p>You
|
590 |
-
"16": { title: "Edge of the Woods", content: `<p>
|
591 |
-
"17": { title: "Rocky Foothills Path", content: `<p>The climb is arduous
|
592 |
-
"18": { title: "Distant Observation", content: `<p>
|
593 |
-
"19": { title: "Blocked Pass", content: `<p>
|
594 |
-
"20": { title: "Goat Trail", content: `<p>
|
595 |
-
"30": { title: "Hidden Cove", content: `<p>Your careful descent brings you to a secluded cove.
|
596 |
-
"31": { title: "Tumbled Down", content: `<p>You lose your footing
|
597 |
-
"32": { title: "No Easier Path", content: `<p>You scan the cliffs intently
|
598 |
-
"33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot a series of barely visible handholds and
|
599 |
-
"35": { title: "Dark Cave", content: `<p>
|
600 |
-
"40": { title: "Overgrown Shrine", content: `<p>
|
601 |
-
"
|
602 |
-
"
|
603 |
-
"
|
604 |
-
"
|
605 |
-
"
|
606 |
-
"
|
607 |
-
"
|
608 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
609 |
};
|
610 |
|
611 |
// Game State
|
@@ -621,8 +632,10 @@
|
|
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 |
-
|
|
|
626 |
renderPage(gameState.currentPageId);
|
627 |
}
|
628 |
|
@@ -633,7 +646,17 @@
|
|
633 |
let rollResultMessage = "";
|
634 |
const check = choiceData.check;
|
635 |
|
636 |
-
if (isNaN(optionNextPageId) && !check
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
|
638 |
if (check) {
|
639 |
const statValue = gameState.character.stats[check.stat] || 10;
|
@@ -644,92 +667,153 @@
|
|
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
|
648 |
} else {
|
649 |
nextPageId = parseInt(check.onFailure);
|
650 |
-
rollResultMessage = `<p class="roll-failure"><em
|
651 |
-
if (isNaN(nextPageId)) {
|
|
|
|
|
|
|
|
|
652 |
}
|
653 |
}
|
654 |
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
660 |
gameState.currentPageId = nextPageId;
|
661 |
-
|
|
|
|
|
|
|
662 |
|
663 |
-
|
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>");
|
694 |
-
return;
|
695 |
-
}
|
696 |
renderPageInternal(nextPageId, gameData[nextPageId], rollResultMessage);
|
697 |
}
|
698 |
|
|
|
699 |
function renderPageInternal(pageId, pageData, message = "") {
|
700 |
-
if (!pageData) {
|
|
|
|
|
|
|
|
|
|
|
|
|
701 |
storyTitleElement.textContent = pageData.title || "Untitled Page";
|
702 |
storyContentElement.innerHTML = message + (pageData.content || "<p>...</p>");
|
|
|
703 |
updateStatsDisplay();
|
704 |
updateInventoryDisplay();
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
733 |
updateScene(pageData.illustration || 'default');
|
734 |
}
|
735 |
|
@@ -745,139 +829,316 @@
|
|
745 |
if(gameState.character.inventory.length === 0){
|
746 |
h+='<em>Empty</em>';
|
747 |
} else {
|
748 |
-
gameState.character.inventory.forEach(
|
749 |
-
const
|
750 |
-
const
|
751 |
-
h
|
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;
|
768 |
case 'temple': assemblyFunction = createTempleAssembly; break;
|
769 |
case 'resistance-meeting': assemblyFunction = createResistanceMeetingAssembly; break;
|
770 |
-
case 'shadowwood-forest': assemblyFunction = createForestAssembly; 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 |
-
|
|
|
|
|
|
|
800 |
camera.position.set(0, 2, 5); camera.lookAt(0, 1, 0);
|
801 |
assemblyFunction = createClearingStatueAssembly; break;
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
806 |
case 'hidden-cove-beach-dark-cave-entrance':
|
807 |
-
|
808 |
-
scene.
|
809 |
-
|
|
|
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(
|
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 |
-
|
823 |
-
|
|
|
|
|
|
|
|
|
824 |
} catch (error) {
|
825 |
console.error(`Error creating assembly for ${illustrationKey}:`, error);
|
826 |
-
currentAssemblyGroup
|
|
|
827 |
scene.add(currentAssemblyGroup);
|
|
|
828 |
}
|
|
|
829 |
}
|
830 |
|
831 |
function adjustLighting(illustrationKey) {
|
832 |
-
scene
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
const ambient = scene.children.find(c => c.isAmbientLight);
|
|
|
|
|
|
|
|
|
|
|
838 |
let directionalLight;
|
|
|
|
|
|
|
|
|
|
|
|
|
839 |
switch (illustrationKey) {
|
840 |
case 'crossroads-signpost-sunny':
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
break;
|
845 |
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
846 |
case 'overgrown-forest-path-glowing-fungi-vines':
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
break;
|
851 |
case 'dark-cave-entrance-dripping-water':
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
break;
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
877 |
} catch (error) {
|
878 |
-
console.error("
|
879 |
-
storyTitleElement.textContent = "Error";
|
880 |
-
storyContentElement.innerHTML = `<p>
|
|
|
|
|
|
|
881 |
}
|
882 |
});
|
883 |
</script>
|
|
|
125 |
<p>Please wait while the adventure loads.</p>
|
126 |
</div>
|
127 |
<div id="stats-inventory-container">
|
128 |
+
<div id="stats-display"></div>
|
129 |
+
<div id="inventory-display"></div>
|
130 |
</div>
|
131 |
<div id="choices-container">
|
132 |
+
<h3>What will you do?</h3>
|
133 |
+
<div id="choices"></div>
|
134 |
</div>
|
135 |
</div>
|
136 |
</div>
|
|
|
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"},
|
|
|
573 |
};
|
574 |
|
575 |
const gameData = {
|
576 |
+
"1": { title: "The Crossroads", content: `<p>Dust swirls around a weathered signpost under a bright, midday sun. Paths lead north into the gloomy Shadowwood, east towards rolling green hills, and west towards coastal cliffs battered by sea spray. 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" },
|
577 |
+
"2": { title: "Rolling Hills", content: `<p>Verdant hills stretch before you, dotted with wildflowers. A gentle breeze whispers through the tall grass. In the distance, you see a lone figure tending to a flock of sheep. It feels peaceful, almost unnervingly so after the crossroads.</p>`, options: [ { text: "Follow the narrow path winding through the hills", next: 4 }, { text: "Try to hail the distant shepherd (Charisma Check?)", next: 99 } ], illustration: "rolling-green-hills-shepherd-distance" },
|
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 |
|
633 |
// Game Logic Functions
|
634 |
function startGame() {
|
635 |
+
// Reset state if restarting
|
636 |
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: [] };
|
637 |
+
// Deep copy necessary for nested objects like stats
|
638 |
+
gameState = { currentPageId: 1, character: JSON.parse(JSON.stringify(defaultChar)) };
|
639 |
renderPage(gameState.currentPageId);
|
640 |
}
|
641 |
|
|
|
646 |
let rollResultMessage = "";
|
647 |
const check = choiceData.check;
|
648 |
|
649 |
+
if (isNaN(optionNextPageId) && !check && choiceData.next !== 1) { // Allow restart choice
|
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 |
+
// Handle restart explicitly
|
656 |
+
if (choiceData.next === 1 && gameState.currentPageId === 99) {
|
657 |
+
startGame();
|
658 |
+
return;
|
659 |
+
}
|
660 |
|
661 |
if (check) {
|
662 |
const statValue = gameState.character.stats[check.stat] || 10;
|
|
|
667 |
console.log(`Check: ${check.stat} (DC ${dc}) | Roll: ${roll} + Mod: ${modifier} = ${totalResult}`);
|
668 |
if (totalResult >= dc) {
|
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; // Default to game over on invalid failure ID
|
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 |
+
if (targetPageData) {
|
685 |
+
if (targetPageData.hpLoss) {
|
686 |
+
gameState.character.stats.hp -= targetPageData.hpLoss;
|
687 |
+
console.log(`Lost ${targetPageData.hpLoss} HP.`);
|
688 |
+
if (gameState.character.stats.hp <= 0) {
|
689 |
+
gameState.character.stats.hp = 0;
|
690 |
+
console.log("Player died!");
|
691 |
+
nextPageId = 99; // Force game over if HP drops to 0 or below
|
692 |
+
rollResultMessage += "<p><em>You have succumbed to your injuries!</em></p>";
|
693 |
+
}
|
694 |
+
}
|
695 |
+
// TODO: Implement hpGain (similar to hpLoss but adding HP)
|
696 |
+
// if (targetPageData.reward && targetPageData.reward.hpGain) {
|
697 |
+
// gameState.character.stats.hp = Math.min(gameState.character.stats.maxHp, gameState.character.stats.hp + targetPageData.reward.hpGain);
|
698 |
+
// console.log(`Gained ${targetPageData.reward.hpGain} HP.`);
|
699 |
+
// }
|
700 |
+
|
701 |
+
if (targetPageData.reward) {
|
702 |
+
if (targetPageData.reward.xp) {
|
703 |
+
gameState.character.xp += targetPageData.reward.xp;
|
704 |
+
console.log(`Gained ${targetPageData.reward.xp} XP! Total: ${gameState.character.xp}`);
|
705 |
+
// TODO: Implement Level Up Check
|
706 |
+
// if (gameState.character.xp >= gameState.character.xpToNextLevel) { ... }
|
707 |
+
}
|
708 |
+
if (targetPageData.reward.statIncrease) {
|
709 |
+
const stat = targetPageData.reward.statIncrease.stat;
|
710 |
+
const amount = targetPageData.reward.statIncrease.amount;
|
711 |
+
if (gameState.character.stats.hasOwnProperty(stat)) {
|
712 |
+
gameState.character.stats[stat] += amount;
|
713 |
+
console.log(`Stat ${stat} increased by ${amount}. New value: ${gameState.character.stats[stat]}`);
|
714 |
+
// Recalculate Max HP if Constitution changes
|
715 |
+
if (stat === 'constitution') {
|
716 |
+
const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
|
717 |
+
gameState.character.stats.maxHp = 10 + (conModifier * gameState.character.level); // Base HP 10 for level 1 + Con mod
|
718 |
+
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp); // Ensure current HP doesn't exceed new max
|
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; // Base 10 for level 1
|
744 |
+
gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp); // Clamp HP
|
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 |
+
console.error(`Render Error: No data for page ${pageId}`);
|
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; // Ensure we treat this as the game over page
|
757 |
+
}
|
758 |
+
|
759 |
storyTitleElement.textContent = pageData.title || "Untitled Page";
|
760 |
storyContentElement.innerHTML = message + (pageData.content || "<p>...</p>");
|
761 |
+
|
762 |
updateStatsDisplay();
|
763 |
updateInventoryDisplay();
|
764 |
+
|
765 |
+
choicesElement.innerHTML = ''; // Clear previous choices
|
766 |
+
|
767 |
+
const options = pageData.options || [];
|
768 |
+
const isGameOverOrEnd = pageData.gameOver || options.length === 0;
|
769 |
+
|
770 |
+
if (!isGameOverOrEnd) {
|
771 |
+
options.forEach(option => {
|
772 |
+
const button = document.createElement('button');
|
773 |
+
button.classList.add('choice-button');
|
774 |
+
button.textContent = option.text;
|
775 |
+
let requirementMet = true;
|
776 |
+
let requirementText = "";
|
777 |
+
|
778 |
+
// Example: Check for required item
|
779 |
+
if (option.requireItem) {
|
780 |
+
if (!gameState.character.inventory.includes(option.requireItem)) {
|
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, // From original example
|
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 }); // Always restart for now
|
811 |
+
choicesElement.appendChild(button);
|
812 |
+
if (!pageData.gameOver) {
|
813 |
+
choicesElement.insertAdjacentHTML('afterbegin', '<p><i>There are no further paths from here.</i></p>');
|
814 |
+
}
|
815 |
+
}
|
816 |
+
|
817 |
updateScene(pageData.illustration || 'default');
|
818 |
}
|
819 |
|
|
|
829 |
if(gameState.character.inventory.length === 0){
|
830 |
h+='<em>Empty</em>';
|
831 |
} else {
|
832 |
+
gameState.character.inventory.forEach(itemName=>{
|
833 |
+
const item = itemsData[itemName] || {type:'unknown',description:'An unknown item.'};
|
834 |
+
const itemClass = `item-${item.type || 'unknown'}`;
|
835 |
+
h += `<span class="${itemClass}" title="${item.description || 'No description.'}">${itemName}</span>`;
|
836 |
});
|
837 |
}
|
838 |
inventoryElement.innerHTML = h;
|
839 |
}
|
840 |
|
841 |
function updateScene(illustrationKey) {
|
842 |
+
if (!scene) return; // Don't try to update if Three.js isn't initialized
|
843 |
+
|
844 |
if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); }
|
845 |
+
scene.fog = null; // Reset fog
|
846 |
+
scene.background = new THREE.Color(0x222222); // Reset background
|
847 |
+
camera.position.set(0, 2.5, 7); // Reset camera position
|
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); // Light blue fog
|
867 |
+
scene.background = new THREE.Color(0x87CEEB); // Sky blue background
|
868 |
camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0);
|
869 |
assemblyFunction = createCrossroadsAssembly; break;
|
870 |
case 'rolling-green-hills-shepherd-distance':
|
871 |
+
scene.fog = new THREE.Fog(0xA8E4A0, 15, 50); // Light green fog
|
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 |
+
console.warn(`Unknown illustration key: "${illustrationKey}". Using default scene.`);
|
1014 |
assemblyFunction = createDefaultAssembly; break;
|
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('error'); // Use default/error lighting
|
1030 |
}
|
1031 |
+
onWindowResize(); // Ensure camera aspect is correct after potential changes
|
1032 |
}
|
1033 |
|
1034 |
function adjustLighting(illustrationKey) {
|
1035 |
+
if (!scene) return;
|
1036 |
+
// Remove existing non-ambient lights
|
1037 |
+
const lightsToRemove = scene.children.filter(child => child.isLight && !child.isAmbientLight);
|
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 directionalLight;
|
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 |
+
case 'rolling-green-hills-shepherd-distance':
|
1056 |
+
case 'hilltop-view-overgrown-shrine-wildflowers':
|
1057 |
+
ambientIntensity = 0.8; lightIntensity = 1.5; lightColor = 0xFFF8E1; lightPosition = {x: 10, y: 15, z: 10}; break; // Sunny
|
|
|
1058 |
case 'dark-forest-entrance-gnarled-roots-filtered-light':
|
1059 |
case 'overgrown-forest-path-glowing-fungi-vines':
|
1060 |
+
case 'forest-clearing-mossy-statue-weathered-stone': // Dim forest light
|
1061 |
+
case 'two-goblins-ambush-forest-path-spears':
|
1062 |
+
ambientIntensity = 0.3; lightIntensity = 0.6; lightColor = 0xA8E4A0; lightPosition = {x: 5, y: 10, z: 5}; break; // Filtered green light
|
|
|
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 |
+
// Add new directional light
|
1088 |
+
directionalLight = new THREE.DirectionalLight(lightColor, lightIntensity);
|
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 |
+
// Optionally add a target for the light if needed, e.g., make it point at the center assembly
|
1102 |
+
// directionalLight.target.position.set(0, 0, 0);
|
1103 |
+
// scene.add(directionalLight.target);
|
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 |
+
startGame();
|
1131 |
+
console.log("Game Started.");
|
1132 |
+
} else {
|
1133 |
+
throw new Error("Three.js initialization failed silently.");
|
1134 |
+
}
|
1135 |
} catch (error) {
|
1136 |
+
console.error("Initialization failed:", error);
|
1137 |
+
storyTitleElement.textContent = "Initialization Error";
|
1138 |
+
storyContentElement.innerHTML = `<p>A critical error occurred during setup. Please check the console (F12) for details.</p><pre>${error.stack || error}</pre>`;
|
1139 |
+
// Optionally disable choices or show a specific error state UI
|
1140 |
+
choicesElement.innerHTML = '<p>Cannot proceed due to initialization error.</p>';
|
1141 |
+
if (sceneContainer) sceneContainer.innerHTML = '<p style="color:red; padding: 10px;">3D Scene Failed to Load</p>';
|
1142 |
}
|
1143 |
});
|
1144 |
</script>
|