From 45508abca46f2de66c9e61b9b61c87ce9899c372 Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 5 Jan 2026 14:45:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E4=BC=98=E5=8C=96=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=80=E8=83=BD=E5=8D=A1=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除initSkills和addSkill方法中多余的entity参数,改为使用组件内ent属性 - 在HeroSkillsComp中添加技能卡选择事件监听和处理 - 在MissionCardComp中实现技能卡选择界面和事件分发 --- assets/script/game/hero/Hero.ts | 2 +- assets/script/game/hero/HeroSkills.ts | 34 ++++++++++++++++++----- assets/script/game/hero/Mon.ts | 2 +- assets/script/game/map/MissionCardComp.ts | 29 +++++++++++++++++-- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index 96a4546f..6995003b 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -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; diff --git a/assets/script/game/hero/HeroSkills.ts b/assets/script/game/hero/HeroSkills.ts index db4f1826..0b40ef75 100644 --- a/assets/script/game/hero/HeroSkills.ts +++ b/assets/script/game/hero/HeroSkills.ts @@ -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) { diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index 03ecf725..4f9f9374 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -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); // 重置视图状态(对象池复用时必须) diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index f524d134..bdfbe42e 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -4,6 +4,7 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { GameEvent } from "../common/config/GameEvent"; import { talConf, ItalConf } from "../common/config/TalSet"; +import { SkillSet } from "../common/config/SkillSet"; import { ItemSet } from "../common/config/ItemSet"; import { smc } from "../common/SingletonModuleComp"; @@ -48,6 +49,7 @@ export class MissionCardComp extends CCComp { onLoad() { oops.message.on(GameEvent.TalentSelect, this.onTalentSelect, this); + oops.message.on(GameEvent.HeroSkillSelect, this.onHeroSkillSelect, this); oops.message.on(GameEvent.ShopOpen, this.onShopOpen, this); oops.message.on(GameEvent.MissionStart, this.init, this); @@ -55,6 +57,7 @@ export class MissionCardComp extends CCComp { onDestroy() { oops.message.off(GameEvent.TalentSelect, this.onTalentSelect, this); + oops.message.off(GameEvent.HeroSkillSelect, this.onHeroSkillSelect, this); oops.message.off(GameEvent.ShopOpen, this.onShopOpen, this); this.ent.destroy(); } @@ -104,6 +107,15 @@ export class MissionCardComp extends CCComp { this.playShowAnimation(); } + private onHeroSkillSelect(event: string, args: any) { + this.node.active = true; + this.hasSelected = false; + this.curCardType = CardType.Skill; + this.resetCardStates(); + this.refCards(); + this.playShowAnimation(); + } + private playShowAnimation() { const cards = [this.card1, this.card2, this.card3, this.card4]; cards.forEach((card, index) => { @@ -123,7 +135,10 @@ export class MissionCardComp extends CCComp { if (this.curCardType === CardType.Talent) { allData = Object.values(talConf); - } + } else if (this.curCardType === CardType.Skill) { + // 过滤掉怪物技能 (uuid >= 6200) + allData = Object.values(SkillSet).filter((s:any) => s.uuid < 6200); + } // 后续扩展其他类型 // else if (this.curCardType === CardType.Skill) { ... } @@ -158,7 +173,15 @@ export class MissionCardComp extends CCComp { let info = card.getChildByName("info")?.getChildByName("Label") if(info){ // 根据类型显示不同描述,目前天赋用desc - let desc = data.desc || ""; + let desc = ""; + if (this.curCardType === CardType.Talent) { + desc = data.desc || ""; + } else if (this.curCardType === CardType.Skill) { + desc = data.info || ""; + } else { + desc = data.desc || ""; + } + // 如果是物品,显示价格 if (this.curCardType === CardType.Potion && data.price) { desc += `\n价格: ${data.price}`; @@ -286,6 +309,8 @@ export class MissionCardComp extends CCComp { // 根据类型发送不同事件 if (this.curCardType === CardType.Talent) { oops.message.dispatchEvent(GameEvent.UseTalentCard, selectedData.uuid); + } else if (this.curCardType === CardType.Skill) { + oops.message.dispatchEvent(GameEvent.UseSkillCard, selectedData.uuid); } // 后续扩展其他类型事件 this.node.active = false;