220 lines
8.4 KiB
TypeScript
220 lines
8.4 KiB
TypeScript
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";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HeroConComp')
|
|
@ecs.register('HeroCon')
|
|
export class HeroConComp extends CCComp {
|
|
/** 视图层逻辑代码分离演示 */
|
|
heroView:HeroViewComp=null
|
|
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.heroView=this.node.getComponent(HeroViewComp)
|
|
console.log("[HeroConCompComp]:onLoad",this.heroView)
|
|
}
|
|
start() {
|
|
console.log("[HeroConCompComp]:start",this.heroView)
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, 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
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
equip_change(e:GameEvent,data:any){
|
|
console.log("[HeroConCompComp]:equip_change",data)
|
|
}
|
|
fight_ready(e:GameEvent,data:any){
|
|
console.log("[HeroConCompComp]:fight_ready",data)
|
|
}
|
|
use_special_card(e:GameEvent,data:any){
|
|
console.log("[HeroConCompComp]:use_special_card",data)
|
|
}
|
|
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
|
|
}
|
|
}
|
|
|
|
use_talent_card(e:GameEvent,data:any){
|
|
console.log("[HeroConCompComp]:use_talent_card",data)
|
|
let tal=TalentList[data.uuid]
|
|
switch(tal.buffType){
|
|
case BuffAttr.ATK:
|
|
this.heroView.TALENT[BuffAttr.ATK]+=tal.value
|
|
this.heroView.count_atrr(BuffAttr.ATK)
|
|
break
|
|
case BuffAttr.ATK_CD:
|
|
this.heroView.TALENT[BuffAttr.ATK_CD]+=tal.value
|
|
this.heroView.count_atrr(BuffAttr.ATK_CD)
|
|
break
|
|
case BuffAttr.SKILL_CD:
|
|
smc.vmdata.hero.skill_cd_buff+=tal.value //直接加到vmdata中
|
|
break
|
|
case BuffAttr.HP:
|
|
this.heroView.TALENT[BuffAttr.HP]+=tal.value
|
|
this.heroView.count_atrr(BuffAttr.HP)
|
|
break
|
|
case BuffAttr.DEF:
|
|
this.heroView.change_def(tal.value)
|
|
break
|
|
case BuffAttr.CRITICAL:
|
|
this.heroView.change_crit(tal.value)
|
|
break
|
|
case BuffAttr.CRITICAL_DMG:
|
|
this.heroView.change_crit_d(tal.value)
|
|
break
|
|
case BuffAttr.DODGE:
|
|
this.heroView.change_dodge(tal.value)
|
|
break
|
|
case BuffAttr.PUNCTURE:
|
|
this.heroView.change_puncture(tal.value)
|
|
break
|
|
case BuffAttr.PUNCTURE_DMG:
|
|
this.heroView.change_puncture_damage(tal.value)
|
|
break
|
|
case BuffAttr.FROST_RATIO:
|
|
this.heroView.change_frost_ratto(tal.value)
|
|
break
|
|
case BuffAttr.KNOCKBACK:
|
|
this.heroView.change_knockback(tal.value)
|
|
break
|
|
case BuffAttr.STUN_RATTO:
|
|
this.heroView.change_stun_ratto(tal.value)
|
|
break
|
|
case BuffAttr.LIFESTEAL:
|
|
this.heroView.change_lifesteal(tal.value)
|
|
break
|
|
case BuffAttr.WFUNY:
|
|
this.heroView.change_wfuny(tal.value)
|
|
break
|
|
}
|
|
}
|
|
remove_talent_card(e:GameEvent,data:any){
|
|
console.log("[HeroConCompComp]:remove_talent_card",data)
|
|
let tal=TalentList[data.uuid]
|
|
switch(tal.buffType){
|
|
case BuffAttr.ATK:
|
|
this.heroView.TALENT[BuffAttr.ATK]-=tal.value
|
|
this.heroView.count_atrr(BuffAttr.ATK)
|
|
break
|
|
case BuffAttr.ATK_CD:
|
|
this.heroView.TALENT[BuffAttr.ATK_CD]-=tal.value
|
|
this.heroView.count_atrr(BuffAttr.ATK_CD)
|
|
break
|
|
case BuffAttr.HP:
|
|
this.heroView.TALENT[BuffAttr.HP]-=tal.value
|
|
break
|
|
case BuffAttr.DEF:
|
|
this.heroView.change_def(-tal.value)
|
|
break
|
|
case BuffAttr.CRITICAL:
|
|
this.heroView.change_crit(-tal.value)
|
|
break
|
|
case BuffAttr.CRITICAL_DMG:
|
|
this.heroView.change_crit_d(-tal.value)
|
|
break
|
|
case BuffAttr.DODGE:
|
|
this.heroView.change_dodge(-tal.value)
|
|
break
|
|
case BuffAttr.PUNCTURE:
|
|
this.heroView.change_puncture(-tal.value)
|
|
break
|
|
case BuffAttr.PUNCTURE_DMG:
|
|
this.heroView.change_puncture_damage(-tal.value)
|
|
break
|
|
case BuffAttr.FROST_RATIO:
|
|
this.heroView.change_frost_ratto(-tal.value)
|
|
break
|
|
|
|
case BuffAttr.KNOCKBACK:
|
|
this.heroView.change_knockback(-tal.value)
|
|
break
|
|
case BuffAttr.STUN_RATTO:
|
|
this.heroView.change_stun_ratto(-tal.value)
|
|
break
|
|
case BuffAttr.REFLECT:
|
|
this.heroView.change_reflect(-tal.value)
|
|
break
|
|
case BuffAttr.LIFESTEAL:
|
|
this.heroView.change_lifesteal(-tal.value)
|
|
break
|
|
}
|
|
}
|
|
/** 全局消息逻辑处理 */
|
|
// private onHandler(event: string, args: any) {
|
|
// switch (event) {
|
|
// case ModuleEvent.Cmd:
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |