You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
932 B

  1. let objects = require('../../objects/objects');
  2. let physics = require('../physics');
  3. const canPath = (pos, positions, maxDistance = 0) => {
  4. return positions.some(p => {
  5. const path = physics.getPath(pos, p);
  6. //Are we on the position?
  7. if (!path.length)
  8. return (p.x === pos.x && p.y === pos.y);
  9. const { x, y } = path[path.length - 1];
  10. //Can we get close enough to the position?
  11. const isCloseEnough = Math.max(Math.abs(p.x - x), Math.abs(p.y - y)) <= maxDistance;
  12. if (isCloseEnough)
  13. return true;
  14. return false;
  15. });
  16. };
  17. module.exports = (map, pos) => {
  18. const canPathToSpawn = canPath(pos, map.spawn);
  19. if (canPathToSpawn)
  20. return true;
  21. const portals = objects.objects.filter(o => o.portal);
  22. const canPathToPortal = canPath(pos, portals);
  23. if (canPathToPortal)
  24. return true;
  25. const doors = objects.objects.filter(o => o.door);
  26. const canPathToDoor = canPath(pos, doors, 1);
  27. return canPathToDoor;
  28. };