humus-old/common/combat/damaging.trait.js

43 lines
844 B
JavaScript
Raw Normal View History

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