feat: loot particles

This commit is contained in:
cha0s 2019-11-03 13:27:51 -06:00
parent a3c68fa56e
commit 71027a8af6
2 changed files with 29 additions and 23 deletions

View File

@ -1,6 +1,6 @@
import {compose, Property} from '@avocado/core'; import {compose, Property} from '@avocado/core';
import {StateProperty, Trait, Entity} from '@avocado/entity'; import {StateProperty, Trait, Entity} from '@avocado/entity';
import {Rectangle, Vector} from '@avocado/math'; import {randomNumber, Rectangle, Vector} from '@avocado/math';
const decorate = compose( const decorate = compose(
StateProperty('lootable', { StateProperty('lootable', {
@ -41,28 +41,41 @@ export class Lootable extends decorate(Trait) {
return jsons; return jsons;
} }
listeners() { hooks() {
const listeners = {}; const hooks = {};
if (AVOCADO_SERVER) { if (AVOCADO_SERVER) {
listeners['died'] = () => { hooks['died'] = () => {
const jsons = this.calculateLoot(); const jsons = this.calculateLoot();
const position = this.entity.position; const position = this.entity.position;
const promises = [];
for (let i = 0; i < jsons.length; i++) { for (let i = 0; i < jsons.length; i++) {
const offset = Vector.sub( const json = jsons[i];
[ if (!json.traits) {
Math.floor(Math.random() * 16), json.traits = {};
Math.floor(Math.random() * 16) }
], json.traits.emitted = {
[8, 8] params: {
); force: [0, 16],
this.entity.spawnRawAt( velocity: [
Vector.add(position, offset), randomNumber(-0.5, 0.5),
jsons[i] randomNumber(-2.5, -1.5)
); ],
position,
transient: false,
ttl: 0.25,
},
};
const promise = this.entity.emitParticleJson(
json
).then((particle) => {
this.entity.list.addEntity(particle);
});
promises.push(promise);
} }
return Promise.all(promises);
}; };
} }
return listeners; return hooks;
} }
} }

View File

@ -119,12 +119,6 @@ export function kittyJSON() {
lootable: { lootable: {
params: { params: {
table: [ table: [
{
perc: 20,
json: {
uri: '/rock.entity.json',
},
},
{ {
perc: 70, perc: 70,
json: { json: {
@ -151,7 +145,6 @@ export function kittyJSON() {
}, },
}, },
}, },
spawner: {},
vulnerable: {}, vulnerable: {},
}, },
}; };