fix: to each their own

This commit is contained in:
cha0s 2024-07-24 01:50:33 -05:00
parent 3d7b0fc14e
commit 52f19b1d89
3 changed files with 27 additions and 20 deletions

View File

@ -168,6 +168,7 @@ export default async function createHomestead(id) {
}, },
], ],
collisionStartScript: ` collisionStartScript: `
if (other.Player) {
ecs.switchEcs( ecs.switchEcs(
other, other,
'town', 'town',
@ -178,6 +179,7 @@ export default async function createHomestead(id) {
}, },
}, },
); );
}
`, `,
}, },

View File

@ -38,9 +38,10 @@ export default async function createTown() {
}, },
], ],
collisionStartScript: ` collisionStartScript: `
if (other.Player) {
ecs.switchEcs( ecs.switchEcs(
other, other,
['homesteads', '0'].join('/'), ['homesteads', other.Player.id].join('/'),
{ {
Position: { Position: {
x: 20, x: 20,
@ -48,6 +49,7 @@ export default async function createTown() {
}, },
}, },
); );
}
`, `,
}, },
Position: {x: 952, y: 480}, Position: {x: 952, y: 480},

View File

@ -63,6 +63,7 @@ export default class Engine {
if (entity !== connectedPlayer.entity) { if (entity !== connectedPlayer.entity) {
continue; continue;
} }
const {id} = entity.Player;
// remove entity link to connection to start queueing actions and pause updates // remove entity link to connection to start queueing actions and pause updates
delete connectedPlayer.entity; delete connectedPlayer.entity;
// forget previous state // 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 // 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 = 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); await this.loadEcs(entityJson.Ecs.path);
} }
const ecs = this.ecses[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( this.connectedPlayers.set(
connection, connection,
{ {
entity: ecs.get(entity), entity,
id, id,
memory: { memory: {
chunks: new Map(), chunks: new Map(),