refactor: simplify
This commit is contained in:
parent
84affcbc64
commit
42fe27f0a3
|
@ -165,20 +165,12 @@ export default class Alive extends decorate(Trait) {
|
||||||
methods() {
|
methods() {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
dieIfPrescribed: () => {
|
|
||||||
if (this._deathCondition.check(this._context)) {
|
|
||||||
this.entity.forceDeath();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
forceDeath: () => {
|
forceDeath: () => {
|
||||||
if (this.entity.isDying) {
|
if (this.entity.isDying) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.entity.isDying = true;
|
this.entity.isDying = true;
|
||||||
const dyingTickingPromise = this._deathActions.tickingPromise(
|
const dyingTickingPromise = this._deathActions.tickingPromise(this._context);
|
||||||
this._context
|
|
||||||
)
|
|
||||||
this.entity.addTickingPromise(dyingTickingPromise).then(() => {
|
this.entity.addTickingPromise(dyingTickingPromise).then(() => {
|
||||||
const diedPromises = this.entity.invokeHookFlat('died');
|
const diedPromises = this.entity.invokeHookFlat('died');
|
||||||
Promise.all(diedPromises).then(() => {
|
Promise.all(diedPromises).then(() => {
|
||||||
|
@ -192,7 +184,9 @@ export default class Alive extends decorate(Trait) {
|
||||||
|
|
||||||
tick(elapsed) {
|
tick(elapsed) {
|
||||||
if (AVOCADO_SERVER) {
|
if (AVOCADO_SERVER) {
|
||||||
this.entity.dieIfPrescribed();
|
if (!this.entity.isDying && this._deathCondition.check(this._context)) {
|
||||||
|
this.entity.forceDeath();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user