/** @format */ import {ECSSystem} from '../lib/ECSSystem' import {GenFilterKey} from '../lib/ECSComponent' import {FightWorld} from '../worlds/FightWorld' import {ComDie} from '../components/ComDie' import {ComLifeTime} from '../components/ComLifeTime' import {ComRole} from '../components/ComRole' import {ComBehaviorTree} from '../components/ComBehaviorTree' const FILTER_LIFE_TIME = GenFilterKey([ComLifeTime, ComRole, ComBehaviorTree], [ComDie]) export class SysLifeTime extends ECSSystem { /** 连接 */ public onAdd(world: FightWorld): void {} /** 断开连接 */ public onRemove(world: FightWorld): void {} /** 添加实体 */ public onEntityEnter(world: FightWorld, entity: number): void {} /** */ public onEntityLeave(world: FightWorld, entity: number): void {} /** 更新 */ public onUpdate(world: FightWorld, dt: number): void { let filter = world.getFilter(FILTER_LIFE_TIME) filter.walk((entity: number) => { let comLifeTime = world.getComponent(entity, ComLifeTime) if (!comLifeTime.dirty) return comLifeTime.countDown -= dt if (comLifeTime.countDown <= 0) { let comRole = world.getComponent(entity, ComRole) comLifeTime.dirty = false comRole.nowHP = 0 comRole.shieldHP = 0 comRole.HPDirty = true } return false }) } }