refactor: time-based ticks

This commit is contained in:
cha0s 2021-02-10 15:29:51 -06:00
parent 0ff8b73ffd
commit 43851a275a

View File

@ -10,8 +10,6 @@ const decorate = compose(
export default (latus) => class Plant extends decorate(Trait) { export default (latus) => class Plant extends decorate(Trait) {
static STIM_P = 10 / (latus.get('%humus.tps', 60) * 60);
constructor() { constructor() {
super(); super();
this.growthElapsed = 0; this.growthElapsed = 0;
@ -114,15 +112,15 @@ export default (latus) => class Plant extends decorate(Trait) {
: []; : [];
} }
tick() { tick(elapsed) {
if ('client' === process.env.SIDE) { if ('client' === process.env.SIDE) {
return; return;
} }
if (this.growthCondition(this.growthConditionContext)) { if (this.growthCondition(this.growthConditionContext)) {
const {growthStage} = this.entity; const {growthStage} = this.entity;
const stageSpec = this.params.stageSpecs[growthStage]; const stageSpec = this.params.stageSpecs[growthStage];
if (Math.random() < this.constructor.STIM_P) { if (Math.random() < (4 / (60 / elapsed))) {
this.growthElapsed += 0.1; this.growthElapsed += 0.25;
} }
if ('growAt' in stageSpec) { if ('growAt' in stageSpec) {
if (this.growthElapsed >= stageSpec.growAt) { if (this.growthElapsed >= stageSpec.growAt) {