From a3a19b1960a1379324a77175ea4bd5b42f5b7da7 Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 30 Mar 2026 15:22:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(map):=20=E9=87=8D=E6=9E=84=E6=80=AA?= =?UTF-8?q?=E7=89=A9=E7=94=9F=E6=88=90=E4=BD=8D=E7=BD=AE=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=A5=E6=94=B9=E5=96=84=E5=88=86=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的 MonStart 导入 - 将 spawnCount 重命名为 waveSpawnOrder 以更准确反映其用途 - 使用固定的横向间隔(WAVE_SPAWN_X_INTERVAL)和起始位置(WAVE_SPAWN_START_X)替代随机高度偏移 - 简化 addMonster 方法签名,移除冗余的 i 参数 - 确保每波开始时重置 waveSpawnOrder 计数器 --- assets/script/game/map/MissionMonComp.ts | 26 +++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index 3b262ce6..c27c834d 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -4,7 +4,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { Monster } from "../hero/Mon"; -import { HeroInfo, MonStart } from "../common/config/heroSet"; +import { HeroInfo } from "../common/config/heroSet"; import { smc } from "../common/SingletonModuleComp"; import { GameEvent } from "../common/config/GameEvent"; import {BoxSet } from "../common/config/GameSet"; @@ -18,7 +18,8 @@ const { ccclass, property } = _decorator; @ecs.register('MissionMonComp', false) export class MissionMonCompComp extends CCComp { private static readonly BOSS_RENDER_PRIORITY = 1000000; - private static readonly MON_DROP_HEIGHT = 300; + private static readonly WAVE_SPAWN_START_X = 400; + private static readonly WAVE_SPAWN_X_INTERVAL = 60; @property({ tooltip: "是否启用调试日志" }) private debugMode: boolean = false; @property({ tooltip: "每波基础普通怪数量" }) @@ -37,7 +38,7 @@ export class MissionMonCompComp extends CCComp { level: number, }> = []; - private spawnCount: number = 0; // 总生成计数,用于控制横向分布位置 + private waveSpawnOrder: number = 0; /** 全局生成顺序计数器,用于层级管理(预留) */ private globalSpawnOrder: number = 0; /** 插队刷怪处理计时器 */ @@ -81,7 +82,7 @@ export class MissionMonCompComp extends CCComp { this.waveSpawnedCount = 0 this.bossSpawnedInWave = false this.MonQueue = [] - this.spawnCount = 0 + this.waveSpawnOrder = 0 this.startNextWave() mLogger.log(this.debugMode, 'MissionMonComp', "[MissionMonComp] Starting Wave System"); } @@ -108,8 +109,7 @@ export class MissionMonCompComp extends CCComp { if (!item) return; // 特殊怪同样走随机成长类型,保持局内随机性一致 const upType = this.getRandomUpType(); - this.addMonster(item.uuid, this.spawnCount, BossList.includes(item.uuid), upType); - this.spawnCount += 1; + this.addMonster(item.uuid, BossList.includes(item.uuid), upType); } private updateWaveSpawn(dt: number) { @@ -120,17 +120,15 @@ export class MissionMonCompComp extends CCComp { if (this.isBossWave() && !this.bossSpawnedInWave) { const bossUuid = this.getRandomBossUuid(); const bossUpType = this.getRandomUpType(); - this.addMonster(bossUuid, this.spawnCount, true, bossUpType); - this.spawnCount += 1; + this.addMonster(bossUuid, true, bossUpType); this.bossSpawnedInWave = true; } return; } const uuid = this.getRandomNormalMonsterUuid(); const upType = this.getRandomUpType(); - this.addMonster(uuid, this.spawnCount, false, upType); + this.addMonster(uuid, false, upType); this.waveSpawnedCount += 1; - this.spawnCount += 1; } private startNextWave() { @@ -138,6 +136,7 @@ export class MissionMonCompComp extends CCComp { smc.vmdata.mission_data.level = this.currentWave; this.waveTargetCount = Math.max(1, this.baseMonstersPerWave + (this.currentWave - 1) * this.waveMonsterGrowth); this.waveSpawnedCount = 0; + this.waveSpawnOrder = 0; this.bossSpawnedInWave = false; this.waveSpawnTimer = this.waveSpawnCd; oops.message.dispatchEvent(GameEvent.NewWave, { @@ -203,17 +202,16 @@ export class MissionMonCompComp extends CCComp { private addMonster( uuid: number = 1001, - i: number = 0, isBoss: boolean = false, upType: UpType = UpType.AP1_HP1, ) { // 创建 ECS 怪物实体 let mon = ecs.getEntity(Monster); let scale = -1; - // 按生成序号做横向错列,减轻重叠感 + const spawnX = MissionMonCompComp.WAVE_SPAWN_START_X + this.waveSpawnOrder * MissionMonCompComp.WAVE_SPAWN_X_INTERVAL; const landingY = BoxSet.GAME_LINE + (isBoss ? 6 : 0); - const dropOffset = MissionMonCompComp.MON_DROP_HEIGHT + Math.floor(Math.random() * 40); - let pos: Vec3 = v3(MonStart.START_X, landingY + dropOffset, 0); + let pos: Vec3 = v3(spawnX, landingY, 0); + this.waveSpawnOrder += 1; // 递增全局生成顺序,做溢出保护 this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999;