永久数据不再mvvm显示
This commit is contained in:
@@ -17,121 +17,16 @@ const { ccclass, property } = _decorator;
|
||||
export class HeroConComp extends CCComp {
|
||||
private heroView: HeroViewComp = null;
|
||||
|
||||
// Buff处理方法映射表
|
||||
private static readonly BUFF_HANDLERS = new Map<BuffAttr, string>([
|
||||
[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_RATIO, '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.apply_buff(BuffAttr.AP, value); }
|
||||
private handleATKBuff(value: number): void { this.heroView.apply_buff(BuffAttr.ATK, value); }
|
||||
private handleSpeedBuff(value: number): void { this.heroView.apply_buff(BuffAttr.ATK_CD, value); }
|
||||
private handleDefBuff(value: number): void { this.heroView.apply_buff(BuffAttr.DEF, value); }
|
||||
private handleHPBuff(value: number): void { this.heroView.apply_buff(BuffAttr.HP, value); }
|
||||
private handleHPMaxBuff(value: number): void { this.heroView.apply_buff(BuffAttr.HP_MAX, value); }
|
||||
private handleCritBuff(value: number): void { this.heroView.apply_buff(BuffAttr.CRITICAL, value); }
|
||||
private handleCritDmgBuff(value: number): void { this.heroView.apply_buff(BuffAttr.CRITICAL_DMG, value); }
|
||||
private handleDodgeBuff(value: number): void { this.heroView.apply_buff(BuffAttr.DODGE, value); }
|
||||
private handlePunctureBuff(value: number): void { this.heroView.apply_buff(BuffAttr.PUNCTURE, value); }
|
||||
private handlePunctureDmgBuff(value: number): void { this.heroView.apply_buff(BuffAttr.PUNCTURE_DMG, value); }
|
||||
private handleFrostBuff(value: number): void { this.heroView.apply_buff(BuffAttr.FROST_RATIO, value); }
|
||||
private handleKnockbackBuff(value: number): void { this.heroView.apply_buff(BuffAttr.KNOCKBACK, value); }
|
||||
private handleStunBuff(value: number): void { this.heroView.apply_buff(BuffAttr.STUN_RATIO, value); }
|
||||
private handleReflectBuff(value: number): void { this.heroView.apply_buff(BuffAttr.REFLECT, value); }
|
||||
private handleLifestealBuff(value: number): void { this.heroView.apply_buff(BuffAttr.LIFESTEAL, value); }
|
||||
|
||||
/** 组件重置 */
|
||||
reset(): void {
|
||||
this.node.destroy();
|
||||
|
||||
Reference in New Issue
Block a user