import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { BoxSet } from "../common/config/BoxSet"; import { SkillSet } from "../common/config/SkillSet"; import { smc } from "../common/SingletonModuleComp"; import { HeroViewComp } from "../hero/HeroViewComp"; import { FightConComp } from "../map/FightConComp"; import { SkillCom } from "./SkillCom"; import { instantiate, Node, Prefab, Vec3 ,tween, v3,animation,Label,resources,SpriteFrame,Sprite} from "cc"; /** Skill 模块 */ @ecs.register(`Skill`) export class Skill extends ecs.Entity { FIGHTCON:FightConComp=null! SkillView!: SkillCom; /** 实始添加的数据层组件 */ protected init() { } /** 模块资源释放 */ destroy() { // 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放 this.remove(SkillCom); super.destroy(); } load( startPos: Vec3, // 起始位置 parent: Node, // 父节点 uuid: number, // 技能ID targetPos: Vec3, // 目标位置 caster:any=null, // 施法者 angle:number=0, dmg:number=0 ) { let FIGHTCON=parent.getComponent(FightConComp); const config = SkillSet[uuid]; if (!config) { console.error("[Skill] 技能配置不存在:", uuid); return; } // 检查施法者 if (!caster) { console.error("[Skill] 施法者为空"); return; } // 加载预制体 const path = `game/skills/${config.sp_name}`; const prefab = oops.res.get(path, Prefab); if (!prefab) { console.error("[Skill] 预制体加载失败:", path); return; } const node = instantiate(prefab); // 设置节点属性 node.parent = parent; node.setPosition(startPos); node.angle+=angle // 添加技能组件 const SComp = node.getComponent(SkillCom); // 初始化技能参数 if (!SComp) { console.error("[Skill] 技能组件获取失败"); return; } // 确保caster有必要的属性 if (typeof caster.ap === 'undefined') { console.error("[Skill] caster.ap 未定义"); return; } if (typeof caster.box_group === 'undefined') { console.error("[Skill] caster.box_group 未定义"); return; } let ap_data = this.get_ap(caster,dmg,uuid,FIGHTCON) SComp.ap = ap_data.ap SComp.caster_crit = ap_data.crit SComp.caster_crit_d = ap_data.crit_d SComp.puncture = ap_data.puncture SComp.puncture_damage = ap_data.puncture_damage // 设置技能组件属性 Object.assign(SComp, { s_uuid: uuid, AType: config.AType, speed: config.speed, atk_count: 0, startPos: startPos, targetPos: targetPos, caster: caster, prefabName: config.sp_name, group: caster.box_group, fac: caster.fac, animName: config.animName }); this.add(SComp); } get_ap(view:HeroViewComp,dmg:number=0,uuid:number=0,FIGHTCON:FightConComp=null!){ let ap=0 let crit=0 let crit_d=0 let buff_ap=1 let buff=null let puncture=0 let puncture_damage=0 if(view.is_master) buff=FIGHTCON.hero_buff if(view.is_friend) buff=FIGHTCON.friend_buff if(view.is_boss) buff=FIGHTCON.enemy_buff if(view.is_kalami) buff=FIGHTCON.enemy_buff if(buff!==null) { buff_ap=(100+buff.ATK)/100 //装备区 总加成 } // 汇总DEBUFF_DECD并处理count值 let BUFF_ATK = 0 let DEBUFF_DEATK = 0 if(view.BUFF_ATKS.length>0){ for (let i = view.BUFF_ATKS.length - 1; i >= 0; i--) { BUFF_ATK += view.BUFF_ATKS[i].value; view.BUFF_ATKS[i].count--; if (view.BUFF_ATKS[i].count <= 0) { view.BUFF_ATKS.splice(i, 1); } } } if(view.DEBUFF_DEATKS.length>0) { for (let i = view.DEBUFF_DEATKS.length - 1; i >= 0; i--) { DEBUFF_DEATK += view.DEBUFF_DEATKS[i].value; view.DEBUFF_DEATKS[i].count--; if (view.DEBUFF_DEATKS[i].count <= 0) { view.DEBUFF_DEATKS.splice(i, 1); } } } let BUFF_AP=(100-DEBUFF_DEATK+BUFF_ATK+dmg)/100 //buff区 总加成 puncture =buff.PUNCTURE+view.puncture puncture_damage=buff.PUNCTURE_DMG+view.puncture_damage ap=view.ap*buff_ap*BUFF_AP*SkillSet[uuid].ap/100 crit=view.crit+buff.CRITICAL crit_d=view.crit_d+buff.CRITICAL_DMG return {ap,crit,crit_d,puncture,puncture_damage} } }