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

122 lines
2.4 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-10-02 00:38:09 -05:00
params: {
collidesWithGroups: [
'default',
'environmental',
'projectile',
],
},
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-07-23 00:29:07 -05:00
magnetic: {
params: {
isAttractor: true,
},
2019-10-07 06:29:40 -05:00
state: {
attraction: 20,
}
2019-07-23 00:29:07 -05:00
},
2019-03-27 15:51:58 -05:00
mobile: {
state: {
speed: 100,
},
},
2019-04-08 13:32:52 -05:00
physical: {},
positioned: {
state: {
2019-09-30 01:36:17 -05:00
x: x,
y: y,
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;
}