/** @format */ import {ECSSystem} from '../lib/ECSSystem' import {GenFilterKey} from '../lib/ECSComponent' import {FightWorld} from '../worlds/FightWorld' import {ComDie} from '../components/ComDie' import {ComNodeConfig} from '../components/ComNodeConfig' import {ComCocosNode} from '../components/ComCocosNode' import {ComTransform} from '../components/ComTransform' import {ComRole} from '../components/ComRole' import {ComRoleSpine} from '../components/ComRoleSpine' import {ComEnter} from '../components/ComEnter' import {ComBehaviorTree} from '../components/ComBehaviorTree' import {BT} from '../../behaviorTree/BehaviorTree' import {EventEnter} from '../core/NodeEvent' const FILTER_ENTER = GenFilterKey([ComCocosNode, ComEnter, ComRole]) export class SysEnter 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_ENTER) filter.walk((entity: number) => { let comEnter = world.getComponent(entity, ComEnter) let comCocosNode = world.getComponent(entity, ComCocosNode) if (!comCocosNode.loaded) return let comRole = world.getComponent(entity, ComRole) comEnter.countDown -= dt if (comEnter.countDown <= 0) { world.removeComponent(entity, ComEnter) // 添加behavior tree let comBehavior = world.addComponent(entity, ComBehaviorTree) comBehavior.bb = new BT.BlackBoard() world.initRoleBehavior(comBehavior, comRole.roleCfg) comCocosNode.events.push(new EventEnter()) } return false }) } }