LevelStateManager.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator } from 'cc';
  2. import { BaseSingleton } from '../Core/BaseSingleton';
  3. import EventBus, { GameEvents } from '../Core/EventBus';
  4. import { EnemyController } from '../CombatSystem/EnemyController';
  5. const { ccclass } = _decorator;
  6. @ccclass('LevelStateManager')
  7. export class LevelStateManager extends BaseSingleton {
  8. public static _instance: LevelStateManager;
  9. private currentWave = 1;
  10. private currentWaveEnemyCount = 0;
  11. private totalEnemiesInWave = 0;
  12. protected init() {
  13. // 临时监听示例,如需根据 LevelConfigManager 生成波次数据再完善
  14. EventBus.getInstance().on('NEXT_WAVE', this.nextWave, this);
  15. }
  16. public setWaveInfo(wave: number, totalEnemies: number) {
  17. this.currentWave = wave;
  18. this.totalEnemiesInWave = totalEnemies;
  19. this.currentWaveEnemyCount = 0;
  20. }
  21. public enemySpawned() {
  22. this.currentWaveEnemyCount++;
  23. }
  24. public enemyKilled() {
  25. this.currentWaveEnemyCount--;
  26. if (this.currentWaveEnemyCount <= 0) {
  27. EventBus.getInstance().emit('WAVE_CLEAR', this.currentWave);
  28. }
  29. }
  30. private nextWave() {
  31. this.currentWave++;
  32. // TODO: 读取 LevelConfigManager 获得下一波敌人信息并驱动 EnemyController
  33. EnemyController.getInstance()?.resumeSpawning();
  34. }
  35. }