@@ -27,6 +27,7 @@ define([ | |||||
lastY: 0, | lastY: 0, | ||||
init: function () { | init: function () { | ||||
events.on('onRespawn', this.onDeath.bind(this)); | |||||
events.on('onDeath', this.onDeath.bind(this)); | events.on('onDeath', this.onDeath.bind(this)); | ||||
events.on('onClearQueue', this.onDeath.bind(this)); | events.on('onClearQueue', this.onDeath.bind(this)); | ||||
@@ -17,7 +17,9 @@ module.exports = { | |||||
}, | }, | ||||
collisionEnter: async function (obj) { | collisionEnter: async function (obj) { | ||||
if (!obj.player) | |||||
const { player, syncer, instance: { physics, syncer: globalSyncer } } = obj; | |||||
if (!player) | |||||
return; | return; | ||||
else if (this.patronLevel) { | else if (this.patronLevel) { | ||||
if (!roles.isRoleLevel(obj, this.patronLevel, 'enter this area')) | if (!roles.isRoleLevel(obj, this.patronLevel, 'enter this area')) | ||||
@@ -25,21 +27,20 @@ module.exports = { | |||||
} | } | ||||
if (obj.zoneName === this.toZone) { | if (obj.zoneName === this.toZone) { | ||||
physics.removeObject(obj, obj.x, obj.y); | |||||
obj.x = this.toPos.x; | obj.x = this.toPos.x; | ||||
obj.y = this.toPos.y; | 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; | return; | ||||
} | } | ||||
@@ -317,10 +317,13 @@ module.exports = { | |||||
} else | } else | ||||
return false; | return false; | ||||
} else { | } 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; | let syncer = this.syncer; | ||||
@@ -114,14 +114,20 @@ module.exports = { | |||||
obj.collisionEnter(c); | obj.collisionEnter(c); | ||||
} | } | ||||
} else { | } else { | ||||
//If a callback returns true, it means we collide | |||||
//If a callback returns true, it means we collide | |||||
if (c.collisionEnter(obj)) | if (c.collisionEnter(obj)) | ||||
return; | return; | ||||
obj.collisionEnter(c); | 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; | return true; | ||||
}, | }, | ||||