feat: 添加卡牌使用组件并集成至卡牌系统

- 新增 CardUseComp 组件,用于处理卡牌使用逻辑和效果分发
- 在 CardComp 中集成 CardUseComp,卡牌使用时触发效果事件
- 修改 MissionCardComp,任务开始时自动发牌至槽位
- 更新预制体资源,修复卡牌 UI 节点引用
This commit is contained in:
walkpan
2026-03-14 13:07:26 +08:00
parent 4530f9e219
commit 2f1af99a1b
6 changed files with 408 additions and 291 deletions

View File

@@ -3,6 +3,7 @@ import { _decorator, EventTouch, Label, Node, NodeEventType, Sprite, SpriteAtlas
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { CardConfig, CardType } from "../common/config/CardSet";
import { CardUseComp } from "./CardUseComp";
@@ -44,12 +45,14 @@ export class CardComp extends CCComp {
private isUsing: boolean = false;
private restPosition: Vec3 = new Vec3();
private opacityComp: UIOpacity | null = null;
private cardUseComp: CardUseComp | null = null;
onLoad() {
/** 初始阶段只做UI状态准备不触发业务逻辑 */
this.bindEvents();
this.restPosition = this.node.position.clone();
this.opacityComp = this.node.getComponent(UIOpacity) || this.node.addComponent(UIOpacity);
this.cardUseComp = this.resolveCardUseComp();
this.opacityComp.opacity = 255;
this.updateLockUI();
this.applyEmptyUI();
@@ -127,7 +130,6 @@ export class CardComp extends CCComp {
return true;
}
/** 使用当前卡牌仅做UI层清空不触发效果事件下一步再接 */
useCard(): CardConfig | null {
if (!this.cardData || this.isUsing) return null;
this.isUsing = true;
@@ -137,12 +139,13 @@ export class CardComp extends CCComp {
type: used.type
});
this.playUseDisappearAnim(() => {
this.cardUseComp?.onCardUsed(used);
this.clearAfterUse();
this.isUsing = false;
});
return used;
}
/** 查询槽位是否有卡 */
hasCard(): boolean {
return !!this.cardData;
@@ -349,6 +352,17 @@ export class CardComp extends CCComp {
if (label) label.string = value;
}
private resolveCardUseComp(): CardUseComp | null {
let current: Node | null = this.node.parent;
while (current) {
const comp = current.getComponent(CardUseComp);
if (comp) return comp;
current = current.parent;
}
mLogger.log(this.debugMode, "CardComp", "CardUseComp not found for", this.node.name);
return null;
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();