humus-old/server/create-entity-for-connection.js
2019-05-27 17:30:40 -05:00

102 lines
2.0 KiB
JavaScript

import {Entity} from '@avocado/entity';
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
// let entity = new Entity();
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
const entity = new Entity({
traits: {
alive: {
state: {
life: 500,
maxLife: 500,
},
},
animated: {
params: {
animations: {
idle: {
offset: [0, -12],
uri: '/idle.animation.json',
},
moving: {
offset: [0, -12],
uri: '/moving.animation.json',
},
}
},
},
collider: {
// params: {
// collisionGroup: 'player',
// },
},
controllable: {},
directional: {
params: {
directionCount: 4,
},
},
emitter: {},
existent: {
state: {
name: socket.socket.id,
},
},
followed: {},
informed: {},
layered: {},
listed: {},
mobile: {
state: {
speed: 100,
},
},
physical: {},
positioned: {
state: {
x: x * 4,
y: y * 4,
},
},
receptacle: {
params: {
slots: {
0: {
qty: 10,
uri: '/potion.entity.json',
},
1: {
qty: 1,
uri: '/rock.entity.json',
},
2: {
qty: 1,
uri: '/hoe.entity.json',
},
},
},
},
roomed: {},
shaped: {
params: {
shape: {
type: 'circle',
radius: 4,
},
},
},
visible: {},
vulnerable: {},
wielder: {
state: {
activeSlotIndex: 0,
},
},
},
});
// Embed socket.
entity.socket = socket;
return entity;
}