refactor(map): 重构怪物生成位置逻辑以改善分布
- 移除未使用的 MonStart 导入 - 将 spawnCount 重命名为 waveSpawnOrder 以更准确反映其用途 - 使用固定的横向间隔(WAVE_SPAWN_X_INTERVAL)和起始位置(WAVE_SPAWN_START_X)替代随机高度偏移 - 简化 addMonster 方法签名,移除冗余的 i 参数 - 确保每波开始时重置 waveSpawnOrder 计数器
This commit is contained in:
@@ -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>(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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user