119 lines
2.3 KiB
JavaScript
119 lines
2.3 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: {
|
|
collidesWithGroups: [
|
|
'default',
|
|
'environmental',
|
|
'projectile',
|
|
],
|
|
},
|
|
},
|
|
controllable: {},
|
|
directional: {
|
|
params: {
|
|
directionCount: 4,
|
|
},
|
|
},
|
|
emitter: {},
|
|
existent: {
|
|
state: {
|
|
name: socket.socket.id,
|
|
},
|
|
},
|
|
followed: {},
|
|
informed: {},
|
|
layered: {},
|
|
listed: {},
|
|
magnetic: {
|
|
params: {
|
|
isAttractor: true,
|
|
},
|
|
},
|
|
mobile: {
|
|
state: {
|
|
speed: 100,
|
|
},
|
|
},
|
|
physical: {},
|
|
positioned: {
|
|
state: {
|
|
x: x,
|
|
y: y,
|
|
},
|
|
},
|
|
receptacle: {
|
|
params: {
|
|
slots: {
|
|
0: {
|
|
qty: 10,
|
|
uri: '/potion.entity.json',
|
|
},
|
|
1: {
|
|
qty: 1,
|
|
uri: '/rock.entity.json',
|
|
},
|
|
2: {
|
|
qty: 1,
|
|
uri: '/hoe.entity.json',
|
|
},
|
|
3: {
|
|
qty: 1,
|
|
uri: '/watering-can.entity.json',
|
|
},
|
|
4: {
|
|
qty: 1,
|
|
uri: '/tomato-seeds.entity.json',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
roomed: {},
|
|
shaped: {
|
|
params: {
|
|
shape: {
|
|
type: 'circle',
|
|
radius: 4,
|
|
},
|
|
},
|
|
},
|
|
visible: {},
|
|
vulnerable: {},
|
|
wielder: {
|
|
state: {
|
|
activeSlotIndex: 0,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
// Embed socket.
|
|
entity.socket = socket;
|
|
return entity;
|
|
}
|