Shaun Kichenbrand před 4 roky
rodič
revize
4a4cefbc1c
2 změnil soubory, kde provedl 39 přidání a 26 odebrání
  1. +2
    -26
      src/server/world/map.js
  2. +37
    -0
      src/server/world/map/canPathFromPos.js

+ 2
- 26
src/server/world/map.js Zobrazit soubor

@@ -7,6 +7,7 @@ let randomMap = require('./randomMap');
let events = require('../misc/events');

const mapObjects = require('./map/mapObjects');
const canPathFromPos = require('./map/canPathFromPos');

let mapFile = null;
let mapScale = null;
@@ -441,31 +442,6 @@ 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 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;

const portals = objects.objects.filter(o => o.portal);
const canPathToPortal = fnCanPath(portals);

return canPathToPortal;
return canPathFromPos(this, pos);
}
};

+ 37
- 0
src/server/world/map/canPathFromPos.js Zobrazit soubor

@@ -0,0 +1,37 @@
let objects = require('../../objects/objects');
let physics = require('../physics');

const canPath = (pos, positions, maxDistance = 0) => {
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 get close enough to the position?
const isCloseEnough = Math.max(Math.abs(p.x - x), Math.abs(p.y - y)) <= maxDistance;
if (isCloseEnough)
return true;

return false;
});
};

module.exports = (map, pos) => {
const canPathToSpawn = canPath(pos, map.spawn);

if (canPathToSpawn)
return true;

const portals = objects.objects.filter(o => o.portal);
const canPathToPortal = canPath(pos, portals);

if (canPathToPortal)
return true;

const doors = objects.objects.filter(o => o.door);
const canPathToDoor = canPath(pos, doors, 1);

return canPathToDoor;
};

Načítá se…
Zrušit
Uložit