From e1b4f9c3443d47887bde8ffef529b7b4f4d80571 Mon Sep 17 00:00:00 2001 From: Big Bad Waffle Date: Fri, 20 Dec 2019 20:01:37 +0000 Subject: [PATCH] another fix for #1325 to cater for portals (cherry picked from commit 4a587582d0cc665dd8b2a49fdb7cdb2d59fc9c78) --- src/server/world/map.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/server/world/map.js b/src/server/world/map.js index 3669b245..58d4b113 100644 --- a/src/server/world/map.js +++ b/src/server/world/map.js @@ -442,17 +442,31 @@ module.exports = { //Find if any spawns can path to a position. This is important for when maps change and players // log in on tiles that aren't blocking but not able to reach anywhere useful canPathFromPos: function (pos) { - const canPath = this.spawn.some(s => { - const path = physics.getPath(pos, s); - if (!path.length) - return true; - - const { x, y } = path[path.length - 1]; - const isFullPath = (s.x === x && s.y === y); + const fnCanPath = positions => { + return positions.some(p => { + const path = physics.getPath(pos, p); + //Are we on the position? + if (!path.length) + return true; + + const { x, y } = path[path.length - 1]; + //Can we reach the position? + const isFullPath = (p.x === x && p.y === y); + if (isFullPath) + return true; + + return false; + }); + }; + + const canPathToSpawn = fnCanPath(this.spawn); + + if (canPathToSpawn) + return true; - return isFullPath; - }); + const portals = objects.objects.filter(o => o.portal); + const canPathToPortal = fnCanPath(portals); - return canPath; + return canPathToPortal; } };