IN_game.ts 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. import { _decorator, Component, Node, ProgressBar } from 'cc';
  2. import EventBus, { GameEvents } from '../Core/EventBus';
  3. import { GameBlockSelection } from '../CombatSystem/BlockSelection/GameBlockSelection';
  4. import { Wall } from '../CombatSystem/Wall';
  5. import { GameStartMove } from '../Animations/GameStartMove';
  6. import { LevelSessionManager } from '../Core/LevelSessionManager';
  7. import { SkillManager } from '../CombatSystem/SkillSelection/SkillManager';
  8. import { BackgroundManager } from './BackgroundManager';
  9. import { GroundBurnAreaManager } from '../CombatSystem/BulletEffects/GroundBurnAreaManager';
  10. import { ScreenShakeManager } from '../CombatSystem/EnemyWeapon/ScreenShakeManager';
  11. import { Audio } from '../AudioManager/AudioManager';
  12. const { ccclass, property } = _decorator;
  13. /**
  14. * 游戏内状态枚举
  15. * 仅在 AppState.IN_GAME 时使用
  16. */
  17. export enum GameState {
  18. PLAYING = 'playing',
  19. SUCCESS = 'success',
  20. DEFEAT = 'defeat',
  21. PAUSED = 'paused',
  22. BLOCK_SELECTION = 'block_selection'
  23. }
  24. /**
  25. * 游戏内状态管理器
  26. * 负责管理游戏进行中的所有状态和逻辑
  27. */
  28. @ccclass('InGameManager')
  29. export class InGameManager extends Component {
  30. // === 游戏内UI节点引用 ===
  31. @property({
  32. type: Node,
  33. tooltip: '拖拽BallController节点到这里'
  34. })
  35. public ballController: Node = null;
  36. @property({
  37. type: Node,
  38. tooltip: '拖拽GameBlockSelection节点到这里'
  39. })
  40. public gameBlockSelection: Node = null;
  41. @property({
  42. type: Node,
  43. tooltip: '拖拽GameArea节点到这里'
  44. })
  45. public gameArea: Node = null;
  46. @property({
  47. type: Node,
  48. tooltip: '拖拽EnemyController节点到这里'
  49. })
  50. public enemyManager: Node = null;
  51. @property({
  52. type: Node,
  53. tooltip: '摄像机节点,用于获取GameStartMove组件'
  54. })
  55. public cameraNode: Node = null;
  56. @property({
  57. type: Node,
  58. tooltip: '墙体节点,用于获取Wall组件'
  59. })
  60. public wallNode: Node = null;
  61. @property({
  62. type: Node,
  63. tooltip: '上围栏墙体节点 (TopFence)'
  64. })
  65. public topFenceNode: Node = null;
  66. @property({
  67. type: Node,
  68. tooltip: '下围栏墙体节点 (BottomFence)'
  69. })
  70. public bottomFenceNode: Node = null;
  71. // === 游戏配置属性 ===
  72. @property({
  73. tooltip: '状态检查间隔(秒)'
  74. })
  75. public checkInterval: number = 1.0;
  76. // === 私有属性 ===
  77. private gameStarted: boolean = false;
  78. private currentState: GameState = GameState.PLAYING;
  79. private checkTimer: number = 0;
  80. // EnemyController现在通过事件系统通信,不再直接引用
  81. private enemySpawningStarted: boolean = false;
  82. private totalEnemiesSpawned: number = 0;
  83. private currentWave: number = 1;
  84. private currentWaveEnemyCount: number = 0;
  85. private currentWaveTotalEnemies: number = 0;
  86. public levelWaves: any[] = [];
  87. private levelTotalEnemies: number = 0;
  88. private enemiesKilled: number = 0;
  89. // === 背景管理器组件 ===
  90. private backgroundManager: BackgroundManager = null;
  91. // === 地面燃烧区域管理器 ===
  92. private groundBurnAreaManager: GroundBurnAreaManager = null;
  93. // 游戏计时器
  94. private gameStartTime: number = 0;
  95. private gameEndTime: number = 0;
  96. // 游戏区域的边界
  97. private gameBounds = {
  98. left: 0,
  99. right: 0,
  100. top: 0,
  101. bottom: 0
  102. };
  103. private preparingNextWave = false;
  104. // 能量系统
  105. private energyPoints: number = 0;
  106. private energyMax: number = 0; // 必须从关卡配置中读取
  107. private energyBar: ProgressBar = null;
  108. private selectSkillUI: Node = null;
  109. // 新增:能量条升级系统
  110. private energyUpgradeCount: number = 0; // 当前能量条升级次数
  111. private energyMaxUpgrades: number[] = []; // 每次升级后的最大值配置
  112. // 能量条UI节点
  113. @property({
  114. type: Node,
  115. tooltip: '拖拽能量条节点到这里 (Canvas/GameLevelUI/EnergyBar)'
  116. })
  117. public energyBarNode: Node = null;
  118. // 技能选择UI节点
  119. @property({
  120. type: Node,
  121. tooltip: '拖拽技能选择UI节点到这里 (Canvas/GameLevelUI/SelectSkillUI)'
  122. })
  123. public selectSkillUINode: Node = null;
  124. // === 背景管理器 ===
  125. @property({
  126. type: Node,
  127. tooltip: '拖拽BackgroundManager节点到这里'
  128. })
  129. public backgroundManagerNode: Node = null;
  130. @property({
  131. type: Node,
  132. tooltip: '拖拽GroundBurnAreaManager节点到这里'
  133. })
  134. public groundBurnAreaManagerNode: Node = null;
  135. // GameBlockSelection组件
  136. private blockSelectionComponent: GameBlockSelection = null;
  137. private pendingSkillSelection: boolean = false;
  138. private pendingBlockSelection: boolean = false;
  139. private shouldShowNextWavePrompt: boolean = false;
  140. // 墙体组件引用
  141. private wallComponent: Wall = null;
  142. private topFenceComponent: Wall = null;
  143. private bottomFenceComponent: Wall = null;
  144. // GameStartMove组件引用
  145. private gameStartMoveComponent: GameStartMove = null;
  146. start() {
  147. this.initializeGameState();
  148. this.setupEventListeners();
  149. this.initGameBlockSelection();
  150. this.initGameStartMove();
  151. this.initWallComponent();
  152. this.initUINodes();
  153. this.initScreenShakeManager();
  154. }
  155. onEnable() {
  156. // 旧战斗音乐播放逻辑移除,改为统一入口
  157. // this.playBattleMusicSync();
  158. Audio.updateBGMByTopUI();
  159. }
  160. onDisable() {
  161. console.log('[InGameManager] GameLevelUI节点隐藏,停止战斗音乐');
  162. // 当GameLevelUI节点隐藏时,立即停止战斗音乐
  163. Audio.stopMusic();
  164. }
  165. update(deltaTime: number) {
  166. if (this.currentState !== GameState.PLAYING) {
  167. return;
  168. }
  169. this.checkTimer += deltaTime;
  170. if (this.checkTimer >= this.checkInterval) {
  171. this.checkTimer = 0;
  172. this.checkGameState();
  173. }
  174. }
  175. /**
  176. * 初始化游戏状态
  177. */
  178. private initializeGameState() {
  179. this.currentState = GameState.PLAYING;
  180. this.checkTimer = 0;
  181. this.enemySpawningStarted = false;
  182. this.totalEnemiesSpawned = 0;
  183. this.currentWave = 1;
  184. this.currentWaveEnemyCount = 0;
  185. this.currentWaveTotalEnemies = 0;
  186. this.energyPoints = 0;
  187. this.pendingSkillSelection = false;
  188. }
  189. /**
  190. * 设置事件监听器
  191. */
  192. private setupEventListeners() {
  193. const eventBus = EventBus.getInstance();
  194. eventBus.on(GameEvents.GAME_SUCCESS, this.onGameSuccessEvent, this);
  195. eventBus.on(GameEvents.GAME_DEFEAT, this.onGameDefeatEvent, this);
  196. eventBus.on(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
  197. eventBus.on(GameEvents.GAME_RESUME_SKILL_SELECTION, this.onGameResumeEvent, this);
  198. eventBus.on(GameEvents.GAME_RESUME_BLOCK_SELECTION, this.onGameResumeEvent, this);
  199. eventBus.on('ENEMY_KILLED', this.onEnemyKilledEvent, this);
  200. eventBus.on(GameEvents.RESET_ENERGY_SYSTEM, this.resetEnergySystem, this);
  201. eventBus.on(GameEvents.WALL_DESTROYED, this.onWallDestroyedEvent, this);
  202. }
  203. /**
  204. * 初始化GameBlockSelection组件
  205. */
  206. private initGameBlockSelection() {
  207. if (this.gameBlockSelection) {
  208. this.blockSelectionComponent = this.gameBlockSelection.getComponent(GameBlockSelection);
  209. }
  210. }
  211. /**
  212. * 初始化GameStartMove组件
  213. */
  214. private initGameStartMove() {
  215. if (this.cameraNode) {
  216. this.gameStartMoveComponent = this.cameraNode.getComponent(GameStartMove);
  217. }
  218. }
  219. /**
  220. * EnemyController现在通过事件系统通信,不再需要直接初始化
  221. */
  222. /**
  223. * 初始化墙体组件
  224. */
  225. private initWallComponent() {
  226. // 初始化主墙体
  227. if (this.wallNode) {
  228. this.wallComponent = this.wallNode.getComponent(Wall);
  229. if (this.wallComponent) {
  230. console.log('[InGameManager] 主墙体组件初始化成功');
  231. } else {
  232. console.warn('[InGameManager] 未找到主墙体Wall组件');
  233. }
  234. } else {
  235. console.warn('[InGameManager] 主墙体节点未通过装饰器挂载');
  236. }
  237. // 初始化上围栏
  238. if (this.topFenceNode) {
  239. this.topFenceComponent = this.topFenceNode.getComponent(Wall);
  240. if (this.topFenceComponent) {
  241. console.log('[InGameManager] 上围栏墙体组件初始化成功');
  242. } else {
  243. console.warn('[InGameManager] 未找到上围栏Wall组件');
  244. }
  245. } else {
  246. console.warn('[InGameManager] 上围栏节点未通过装饰器挂载');
  247. }
  248. // 初始化下围栏
  249. if (this.bottomFenceNode) {
  250. this.bottomFenceComponent = this.bottomFenceNode.getComponent(Wall);
  251. if (this.bottomFenceComponent) {
  252. console.log('[InGameManager] 下围栏墙体组件初始化成功');
  253. } else {
  254. console.warn('[InGameManager] 未找到下围栏Wall组件');
  255. }
  256. } else {
  257. console.warn('[InGameManager] 下围栏节点未通过装饰器挂载');
  258. }
  259. }
  260. /**
  261. * 初始化ScreenShakeManager
  262. */
  263. private initScreenShakeManager() {
  264. if (this.cameraNode) {
  265. ScreenShakeManager.getInstance().initialize(this.cameraNode);
  266. console.log('[InGameManager] ScreenShakeManager初始化成功');
  267. } else {
  268. console.warn('[InGameManager] 相机节点未设置,ScreenShakeManager初始化失败');
  269. }
  270. }
  271. /**
  272. * 获取指定波次的敌人配置
  273. */
  274. private getWaveEnemyConfigs(wave: number): any[] {
  275. if (!this.levelWaves || wave < 1 || wave > this.levelWaves.length) {
  276. return [];
  277. }
  278. const waveConfig = this.levelWaves[wave - 1];
  279. return waveConfig?.enemies || [];
  280. }
  281. /**
  282. * 检查是否应该播放diban动画
  283. */
  284. public shouldPlayDibanAnimation(): boolean {
  285. return this.preparingNextWave && this.currentState === GameState.BLOCK_SELECTION;
  286. }
  287. /**
  288. * 技能选择完成后的处理
  289. */
  290. public onSkillSelectionComplete() {
  291. console.log('[InGameManager] 技能选择完成');
  292. // 关闭技能选择UI
  293. if (this.selectSkillUI) {
  294. this.selectSkillUI.active = false;
  295. console.log('[InGameManager] 技能选择UI已关闭');
  296. }
  297. // 恢复游戏
  298. this.resumeGame();
  299. // 发射技能选择结束恢复事件
  300. EventBus.getInstance().emit(GameEvents.GAME_RESUME_SKILL_SELECTION);
  301. // 如果有等待的diban动画,现在播放diban动画
  302. if (this.pendingBlockSelection) {
  303. console.log('[InGameManager] 技能选择完成,现在播放diban动画');
  304. this.playDibanAnimationAfterSkill();
  305. }
  306. }
  307. /**
  308. * 在技能选择后播放diban动画
  309. */
  310. public playDibanAnimationAfterSkill() {
  311. if (this.pendingBlockSelection) {
  312. console.log('[InGameManager] 技能选择完成,现在播放diban动画');
  313. this.pendingBlockSelection = false;
  314. if (this.currentWave < (this.levelWaves?.length || 1)) {
  315. this.playDibanAnimationForNextWave();
  316. } else {
  317. console.log('[InGameManager] 最后一波结束,触发游戏胜利');
  318. this.triggerGameSuccess();
  319. }
  320. } else if (this.shouldPlayDibanAnimation()) {
  321. this.playDibanAnimationForNextWave();
  322. }
  323. }
  324. /**
  325. * 播放下一波diban动画
  326. */
  327. private playDibanAnimationForNextWave() {
  328. // 如果游戏已经结束,不播放diban动画
  329. if (this.isGameOver()) {
  330. console.warn('[InGameManager] 游戏已经结束(胜利或失败),不播放下一波diban动画!');
  331. return;
  332. }
  333. console.log('[InGameManager] 播放diban动画');
  334. // 生成方块选择(不显示UI)
  335. if (this.blockSelectionComponent) {
  336. this.blockSelectionComponent.generateBlockSelection();
  337. }
  338. // 使用GameStartMove组件播放diban上滑动画和镜头下移动画
  339. if (this.gameStartMoveComponent) {
  340. console.log('[InGameManager] 调用GameStartMove组件播放diban上滑动画');
  341. this.gameStartMoveComponent.slideUpFromBottom(0.3);
  342. } else {
  343. console.warn('[InGameManager] GameStartMove组件未找到,无法播放diban动画');
  344. }
  345. // 使用底板选择专用暂停事件,小球继续运动
  346. EventBus.getInstance().emit(GameEvents.GAME_PAUSE_BLOCK_SELECTION);
  347. }
  348. /**
  349. * 处理游戏成功事件
  350. */
  351. private onGameSuccessEvent() {
  352. console.log('[InGameManager] 接收到游戏成功事件');
  353. this.currentState = GameState.SUCCESS;
  354. // 游戏结束时进入暂停状态,停止所有游戏对象的行为
  355. console.log('[InGameManager] 游戏成功,触发游戏暂停');
  356. const eventBus = EventBus.getInstance();
  357. eventBus.emit(GameEvents.GAME_PAUSE);
  358. }
  359. /**
  360. * 处理游戏失败事件
  361. */
  362. private onGameDefeatEvent() {
  363. console.log('[InGameManager] 接收到游戏失败事件');
  364. this.currentState = GameState.DEFEAT;
  365. // 游戏结束时进入暂停状态,停止所有游戏对象的行为
  366. console.log('[InGameManager] 游戏失败,触发游戏暂停');
  367. const eventBus = EventBus.getInstance();
  368. eventBus.emit(GameEvents.GAME_PAUSE);
  369. }
  370. /**
  371. * 处理游戏恢复事件
  372. */
  373. private onGameResumeEvent() {
  374. console.log('[InGameManager] 接收到游戏恢复事件');
  375. }
  376. /**
  377. * 墙体被摧毁事件处理
  378. * 墙体现在直接触发GAME_DEFEAT事件,与菜单退出处理流程一致
  379. */
  380. private onWallDestroyedEvent() {
  381. console.log('[InGameManager] 收到墙体被摧毁事件,墙体已直接触发GAME_DEFEAT事件');
  382. // 不再需要调用checkGameState,因为墙体已直接触发GAME_DEFEAT事件
  383. }
  384. /**
  385. * 处理敌人被击杀事件
  386. */
  387. private onEnemyKilledEvent() {
  388. // 游戏状态检查现在通过事件系统处理
  389. if (this.isGameOver()) {
  390. console.warn('[InGameManager] 游戏已结束状态下onEnemyKilledEvent被调用!');
  391. return;
  392. }
  393. // 如果游戏状态已经是成功或失败,不处理敌人击杀事件
  394. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  395. console.warn(`[InGameManager] 游戏已结束(${this.currentState}),跳过敌人击杀事件处理`);
  396. return;
  397. }
  398. this.enemiesKilled++;
  399. this.currentWaveEnemyCount++;
  400. const remaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
  401. console.log(`[InGameManager] 敌人被消灭,当前波剩余敌人: ${remaining}/${this.currentWaveTotalEnemies}`);
  402. // 每死一个敌人就立即增加能量
  403. const energyBeforeIncrement = this.energyPoints;
  404. this.incrementEnergy();
  405. // 通过事件系统更新敌人计数标签
  406. EventBus.getInstance().emit(GameEvents.ENEMY_UPDATE_COUNT, this.currentWaveEnemyCount);
  407. // 检查能量是否已满,如果满了需要触发技能选择
  408. const energyWillBeFull = energyBeforeIncrement + 1 >= this.energyMax;
  409. // 基于UI显示的敌人数量判断波次是否结束(Canvas-001/TopArea/EnemyNode/EnemyNumber为0)
  410. const isWaveEnd = remaining <= 0;
  411. if (isWaveEnd) {
  412. console.log(`[InGameManager] 波次结束检测: remaining=${remaining}`);
  413. // 如果能量已满,设置等待方块选择状态
  414. if (energyWillBeFull) {
  415. this.pendingBlockSelection = true;
  416. this.preparingNextWave = true;
  417. this.currentState = GameState.BLOCK_SELECTION;
  418. } else {
  419. if (this.currentWave < (this.levelWaves?.length || 1)) {
  420. this.showNextWavePrompt();
  421. } else {
  422. this.triggerGameSuccess();
  423. }
  424. }
  425. } else if (energyWillBeFull) {
  426. // 如果波次未结束但能量已满,设置状态为方块选择
  427. // 注意:onEnergyFull()已在incrementEnergy()中调用,这里不需要重复调用
  428. console.log('[InGameManager] 能量已满但波次未结束,设置方块选择状态');
  429. this.currentState = GameState.BLOCK_SELECTION;
  430. }
  431. }
  432. /**
  433. * 增加能量值
  434. */
  435. private incrementEnergy() {
  436. // 获取技能等级
  437. const energyHunterLevel = SkillManager.getInstance() ? SkillManager.getInstance().getSkillLevel('energy_hunter') : 0;
  438. const baseEnergy = 1;
  439. const bonusEnergy = SkillManager.calculateEnergyBonus ? SkillManager.calculateEnergyBonus(baseEnergy, energyHunterLevel) : baseEnergy;
  440. this.energyPoints += bonusEnergy;
  441. console.log(`[InGameManager] 能量值增加: +${bonusEnergy}, 当前: ${this.energyPoints}/${this.energyMax}`);
  442. // 检查是否达到当前能量最大值
  443. if (this.energyPoints >= this.energyMax) {
  444. this.onEnergyFull();
  445. // 能量满后重置为0,开始下一轮积累
  446. this.energyPoints = 0;
  447. }
  448. this.updateEnergyBar();
  449. }
  450. /**
  451. * 显示下一波提示
  452. */
  453. private showNextWavePrompt() {
  454. // 设置准备下一波的状态
  455. this.preparingNextWave = true;
  456. this.pendingBlockSelection = true;
  457. this.currentState = GameState.BLOCK_SELECTION;
  458. console.log('[InGameManager] 设置准备下一波状态,准备播放diban动画');
  459. // 如果当前没有技能选择UI显示,立即播放diban动画
  460. if (!this.selectSkillUI || !this.selectSkillUI.active) {
  461. this.playDibanAnimationForNextWave();
  462. }
  463. // 如果技能选择UI正在显示,则等待技能选择完成后再播放diban动画
  464. // 这种情况下,pendingBlockSelection已经在onEnemyKilledEvent中设置为true
  465. }
  466. /**
  467. * 游戏状态检查
  468. * 现在只检查敌人击败状态,墙体摧毁直接触发GAME_DEFEAT事件
  469. */
  470. private checkGameState() {
  471. // 如果游戏已经结束,不再进行状态检查
  472. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  473. return;
  474. }
  475. // 墙体摧毁检查已移除,因为墙体现在直接触发GAME_DEFEAT事件
  476. // 这样与菜单退出的失败处理流程保持一致
  477. if (this.checkAllEnemiesDefeated()) {
  478. this.triggerGameSuccess();
  479. return;
  480. }
  481. }
  482. /**
  483. * 检查所有敌人是否被击败
  484. */
  485. private checkAllEnemiesDefeated(): boolean {
  486. // 如果敌人生成还未开始,不进行胜利检查
  487. if (!this.enemySpawningStarted) {
  488. return false;
  489. }
  490. // 基于当前波次的敌人击杀数量判断是否胜利
  491. // 如果当前波次的剩余敌人数量为0,且是最后一波,则胜利
  492. const currentWaveRemaining = this.currentWaveTotalEnemies - this.currentWaveEnemyCount;
  493. const isLastWave = this.currentWave >= (this.levelWaves?.length || 1);
  494. return currentWaveRemaining <= 0 && isLastWave;
  495. }
  496. /**
  497. * 触发游戏成功
  498. * 只负责记录游戏结束时间和发送事件,状态切换由GameEnd.ts统一处理
  499. */
  500. private triggerGameSuccess() {
  501. // 防止重复触发游戏成功
  502. if (this.currentState === GameState.SUCCESS || this.currentState === GameState.DEFEAT) {
  503. console.log('[InGameManager] 游戏已结束,跳过重复的成功触发');
  504. return;
  505. }
  506. // 记录游戏结束时间
  507. this.gameEndTime = Date.now();
  508. // 触发游戏结束状态事件
  509. EventBus.getInstance().emit(GameEvents.ENTER_GAME_END_STATE, { result: 'success' });
  510. console.log('[InGameManager] 游戏成功,发送GAME_SUCCESS事件,状态切换由GameEnd.ts处理');
  511. EventBus.getInstance().emit(GameEvents.GAME_SUCCESS);
  512. }
  513. /**
  514. * 获取游戏持续时间
  515. */
  516. public getGameDuration(): number {
  517. const endTime = this.gameEndTime || Date.now();
  518. return Math.max(0, endTime - this.gameStartTime);
  519. }
  520. /**
  521. * 获取当前游戏状态
  522. */
  523. public getCurrentState(): GameState {
  524. return this.currentState;
  525. }
  526. /**
  527. * 设置游戏状态
  528. */
  529. public setCurrentState(state: GameState) {
  530. this.currentState = state;
  531. // 当游戏状态变为PLAYING时,更新能量条显示
  532. if (state === GameState.PLAYING) {
  533. this.updateEnergyBar();
  534. }
  535. }
  536. /**
  537. * 初始化UI节点
  538. */
  539. private initUINodes() {
  540. // 初始化能量条
  541. if (this.energyBarNode) {
  542. this.energyBar = this.energyBarNode.getComponent(ProgressBar);
  543. if (this.energyBar) {
  544. console.log('[InGameManager] 能量条组件初始化成功');
  545. // 不在初始化阶段更新能量条,等待游戏状态变为PLAYING后再更新
  546. } else {
  547. console.error('[InGameManager] 能量条节点存在但ProgressBar组件未找到');
  548. }
  549. } else {
  550. console.error('[InGameManager] 能量条节点未通过装饰器挂载,请在Inspector中拖拽EnergyBar节点');
  551. }
  552. // 初始化技能选择UI
  553. if (this.selectSkillUINode) {
  554. this.selectSkillUI = this.selectSkillUINode;
  555. console.log('[InGameManager] 技能选择UI节点初始化成功');
  556. } else {
  557. console.error('[InGameManager] 技能选择UI节点未通过装饰器挂载,请在Inspector中拖拽SelectSkillUI节点');
  558. }
  559. // 初始化背景管理器
  560. if (this.backgroundManagerNode) {
  561. this.backgroundManager = this.backgroundManagerNode.getComponent(BackgroundManager);
  562. if (this.backgroundManager) {
  563. console.log('[InGameManager] 背景管理器组件初始化成功');
  564. } else {
  565. console.error('[InGameManager] 背景管理器节点存在但BackgroundManager组件未找到');
  566. }
  567. } else {
  568. console.error('[InGameManager] 背景管理器节点未通过装饰器挂载,请在Inspector中拖拽BackgroundManager节点');
  569. }
  570. // 初始化地面燃烧区域管理器
  571. if (this.groundBurnAreaManagerNode) {
  572. this.groundBurnAreaManager = this.groundBurnAreaManagerNode.getComponent(GroundBurnAreaManager);
  573. if (this.groundBurnAreaManager) {
  574. console.log('[InGameManager] 地面燃烧区域管理器组件初始化成功');
  575. } else {
  576. console.error('[InGameManager] 地面燃烧区域管理器节点存在但GroundBurnAreaManager组件未找到');
  577. }
  578. } else {
  579. console.error('[InGameManager] 地面燃烧区域管理器节点未通过装饰器挂载,请在Inspector中拖拽GroundBurnAreaManager节点');
  580. }
  581. }
  582. /**
  583. * 更新能量条显示
  584. */
  585. private updateEnergyBar() {
  586. // 只有在游戏状态为PLAYING时才更新能量条,避免初始化阶段的报错
  587. if (this.currentState !== GameState.PLAYING) {
  588. return;
  589. }
  590. if (this.energyBar && this.energyMax > 0) {
  591. const progress = this.energyPoints / this.energyMax;
  592. this.energyBar.progress = Math.min(progress, 1.0);
  593. console.log(`[InGameManager] 能量条更新: ${this.energyPoints}/${this.energyMax} (${Math.round(progress * 100)}%)`);
  594. } else {
  595. console.warn('[InGameManager] 能量条组件未初始化或energyMax未设置,无法更新显示');
  596. }
  597. }
  598. /**
  599. * 能量满时的处理
  600. */
  601. private onEnergyFull() {
  602. console.log('[InGameManager] 能量已满,开始升级处理');
  603. // 升级能量条
  604. this.upgradeEnergySystem();
  605. // 显示技能选择UI
  606. this.showSkillSelection();
  607. }
  608. /**
  609. * 升级能量系统
  610. */
  611. private upgradeEnergySystem() {
  612. // 增加升级次数
  613. this.energyUpgradeCount++;
  614. // 更新能量最大值
  615. // energyMaxUpgrades数组索引0是初始值,索引1是第1次升级后的值,以此类推
  616. if (this.energyUpgradeCount < this.energyMaxUpgrades.length) {
  617. const newMaxEnergy = this.energyMaxUpgrades[this.energyUpgradeCount];
  618. this.energyMax = newMaxEnergy;
  619. console.log(`[InGameManager] 能量条升级 ${this.energyUpgradeCount} 次,新的最大值: ${this.energyMax}`);
  620. } else {
  621. // 超出配置次数,按照上一次的值+1递增
  622. this.energyMax = this.energyMax + 1;
  623. console.log(`[InGameManager] 能量条升级超出配置次数,使用递增模式,新的最大值: ${this.energyMax}`);
  624. }
  625. // 立即更新能量条显示,确保新的最大值生效
  626. this.updateEnergyBar();
  627. }
  628. /**
  629. * 显示技能选择UI
  630. */
  631. private showSkillSelection() {
  632. if (this.selectSkillUI) {
  633. this.selectSkillUI.active = true;
  634. // 使用技能选择专用暂停事件,所有小球停止运动
  635. EventBus.getInstance().emit(GameEvents.GAME_PAUSE_SKILL_SELECTION);
  636. // 注意:不调用StartGame.resetEnergy(),因为那会重置整个能量系统包括最大值
  637. // 能量点数已在onEnergyFull()中重置为0
  638. }
  639. }
  640. /**
  641. * 恢复游戏
  642. */
  643. private resumeGame() {
  644. console.log('[InGameManager] 恢复游戏');
  645. EventBus.getInstance().emit(GameEvents.GAME_RESUME);
  646. }
  647. /**
  648. * 检查游戏是否结束
  649. */
  650. private isGameOver(): boolean {
  651. let gameOver = false;
  652. EventBus.getInstance().emit(GameEvents.GAME_CHECK_OVER, (isOver: boolean) => {
  653. gameOver = isOver;
  654. });
  655. return gameOver;
  656. }
  657. /**
  658. * 设置当前波次
  659. */
  660. public setCurrentWave(wave: number, enemyCount: number = 0) {
  661. this.currentWave = wave;
  662. this.currentWaveEnemyCount = 0; // 重置当前击杀数
  663. this.currentWaveTotalEnemies = enemyCount; // 设置该波次总敌人数
  664. const totalWaves = this.levelWaves?.length || 1;
  665. // 获取波次敌人配置
  666. const waveEnemyConfigs = this.getWaveEnemyConfigs(wave);
  667. // 获取当前波次的血量系数
  668. let healthMultiplier = 1.0;
  669. if (this.levelWaves && this.levelWaves.length > 0) {
  670. const waveIndex = wave - 1; // 波次从1开始,数组从0开始
  671. if (waveIndex >= 0 && waveIndex < this.levelWaves.length) {
  672. const waveData = this.levelWaves[waveIndex];
  673. if (waveData && typeof waveData.healthMultiplier === 'number') {
  674. healthMultiplier = waveData.healthMultiplier;
  675. }
  676. }
  677. }
  678. // 通过事件系统启动波次
  679. EventBus.getInstance().emit(GameEvents.ENEMY_START_WAVE, {
  680. wave: wave,
  681. totalWaves: totalWaves,
  682. enemyCount: enemyCount,
  683. waveEnemyConfigs: waveEnemyConfigs,
  684. healthMultiplier: healthMultiplier
  685. });
  686. }
  687. /**
  688. * 更新当前波次敌人数量
  689. */
  690. public updateCurrentWaveEnemyCount(count: number) {
  691. this.currentWaveEnemyCount = count;
  692. }
  693. /**
  694. * 获取当前波次
  695. */
  696. public getCurrentWave(): number {
  697. return this.currentWave;
  698. }
  699. /**
  700. * 获取当前波次敌人数量
  701. */
  702. public getCurrentWaveEnemyCount(): number {
  703. return this.currentWaveEnemyCount;
  704. }
  705. /**
  706. * 获取当前波次总敌人数量
  707. */
  708. public getCurrentWaveTotalEnemies(): number {
  709. return this.currentWaveTotalEnemies;
  710. }
  711. /**
  712. * 进入下一波
  713. */
  714. public nextWave() {
  715. this.currentWave++;
  716. // 根据关卡配置获取下一波敌人数
  717. let enemyTotal = 0;
  718. if (this.levelWaves && this.levelWaves.length >= this.currentWave) {
  719. const waveCfg = this.levelWaves[this.currentWave - 1];
  720. if (waveCfg && waveCfg.enemies) {
  721. enemyTotal = waveCfg.enemies.reduce((t: number, g: any) => t + (g.count || 0), 0);
  722. }
  723. }
  724. this.setCurrentWave(this.currentWave, enemyTotal);
  725. }
  726. /**
  727. * 获取当前能量值
  728. */
  729. public getCurrentEnergy(): number {
  730. return this.energyPoints;
  731. }
  732. /**
  733. * 获取最大能量值
  734. */
  735. public getMaxEnergy(): number {
  736. return this.energyMax;
  737. }
  738. /**
  739. * 获取墙体健康度(返回主墙体健康度)
  740. */
  741. public getWallHealth(): number {
  742. if (this.wallComponent) {
  743. return this.wallComponent.getCurrentHealth();
  744. }
  745. return 0;
  746. }
  747. /**
  748. * 获取所有墙体的健康度
  749. */
  750. public getAllWallsHealth(): { main: number; topFence: number; bottomFence: number } {
  751. return {
  752. main: this.wallComponent ? this.wallComponent.getCurrentHealth() : 0,
  753. topFence: this.topFenceComponent ? this.topFenceComponent.getCurrentHealth() : 0,
  754. bottomFence: this.bottomFenceComponent ? this.bottomFenceComponent.getCurrentHealth() : 0
  755. };
  756. }
  757. /**
  758. * 根据等级获取墙体健康度
  759. */
  760. public getWallHealthByLevel(level: number): number {
  761. if (this.wallComponent) {
  762. return this.wallComponent.getWallHealthByLevel(level);
  763. }
  764. return 100;
  765. }
  766. /**
  767. * 获取当前墙体等级(返回主墙体等级)
  768. */
  769. public getCurrentWallLevel(): number {
  770. if (this.wallComponent) {
  771. return this.wallComponent.getCurrentWallLevel();
  772. }
  773. return 1;
  774. }
  775. /**
  776. * 获取当前墙体健康度(返回主墙体健康度)
  777. */
  778. public getCurrentWallHealth(): number {
  779. if (this.wallComponent) {
  780. return this.wallComponent.getCurrentHealth();
  781. }
  782. return 100;
  783. }
  784. /**
  785. * 获取所有墙体的等级
  786. */
  787. public getAllWallsLevel(): { main: number; topFence: number; bottomFence: number } {
  788. return {
  789. main: this.wallComponent ? this.wallComponent.getCurrentWallLevel() : 1,
  790. topFence: this.topFenceComponent ? this.topFenceComponent.getCurrentWallLevel() : 1,
  791. bottomFence: this.bottomFenceComponent ? this.bottomFenceComponent.getCurrentWallLevel() : 1
  792. };
  793. }
  794. /**
  795. * 处理确认操作(方块选择确认)
  796. */
  797. public handleConfirmAction() {
  798. console.log('[InGameManager] 处理方块选择确认操作');
  799. // 如果是在准备下一波的状态,需要先切换到下一波
  800. if (this.preparingNextWave) {
  801. console.log('[InGameManager] 检测到准备下一波状态,切换到下一波');
  802. this.nextWave();
  803. // 重置状态
  804. this.preparingNextWave = false;
  805. this.pendingBlockSelection = false;
  806. this.currentState = GameState.PLAYING;
  807. }
  808. // 触发进入游玩状态事件
  809. EventBus.getInstance().emit(GameEvents.ENTER_PLAYING_STATE);
  810. // 注意:不再发送GAME_START事件,避免重复触发游戏启动流程
  811. // 游戏启动流程已在用户点击战斗按钮时完成,这里只需要启动游戏逻辑
  812. // 通过事件系统启动球的移动
  813. EventBus.getInstance().emit(GameEvents.BALL_START);
  814. console.log('[InGameManager] 发送BALL_START事件,球已启动');
  815. // 通过事件系统开始当前波次的敌人生成
  816. EventBus.getInstance().emit(GameEvents.ENEMY_START_GAME);
  817. EventBus.getInstance().emit(GameEvents.ENEMY_SHOW_START_WAVE_PROMPT);
  818. console.log(`[InGameManager] 波次 ${this.currentWave} 敌人生成已启动`);
  819. }
  820. /**
  821. * 重置能量值(供StartGame调用)
  822. */
  823. public resetEnergyValue() {
  824. this.energyPoints = 0;
  825. this.updateEnergyBar();
  826. console.log('[InGameManager] 能量值重置完成');
  827. }
  828. /**
  829. * 重置波次信息(供StartGame调用)
  830. */
  831. public resetWaveInfo() {
  832. this.currentWave = 1;
  833. this.currentWaveEnemyCount = 0;
  834. this.currentWaveTotalEnemies = 0;
  835. this.enemiesKilled = 0;
  836. this.totalEnemiesSpawned = 0;
  837. this.levelTotalEnemies = 0;
  838. console.log('[InGameManager] 波次信息重置完成');
  839. }
  840. /**
  841. * 重置能量系统(供StartGame调用)
  842. * 注意:只在游戏真正重新开始时重置升级状态,技能选择后不应重置升级状态
  843. */
  844. public resetEnergySystem() {
  845. this.energyPoints = 0;
  846. // 只有在游戏状态不是BLOCK_SELECTION时才重置升级状态
  847. // 这样可以避免技能选择后重置已获得的能量升级
  848. if (this.currentState !== GameState.BLOCK_SELECTION) {
  849. this.energyUpgradeCount = 0;
  850. // 重置energyMax到初始值(energyMaxUpgrades数组的第一个值)
  851. if (this.energyMaxUpgrades && this.energyMaxUpgrades.length > 0) {
  852. this.energyMax = this.energyMaxUpgrades[0];
  853. }
  854. console.log('[InGameManager] 能量系统完全重置(包括升级状态)');
  855. } else {
  856. console.log('[InGameManager] 技能选择状态下,仅重置能量点数,保持升级状态');
  857. }
  858. this.updateEnergyBar();
  859. console.log('[InGameManager] 能量系统重置完成');
  860. }
  861. /**
  862. * 清理游戏数据,为返回主页面做准备
  863. * 当游戏胜利或失败返回主页面时调用
  864. */
  865. private cleanupGameDataForMainMenu() {
  866. console.log('[InGameManager] 开始清理游戏数据,准备返回主页面');
  867. const eventBus = EventBus.getInstance();
  868. // 1. 清空场上的所有游戏对象
  869. console.log('[InGameManager] 清空场上敌人、方块、球');
  870. eventBus.emit(GameEvents.CLEAR_ALL_ENEMIES); // 清空所有敌人
  871. eventBus.emit(GameEvents.CLEAR_ALL_BULLETS); // 清空所有子弹
  872. eventBus.emit(GameEvents.CLEAR_ALL_GAME_OBJECTS); // 清空其他游戏对象
  873. // 2. 重置能量系统
  874. console.log('[InGameManager] 重置能量系统');
  875. this.energyPoints = 0;
  876. this.updateEnergyBar();
  877. // 3. 清空技能选择数据(重置临时技能状态)
  878. console.log('[InGameManager] 清空技能选择数据');
  879. const skillManager = SkillManager.getInstance();
  880. if (skillManager) {
  881. skillManager.resetAllSkillLevels();
  882. }
  883. // 4. 重置关卡数据和游戏状态
  884. console.log('[InGameManager] 重置关卡数据和游戏状态');
  885. this.currentWave = 1;
  886. this.currentWaveEnemyCount = 0;
  887. this.currentWaveTotalEnemies = 0;
  888. this.enemiesKilled = 0;
  889. this.totalEnemiesSpawned = 0;
  890. this.levelTotalEnemies = 0;
  891. this.levelWaves = [];
  892. this.gameStarted = false;
  893. this.enemySpawningStarted = false;
  894. this.preparingNextWave = false;
  895. this.pendingSkillSelection = false;
  896. this.pendingBlockSelection = false;
  897. this.shouldShowNextWavePrompt = false;
  898. // 5. 重置UI状态
  899. console.log('[InGameManager] 重置UI状态');
  900. if (this.selectSkillUI) {
  901. this.selectSkillUI.active = false;
  902. }
  903. // 6. 清理会话数据(局内金币等临时数据)
  904. console.log('[InGameManager] 清理会话数据');
  905. if (LevelSessionManager.inst) {
  906. LevelSessionManager.inst.clear(); // 清空局内金币等临时数据
  907. }
  908. // 7. 通过事件系统通知其他组件进行清理
  909. eventBus.emit(GameEvents.RESET_BALL_CONTROLLER); // 重置球控制器
  910. eventBus.emit(GameEvents.RESET_BLOCK_MANAGER); // 重置方块管理器
  911. eventBus.emit(GameEvents.RESET_BLOCK_SELECTION); // 重置方块选择
  912. eventBus.emit(GameEvents.RESET_ENEMY_CONTROLLER); // 重置敌人控制器
  913. eventBus.emit(GameEvents.RESET_WALL_HEALTH); // 重置墙体血量
  914. eventBus.emit(GameEvents.RESET_UI_STATES); // 重置UI状态
  915. // 8. 重置镜头位置
  916. console.log('[InGameManager] 重置镜头位置');
  917. if (this.gameStartMoveComponent) {
  918. this.gameStartMoveComponent.resetCameraToOriginalPositionImmediate();
  919. } else {
  920. console.warn('[InGameManager] GameStartMove组件未找到,无法重置镜头位置');
  921. }
  922. // 9. 发送游戏结束事件,确保游戏状态正确转换
  923. console.log('[InGameManager] 发送游戏结束事件');
  924. eventBus.emit('GAME_END');
  925. // 10. 重置游戏状态为初始状态
  926. this.currentState = GameState.PLAYING;
  927. // 11. 重置游戏结束时间,确保下次游戏状态检查正常
  928. this.gameEndTime = 0;
  929. console.log('[InGameManager] 游戏数据清理完成,可以安全返回主页面');
  930. }
  931. /**
  932. * 重置游戏状态(供StartGame调用)
  933. */
  934. public resetGameStates() {
  935. this.currentState = GameState.PLAYING;
  936. this.gameStarted = false;
  937. this.enemySpawningStarted = false;
  938. this.preparingNextWave = false;
  939. this.pendingSkillSelection = false;
  940. this.pendingBlockSelection = false;
  941. this.shouldShowNextWavePrompt = false;
  942. this.gameStartTime = 0;
  943. this.gameEndTime = 0;
  944. this.checkTimer = 0;
  945. console.log('[InGameManager] 游戏状态重置完成');
  946. }
  947. // resetGameRecord方法已被移除,避免与cleanupGameDataForMainMenu重复
  948. // 所有清理逻辑已统一在cleanupGameDataForMainMenu中处理
  949. /**
  950. * 手动触发游戏数据清理(供外部调用)
  951. * 可以在返回主菜单按钮点击时调用
  952. */
  953. public triggerGameDataCleanup() {
  954. this.cleanupGameDataForMainMenu();
  955. }
  956. /**
  957. * 应用关卡配置
  958. */
  959. public async applyLevelConfig(levelConfig: any) {
  960. console.log('[InGameManager] 应用关卡配置');
  961. // 应用能量配置 - 现在从energyMaxUpgrades数组获取初始值
  962. let initialEnergyMax = 5; // 默认值
  963. // 先读取energyMaxUpgrades配置以获取初始能量最大值
  964. if (levelConfig.levelSettings && levelConfig.levelSettings.energyMaxUpgrades && Array.isArray(levelConfig.levelSettings.energyMaxUpgrades) && levelConfig.levelSettings.energyMaxUpgrades.length > 0) {
  965. initialEnergyMax = levelConfig.levelSettings.energyMaxUpgrades[0];
  966. console.log(`[InGameManager] 从energyMaxUpgrades获取初始能量配置: ${initialEnergyMax}`);
  967. } else {
  968. console.warn('[InGameManager] 警告:关卡配置中缺少 energyMaxUpgrades 设置,使用默认值!');
  969. }
  970. this.energyMax = initialEnergyMax;
  971. this.updateEnergyBar();
  972. // 应用新的能量条升级配置
  973. if (levelConfig.levelSettings) {
  974. // 读取能量条升级后最大值配置
  975. if (levelConfig.levelSettings.energyMaxUpgrades && Array.isArray(levelConfig.levelSettings.energyMaxUpgrades)) {
  976. this.energyMaxUpgrades = [...levelConfig.levelSettings.energyMaxUpgrades];
  977. console.log(`[InGameManager] 应用能量条升级配置: ${this.energyMaxUpgrades.length}个配置`);
  978. } else {
  979. // 默认升级配置(基于初始最大值递增)
  980. this.energyMaxUpgrades = [];
  981. for (let i = 0; i < 20; i++) {
  982. this.energyMaxUpgrades.push(this.energyMax + i + 1);
  983. }
  984. console.log('[InGameManager] 使用默认能量条升级配置');
  985. }
  986. this.energyUpgradeCount = 0;
  987. console.log('[InGameManager] 初始化能量条升级系统');
  988. }
  989. // 如果有武器配置,应用武器
  990. if (levelConfig.weapons && Array.isArray(levelConfig.weapons)) {
  991. console.log('[InGameManager] 应用武器配置');
  992. // TODO: 应用武器配置逻辑
  993. }
  994. // 如果有波次配置,设置敌人波次
  995. if (levelConfig.waves && Array.isArray(levelConfig.waves)) {
  996. this.levelWaves = levelConfig.waves;
  997. this.currentWave = 1;
  998. // 计算本关卡总敌人数
  999. this.levelTotalEnemies = 0;
  1000. for (const wave of this.levelWaves) {
  1001. for (const enemy of wave.enemies || []) {
  1002. this.levelTotalEnemies += enemy.count || 0;
  1003. }
  1004. }
  1005. console.log(`[InGameManager] 应用波次配置: ${this.levelWaves.length}波,总敌人数: ${this.levelTotalEnemies}`);
  1006. // 通过事件系统通知 EnemyController 初始化第一波数据及 UI
  1007. const firstWaveEnemies = this.levelWaves.length > 0 && this.levelWaves[0].enemies ?
  1008. this.levelWaves[0].enemies.reduce((t: number, g: any) => t + (g.count || 0), 0) : 0;
  1009. // 通过事件系统调用setCurrentWave
  1010. this.setCurrentWave(1, firstWaveEnemies);
  1011. }
  1012. // 应用背景图片配置
  1013. if (this.backgroundManager && levelConfig.backgroundImage) {
  1014. // 转换路径格式:从 "images/LevelBackground/BG1" 转换为 "LevelBackground/BG1"
  1015. const bundlePath = levelConfig.backgroundImage.replace('images/', '');
  1016. await this.backgroundManager.setBackground(bundlePath);
  1017. console.log(`[InGameManager] 应用背景配置: ${levelConfig.backgroundImage}`);
  1018. } else if (this.backgroundManager) {
  1019. // 如果没有指定背景图片,使用默认背景
  1020. await this.backgroundManager.setBackground('LevelBackground/BG1');
  1021. console.log('[InGameManager] 使用默认背景: LevelBackground/BG1');
  1022. }
  1023. }
  1024. /**
  1025. * 同步播放战斗音乐(立即执行,不等待异步操作)
  1026. */
  1027. private playBattleMusicSync() {
  1028. try {
  1029. console.log('[InGameManager] 立即播放战斗音乐');
  1030. // 先停止当前播放的音乐
  1031. Audio.stopMusic();
  1032. // 设置音乐音量
  1033. Audio.setMusicVolume(0.8);
  1034. // 播放战斗音乐(循环播放)- 不等待异步操作
  1035. Audio.updateBGMByTopUI();
  1036. console.log('[InGameManager] 战斗音乐播放指令已发送');
  1037. } catch (error) {
  1038. console.error('[InGameManager] 播放战斗音乐失败:', error);
  1039. }
  1040. }
  1041. onDestroy() {
  1042. const eventBus = EventBus.getInstance();
  1043. eventBus.off(GameEvents.GAME_SUCCESS, this.onGameSuccessEvent, this);
  1044. eventBus.off(GameEvents.GAME_DEFEAT, this.onGameDefeatEvent, this);
  1045. eventBus.off(GameEvents.GAME_RESUME, this.onGameResumeEvent, this);
  1046. eventBus.off(GameEvents.GAME_RESUME_SKILL_SELECTION, this.onGameResumeEvent, this);
  1047. eventBus.off(GameEvents.GAME_RESUME_BLOCK_SELECTION, this.onGameResumeEvent, this);
  1048. eventBus.off('ENEMY_KILLED', this.onEnemyKilledEvent, this);
  1049. eventBus.off(GameEvents.RESET_ENERGY_SYSTEM, this.resetEnergySystem, this);
  1050. eventBus.off(GameEvents.WALL_DESTROYED, this.onWallDestroyedEvent, this);
  1051. }
  1052. }