Browse Source

bug: Fixed an issue causing portals to not spawn you in the correct location

tags/v0.10.6^2
Shaun 2 years ago
parent
commit
90b71ad704
3 changed files with 28 additions and 18 deletions
  1. +13
    -9
      src/server/components/portal.js
  2. +15
    -7
      src/server/components/portal/sendObjToZone.js
  3. +0
    -2
      src/server/objects/objects.js

+ 13
- 9
src/server/components/portal.js View File

@@ -16,18 +16,22 @@ module.exports = {
this.patronLevel = ~~blueprint.patron;
},

collisionEnter: async function (obj) {
collisionEnter: function (obj) {
if (!obj.player)
return;

const { toZone: zoneName, toPos, toRelativePos } = this;
(async () => {
const { toZone: zoneName, toPos, toRelativePos } = this;

await sendObjToZone({
obj,
invokingObj: this,
zoneName,
toPos,
toRelativePos
});
await sendObjToZone({
obj,
invokingObj: this,
zoneName,
toPos,
toRelativePos
});
})();

return true;
}
};

+ 15
- 7
src/server/components/portal/sendObjToZone.js View File

@@ -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 => {


+ 0
- 2
src/server/objects/objects.js View File

@@ -341,9 +341,7 @@ module.exports = {
o.update();

//When objects are sent to other zones, we destroy them immediately (thhrough sendObjToZone)
// In these cases, we DO need to remove it
if (o.forceDestroy) {
objects.splice(i, 1);
i--;
len--;
continue;


Loading…
Cancel
Save