From 860808308ad8c1d35046f0371e54b1a328c95bfc Mon Sep 17 00:00:00 2001 From: Shaun Date: Thu, 25 Feb 2021 05:50:01 +0200 Subject: [PATCH] more work --- src/client/js/components/pather.js | 1 + src/server/components/portal.js | 27 ++++++++++++++------------- src/server/objects/objBase.js | 11 +++++++---- src/server/world/physics.js | 10 ++++++++-- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/client/js/components/pather.js b/src/client/js/components/pather.js index 8ec2932f..4b48c58d 100644 --- a/src/client/js/components/pather.js +++ b/src/client/js/components/pather.js @@ -27,6 +27,7 @@ define([ lastY: 0, init: function () { + events.on('onRespawn', this.onDeath.bind(this)); events.on('onDeath', this.onDeath.bind(this)); events.on('onClearQueue', this.onDeath.bind(this)); diff --git a/src/server/components/portal.js b/src/server/components/portal.js index f65f6752..90a27ab2 100644 --- a/src/server/components/portal.js +++ b/src/server/components/portal.js @@ -17,7 +17,9 @@ module.exports = { }, collisionEnter: async function (obj) { - if (!obj.player) + const { player, syncer, instance: { physics, syncer: globalSyncer } } = obj; + + if (!player) return; else if (this.patronLevel) { if (!roles.isRoleLevel(obj, this.patronLevel, 'enter this area')) @@ -25,21 +27,20 @@ module.exports = { } if (obj.zoneName === this.toZone) { + physics.removeObject(obj, obj.x, obj.y); + obj.x = this.toPos.x; obj.y = this.toPos.y; - const syncO = this.obj.syncer.o; - syncO.x = obj.x; - syncO.y = obj.y; - - process.send({ - method: 'rezone', - id: obj.serverId, - args: { - obj: simpleObj, - newZone: this.toZone - } - }); + syncer.set(false, null, 'x', obj.x); + syncer.set(false, null, 'y', obj.y); + + physics.addObject(obj, obj.x, obj.y); + + globalSyncer.queue('onRespawn', { + x: obj.x, + y: obj.y + }, [obj.serverId]); return; } diff --git a/src/server/objects/objBase.js b/src/server/objects/objBase.js index 9cb68ed8..1bbc948d 100644 --- a/src/server/objects/objBase.js +++ b/src/server/objects/objBase.js @@ -317,10 +317,13 @@ module.exports = { } else return false; } else { - physics.removeObject(this, this.x, this.y, data.x, data.y); - physics.addObject(this, data.x, data.y, this.x, this.y); - this.x = data.x; - this.y = data.y; + const { x: xOld, y: yOld } = this; + const { x: xNew, y: yNew } = data; + + physics.removeObject(this, xOld, yOld, xNew, yNew); + this.x = xNew; + this.y = yNew; + physics.addObject(this, xNew, yNew, xOld, yOld); } let syncer = this.syncer; diff --git a/src/server/world/physics.js b/src/server/world/physics.js index 33b1b0f9..ece43e82 100644 --- a/src/server/world/physics.js +++ b/src/server/world/physics.js @@ -114,14 +114,20 @@ module.exports = { obj.collisionEnter(c); } } else { - //If a callback returns true, it means we collide + //If a callback returns true, it means we collide if (c.collisionEnter(obj)) return; obj.collisionEnter(c); } } - cell.push(obj); + //Perhaps a collisionEvent caused us to move somewhere else, in which case, we don't push to the cell + // as we assume that the collisionEvent handled it for us + if (x === obj.x && y === obj.y) + cell.push(obj); + else + console.log('nopers'); + return true; },