2019-04-19 02:54:59 -05:00
|
|
|
import * as I from 'immutable';
|
|
|
|
|
|
|
|
import {Trait} from '@avocado/entity';
|
|
|
|
|
2019-04-28 22:35:20 -05:00
|
|
|
import {AFFINITY_PHYSICAL} from './constants';
|
|
|
|
|
2019-04-19 02:54:59 -05:00
|
|
|
export class Damaging extends Trait {
|
|
|
|
|
|
|
|
static defaultParams() {
|
|
|
|
return {
|
2019-04-20 16:09:34 -05:00
|
|
|
damagingSound: '',
|
2019-04-19 12:16:28 -05:00
|
|
|
damageSpecs: [],
|
2019-04-19 02:54:59 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize() {
|
|
|
|
this._collidingWith = [];
|
2019-04-19 12:16:28 -05:00
|
|
|
const damageSpecsJSON = this.params.get('damageSpecs').toJS();
|
|
|
|
this._damageSpecs = damageSpecsJSON.map((damageSpec) => {
|
|
|
|
return {
|
2019-04-28 22:35:20 -05:00
|
|
|
affinity: AFFINITY_PHYSICAL,
|
2019-04-19 12:16:28 -05:00
|
|
|
lock: 0.1,
|
|
|
|
power: 0,
|
|
|
|
variance: 0.2,
|
|
|
|
...damageSpec,
|
|
|
|
};
|
|
|
|
});
|
2019-04-20 16:09:34 -05:00
|
|
|
this._damagingSound = this.params.get('damagingSound');
|
2019-04-19 02:54:59 -05:00
|
|
|
}
|
|
|
|
|
2019-04-19 12:16:28 -05:00
|
|
|
get damageSpecs() {
|
|
|
|
return this._damageSpecs;
|
2019-04-19 02:54:59 -05:00
|
|
|
}
|
|
|
|
|
2019-04-20 16:09:34 -05:00
|
|
|
get damagingSound() {
|
|
|
|
return this._damagingSound;
|
|
|
|
}
|
|
|
|
|
2019-04-19 02:54:59 -05:00
|
|
|
tick(elapsed) {
|
2019-04-22 21:03:16 -05:00
|
|
|
if (AVOCADO_SERVER) {
|
|
|
|
const isCollidingWith = this.entity.isCollidingWith;
|
2019-05-01 17:34:30 -05:00
|
|
|
for (let i = 0; i < isCollidingWith.length; i++) {
|
|
|
|
const entity = isCollidingWith[i];
|
2019-05-01 20:06:05 -05:00
|
|
|
if (entity.is('vulnerable')) {
|
|
|
|
if (!entity.isInvulnerable) {
|
|
|
|
entity.takeDamageFrom(this.entity);
|
|
|
|
}
|
2019-04-22 21:03:16 -05:00
|
|
|
}
|
2019-04-19 02:54:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|