Fixed bug with vision when standing in doorway

This commit is contained in:
2026-02-07 13:04:49 +11:00
parent 02f850da35
commit da544438e1
3 changed files with 91 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import type { World, EntityId, Action, SimEvent, Actor, CombatantActor, Collecti
import { calculateDamage } from "../gameplay/CombatLogic";
import { isBlocked, tryDestructTile } from "../world/world-logic";
import { isDestructibleByWalk } from "../../core/terrain";
import { isDestructibleByWalk, TileType } from "../../core/terrain";
import { GAME_CONFIG } from "../../core/config/GameConfig";
import { type EntityAccessor } from "../EntityAccessor";
import { AISystem } from "../ecs/AISystem";
@@ -102,8 +102,25 @@ function handleMove(w: World, actor: Actor, action: { dx: number; dy: number },
const events: SimEvent[] = [{ type: "moved", actorId: actor.id, from, to }];
const tileIdx = ny * w.width + nx;
if (isDestructibleByWalk(w.tiles[tileIdx])) {
tryDestructTile(w, nx, ny);
const tile = w.tiles[tileIdx];
if (isDestructibleByWalk(tile)) {
// Only open if it's currently closed.
// tryDestructTile toggles, so we must be specific for doors.
if (tile === TileType.DOOR_CLOSED) {
tryDestructTile(w, nx, ny);
} else if (tile !== TileType.DOOR_OPEN) {
// For other destructibles like grass
tryDestructTile(w, nx, ny);
}
}
// Handle "from" tile - Close door if we just left it and no one else is there
const fromIdx = from.y * w.width + from.x;
if (w.tiles[fromIdx] === TileType.DOOR_OPEN) {
const actorsLeft = accessor.getActorsAt(from.x, from.y);
if (actorsLeft.length === 0) {
w.tiles[fromIdx] = TileType.DOOR_CLOSED;
}
}
if (actor.category === "combatant" && actor.isPlayer) {