diff --git a/packages/behavior/traits/behaved.trait.js b/packages/behavior/traits/behaved.trait.js index dccc871..597c9be 100644 --- a/packages/behavior/traits/behaved.trait.js +++ b/packages/behavior/traits/behaved.trait.js @@ -5,7 +5,10 @@ import {createContext} from '../context'; import {Routines} from '../item/routines'; const decorate = compose( - StateProperty('currentRoutine'), + StateProperty('currentRoutine', { + track: true, + }), + StateProperty('isBehaving'), ); export class Behaved extends decorate(Trait) { @@ -19,6 +22,7 @@ export class Behaved extends decorate(Trait) { static defaultState() { return { currentRoutine: 'initial', + isBehaving: true, } } @@ -31,7 +35,6 @@ export class Behaved extends decorate(Trait) { this._context = createContext(); this._context.add('entity', this.entity); this._currentRoutine = undefined; - this._isBehaving = true; const routinesJSON = this.params.routines; this._routines = (new Routines()).fromJSON(routinesJSON); this._routines.context = this._context; @@ -48,10 +51,6 @@ export class Behaved extends decorate(Trait) { return this._context; } - set isBehaving(isBehaving) { - this._isBehaving = isBehaving; - } - updateCurrentRoutine(currentRoutine) { this._currentRoutine = this._routines.routine(currentRoutine); } @@ -64,15 +63,17 @@ export class Behaved extends decorate(Trait) { }, dying: () => { - this._isBehaving = false; + this.entity.isBehaving = false; }, }; } tick(elapsed) { - if (this._currentRoutine && this._isBehaving) { - this._currentRoutine.tick(elapsed); + if (AVOCADO_SERVER) { + if (this._currentRoutine && this.entity.isBehaving) { + this._currentRoutine.tick(elapsed); + } } }