英雄 简单优化

This commit is contained in:
2025-08-08 22:40:07 +08:00
parent bf241345bf
commit 4ea590e708
3 changed files with 131 additions and 263 deletions

View File

@@ -1,196 +1,139 @@
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 { oops } from "db://oops-framework/core/Oops";
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 { smc } from "../common/SingletonModuleComp";
import { SuperCards, SuperCardsType } from "../common/config/CardSet";
import { SuperCardsType } from "../common/config/CardSet";
const { ccclass, property } = _decorator;
/** 视图层对象 */
/** 英雄控制组件 - 处理英雄的装备、强化、天赋等逻辑 */
@ccclass('HeroConComp')
@ecs.register('HeroCon')
export class HeroConComp extends CCComp {
/** 视图层逻辑代码分离演示 */
heroView:HeroViewComp=null
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_RATTO, 'handleStunBuff'],
[BuffAttr.REFLECT, 'handleReflectBuff'],
[BuffAttr.LIFESTEAL, 'handleLifestealBuff']
]);
protected onLoad(): void {
this.on(GameEvent.EquipAdd,this.equip_add,this)
this.on(GameEvent.EquipChange,this.equip_change,this)
this.on(GameEvent.FightReady,this.fight_ready,this)
this.on(GameEvent.UseSpecialCard,this.use_special_card,this)
this.on(GameEvent.UseEnhancement,this.use_enhancement,this)
this.on(GameEvent.UseTalentCard,this.use_talent_card,this)
this.on(GameEvent.RemoveTalent,this.remove_talent_card,this)
this.on(GameEvent.LuckCardUsed,this.luck_card_used,this)
this.heroView=this.node.getComponent(HeroViewComp)
console.log("[HeroConCompComp]:onLoad",this.heroView)
this.heroView = this.node.getComponent(HeroViewComp);
this.registerEvents();
}
start() {
console.log("[HeroConCompComp]:start",this.heroView)
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
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);
}
equip_add(e:GameEvent,data:any){
console.log("[HeroConCompComp]:equip_add",data,this.heroView)
let equip=EquipInfo[data.uuid]
let buffs=equip.buff
let special_attr=equip.special_attr
for(let i=0;i<buffs.length;i++){
let buff=buffs[i]
if(buff.target==EquipAttrTarget.HERO){
switch(buff.type){
case BuffAttr.AP:
this.heroView.add_ap(buff.value,true)
break
case BuffAttr.ATK:
this.heroView.add_ap(buff.value,false)
break
case BuffAttr.ATK_CD:
this.heroView.add_speed(buff.value)
break
case BuffAttr.DEF:
this.heroView.change_def(buff.value)
break
case BuffAttr.HP:
this.heroView.add_hp_max(buff.value,false)
break
case BuffAttr.HP_MAX:
this.heroView.add_hp_max(buff.value,true)
break
case BuffAttr.CRITICAL:
this.heroView.change_crit(buff.value)
break
case BuffAttr.CRITICAL_DMG:
this.heroView.change_crit_d(buff.value)
break
}
}
}
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));
}
equip_change(e:GameEvent,data:any){
console.log("[HeroConCompComp]:equip_change",data)
private onEquipChange(e: GameEvent, data: any): void {
// TODO: 处理装备变更逻辑
}
fight_ready(e:GameEvent,data:any){
console.log("[HeroConCompComp]:fight_ready",data)
private onFightReady(e: GameEvent, data: any): void {
// TODO: 处理战斗准备逻辑
}
use_special_card(e:GameEvent,data:any){
console.log("[HeroConCompComp]:use_special_card",data)
private onUseSpecialCard(e: GameEvent, data: any): void {
// TODO: 处理特殊卡牌使用逻辑
}
use_enhancement(e:GameEvent,data:any){
// console.log("[HeroViewComp]:use_enhancement",data)
switch(data.type){
case EnhancementType.ATTACK:
this.heroView.add_ap(data.value)
break
case EnhancementType.ATTACK_SPEED:
this.heroView.add_speed(data.value)
break
case EnhancementType.HEALTH:
this.heroView.add_hp_max(data.value,true)
break
case EnhancementType.DEF:
this.heroView.change_def(data.value)
break
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);
}
}
use_talent_card(e:GameEvent,data:any){
console.log("[HeroConCompComp]:use_talent_card",data)
let tal=TalentList[data.uuid]
this.do_buff_func(tal.buffType,tal.value)
private onRemoveTalentCard(e: GameEvent, data: any): void {
const talent = TalentList[data.uuid];
if (talent) {
this.applyBuff(talent.buffType, -talent.value);
}
}
remove_talent_card(e:GameEvent,data:any){
let tal=TalentList[data.uuid]
console.log("[HeroConCompComp]:remove_talent_card",data,tal)
this.do_buff_func(tal.buffType,-tal.value)
}
luck_card_used(e:GameEvent,card:any){
switch(card.type){
private onLuckCardUsed(e: GameEvent, card: any): void {
switch (card.type) {
case SuperCardsType.BUFF:
this.do_buff_func(card.value1,card.value2)
break
this.applyBuff(card.value1, card.value2);
break;
case SuperCardsType.AOE:
//do skill
break
// TODO: 处理AOE技能
break;
}
}
do_buff_func(buffType:number,value:number){
switch(buffType){
case BuffAttr.AP:
this.heroView.ap_base+=value
this.heroView.count_atrr(BuffAttr.ATK)
break
case BuffAttr.HP_MAX:
this.heroView.hp_base+=value
this.heroView.count_atrr(BuffAttr.HP)
break
case BuffAttr.ATK:
this.heroView.TALENT[BuffAttr.ATK]+=value
this.heroView.count_atrr(BuffAttr.ATK)
break
case BuffAttr.ATK_CD:
this.heroView.TALENT[BuffAttr.ATK_CD]+=value
this.heroView.count_atrr(BuffAttr.ATK_CD)
break
case BuffAttr.HP:
this.heroView.TALENT[BuffAttr.HP]+=value
break
case BuffAttr.DEF:
this.heroView.change_def(value)
break
case BuffAttr.CRITICAL:
this.heroView.change_crit(value)
break
case BuffAttr.CRITICAL_DMG:
this.heroView.change_crit_d(value)
break
case BuffAttr.DODGE:
this.heroView.change_dodge(value)
break
case BuffAttr.PUNCTURE:
this.heroView.change_puncture(value)
break
case BuffAttr.PUNCTURE_DMG:
this.heroView.change_puncture_damage(value)
break
case BuffAttr.FROST_RATIO:
this.heroView.change_frost_ratto(value)
break
case BuffAttr.KNOCKBACK:
this.heroView.change_knockback(value)
break
case BuffAttr.STUN_RATTO:
this.heroView.change_stun_ratto(value)
break
case BuffAttr.REFLECT:
this.heroView.change_reflect(value)
break
case BuffAttr.LIFESTEAL:
this.heroView.change_lifesteal(value)
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);
}
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
// 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();
}
}