Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getCloserToPC(who) {
let best = 1/0;
let avail = [];
DIRS.forEach(dxy => {
let xy = who.getXY().plus(dxy);
let entity = who.getLevel().getEntity(xy);
if (entity.blocks >= BLOCKS_MOVEMENT) { return; }
let dist = xy.dist8(pc.getXY());
if (dist < best) {
best = dist;
avail = [];
}
if (dist == best) { avail.push(xy); }
});
if (avail.length) {
who.moveTo(avail.random());
}