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.
 
 
 

75 lines
1.4 KiB

  1. let roles = require('../config/roles');
  2. module.exports = {
  3. type: 'portal',
  4. toZone: null,
  5. toPos: null,
  6. toRelativePos: null,
  7. patronLevel: 0,
  8. init: function (blueprint) {
  9. this.toPos = blueprint.pos;
  10. this.toRelativePos = blueprint.toRelativePos;
  11. this.toZone = blueprint.zone;
  12. this.patronLevel = ~~blueprint.patron;
  13. },
  14. collisionEnter: async function (obj) {
  15. const { player, syncer, instance: { physics, syncer: globalSyncer } } = obj;
  16. if (!player)
  17. return;
  18. else if (this.patronLevel) {
  19. if (!roles.isRoleLevel(obj, this.patronLevel, 'enter this area'))
  20. return;
  21. }
  22. if (obj.zoneName === this.toZone) {
  23. physics.removeObject(obj, obj.x, obj.y);
  24. obj.x = this.toPos.x;
  25. obj.y = this.toPos.y;
  26. syncer.set(false, null, 'x', obj.x);
  27. syncer.set(false, null, 'y', obj.y);
  28. physics.addObject(obj, obj.x, obj.y);
  29. globalSyncer.queue('onRespawn', {
  30. x: obj.x,
  31. y: obj.y
  32. }, [obj.serverId]);
  33. return;
  34. }
  35. obj.fireEvent('beforeRezone');
  36. obj.destroyed = true;
  37. await obj.auth.doSave();
  38. const simpleObj = obj.getSimple(true, false, true);
  39. const { toPos, toRelativePos } = this;
  40. if (toPos) {
  41. simpleObj.x = this.toPos.x;
  42. simpleObj.y = this.toPos.y;
  43. } else if (toRelativePos) {
  44. simpleObj.x = this.obj.x + toRelativePos.x;
  45. simpleObj.y = this.obj.y + toRelativePos.y;
  46. }
  47. process.send({
  48. method: 'rezone',
  49. id: obj.serverId,
  50. args: {
  51. obj: simpleObj,
  52. newZone: this.toZone
  53. }
  54. });
  55. }
  56. };