Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added walls for blocking exits when using room coordinates #95

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>} walls Walls permanently restricting access from this room { direction: string }
*
* @extends GameEntity
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 });
}
}
Expand Down Expand Up @@ -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
Expand Down