refactor(hero&mission): 调整英雄站位逻辑与配置

1.  修改游戏地平线Y轴偏移至100,适配新的UI布局
2.  为英雄属性组件添加分路与排位字段并初始化
3.  重构英雄站位分配逻辑,使用新增字段记录英雄位置
4.  更新地图与UI预制体的布局偏移适配新的游戏地平线
This commit is contained in:
walkpan
2026-05-13 00:15:38 +08:00
parent 518f15b1c3
commit 4305a4461e
7 changed files with 2204 additions and 2030 deletions

View File

@@ -11,7 +11,7 @@ export enum BoxSet {
LETF_END = -360,
RIGHT_END = 360,
//游戏地平线
GAME_LINE = 0,
GAME_LINE = 100,
}
export enum FacSet {

View File

@@ -63,6 +63,10 @@ export class HeroAttrsComp extends ecs.Comp {
maxSkillDistance: number = 0; // 最远技能攻击距离缓存受MP影响
minSkillDistance: number = 0; // 最近技能攻击距离缓存不受MP影响用于停止位置判断
// ==================== 阵型位置 ====================
lane: number = -1; // 所在分路0上路, 1中路, 2下路
lane_index: number = -1; // 所在路中的排位0前排, 1后排
// ==================== 标记状态 ====================
is_dead: boolean = false;
is_count_dead: boolean = false;
@@ -308,6 +312,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.maxSkillDistance = 0;
this.minSkillDistance = 0;
this.lane = -1;
this.lane_index = -1;
this.is_dead = false;
this.is_count_dead = false;
this.is_atking = false;

View File

@@ -255,6 +255,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const col = Math.floor(slotIndex / 3);
const laneIdx = lanePriority[slotIndex % 3];
// 动态更新英雄位置数据,为战斗面板排序提供依据
model.lane = laneIdx;
model.lane_index = col;
const targetY = BoxSet.GAME_LINE + laneOffsets[laneIdx];
const targetX = this.heroFrontAnchorX - col * this.heroAllySpacingX;

View File

@@ -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;