Implement Lantern Bearer logic, Phase buttons, and Monster spawning basics

This commit is contained in:
2026-01-04 23:48:53 +01:00
parent 4c8b58151b
commit 056217437c
9 changed files with 638 additions and 102 deletions

View File

@@ -44,10 +44,10 @@ game.onEntityUpdate = (entity) => {
renderer.addEntity(entity);
renderer.updateEntityPosition(entity);
// Center camera on player spawn
if (entity.id === 'p1' && !entity._centered) {
// Center camera on FIRST hero spawn
if (game.heroes && game.heroes[0] && entity.id === game.heroes[0].id && !window._cameraCentered) {
cameraManager.centerOn(entity.x, entity.y);
entity._centered = true;
window._cameraCentered = true;
}
};
@@ -55,9 +55,7 @@ game.onEntityMove = (entity, path) => {
renderer.moveEntityAlongPath(entity, path);
};
game.onEntitySelect = (entityId, isSelected) => {
renderer.toggleEntitySelection(entityId, isSelected);
};
// game.onEntitySelect is now handled by UIManager to wrap the renderer call
renderer.onHeroFinishedMove = (x, y) => {
cameraManager.centerOn(x, y);
@@ -107,10 +105,24 @@ const handleClick = (x, y, doorMesh) => {
}
if (!doorMesh.userData.isOpen) {
const doorExit = doorMesh.userData.cells[0];
if (game.isPlayerAdjacentToDoor(doorMesh.userData.cells)) {
// 1. Check Selection and Leadership (STRICT)
const selectedHero = game.selectedEntity;
if (!selectedHero) {
ui.showModal('Ningún Héroe seleccionado', 'Selecciona al <b>Líder (Portador de la Lámpara)</b> para abrir la puerta.');
return;
}
if (!selectedHero.hasLantern) {
ui.showModal('Acción no permitida', `<b>${selectedHero.name}</b> no lleva la Lámpara. Solo el <b>Líder</b> puede explorar.`);
return;
}
// 2. Check Adjacency
// Since we know selectedHero IS the leader, we can just check if *this* hero is adjacent.
// game.isLeaderAdjacentToDoor checks the 'getLeader()' position, which aligns with selectedHero here.
if (game.isLeaderAdjacentToDoor(doorMesh.userData.cells)) {
// Open door visually
renderer.openDoor(doorMesh);
@@ -119,11 +131,16 @@ const handleClick = (x, y, doorMesh) => {
const exitData = doorMesh.userData.exitData;
if (exitData) {
generator.selectDoor(exitData);
// Allow UI to update phase if not already
// if (game.turnManager.currentPhase !== 'exploration') {
// game.turnManager.setPhase('exploration');
// }
} else {
console.error('[Main] Door missing exitData');
}
} else {
// Optional: Message if too far?
ui.showModal('Demasiado lejos', 'El Líder debe estar <b>adyacente</b> a la puerta para abrirla.');
}
return;
}
@@ -144,6 +161,20 @@ renderer.setupInteraction(
}
);
// Debug: Spawn Monster
window.addEventListener('keydown', (e) => {
if (e.key === 'm' || e.key === 'M') {
const x = game.player.x + 2;
const y = game.player.y;
if (game.dungeon.grid.isOccupied(x, y)) {
console.log("Spawning Orc...");
game.spawnMonster('orc', x, y);
} else {
console.log("Cannot spawn here");
}
}
});
// 7. Start
game.startMission(mission);