import Component from '@/ecs/component.js'; export const DamageTypes = { PAIN: 0, HEALING: 1, MANA: 2, }; export default class Vulnerable extends Component { 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; Types = DamageTypes; damage(specification) { const {Alive} = Component.ecs.get(this.entity); if (Alive) { switch (specification.type) { case DamageTypes.PAIN: { Alive.acceptDamage(specification.amount); } } } Component.markChange(this.entity, 'damage', {[this.id++]: specification}); } }; } }