SysDie.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** @format */
  2. import {ECSSystem} from '../lib/ECSSystem'
  3. import {GenFilterKey} from '../lib/ECSComponent'
  4. import {FightWorld} from '../worlds/FightWorld'
  5. import {ComDie} from '../components/ComDie'
  6. import {ComNodeConfig} from '../components/ComNodeConfig'
  7. import {ComCocosNode} from '../components/ComCocosNode'
  8. import {ComTransform} from '../components/ComTransform'
  9. import {ComRole} from '../components/ComRole'
  10. import {ComRoleSpine} from '../components/ComRoleSpine'
  11. import {ComBehaviorTree} from '../components/ComBehaviorTree'
  12. const FILTER_DIE = GenFilterKey([ComCocosNode, ComDie])
  13. export class SysDie extends ECSSystem {
  14. /** 连接 */
  15. public onAdd(world: FightWorld): void {}
  16. /** 断开连接 */
  17. public onRemove(world: FightWorld): void {}
  18. /** 添加实体 */
  19. public onEntityEnter(world: FightWorld, entity: number): void {}
  20. /** */
  21. public onEntityLeave(world: FightWorld, entity: number): void {}
  22. /** 更新 */
  23. public onUpdate(world: FightWorld, dt: number): void {
  24. let filter = world.getFilter(FILTER_DIE)
  25. filter.walk((entity: number) => {
  26. let comDie = world.getComponent(entity, ComDie)
  27. comDie.countDown -= dt
  28. if (comDie.countDown <= 0) {
  29. if (comDie.spineEntity) {
  30. world.removeNodeEntity(comDie.spineEntity)
  31. }
  32. world.removeNodeEntity(entity)
  33. }
  34. return false
  35. })
  36. }
  37. }