refactor(战斗): 重构英雄与怪物属性系统,简化数据结构

- 移除 HeroSkillsComp 组件,将技能逻辑合并到 HeroAttrsComp
- 将属性从 Attrs 枚举映射改为 HeroAttrsComp 中的独立字段
- 为 HeroAttrsComp 添加攻击和技能冷却时间管理功能
- 统一英雄和怪物的属性初始化方式,简化配置数据
- 在 GameSet 中添加击退概率配置项
- 修复 SkillView 中属性名大小写错误
This commit is contained in:
walkpan
2026-03-11 23:13:21 +08:00
parent 9d6075be6e
commit a544f65d73
9 changed files with 85 additions and 202 deletions

View File

@@ -4,11 +4,10 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { smc } from "../common/SingletonModuleComp";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp";
import { BoxSet, FacSet, IndexSet } from "../common/config/GameSet";
import { BoxSet, FacSet, FightSet, IndexSet } from "../common/config/GameSet";
import { HeroInfo, HeroPos, HType } from "../common/config/heroSet";
import { GameEvent } from "../common/config/GameEvent";
import { getNeAttrs, getAttrs ,Attrs, defaultAttrs} from "../common/config/HeroAttrs";
import { HeroSkillsComp } from "./HeroSkills";
import { Attrs} from "../common/config/HeroAttrs";
import { HeroMoveComp } from "./HeroMove";
import { mLogger } from "../common/Logger";
import { HeroMasterComp } from "./HeroMasterComp";
@@ -17,7 +16,6 @@ import { HeroMasterComp } from "./HeroMasterComp";
export class Hero extends ecs.Entity {
HeroModel!: HeroAttrsComp;
HeroSkills!: HeroSkillsComp;
View!: HeroViewComp;
HeroMove!: HeroMoveComp;
debugMode: boolean = false; // 是否启用调试模式
@@ -25,7 +23,6 @@ export class Hero extends ecs.Entity {
this.addComponents<ecs.Comp>(
HeroMoveComp,
HeroAttrsComp,
HeroSkillsComp,
);
}
@@ -38,7 +35,6 @@ export class Hero extends ecs.Entity {
this.remove(HeroViewComp);
this.remove(HeroAttrsComp);
this.remove(HeroSkillsComp);
this.remove(HeroMasterComp)
super.destroy();
}
@@ -65,7 +61,6 @@ export class Hero extends ecs.Entity {
var hv = node.getComponent(HeroViewComp)!;
const model = this.get(HeroAttrsComp);
const skillsComp = this.get(HeroSkillsComp);
let hero = HeroInfo[uuid]; // 共用英雄数据
// 设置 View 层属性(表现相关)
@@ -84,29 +79,22 @@ export class Hero extends ecs.Entity {
// 只有主角才挂载天赋组件
// ✅ 初始化技能数据(迁移到 HeroSkillsComp
skillsComp.initSkills(hero.skills, uuid);
// 设置基础属性
model.base_ap = hero.ap;
model.base_def = hero.def;
model.base_hp = hero.hp;
model.base_mp = hero.mp;
model.base_speed = hero.speed;
// 初始化属性数组
model.Attrs = getAttrs(); // 属性
model.NeAttrs = getNeAttrs(); //负面属性
model.hp = model.Attrs[Attrs.HP_MAX] = model.base_hp;
model.mp = model.Attrs[Attrs.MP_MAX] = model.base_mp;
model.Attrs[Attrs.DEF] = model.base_def;
model.Attrs[Attrs.AP] = model.base_ap;
model.Attrs[Attrs.SPEED] = hero.speed;
model.ap = hero.ap;
model.hp= model.hp_max = hero.hp;
model.speed = hero.speed;
model.a_cd_max=hero.as
model.s_cd_max=hero.ss
// 初始化技能信息数组
if(hero.skills[0]) model.atk_id=hero.skills[0]
if(hero.skills[1]) {
model.skill_id=hero.skills[1]
}
// 初始化 buff/debuff 系统
model.initAttrs();
model.Attrs[Attrs.REVIVE_COUNT]=1 // 复活次数
model.Attrs[Attrs.BACK_CHANCE]=defaultAttrs[Attrs.BACK_CHANCE]
model.Attrs[Attrs.CON_RES]=defaultAttrs[Attrs.CON_RES] // 控制抗性
model.back_chance=FightSet.BACK_CHANCE
this.add(hv);
oops.message.dispatchEvent(GameEvent.MasterCalled,{uuid:uuid})
const move = this.get(HeroMoveComp);