refactor(monster): 重构怪物分层显示与战斗逻辑

1.  重构怪物挂载逻辑,按Boss/小怪分别挂载到对应场景层
2.  调整怪物出生落点逻辑,移除额外Y轴偏移
3.  优化场景节点清理范围,新增MON/BOSS层清理
4.  重构渲染排序逻辑,分层管理怪物渲染层级
5.  新增5套攻击技能预制体与动画资源
6.  修复技能配置参数冗余注释与类型错误
This commit is contained in:
panFD
2026-08-13 23:05:51 +08:00
parent d54e6ce1d6
commit 9579c4f75e
26 changed files with 2639 additions and 253 deletions

View File

@@ -1,4 +1,4 @@
// ========== 从 HeroAttrs.ts 导入属性相关定义 ==========
// ========== 从 HeroAttrs.ts 导入属性相关定义 ==========
import { Attrs } from "./HeroAttrs";
export enum HSSet {
@@ -134,7 +134,6 @@ export interface SkillConfig {
gold?: number, // 获取金币技能的金币值
hit_count: number, // 可命中次数
hitcd: number, // 持续伤害的伤害间隔(秒)
/** @deprecated 已下沉到 SkillView @propertyprefab 配置),此处仅作兜底 */
speed: number, // 移动速度
with: number, // 宽度(暂时无用)
ready: number, // 前摇时间
@@ -143,14 +142,11 @@ export interface SkillConfig {
EAnm: number, // 结束动画ID
DAnm: string, // 命中后动画ID
IType: IType, // 技能类型(近战/远程/辅助)
/** @deprecated 已下沉到 SkillView @propertyprefab 配置),此处仅作兜底 */
RType: RType, // 技能运行类型(直线/贝塞尔/固定起点/固定终点)
/** @deprecated 已下沉到 SkillView @propertyprefab 配置),此处仅作兜底 */
EType: EType, // 结束条件(动画结束/时间结束/距离结束/碰撞/次数结束)
bezier_start_y?: number, // 贝塞尔起始抬升高度
bezier_mid_y?: number, // 贝塞尔中间高度增量
bezier_arc?: number, // 贝塞尔弧度系数
/** @deprecated 已下沉到 SkillView @propertyprefab 配置),此处仅作兜底 */
time?: number, // timeEnd 持续时间(秒)
kind?: SkillKind, // 主效果类型
crt?: number, // 额外暴击率
@@ -222,22 +218,22 @@ export const SkillSet: Record<number, SkillConfig> = {
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
},
6002: {
6002: {
uuid: 6002, name: "飞刀", sp_name: "a2", icon: "Sword-FA_WP_Main_Sword_009_GraySilver", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
},
6003: {
6003: {
uuid: 6003, name: "匕首", sp_name: "a3", icon: "Sword-FA_WP_Main_Sword_019_WoodSilver", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
},
6004: {
6004: {
uuid: 6004, name: "飞斧", sp_name: "a4", icon: "Axe-FA_WP_Main_Axe_004_WoodGray", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
},
6005: {
6005: {
uuid: 6005, name: "飞枪", sp_name: "a5", icon: "Spear-FA_WP_Main_Spear_010_MetalBlue", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
@@ -245,7 +241,7 @@ export const SkillSet: Record<number, SkillConfig> = {
6006: {
uuid: 6006, name: "攻击", sp_name: "atk", icon: "Stat_Attack_01", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",
DTType: DTType.single, ap: 100, hit_count: 1, hitcd: 0.2, speed: 720, with: 0, ready: 0.2, EAnm: 0, DAnm: "", IType: IType.Melee, is_accel: true,
RType: RType.fixed, EType: EType.collision, info: "造成攻击力100%的伤害",
RType: RType.bezier, EType: EType.collision, info: "造成攻击力100%的伤害",
},
6007: {
uuid: 6007, name: "飞棒", sp_name: "b1", icon: "Blunt-FA_WP_Main_Blunt_002_Wood", TGroup: TGroup.Enemy, readyAnm: "", endAnm: "", act: "atk",

View File

@@ -148,8 +148,9 @@ export class Monster extends ecs.Entity {
(node as any)._baseScale = node.scale.clone();
}
// 统一挂到实体显示层 HERO 节点下
node.parent = scene.entityLayer!.node!.getChildByName("HERO")!;
// 按身份挂载显示层Boss → BOSS 层(最底),小怪 → MON 层(编辑器已配置好层级顺序)
const layerName = is_boss ? "BOSS" : "MON";
node.parent = scene.entityLayer!.node!.getChildByName(layerName)!;
var view = node.getComponent(HeroViewComp)!;
const collider = node.getComponent(BoxCollider2D);
// 入场期间关闭碰撞,防止下落时提前参与战斗

View File

@@ -145,7 +145,9 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const enemyX = enemy.node.position.x;
const dist = Math.abs(selfX - enemyX);
const attackRange = model.dis;
const inRange = dist <= attackRange;
/** 近战贴身作战:攻击距离 dis(100) 大于技能范围(60),推进到与敌人相隔 60 才停下,保证技能可命中且不过度贴身 */
const stopRange = model.type === 0 ? 60 : attackRange;
const inRange = dist <= stopRange;
if (inRange) {
/** 进入攻击范围:停止移动,进入攻击状态,由 SCastSystem 负责技能释放 */
@@ -216,13 +218,19 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
private updateRenderOrder() {
const scene = smc.map?.MapView?.scene;
const actorRoot = scene?.entityLayer?.node?.getChildByName("HERO");
if (!actorRoot) return;
const layerNode = scene?.entityLayer?.node;
if (!layerNode) return;
const now = Date.now() / 1000;
if (now - this.lastRenderSortAt < this.renderSortInterval) return;
this.lastRenderSortAt = now;
const heroRoot = layerNode.getChildByName("HERO");
const monRoot = layerNode.getChildByName("MON");
const bossRoot = layerNode.getChildByName("BOSS");
/** 分层重排同层节点:各阵营层内按 Y 轴路次 -> 前后位置 -> 出生序 -> eid 排序
* Boss 已有独立 BOSS 层固定在最底,无需 bossPriority 参与排序) */
this.renderEntryCount = 0;
ecs.query(this.getHeroViewMatcher()).forEach(e => {
const attrs = e.get(HeroAttrsComp);
@@ -230,8 +238,16 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (!attrs || !actorView?.node || attrs.is_dead) return;
if (attrs.fac !== FacSet.HERO && attrs.fac !== FacSet.MON) return;
if (actorView.node.parent !== actorRoot) {
actorView.node.parent = actorRoot;
/** 按阵营/身份归位到对应显示层 */
let targetRoot: Node | null | undefined;
if (attrs.fac === FacSet.HERO) {
targetRoot = heroRoot;
} else {
targetRoot = attrs.is_boss ? (bossRoot ?? monRoot ?? heroRoot) : (monRoot ?? heroRoot);
}
if (!targetRoot) return;
if (actorView.node.parent !== targetRoot) {
actorView.node.parent = targetRoot;
}
/** 统一从 MoveComp 获取 spawnOrder */
@@ -250,7 +266,6 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
this.renderEntries.push(entry);
}
entry.node = actorView.node;
entry.bossPriority = attrs.is_boss ? 1 : 0;
entry.laneScore = laneScore;
entry.frontScore = frontScore;
entry.spawnOrder = spawnOrder;
@@ -259,9 +274,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
});
this.renderEntries.length = this.renderEntryCount;
/** 定时重排同层节点Boss 优先级 -> Y 轴路次 -> 前后位置 -> 出生序 -> eid */
this.renderEntries.sort((a, b) => {
if (a.bossPriority !== b.bossPriority) return a.bossPriority - b.bossPriority;
// Y轴靠下的laneScore 较大)应该在后面,从而渲染在上面
if (Math.abs(a.laneScore - b.laneScore) > 10) return a.laneScore - b.laneScore;
if (a.frontScore !== b.frontScore) return a.frontScore - b.frontScore;
@@ -269,8 +282,14 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
return a.eid - b.eid;
});
this.renderEntries.forEach((item, index) => {
/** 分层应用 siblingIndex各层内部从 0 递增 */
const layerCounters = new Map<Node, number>();
this.renderEntries.forEach((item) => {
const parent = item.node.parent;
if (!parent) return;
const index = layerCounters.get(parent) ?? 0;
item.node.setSiblingIndex(index);
layerCounters.set(parent, index + 1);
});
}
}

View File

@@ -1005,21 +1005,17 @@ export class MissionComp extends CCComp {
this.clearBattleSceneNodes();
}
/** 清理战斗场景中的 HERO 和 SKILL 根节点下的所有子节点 */
/** 清理战斗场景中的 HERO/MON/BOSS 和 SKILL 根节点下的所有子节点 */
private clearBattleSceneNodes() {
const scene = smc.map?.MapView?.scene;
const layer = scene?.entityLayer?.node;
if (!layer) return;
const heroRoot = layer.getChildByName("HERO");
const skillRoot = layer.getChildByName("SKILL");
if (heroRoot) {
for (let i = heroRoot.children.length - 1; i >= 0; i--) {
heroRoot.children[i].destroy();
}
}
if (skillRoot) {
for (let i = skillRoot.children.length - 1; i >= 0; i--) {
skillRoot.children[i].destroy();
for (const name of ["HERO", "MON", "BOSS", "SKILL"]) {
const root = layer.getChildByName(name);
if (root) {
for (let i = root.children.length - 1; i >= 0; i--) {
root.children[i].destroy();
}
}
}
}

View File

@@ -142,7 +142,7 @@ export class MissionMonCompComp extends CCComp {
const spawnX = MissionMonCompComp.SPAWN_X_MIN
+ (MissionMonCompComp.SPAWN_X_MAX - MissionMonCompComp.SPAWN_X_MIN)
* (posIndex / Math.max(1, BOSS_COUNT + MINION_COUNT - 1));
const landingY = basePos.y + (monData.isBoss ? 6 : 0);
const landingY = basePos.y;
const spawnPos: Vec3 = v3(spawnX, landingY + MissionMonCompComp.MON_DROP_HEIGHT, 0);
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999;