2024-07-26 10:36:59 -05:00
|
|
|
import Component from '@/ecs/component.js';
|
|
|
|
|
2024-07-27 10:52:49 -05:00
|
|
|
export const DamageTypes = {
|
|
|
|
PAIN: 0,
|
|
|
|
HEALING: 1,
|
|
|
|
MANA: 2,
|
|
|
|
};
|
|
|
|
|
2024-07-26 10:36:59 -05:00
|
|
|
export default class Vulnerable extends Component {
|
2024-07-26 18:05:24 -05:00
|
|
|
mergeDiff(original, update) {
|
|
|
|
const merged = {};
|
|
|
|
if (update.damage) {
|
|
|
|
merged.damage = {
|
|
|
|
...original.damage,
|
|
|
|
...update.damage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return merged;
|
|
|
|
}
|
|
|
|
instanceFromSchema() {
|
|
|
|
const Component = this;
|
|
|
|
return class VulnerableInstance extends super.instanceFromSchema() {
|
|
|
|
id = 0;
|
2024-07-27 10:52:49 -05:00
|
|
|
Types = DamageTypes;
|
2024-07-26 18:05:24 -05:00
|
|
|
damage(specification) {
|
2024-07-27 12:31:52 -05:00
|
|
|
const {Alive} = Component.ecs.get(this.entity);
|
|
|
|
if (Alive) {
|
|
|
|
switch (specification.type) {
|
|
|
|
case DamageTypes.PAIN: {
|
|
|
|
Alive.acceptDamage(specification.amount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 18:05:24 -05:00
|
|
|
Component.markChange(this.entity, 'damage', {[this.id++]: specification});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-07-26 10:36:59 -05:00
|
|
|
}
|