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 { GameEvent } from "../common/config/GameEvent"; import { EquipAttrTarget, EquipInfo } from "../common/config/Equips"; import { HeroViewComp } from "./HeroViewComp"; import { BuffAttr } from "../common/config/SkillSet"; import { EnhancementType } from "../common/config/LevelUp"; import { TalentList } from "../common/config/TalentSet"; import { SuperCardsType } from "../common/config/CardSet"; const { ccclass, property } = _decorator; /** 英雄控制组件 - 处理英雄的装备、强化、天赋等逻辑 */ @ccclass('HeroConComp') @ecs.register('HeroCon') export class HeroConComp extends CCComp { private heroView: HeroViewComp = null; // Buff处理方法映射表 private static readonly BUFF_HANDLERS = new Map([ [BuffAttr.AP, 'handleAPBuff'], [BuffAttr.ATK, 'handleATKBuff'], [BuffAttr.ATK_CD, 'handleSpeedBuff'], [BuffAttr.DEF, 'handleDefBuff'], [BuffAttr.HP, 'handleHPBuff'], // 生命值比例 [BuffAttr.HP_MAX, 'handleHPMaxBuff'], // 生命值数值 [BuffAttr.CRITICAL, 'handleCritBuff'], [BuffAttr.CRITICAL_DMG, 'handleCritDmgBuff'], [BuffAttr.DODGE, 'handleDodgeBuff'], [BuffAttr.PUNCTURE, 'handlePunctureBuff'], [BuffAttr.PUNCTURE_DMG, 'handlePunctureDmgBuff'], [BuffAttr.FROST_RATIO, 'handleFrostBuff'], [BuffAttr.KNOCKBACK, 'handleKnockbackBuff'], [BuffAttr.STUN_RATTO, 'handleStunBuff'], [BuffAttr.REFLECT, 'handleReflectBuff'], [BuffAttr.LIFESTEAL, 'handleLifestealBuff'] ]); protected onLoad(): void { this.heroView = this.node.getComponent(HeroViewComp); this.registerEvents(); } private registerEvents(): void { this.on(GameEvent.EquipAdd, this.onEquipAdd, this); this.on(GameEvent.EquipChange, this.onEquipChange, this); this.on(GameEvent.FightReady, this.onFightReady, this); this.on(GameEvent.UseSpecialCard, this.onUseSpecialCard, this); this.on(GameEvent.UseEnhancement, this.onUseEnhancement, this); this.on(GameEvent.UseTalentCard, this.onUseTalentCard, this); this.on(GameEvent.RemoveTalent, this.onRemoveTalentCard, this); this.on(GameEvent.LuckCardUsed, this.onLuckCardUsed, this); } private onEquipAdd(e: GameEvent, data: any): void { const equip = EquipInfo[data.uuid]; if (!equip?.buff) return; equip.buff .filter(buff => buff.target === EquipAttrTarget.HERO) .forEach(buff => this.applyBuff(buff.type, buff.value)); } private onEquipChange(e: GameEvent, data: any): void { // TODO: 处理装备变更逻辑 } private onFightReady(e: GameEvent, data: any): void { // TODO: 处理战斗准备逻辑 } private onUseSpecialCard(e: GameEvent, data: any): void { // TODO: 处理特殊卡牌使用逻辑 } private onUseEnhancement(e: GameEvent, data: any): void { const enhancementMap = { [EnhancementType.ATTACK]: () => this.handleATKBuff(data.value), [EnhancementType.ATTACK_SPEED]: () => this.handleSpeedBuff(data.value), [EnhancementType.HEALTH]: () => this.handleHPMaxBuff(data.value), [EnhancementType.DEF]: () => this.handleDefBuff(data.value) }; enhancementMap[data.type]?.(); } private onUseTalentCard(e: GameEvent, data: any): void { const talent = TalentList[data.uuid]; if (talent) { this.applyBuff(talent.buffType, talent.value); } } private onRemoveTalentCard(e: GameEvent, data: any): void { const talent = TalentList[data.uuid]; if (talent) { this.applyBuff(talent.buffType, -talent.value); } } private onLuckCardUsed(e: GameEvent, card: any): void { switch (card.type) { case SuperCardsType.BUFF: this.applyBuff(card.value1, card.value2); break; case SuperCardsType.AOE: // TODO: 处理AOE技能 break; } } /** 统一的Buff应用方法 */ private applyBuff(buffType: BuffAttr, value: number): void { const handlerName = HeroConComp.BUFF_HANDLERS.get(buffType); if (handlerName && typeof this[handlerName] === 'function') { this[handlerName](value); } } // Buff处理方法 private handleAPBuff(value: number): void { this.heroView.change_ap(value, true); } private handleATKBuff(value: number): void { this.heroView.change_ap(value, false); } private handleSpeedBuff(value: number): void { this.heroView.add_speed(value); } private handleDefBuff(value: number): void { this.heroView.change_def(value); } private handleHPBuff(value: number): void { this.heroView.change_hp_max(value, false); } private handleHPMaxBuff(value: number): void { this.heroView.change_hp_max(value, true); } private handleCritBuff(value: number): void { this.heroView.change_crit(value); } private handleCritDmgBuff(value: number): void { this.heroView.change_crit_d(value); } private handleDodgeBuff(value: number): void { this.heroView.change_dodge(value); } private handlePunctureBuff(value: number): void { this.heroView.change_puncture(value); } private handlePunctureDmgBuff(value: number): void { this.heroView.change_puncture_damage(value); } private handleFrostBuff(value: number): void { this.heroView.change_frost_ratto(value); } private handleKnockbackBuff(value: number): void { this.heroView.change_knockback(value); } private handleStunBuff(value: number): void { this.heroView.change_stun_ratto(value); } private handleReflectBuff(value: number): void { this.heroView.change_reflect(value); } private handleLifestealBuff(value: number): void { this.heroView.change_lifesteal(value); } /** 组件重置 */ reset(): void { this.node.destroy(); } }