How to use the conf.js.DIRS.filter function in conf

To help you get started, we’ve selected a few conf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ondras / sleeping-beauty / src / js / ai.js View on Github external
function wander(who) {
	let result = Promise.resolve();

	if (ROT.RNG.getUniform() < rules.AI_IDLE) { return result; }

	let level = who.getLevel();
	let xy = who.getXY();

	let dirs = DIRS.filter(dxy => {
		let entity = level.getEntity(xy.plus(dxy));
		return entity.blocks < BLOCKS_MOVEMENT;
	});
	
	if (!dirs.length) { return result; }
	
	let dir = dirs.random();
	who.moveTo(xy.plus(dir));
	return result;
}