feat: 添加卡牌使用组件并集成至卡牌系统
- 新增 CardUseComp 组件,用于处理卡牌使用逻辑和效果分发 - 在 CardComp 中集成 CardUseComp,卡牌使用时触发效果事件 - 修改 MissionCardComp,任务开始时自动发牌至槽位 - 更新预制体资源,修复卡牌 UI 节点引用
This commit is contained in:
@@ -3251,7 +3251,9 @@
|
||||
"__prefab": {
|
||||
"__id__": 141
|
||||
},
|
||||
"Lock": null,
|
||||
"Lock": {
|
||||
"__id__": 114
|
||||
},
|
||||
"unLock": null,
|
||||
"ap_node": {
|
||||
"__id__": 81
|
||||
@@ -3262,7 +3264,9 @@
|
||||
"name_node": {
|
||||
"__id__": 108
|
||||
},
|
||||
"icon_node": null,
|
||||
"icon_node": {
|
||||
"__id__": 57
|
||||
},
|
||||
"cost_node": {
|
||||
"__id__": 127
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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();
|
||||
|
||||
67
assets/script/game/map/CardUseComp.ts
Normal file
67
assets/script/game/map/CardUseComp.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { _decorator } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { CardType } from "../common/config/CardSet";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
interface CardUsePayload {
|
||||
uuid: number
|
||||
type: CardType
|
||||
cost: number
|
||||
slotName?: string
|
||||
}
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('CardUseComp')
|
||||
@ecs.register('CardUseComp', false)
|
||||
export class CardUseComp extends CCComp {
|
||||
private debugMode: boolean = true;
|
||||
private useCount: number = 0;
|
||||
|
||||
onLoad() {
|
||||
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
onCardUsed(payload: CardUsePayload) {
|
||||
this.useCount += 1;
|
||||
mLogger.log(this.debugMode, "CardUseComp", "onCardUsed", {
|
||||
useCount: this.useCount,
|
||||
...payload
|
||||
});
|
||||
this.executeCardEffectEntry(payload);
|
||||
}
|
||||
|
||||
private executeCardEffectEntry(payload: CardUsePayload) {
|
||||
const effectTag = this.getEffectEntryTag(payload.type);
|
||||
mLogger.log(this.debugMode, "CardUseComp", "executeCardEffectEntry", payload);
|
||||
mLogger.log(this.debugMode, "CardUseComp", "effect entry tag", effectTag);
|
||||
}
|
||||
|
||||
private getEffectEntryTag(type: CardType): string {
|
||||
switch (type) {
|
||||
case CardType.Hero:
|
||||
return "hero";
|
||||
case CardType.Skill:
|
||||
return "skill";
|
||||
case CardType.Special:
|
||||
return "special";
|
||||
case CardType.Buff:
|
||||
case CardType.Debuff:
|
||||
return "buff";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/map/CardUseComp.ts.meta
Normal file
9
assets/script/game/map/CardUseComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8edfc7ca-1cda-4725-9a0c-ded8f5f95531",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export class MissionCardComp extends CCComp {
|
||||
this.onMissionStart();
|
||||
}
|
||||
|
||||
/** 任务开始时:重置卡池等级、清空4槽、显示面板 */
|
||||
/** 任务开始时:重置卡池等级、清空4槽、显示面板 刷新一次卡池*/
|
||||
onMissionStart() {
|
||||
this.poolLv = CARD_POOL_INIT_LEVEL;
|
||||
this.layoutCardSlots();
|
||||
@@ -65,6 +65,8 @@ export class MissionCardComp extends CCComp {
|
||||
}
|
||||
this.updatePoolLvUI();
|
||||
this.node.active = true;
|
||||
const cards = this.buildDrawCards();
|
||||
this.dispatchCardsToSlots(cards);
|
||||
mLogger.log(this.debugMode, "MissionCardComp", "mission start", {
|
||||
poolLv: this.poolLv
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user