refactor(map): 简化英雄出生位置计算逻辑
移除英雄出生时的横向间隔和占位检测机制,改为直接使用起始X坐标。这消除了不必要的循环和位置冲突检查,使出生逻辑更简洁高效。
This commit is contained in:
@@ -10,7 +10,6 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||
import { FacSet } from "../common/config/GameSet";
|
||||
import { oneCom } from "../skill/oncend";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -19,14 +18,10 @@ const { ccclass } = _decorator;
|
||||
export class MissionHeroCompComp extends CCComp {
|
||||
/** 英雄出生时的掉落高度,用于表现从空中落地 */
|
||||
private static readonly HERO_DROP_HEIGHT = 260
|
||||
/** 出生点横向间隔 */
|
||||
private static readonly HERO_SPAWN_STEP_X = -60
|
||||
/** 近战起始出生 X */
|
||||
private static readonly HERO_SPAWN_START_MELEE_X = -280
|
||||
/** 远程(含中程)起始出生 X */
|
||||
private static readonly HERO_SPAWN_START_RANGED_X = -280
|
||||
/** 占位判断容差 */
|
||||
private static readonly HERO_SPAWN_OCCUPY_EPSILON_X = 10
|
||||
/** 预留计时器 */
|
||||
timer:Timer=new Timer(2)
|
||||
/** 预留状态:友方是否全部死亡 */
|
||||
@@ -109,16 +104,7 @@ export class MissionHeroCompComp extends CCComp {
|
||||
const hero_pos = 0;
|
||||
const baseY = HeroPos[hero_pos].pos.y;
|
||||
const startX = this.resolveSpawnStartX(uuid);
|
||||
let candidateX = startX;
|
||||
let guard = 0;
|
||||
while (guard < 50) {
|
||||
if (!this.isSpawnXOccupied(candidateX, baseY)) {
|
||||
break;
|
||||
}
|
||||
candidateX += MissionHeroCompComp.HERO_SPAWN_STEP_X;
|
||||
guard += 1;
|
||||
}
|
||||
return v3(candidateX, baseY, 0);
|
||||
return v3(startX, baseY, 0);
|
||||
}
|
||||
|
||||
private resolveSpawnStartX(uuid: number): number {
|
||||
@@ -128,21 +114,6 @@ export class MissionHeroCompComp extends CCComp {
|
||||
: MissionHeroCompComp.HERO_SPAWN_START_RANGED_X;
|
||||
}
|
||||
|
||||
private isSpawnXOccupied(targetX: number, baseY: number): boolean {
|
||||
const aliveHeroes = this.getAliveHeroes();
|
||||
for (let i = 0; i < aliveHeroes.length; i++) {
|
||||
const view = aliveHeroes[i].get(HeroViewComp);
|
||||
const node = view?.node;
|
||||
if (!node || !node.isValid) continue;
|
||||
const pos = node.getPosition();
|
||||
if (Math.abs(pos.y - baseY) > 80) continue;
|
||||
if (Math.abs(pos.x - targetX) <= MissionHeroCompComp.HERO_SPAWN_OCCUPY_EPSILON_X) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 添加合成后的新英雄,并覆盖为聚合后的属性 */
|
||||
private addMergedHero(uuid:number, hero_lv:number, ap:number, hp_max:number): number {
|
||||
const hero = this.addHero(uuid, hero_lv);
|
||||
|
||||
Reference in New Issue
Block a user