fix(game): 优化怪物生成槽位分配策略,移除无效状态

移除 nextAssignSlotIndex 状态变量,改为根据怪物类型动态计算槽位优先级。近战怪物优先分配前部槽位,其他类型优先分配后部槽位,以平衡各槽位负载。
This commit is contained in:
walkpan
2026-03-31 22:50:16 +08:00
parent 8c259bc674
commit 330ceca71a

View File

@@ -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 { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Monster } from "../hero/Mon"; import { Monster } from "../hero/Mon";
import { HeroInfo } from "../common/config/heroSet"; import { HeroInfo, HType } from "../common/config/heroSet";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { GameEvent } from "../common/config/GameEvent"; import { GameEvent } from "../common/config/GameEvent";
import {BoxSet } from "../common/config/GameSet"; import {BoxSet } from "../common/config/GameSet";
@@ -47,7 +47,6 @@ export class MissionMonCompComp extends CCComp {
monLv: number, monLv: number,
}>> = []; }>> = [];
private slotOccupiedEids: Array<number | null> = []; private slotOccupiedEids: Array<number | null> = [];
private nextAssignSlotIndex: number = 0;
/** 全局生成顺序计数器,用于层级管理(预留) */ /** 全局生成顺序计数器,用于层级管理(预留) */
private globalSpawnOrder: number = 0; private globalSpawnOrder: number = 0;
/** 插队刷怪处理计时器 */ /** 插队刷怪处理计时器 */
@@ -149,7 +148,6 @@ export class MissionMonCompComp extends CCComp {
this.waveSpawnedCount = 0; this.waveSpawnedCount = 0;
this.bossSpawnedInWave = false; this.bossSpawnedInWave = false;
this.waveSpawnTimer = this.waveSpawnCd; this.waveSpawnTimer = this.waveSpawnCd;
this.nextAssignSlotIndex = 0;
this.primeWaveInitialBurst(); this.primeWaveInitialBurst();
oops.message.dispatchEvent(GameEvent.NewWave, { oops.message.dispatchEvent(GameEvent.NewWave, {
wave: this.currentWave, wave: this.currentWave,
@@ -233,7 +231,6 @@ export class MissionMonCompComp extends CCComp {
{ length: MissionMonCompComp.MON_SLOT_COUNT }, { length: MissionMonCompComp.MON_SLOT_COUNT },
() => null () => null
); );
this.nextAssignSlotIndex = 0;
} }
private hasPendingSlotQueue() { private hasPendingSlotQueue() {
@@ -271,18 +268,26 @@ export class MissionMonCompComp extends CCComp {
return occupied + this.slotSpawnQueues[slotIndex].length; return occupied + this.slotSpawnQueues[slotIndex].length;
} }
private pickAssignSlotIndex(): number { private resolveSlotPriorityIndexes(uuid: number): number[] {
const type = HeroInfo[uuid]?.type;
if (type === HType.Melee) {
return [0, 1, 2, 3, 4, 5];
}
return [5, 4, 3, 2, 1, 0];
}
private pickAssignSlotIndex(uuid: number): number {
const slotPriority = this.resolveSlotPriorityIndexes(uuid);
let bestLoad = Number.MAX_SAFE_INTEGER; let bestLoad = Number.MAX_SAFE_INTEGER;
let bestIndex = this.nextAssignSlotIndex % MissionMonCompComp.MON_SLOT_COUNT; let bestIndex = slotPriority[0] ?? 0;
for (let step = 0; step < MissionMonCompComp.MON_SLOT_COUNT; step++) { for (let i = 0; i < slotPriority.length; i++) {
const index = (this.nextAssignSlotIndex + step) % MissionMonCompComp.MON_SLOT_COUNT; const index = slotPriority[i];
const load = this.getSlotQueueLoad(index); const load = this.getSlotQueueLoad(index);
if (load < bestLoad) { if (load < bestLoad) {
bestLoad = load; bestLoad = load;
bestIndex = index; bestIndex = index;
} }
} }
this.nextAssignSlotIndex = (bestIndex + 1) % MissionMonCompComp.MON_SLOT_COUNT;
return bestIndex; return bestIndex;
} }
@@ -293,7 +298,7 @@ export class MissionMonCompComp extends CCComp {
monLv: number = 1, monLv: number = 1,
priority: boolean = false, priority: boolean = false,
) { ) {
const slotIndex = this.pickAssignSlotIndex(); const slotIndex = this.pickAssignSlotIndex(uuid);
const request = { uuid, isBoss, upType, monLv }; const request = { uuid, isBoss, upType, monLv };
if (priority) { if (priority) {
this.slotSpawnQueues[slotIndex].unshift(request); this.slotSpawnQueues[slotIndex].unshift(request);