diff --git a/src/Room.js b/src/Room.js index c7232295..a4d60638 100644 --- a/src/Room.js +++ b/src/Room.js @@ -17,6 +17,7 @@ const Logger = require('./Logger'); * @property {string} script Name of custom script attached to this room * @property {string} title Title shown on look/scan * @property {object} doors Doors restricting access to this room. See documentation for format + * @property {Array} walls Walls permanently restricting access from this room { direction: string } * * @extends GameEntity */ @@ -50,6 +51,7 @@ class Room extends GameEntity { // create by-val copies of the doors config so the lock/unlock don't accidentally modify the original definition this.doors = new Map(Object.entries(JSON.parse(JSON.stringify(def.doors || {})))); this.defaultDoors = def.doors; + this.walls = def.walls || []; this.items = new Set(); this.npcs = new Set(); @@ -175,7 +177,8 @@ class Room extends GameEntity { this.coordinates.z + z ); - if (room && !exits.find(ex => ex.direction === adj.dir)) { + //Generate exits based on coordinates and walls + if (room && !exits.find(ex => ex.direction === adj.dir) && !this.hasWall(adj.dir)) { exits.push({ roomId: room.entityReference, direction: adj.dir, inferred: true }); } } @@ -217,6 +220,18 @@ class Room extends GameEntity { return roomExit || false; } + /** + * Check to see if this room has a wall preventing movement in this direction + * @param {String} direction + * @return {boolean} + */ + hasWall(direction) { + if(this.walls.find(ex => ex.direction === direction) ){ + return true; + } + return false; + } + /** * Check to see if this room has a door preventing movement from `fromRoom` to here * @param {Room} fromRoom