humus-old/server/create-entity-for-connection.js

110 lines
2.2 KiB
JavaScript
Raw Normal View History

import {Entity} from '@avocado/entity';
2019-03-27 15:51:58 -05:00
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
2019-05-04 11:39:43 -05:00
// let entity = new Entity();
2019-04-22 14:18:02 -05:00
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
2019-05-04 11:39:43 -05:00
const entity = new Entity({
2019-03-27 15:51:58 -05:00
traits: {
2019-04-22 21:03:28 -05:00
alive: {
state: {
2019-05-26 12:00:09 -05:00
life: 500,
maxLife: 500,
2019-04-22 21:03:28 -05:00
},
},
2019-03-27 15:51:58 -05:00
animated: {
params: {
animations: {
idle: {
offset: [0, -12],
uri: '/idle.animation.json',
},
moving: {
offset: [0, -12],
uri: '/moving.animation.json',
},
}
},
},
2019-05-21 03:10:07 -05:00
collider: {
2019-05-25 15:18:54 -05:00
// params: {
// collisionGroup: 'player',
// },
2019-05-21 03:10:07 -05:00
},
2019-05-04 11:39:43 -05:00
controllable: {},
2019-03-27 15:51:58 -05:00
directional: {
params: {
directionCount: 4,
},
},
2019-04-22 18:20:38 -05:00
emitter: {},
2019-05-07 03:21:58 -05:00
existent: {
state: {
name: socket.socket.id,
},
},
2019-04-05 11:59:14 -05:00
followed: {},
2019-05-04 11:39:43 -05:00
informed: {},
2019-05-06 04:04:03 -05:00
layered: {},
listed: {},
2019-03-27 15:51:58 -05:00
mobile: {
state: {
speed: 100,
},
},
2019-04-08 13:32:52 -05:00
physical: {},
positioned: {
state: {
2019-04-22 14:18:02 -05:00
x: x * 4,
y: y * 4,
2019-04-08 13:32:52 -05:00
},
},
2019-05-26 08:07:45 -05:00
receptacle: {
params: {
slots: {
0: {
qty: 10,
uri: '/potion.entity.json',
},
2019-05-26 12:00:09 -05:00
1: {
qty: 1,
uri: '/rock.entity.json',
},
2019-05-27 17:30:40 -05:00
2: {
qty: 1,
uri: '/hoe.entity.json',
},
2019-05-28 20:35:24 -05:00
3: {
qty: 1,
uri: '/watering-can.entity.json',
},
2019-05-30 09:12:17 -05:00
4: {
qty: 1,
uri: '/tomato-seeds.entity.json',
},
2019-05-26 08:07:45 -05:00
},
},
},
2019-05-06 04:04:03 -05:00
roomed: {},
2019-04-08 13:32:52 -05:00
shaped: {
2019-03-27 15:51:58 -05:00
params: {
shape: {
2019-04-13 03:19:41 -05:00
type: 'circle',
radius: 4,
2019-04-08 13:32:52 -05:00
},
2019-03-27 15:51:58 -05:00
},
},
2019-05-04 11:39:43 -05:00
visible: {},
vulnerable: {},
2019-05-26 08:07:45 -05:00
wielder: {
state: {
activeSlotIndex: 0,
},
},
2019-03-27 15:51:58 -05:00
},
});
// Embed socket.
entity.socket = socket;
return entity;
}