refactor(hero): 优化技能初始化逻辑并添加技能卡选择功能
- 移除initSkills和addSkill方法中多余的entity参数,改为使用组件内ent属性 - 在HeroSkillsComp中添加技能卡选择事件监听和处理 - 在MissionCardComp中实现技能卡选择界面和事件分发
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user