diff --git a/app/server/create/homestead.js b/app/server/create/homestead.js index 2923560..1b81778 100644 --- a/app/server/create/homestead.js +++ b/app/server/create/homestead.js @@ -168,16 +168,18 @@ export default async function createHomestead(id) { }, ], collisionStartScript: ` - ecs.switchEcs( - other, - 'town', - { - Position: { - x: 940, - y: 480, + if (other.Player) { + ecs.switchEcs( + other, + 'town', + { + Position: { + x: 940, + y: 480, + }, }, - }, - ); + ); + } `, }, diff --git a/app/server/create/town.js b/app/server/create/town.js index 2fbac0c..0fbd66f 100644 --- a/app/server/create/town.js +++ b/app/server/create/town.js @@ -38,16 +38,18 @@ export default async function createTown() { }, ], collisionStartScript: ` - ecs.switchEcs( - other, - ['homesteads', '0'].join('/'), - { - Position: { - x: 20, - y: 438, + if (other.Player) { + ecs.switchEcs( + other, + ['homesteads', other.Player.id].join('/'), + { + Position: { + x: 20, + y: 438, + }, }, - }, - ); + ); + } `, }, Position: {x: 952, y: 480}, diff --git a/app/server/engine.js b/app/server/engine.js index 8f76a0f..ad38a09 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -63,6 +63,7 @@ export default class Engine { if (entity !== connectedPlayer.entity) { continue; } + const {id} = entity.Player; // remove entity link to connection to start queueing actions and pause updates delete connectedPlayer.entity; // forget previous state @@ -93,6 +94,7 @@ export default class Engine { } // recreate the entity in the new ECS and again associate it with the connection connectedPlayer.entity = engine.ecses[path].get(await engine.ecses[path].create(dumped)); + connectedPlayer.entity.Player.id = id } } } @@ -226,11 +228,12 @@ export default class Engine { await this.loadEcs(entityJson.Ecs.path); } const ecs = this.ecses[entityJson.Ecs.path]; - const entity = await ecs.create(entityJson); + const entity = ecs.get(await ecs.create(entityJson)); + entity.Player.id = id this.connectedPlayers.set( connection, { - entity: ecs.get(entity), + entity, id, memory: { chunks: new Map(),