refactor: simplification
This commit is contained in:
parent
0d784d6634
commit
53aae792cb
|
@ -43,6 +43,7 @@ export class Vulnerable extends Trait {
|
|||
constructor(entity, params, state) {
|
||||
super(entity, params, state);
|
||||
this.damageId = 0;
|
||||
this.damageTickingPromises = [];
|
||||
this.damages = [];
|
||||
this._hasAddedEmitter = false;
|
||||
this._hasAddedEmitterRenderer = false;
|
||||
|
@ -51,12 +52,11 @@ export class Vulnerable extends Trait {
|
|||
this.locks = new Map();
|
||||
const tookDamageActionsJSON = this.params.tookDamageActions;
|
||||
this._tookDamageActions = behaviorItemFromJSON(tookDamageActionsJSON);
|
||||
this.tookDamageActionsList = [];
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.locks.clear();
|
||||
this.tookDamageActionsList = [];
|
||||
this.damageTickingPromises = [];
|
||||
}
|
||||
|
||||
hydrate() {
|
||||
|
@ -70,16 +70,12 @@ export class Vulnerable extends Trait {
|
|||
damage,
|
||||
entity: this.entity,
|
||||
});
|
||||
const Actions = this._tookDamageActions.constructor;
|
||||
const actions = new Actions();
|
||||
actions.clone(this._tookDamageActions);
|
||||
const tuple = {context, actions};
|
||||
this.tookDamageActionsList.push(tuple);
|
||||
actions.on('actionsFinished', () => {
|
||||
const tickingPromise = this._tookDamageActions.tickingPromise(
|
||||
context
|
||||
).then(() => {
|
||||
context.destroy();
|
||||
const index = this.tookDamageActionsList.indexOf(tuple);
|
||||
this.tookDamageActionsList.splice(tuple);
|
||||
});
|
||||
this.damageTickingPromises.push(tickingPromise);
|
||||
}
|
||||
|
||||
acceptPacket(packet) {
|
||||
|
@ -241,11 +237,8 @@ export class Vulnerable extends Trait {
|
|||
}
|
||||
|
||||
tick(elapsed) {
|
||||
if (AVOCADO_CLIENT) {
|
||||
for (let i = 0; i < this.tookDamageActionsList.length; ++i) {
|
||||
const {context, actions} = this.tookDamageActionsList[i];
|
||||
actions.tick(context, elapsed);
|
||||
}
|
||||
for (let i = 0; i < this.damageTickingPromises.length; ++i) {
|
||||
this.damageTickingPromises[i].tick(elapsed);
|
||||
}
|
||||
if (AVOCADO_SERVER) {
|
||||
const keyIterator = this.locks.keys();
|
||||
|
|
Loading…
Reference in New Issue
Block a user