silphius/app/ecs/components/vulnerable.js

32 lines
682 B
JavaScript
Raw Normal View History

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() {
damages = {};
id = 0;
2024-07-27 10:52:49 -05:00
Types = DamageTypes;
2024-07-26 18:05:24 -05:00
damage(specification) {
Component.markChange(this.entity, 'damage', {[this.id++]: specification});
}
};
}
2024-07-26 10:36:59 -05:00
}