From 4ea590e7089b729e048f89003b9b1633c9461eb9 Mon Sep 17 00:00:00 2001 From: panfudan Date: Fri, 8 Aug 2025 22:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=20=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script/game/hero/BuffComp.ts | 40 +--- assets/script/game/hero/HeroConComp.ts | 261 +++++++++--------------- assets/script/game/hero/HeroViewComp.ts | 93 +++------ 3 files changed, 131 insertions(+), 263 deletions(-) diff --git a/assets/script/game/hero/BuffComp.ts b/assets/script/game/hero/BuffComp.ts index d1b473a1..602f7ae2 100644 --- a/assets/script/game/hero/BuffComp.ts +++ b/assets/script/game/hero/BuffComp.ts @@ -88,45 +88,7 @@ export class BuffComp extends Component { this.node.getChildByName("shielded").active=val } - vmdata_update(is_hp:boolean=false){ - // console.log("[BuffComp]:to_update_vmdata:"+this.HeroView.hero_name) - let info= null - if(!this.HeroView) return - if(!this.HeroView.is_master) return - info=smc.vmdata.hero - if(info==null) return - let view_atk = 0 //临时buff - let view_deatk = 0 //临时debuff - if(is_hp){ - info.hp=this.HeroView.currentHp - info.hp_max=this.HeroView.currentHpMax - }else{ - info.hp=this.HeroView.currentHp - info.hp_max=this.HeroView.currentHpMax - - for(let i=0;i([ + [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 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(); } } \ No newline at end of file diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 0f4e1427..f0a0509a 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -166,23 +166,7 @@ export class HeroViewComp extends CCComp { DEBUFF_COUNT:number=0; //debuff 持续次数 DEBUFF_UP:number=0; //debuff 概率提升 - TALENT:any={ - [BuffAttr.ATK]:0, - [BuffAttr.CRITICAL]:0, - [BuffAttr.CRITICAL_DMG]:0, - [BuffAttr.DODGE]:0, - [BuffAttr.DEBUFF_COUNT]:0, - [BuffAttr.HP]:0, - [BuffAttr.DEF]:0, - [BuffAttr.PUNCTURE]:0, - [BuffAttr.ATK_CD]:0, - [BuffAttr.SKILL_CD]:0, - [BuffAttr.FROST_RATIO]:0, - [BuffAttr.KNOCKBACK]:0, - [BuffAttr.STUN_RATTO]:0, - [BuffAttr.REFLECT]:0, - [BuffAttr.LIFESTEAL]:0, - } + private damageQueue: Array<{ @@ -212,7 +196,7 @@ export class HeroViewComp extends CCComp { start () { this.as.idle() this.BUFFCOMP=this.node.getComponent(BuffComp); - // this.update_vmdata() + /** 方向 */ this.node.setScale(this.scale,1); this.node.getChildByName("top").setScale(this.scale,1); @@ -223,9 +207,7 @@ export class HeroViewComp extends CCComp { this.node.getChildByName("top").getChildByName("hp").active = true; } - update_vmdata(){ - if(this.is_master) this.BUFFCOMP.vmdata_update() - } + update(dt: number){ if(!smc.mission.play||smc.mission.pause) return // if(this.is_dead) { @@ -233,9 +215,7 @@ export class HeroViewComp extends CCComp { // return // } - if(this.timer.update(dt)){ - // this.add_ap(10) - }; + if(this.DEBUFF_FROST > 0){ this.DEBUFF_FROST -=dt; } @@ -282,80 +262,80 @@ export class HeroViewComp extends CCComp { change_wfuny(wfuny: number){ this.wfuny+=wfuny if(this.wfuny<0) this.wfuny=0 - // this.update_vmdata() + } change_puncture(puncture: number){ this.puncture+=puncture if(this.puncture<1) this.puncture=1 - // this.update_vmdata() + } change_puncture_damage(puncture_damage: number){ this.puncture_damage+=puncture_damage if(this.puncture_damage<0) this.puncture_damage=0 if(this.puncture_damage>80) this.puncture_damage=80 - // this.update_vmdata() + } change_dodge(dodge: number){ this.dod+=dodge if(this.dod<0) this.dod=0 if(this.dod>90) this.dod=90 - // this.update_vmdata() + } change_frost_ratto(frost_ratto: number){ this.frost_ratto+=frost_ratto if(this.frost_ratto<0) this.frost_ratto=0 if(this.frost_ratto>90) this.frost_ratto=90 - // this.update_vmdata() + } change_knockback(knockback: number){ this.knockback+=knockback if(this.knockback<0) this.knockback=0 - // this.update_vmdata() + } change_stun_ratto(stun_ratto: number){ this.stun_ratto+=stun_ratto if(this.stun_ratto<0) this.stun_ratto=0 - // this.update_vmdata() + } change_def(def: number){ this.def+=def if(this.def>90) this.def=90 if(this.def<0) this.def=0 - // this.update_vmdata() + // this.BUFFCOMP.tooltip(TooltipTypes.defup,def.toFixed(0)); } change_crit(crit: number){ this.crit+=crit if(this.crit<0) this.crit=0 - // this.update_vmdata() + } change_crit_d(crit_d: number){ this.crit_d+=crit_d if(this.crit_d<0) this.crit_d=0 - // this.update_vmdata() + } change_reflect(reflect: number){ this.reflect+=reflect if(this.reflect<0) this.reflect=0 - // this.update_vmdata() + } change_lifesteal(lifesteal: number){ this.lifesteal+=lifesteal if(this.lifesteal<0) this.lifesteal=0 - // this.update_vmdata() + } check_atrr(buff:BuffAttr){ switch(buff){ case BuffAttr.ATK: - return Math.floor(this.ap_base*(100+this.ap_buff+this.TALENT[BuffAttr.ATK])/100) + return Math.floor(this.ap_base*(100+this.ap_buff)/100) case BuffAttr.ATK_CD: - return this.cd_base/((this.cd_buff+this.TALENT[BuffAttr.ATK_CD])/100+1) + return this.cd_base/((this.cd_buff)/100+1) case BuffAttr.HP: - return Math.floor(this.hp_base*(100+this.hp_buff+this.TALENT[BuffAttr.HP])/100) + return Math.floor(this.hp_base*(100+this.hp_buff)/100) } } @@ -363,17 +343,17 @@ export class HeroViewComp extends CCComp { switch(buff){ case BuffAttr.ATK: this.ap=this.check_atrr(BuffAttr.ATK) - // this.update_vmdata() + break case BuffAttr.ATK_CD: this.cd=this.check_atrr(BuffAttr.ATK_CD) - // this.update_vmdata() + break case BuffAttr.HP: let diff=this.check_atrr(BuffAttr.HP)-this.currentHpMax this.currentHpMax=this.check_atrr(BuffAttr.HP) this.currentHp+=diff - // this.update_vmdata() + break } } @@ -385,28 +365,18 @@ export class HeroViewComp extends CCComp { } - add_ap(ap: number,is_num:boolean=true){ + change_ap(ap: number,is_num:boolean=true){ // console.log("[HeroViewComp]:add_ap add:",ap,this.ap) if(is_num){ this.ap_base += Math.floor(ap); }else{ - this.ap_base += Math.floor(ap/100*this.ap_base); - } - this.count_atrr(BuffAttr.ATK) - // this.BUFFCOMP.tooltip(TooltipTypes.apup,diff.toFixed(0)); - } - - de_ap(ap: number,is_num:boolean=true){ - //console.log("[HeroViewComp]:de_ap de:",ap,this.ap) - if(is_num){ - this.ap_base -= Math.floor(ap); - }else{ - this.ap_base -= Math.floor(ap/100*this.ap_base); + this.ap_buff += Math.floor(ap/100*this.ap_base); } + this.count_atrr(BuffAttr.ATK) } - add_hp_max(hp: number=0,is_num:boolean=false){ + change_hp_max(hp: number=0,is_num:boolean=false){ // console.log("[HeroViewComp]:add_hp_max add:",hp,this.currentHpMax) if(is_num){ this.hp_base += Math.floor(hp) ; @@ -414,13 +384,6 @@ export class HeroViewComp extends CCComp { this.hp_buff+=hp } this.count_atrr(BuffAttr.HP) - // this.BUFFCOMP.tooltip(TooltipTypes.hpup,diff.toFixed(0)); - } - - de_hp_max(hp: number=0,is_num:boolean=true){ //最大值 只存在数值添加, 比例通过hp_buff处理 - //console.log("[HeroViewComp]:de_hp_max de:",hp,this.currentHpMax) - this.hp_base -= Math.floor(hp) ; - this.count_atrr(BuffAttr.HP) // this.update_vm } @@ -834,8 +797,8 @@ export class HeroViewComp extends CCComp { if(this.fac==FacSet.MON) return console.log("[HeroViewComp]:升级",this.BUFFCOMP) if(this.hero_uuid!=data.uuid) return - this.add_ap(HeroInfo[data.uuid].ap,true) - this.add_hp_max(HeroInfo[data.uuid].hp,true) + this.change_ap(HeroInfo[data.uuid].ap,true) + this.change_hp_max(HeroInfo[data.uuid].hp,true) this.BUFFCOMP.lv_up() // this.BUFFCOMP.tooltip(TooltipTypes.lvup) }