110 lines
2.2 KiB
JavaScript
110 lines
2.2 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',
|
|
},
|
|
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;
|
|
}
|