fun: harvest some planties!

This commit is contained in:
cha0s 2021-02-16 18:43:42 -06:00
parent dcb57ba53c
commit 9f4e057a3a
2 changed files with 66 additions and 40 deletions

View File

@ -58,52 +58,66 @@ export default () => class Lootable extends decorate(Trait) {
};
}
emitLoot() {
const jsons = this.calculateLoot();
if (0 === jsons.length) {
return true;
}
const {position} = this.entity;
for (let i = 0; i < jsons.length; i++) {
const json = jsons[i];
if (!json.traits) {
json.traits = {};
}
json.traits.Emitted = {
params: {
force: [0, 8],
velocity: {
angle: {
min: 316,
max: 405,
},
magnitude: {
min: 0.7,
max: 0.9,
},
},
position,
transient: false,
ttl: 0.25,
},
};
this.entity.emitParticleJson({
...json,
transmit: false,
});
}
return false;
}
hooks() {
const hooks = {};
if ('client' !== process.env.SIDE) {
let isDying = false;
hooks.died = () => () => {
hooks.destroy = () => () => {
if (isDying) {
return true;
}
isDying = true;
const jsons = this.calculateLoot();
if (0 === jsons.length) {
return true;
}
const {position} = this.entity;
for (let i = 0; i < jsons.length; i++) {
const json = jsons[i];
if (!json.traits) {
json.traits = {};
}
json.traits.Emitted = {
params: {
force: [0, 8],
velocity: {
angle: {
min: 316,
max: 405,
},
magnitude: {
min: 0.7,
max: 0.9,
},
},
position,
transient: false,
ttl: 0.25,
},
};
this.entity.emitParticleJson({
...json,
transmit: false,
});
}
return false;
return this.emitLoot();
};
}
return hooks;
}
methods() {
return {
emitLoot: () => {
this.emitLoot();
},
};
}
};

View File

@ -35,6 +35,7 @@ export default (latus) => class Plant extends decorate(Trait) {
static dependencies() {
return [
'Interactive',
'Pictured',
];
}
@ -67,8 +68,16 @@ export default (latus) => class Plant extends decorate(Trait) {
return {
growthStageChanged: (oldStage, newStage) => {
const stageSpec = this.params.stageSpecs[newStage];
this.entity.currentImage = stageSpec.image;
const {
image,
reset,
ripe,
} = this.params.stageSpecs[newStage];
this.entity.currentImage = image;
this.entity.isInteractive = !!ripe;
if (reset) {
this.growthElapsed = 0;
}
},
};
@ -94,8 +103,9 @@ export default (latus) => class Plant extends decorate(Trait) {
if (!('growAt' in stageSpec)) {
return;
}
this.growthElapsed = stageSpec.growAt;
this.entity.growthStage = growthStage + 1;
this.entity.growthStage = 'undefined' === stageSpec.growTo
? growthStage + 1
: stageSpec.growTo;
},
};
@ -125,7 +135,9 @@ export default (latus) => class Plant extends decorate(Trait) {
}
if ('growAt' in stageSpec) {
if (this.growthElapsed >= stageSpec.growAt) {
this.entity.growthStage = growthStage + 1;
this.entity.growthStage = 'undefined' !== typeof stageSpec.growTo
? stageSpec.growTo
: growthStage + 1;
}
}
}