|
|
@@ -1,3 +1,13 @@ |
|
|
|
const fixPosition = (obj, toPos, toRelativePos, invokingObj) => { |
|
|
|
if (toPos) { |
|
|
|
obj.x = toPos.x; |
|
|
|
obj.y = toPos.y; |
|
|
|
} else if (toRelativePos) { |
|
|
|
obj.x = invokingObj.obj.x + toRelativePos.x; |
|
|
|
obj.y = invokingObj.obj.y + toRelativePos.y; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const sendObjToZone = async ({ obj, invokingObj, zoneName, toPos, toRelativePos }) => { |
|
|
|
const { serverId, instance: { syncer: globalSyncer, physics } } = obj; |
|
|
|
|
|
|
@@ -28,18 +38,16 @@ const sendObjToZone = async ({ obj, invokingObj, zoneName, toPos, toRelativePos |
|
|
|
|
|
|
|
//We set this before saving so that objects aren't saved ON portals |
|
|
|
obj.zoneName = zoneName; |
|
|
|
if (toPos) { |
|
|
|
obj.x = toPos.x; |
|
|
|
obj.y = toPos.y; |
|
|
|
} else if (toRelativePos) { |
|
|
|
obj.x = invokingObj.obj.x + toRelativePos.x; |
|
|
|
obj.y = invokingObj.obj.y + toRelativePos.y; |
|
|
|
} |
|
|
|
fixPosition(obj, toPos, toRelativePos, invokingObj); |
|
|
|
|
|
|
|
//Destroy, flush events and notify other objects |
|
|
|
globalSyncer.processDestroyedObject(obj); |
|
|
|
await obj.auth.doSave(); |
|
|
|
|
|
|
|
//We have to do this again. This is because onCollisionEnter in portal is not blocking (even though it is async) |
|
|
|
// So physics will carry on and allow the obj to move onto the next tile (changing the position while we save above) |
|
|
|
fixPosition(obj, toPos, toRelativePos, invokingObj); |
|
|
|
|
|
|
|
//Test code, remove later |
|
|
|
Object.entries(globalSyncer.buffer).forEach(([k, v]) => { |
|
|
|
v.forEach(e => { |
|
|
|