refactor(hero): 优化技能初始化逻辑并添加技能卡选择功能
- 移除initSkills和addSkill方法中多余的entity参数,改为使用组件内ent属性 - 在HeroSkillsComp中添加技能卡选择事件监听和处理 - 在MissionCardComp中实现技能卡选择界面和事件分发
This commit is contained in:
@@ -93,7 +93,7 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
// ✅ 初始化技能数据(迁移到 HeroSkillsComp)
|
||||
skillsComp.initSkills(hero.skills, uuid, this);
|
||||
skillsComp.initSkills(hero.skills, uuid);
|
||||
|
||||
// 设置基础属性
|
||||
model.base_ap = hero.ap;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { HSSet, SkillSet } from "../common/config/SkillSet";
|
||||
@@ -42,6 +44,23 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
/** AI 检测计时器 */
|
||||
ai_timer: number = 0;
|
||||
|
||||
onLoad() {
|
||||
oops.message.on(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
}
|
||||
|
||||
private onUseSkillCard(event: string, args: any) {
|
||||
const attrsComp = this.ent.get(HeroAttrsComp);
|
||||
if (!attrsComp || !attrsComp.is_master) return;
|
||||
|
||||
const s_uuid = args as number;
|
||||
console.log(`[HeroSkills] 收到技能选择事件,添加技能 ID: ${s_uuid}`);
|
||||
this.addSkill(s_uuid,HSSet.max);
|
||||
}
|
||||
|
||||
// ==================== 辅助方法 ====================
|
||||
|
||||
/**
|
||||
@@ -50,7 +69,7 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
* @param uuid 英雄UUID
|
||||
* @param entity 实体对象(用于更新技能距离缓存)
|
||||
*/
|
||||
initSkills(sUuids: number[], uuid: number, entity?: ecs.Entity) {
|
||||
initSkills(sUuids: number[], uuid: number) {
|
||||
this.skills = [];
|
||||
for (let i = 0; i < sUuids.length; i++) {
|
||||
const s_uuid = sUuids[i];
|
||||
@@ -75,8 +94,8 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
}
|
||||
|
||||
// 更新技能距离缓存
|
||||
if (entity) {
|
||||
const attrsComp = entity.get(HeroAttrsComp);
|
||||
if (this.ent) {
|
||||
const attrsComp = this.ent.get(HeroAttrsComp);
|
||||
if (attrsComp) {
|
||||
attrsComp.updateSkillDistanceCache(this);
|
||||
}
|
||||
@@ -86,9 +105,9 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
/**
|
||||
* 添加单个技能
|
||||
* @param s_uuid 技能配置ID
|
||||
* @param entity 实体对象(用于更新技能距离缓存)
|
||||
* @param hset 技能类型
|
||||
*/
|
||||
addSkill(s_uuid: number, entity?: ecs.Entity, hset: HSSet=HSSet.skill) {
|
||||
addSkill(s_uuid: number, hset: HSSet=HSSet.skill) {
|
||||
const config = SkillSet[s_uuid];
|
||||
if (!config) {
|
||||
console.warn(`[HeroSkills] 技能配置不存在: ${s_uuid}`);
|
||||
@@ -104,8 +123,8 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
};
|
||||
|
||||
// 更新技能距离缓存
|
||||
if (entity) {
|
||||
const attrsComp = entity.get(HeroAttrsComp);
|
||||
if (this.ent) {
|
||||
const attrsComp = this.ent.get(HeroAttrsComp);
|
||||
if (attrsComp) {
|
||||
attrsComp.updateSkillDistanceCache(this);
|
||||
}
|
||||
@@ -261,6 +280,7 @@ export class HeroSkillsComp extends ecs.Comp {
|
||||
}
|
||||
|
||||
reset() {
|
||||
oops.message.off(GameEvent.UseSkillCard, this.onUseSkillCard, this);
|
||||
this.skills = {};
|
||||
}
|
||||
setMaxAuto(on: boolean) {
|
||||
|
||||
@@ -130,7 +130,7 @@ export class Monster extends ecs.Entity {
|
||||
model.Attrs[Attrs.BACK_CHANCE]=15
|
||||
model.Attrs[Attrs.CON_RES]=10
|
||||
// ✅ 初始化技能数据(迁移到 HeroSkillsComp)
|
||||
skillsComp.initSkills(hero.skills, uuid, this);
|
||||
skillsComp.initSkills(hero.skills, uuid);
|
||||
|
||||
this.add(view);
|
||||
// 重置视图状态(对象池复用时必须)
|
||||
|
||||
Reference in New Issue
Block a user