diff --git a/common/traits/controllable.trait.js b/common/traits/controllable.trait.js index da82d93..d481fd1 100644 --- a/common/traits/controllable.trait.js +++ b/common/traits/controllable.trait.js @@ -1,5 +1,6 @@ import * as I from 'immutable'; +import {TickingPromise} from '@avocado/core'; import {Trait} from '@avocado/entity'; // Input handling. @@ -12,6 +13,7 @@ export class Controllable extends Trait { constructor(entity, params, state) { super(entity, params, state); this._inputState = I.Map(); + this._itemPromise = undefined; } set inputState(inputState) { @@ -19,12 +21,18 @@ export class Controllable extends Trait { if (AVOCADO_SERVER) { if (inputState.has('UseItem')) { const slotIndex = inputState.get('UseItem'); - this.entity.useItemInSlot(slotIndex); + this._itemPromise = this.entity.useItemInSlot(slotIndex); + Promise.resolve(this._itemPromise).then(() => { + this._itemPromise = undefined; + }); } } } tick(elapsed) { + if (this._itemPromise && this._itemPromise instanceof TickingPromise) { + this._itemPromise.tick(elapsed); + } const {_inputState: inputState} = this; if (0 === inputState.size) { this.entity.currentAnimation = 'idle';