refactor(hero&mission): 调整英雄站位逻辑与配置
1. 修改游戏地平线Y轴偏移至100,适配新的UI布局 2. 为英雄属性组件添加分路与排位字段并初始化 3. 重构英雄站位分配逻辑,使用新增字段记录英雄位置 4. 更新地图与UI预制体的布局偏移适配新的游戏地平线
This commit is contained in:
@@ -59,7 +59,7 @@ export class MissionHeroCompComp extends CCComp {
|
||||
/** 远程(含中程)英雄起始出生 X 坐标 */
|
||||
private static readonly HERO_SPAWN_START_RANGED_X = -320
|
||||
/** 三路高度偏移(上路, 中路, 下路) */
|
||||
private static readonly HERO_LANE_Y_OFFSETS = [100, 0, -100]
|
||||
private static readonly HERO_LANE_Y_OFFSETS = [ BoxSet.GAME_LINE+90, BoxSet.GAME_LINE, BoxSet.GAME_LINE-90]
|
||||
/** 每路前排容量 */
|
||||
private static readonly HERO_LANE_CAP = 2
|
||||
/** 同路内 X 间距 */
|
||||
@@ -131,6 +131,8 @@ export class MissionHeroCompComp extends CCComp {
|
||||
if (model.is_dead) {
|
||||
view.alive();
|
||||
const { lane, indexInLane } = this.pickLaneForHero(model.hero_uuid, [hero.eid]);
|
||||
model.lane = lane;
|
||||
model.lane_index = indexInLane;
|
||||
const landingPos = this.resolveHeroLandingPos(model.hero_uuid, lane, indexInLane);
|
||||
// 不再直接设置位置,而是播放下落入场动画
|
||||
// 计算出出生点(空中)
|
||||
@@ -168,6 +170,7 @@ export class MissionHeroCompComp extends CCComp {
|
||||
|
||||
/**
|
||||
* 动态分配英雄上场的路和排位(优先中路 -> 上路 -> 下路)
|
||||
* 标记英雄的6个登录点
|
||||
* @param uuid 英雄 UUID
|
||||
* @param excludeEids 排除计算的实体ID数组(避免复活或合成时把自己算成占据的位置)
|
||||
*/
|
||||
@@ -177,40 +180,32 @@ export class MissionHeroCompComp extends CCComp {
|
||||
return m && !m.is_dead && !excludeEids.includes(h.eid);
|
||||
});
|
||||
|
||||
const counts = [0, 0, 0];
|
||||
const baseY = HeroPos[0].pos.y;
|
||||
// 记录6个位置点的占用情况 [lane][indexInLane]
|
||||
const occupied = [
|
||||
[false, false], // 上路 0
|
||||
[false, false], // 中路 1
|
||||
[false, false] // 下路 2
|
||||
];
|
||||
|
||||
for (const h of heroes) {
|
||||
const view = h.get(HeroViewComp);
|
||||
if (!view || !view.node) continue;
|
||||
|
||||
let y = view.node.position.y;
|
||||
// 处理正在掉落状态的英雄(y 值偏高)
|
||||
if (y > baseY + 150) {
|
||||
y -= MissionHeroCompComp.HERO_DROP_HEIGHT;
|
||||
const m = h.get(HeroAttrsComp);
|
||||
if (m && m.lane >= 0 && m.lane <= 2 && m.lane_index >= 0 && m.lane_index <= 1) {
|
||||
occupied[m.lane][m.lane_index] = true;
|
||||
}
|
||||
|
||||
let nearest = 1, best = Infinity;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const d = Math.abs(y - (baseY + MissionHeroCompComp.HERO_LANE_Y_OFFSETS[i]));
|
||||
if (d < best) {
|
||||
best = d;
|
||||
nearest = i;
|
||||
}
|
||||
}
|
||||
counts[nearest]++;
|
||||
}
|
||||
|
||||
// 优先中路(1) -> 上路(0) -> 下路(2)
|
||||
const priority = [1, 0, 2];
|
||||
for (const lane of priority) {
|
||||
if (counts[lane] < MissionHeroCompComp.HERO_LANE_CAP) {
|
||||
return { lane, indexInLane: counts[lane] };
|
||||
for (let indexInLane = 0; indexInLane < MissionHeroCompComp.HERO_LANE_CAP; indexInLane++) {
|
||||
if (!occupied[lane][indexInLane]) {
|
||||
return { lane, indexInLane };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 溢出:仍放中路,沿 X 继续排
|
||||
return { lane: 1, indexInLane: counts[1] };
|
||||
return { lane: 1, indexInLane: 2 };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,6 +230,8 @@ export class MissionHeroCompComp extends CCComp {
|
||||
// 召唤完成后,派发事件以更新英雄面板
|
||||
const model = hero.get(HeroAttrsComp);
|
||||
if (model) {
|
||||
model.lane = lane;
|
||||
model.lane_index = indexInLane;
|
||||
oops.message.dispatchEvent(GameEvent.MasterCalled, {
|
||||
eid: hero.eid,
|
||||
model: model
|
||||
@@ -305,6 +302,8 @@ export class MissionHeroCompComp extends CCComp {
|
||||
// 召唤完成后,派发事件以更新英雄面板
|
||||
const model = hero.get(HeroAttrsComp);
|
||||
if (model) {
|
||||
model.lane = lane;
|
||||
model.lane_index = indexInLane;
|
||||
model.ap = Math.max(0, ap);
|
||||
model.hp_max = Math.max(1, hp_max);
|
||||
model.hp = model.hp_max;
|
||||
|
||||
Reference in New Issue
Block a user