refactor(CHeroComp): 简化英雄卡牌渲染与逻辑处理
移除了SpecialUpgrade卡牌的特殊渲染逻辑,统一使用卡牌uuid进行渲染; 重构了等级标签显示逻辑,仅保留英雄卡局外等级展示; 合并了卡牌使用校验与事件派发逻辑,移除了无用的卡牌类型分支判断。
This commit is contained in:
@@ -19,7 +19,7 @@ import { mLogger } from "../common/Logger";
|
|||||||
import { _decorator, Node, Sprite, Label, RichText, NodeEventType, Vec3, Tween, tween, UIOpacity, SpriteFrame, resources, AnimationClip } from "cc";
|
import { _decorator, Node, Sprite, Label, RichText, NodeEventType, Vec3, Tween, tween, UIOpacity, SpriteFrame, resources, AnimationClip } from "cc";
|
||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
import { CardConfig, CardType } from "../common/config/CardSet";
|
import { CardConfig } from "../common/config/CardSet";
|
||||||
import { HeroInfo } from "../common/config/heroSet";
|
import { HeroInfo } from "../common/config/heroSet";
|
||||||
import { buildSkillDescMoreRich, ISkillDescSource } from "../common/config/HeroSkillDesc";
|
import { buildSkillDescMoreRich, ISkillDescSource } from "../common/config/HeroSkillDesc";
|
||||||
import { oops } from "db://oops-framework/core/Oops";
|
import { oops } from "db://oops-framework/core/Oops";
|
||||||
@@ -238,19 +238,12 @@ export class CHeroComp extends CCComp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态升级卡(SpecialUpgrade + target_hero_eid)按英雄卡样式渲染:
|
const renderUuid = this.cardData.uuid;
|
||||||
// 通过 eid 反查场上实体得到 hero_uuid;实体不存在时降级为本卡 uuid
|
|
||||||
const isUpgradeCard = this.cardData.type === CardType.SpecialUpgrade && !!this.cardData.target_hero_eid;
|
|
||||||
const renderUuid = isUpgradeCard
|
|
||||||
? (this.queryHeroUuidByEid(this.cardData.target_hero_eid as number) ?? this.cardData.uuid)
|
|
||||||
: this.cardData.uuid;
|
|
||||||
const hero = HeroInfo[renderUuid];
|
const hero = HeroInfo[renderUuid];
|
||||||
|
|
||||||
mLogger.log(this.debugMode, "CHeroComp", "updateUI resolve", {
|
mLogger.log(this.debugMode, "CHeroComp", "updateUI resolve", {
|
||||||
nodeName: this.node?.name,
|
nodeName: this.node?.name,
|
||||||
uuid: this.cardData.uuid,
|
uuid: this.cardData.uuid,
|
||||||
type: this.cardData.type,
|
|
||||||
isUpgradeCard,
|
|
||||||
renderUuid,
|
renderUuid,
|
||||||
heroFound: !!hero,
|
heroFound: !!hero,
|
||||||
heroName: hero?.name ?? null,
|
heroName: hero?.name ?? null,
|
||||||
@@ -272,18 +265,10 @@ export class CHeroComp extends CCComp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等级标签(★ 表示卡牌等级;升级卡显示英雄目标等级;普通英雄卡显示局外等级)
|
// 等级标签:英雄卡显示局外等级(Lv.N)
|
||||||
if (this.level_label) {
|
if (this.level_label) {
|
||||||
if (isUpgradeCard) {
|
const heroLv = smc.getHeroOuterLv(this.cardData.uuid);
|
||||||
const heroLv = Math.max(1, this.cardData.hero_lv ?? 1);
|
this.level_label.string = heroLv > 1 ? `Lv.${heroLv}` : "";
|
||||||
this.level_label.string = heroLv > 1 ? `Lv.${heroLv - 1} -> Lv.${heroLv}` : `Lv.${heroLv}`;
|
|
||||||
} else if (this.cardData.type === CardType.Hero) {
|
|
||||||
const heroLv = smc.getHeroOuterLv(this.cardData.uuid);
|
|
||||||
this.level_label.string = heroLv > 1 ? `Lv.${heroLv}` : "";
|
|
||||||
} else {
|
|
||||||
const lv = this.cardData.card_lv ?? 1;
|
|
||||||
this.level_label.string = lv >= 2 ? "★".repeat(lv - 1) : "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 背景:按 card_lv 激活对应颜色子节点(1→green 2→blue 3→purple 4→red 5→yellow)
|
// 背景:按 card_lv 激活对应颜色子节点(1→green 2→blue 3→purple 4→red 5→yellow)
|
||||||
@@ -580,32 +565,22 @@ export class CHeroComp extends CCComp {
|
|||||||
oops.audio.playEffect("music/button");
|
oops.audio.playEffect("music/button");
|
||||||
|
|
||||||
// 英雄卡数量上限校验:guard 模式,MissionCardComp 可设 cancel=true 阻止使用
|
// 英雄卡数量上限校验:guard 模式,MissionCardComp 可设 cancel=true 阻止使用
|
||||||
if (this.cardData.type === CardType.Hero) {
|
const guard = {
|
||||||
const guard = {
|
cancel: false,
|
||||||
cancel: false,
|
reason: "",
|
||||||
reason: "",
|
uuid: this.cardData.uuid,
|
||||||
uuid: this.cardData.uuid,
|
hero_lv: smc.getHeroOuterLv(this.cardData.uuid),
|
||||||
hero_lv: smc.getHeroOuterLv(this.cardData.uuid),
|
card_lv: this.cardData.base_card_lv ?? this.cardData.card_lv ?? 1
|
||||||
card_lv: this.cardData.base_card_lv ?? this.cardData.card_lv ?? 1
|
};
|
||||||
};
|
oops.message.dispatchEvent(GameEvent.UseHeroCard, guard);
|
||||||
oops.message.dispatchEvent(GameEvent.UseHeroCard, guard);
|
if (guard.cancel) return;
|
||||||
if (guard.cancel) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
smc.vmdata.scores.refresh_hit_count++;
|
smc.vmdata.scores.refresh_hit_count++;
|
||||||
|
|
||||||
const used = this.cardData;
|
const used = this.cardData;
|
||||||
|
|
||||||
// 按卡牌类型分发效果事件
|
// 派发英雄召唤事件
|
||||||
switch (used.type) {
|
oops.message.dispatchEvent(GameEvent.CallHero, used);
|
||||||
case CardType.Hero:
|
|
||||||
oops.message.dispatchEvent(GameEvent.CallHero, used);
|
|
||||||
break;
|
|
||||||
case CardType.SpecialUpgrade:
|
|
||||||
case CardType.SpecialRefresh:
|
|
||||||
oops.message.dispatchEvent(GameEvent.UseSpecialCard, used);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 播放购买动画(缩小淡出),刷新卡池由 CardUsed 事件触发
|
// 播放购买动画(缩小淡出),刷新卡池由 CardUsed 事件触发
|
||||||
this.playPurchaseAnim();
|
this.playPurchaseAnim();
|
||||||
|
|||||||
Reference in New Issue
Block a user