SysDizzy.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 {ComRole} from '../components/ComRole'
  7. import {ComDizzy} from '../components/ComDizzy'
  8. import {ComBehaviorTree} from '../components/ComBehaviorTree'
  9. const FILTER_DIZZY_TIME = GenFilterKey([ComDizzy, ComRole, ComBehaviorTree], [ComDie])
  10. export class SysDizzy extends ECSSystem {
  11. /** 连接 */
  12. public onAdd(world: FightWorld): void {}
  13. /** 断开连接 */
  14. public onRemove(world: FightWorld): void {}
  15. /** 添加实体 */
  16. public onEntityEnter(world: FightWorld, entity: number): void {}
  17. /** */
  18. public onEntityLeave(world: FightWorld, entity: number): void {}
  19. /** 更新 */
  20. public onUpdate(world: FightWorld, dt: number): void {
  21. let filter = world.getFilter(FILTER_DIZZY_TIME)
  22. filter.walk((entity: number) => {
  23. let comDizzy = world.getComponent(entity, ComDizzy)
  24. if (!comDizzy.dirty) return
  25. comDizzy.countDown -= dt
  26. if (comDizzy.countDown <= 0) {
  27. comDizzy.dirty = false
  28. }
  29. return false
  30. })
  31. }
  32. }