humus-old/common/combat/damaging.trait.js
2019-04-22 21:03:16 -05:00

51 lines
1.0 KiB
JavaScript

import * as I from 'immutable';
import {Trait} from '@avocado/entity';
export class Damaging extends Trait {
static defaultParams() {
return {
damagingSound: '',
damageSpecs: [],
};
}
initialize() {
this._collidingWith = [];
const damageSpecsJSON = this.params.get('damageSpecs').toJS();
this._damageSpecs = damageSpecsJSON.map((damageSpec) => {
return {
affinity: 'physical',
lock: 0.1,
power: 0,
variance: 0.2,
...damageSpec,
};
});
this._damagingSound = this.params.get('damagingSound');
}
get damageSpecs() {
return this._damageSpecs;
}
get damagingSound() {
return this._damagingSound;
}
tick(elapsed) {
if (AVOCADO_SERVER) {
const isCollidingWith = this.entity.isCollidingWith;
for (let i = 0; i < isCollidingWith.length; ++i) {
const entity = isCollidingWith[i];
if (entity.is('vulnerable') && !entity.isInvulnerable) {
entity.takeDamageFrom(this.entity);
}
}
}
}
}