import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { BoxSet, FacSet } from "../common/config/BoxSet"; import { HType } from "../common/config/heroSet"; import { SkillSet } from "../common/config/SkillSet"; import { smc } from "../common/SingletonModuleComp"; import { HeroViewComp } from "../hero/HeroViewComp"; 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 { 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 ) { 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); var scene = smc.map.MapView.scene; // 设置节点属性 node.parent = scene.entityLayer!.node!; node.setPosition(startPos); if(caster.fac==FacSet.MON){ node.scale=v3(node.scale.x*-1,1,1) }else{ if(caster.type==HType.warrior){ if(caster.node.scale.x<0){ node.scale=v3(node.scale.x*-1,node.scale.y,1) } } } 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) // 只设置必要的运行时属性,配置信息通过 SkillSet[uuid] 访问 Object.assign(SComp, { // 核心标识 s_uuid: uuid, // 位置和施法者信息 startPos: startPos, targetPos: targetPos, caster: caster, group: caster.box_group, fac: caster.fac, // 计算后的战斗数据 ap: ap_data.ap, caster_crit: ap_data.crit, caster_crit_d: ap_data.crit_d, puncture: ap_data.puncture, puncture_damage: ap_data.puncture_damage, burn_count: ap_data.burn_count, burn_value: ap_data.burn_value, stun_time: ap_data.stun_time, stun_ratto: ap_data.stun_ratto, frost_time: ap_data.frost_time, frost_ratto: ap_data.frost_ratto, }); this.add(SComp); } get_ap(view:HeroViewComp,dmg:number=0,uuid:number=0){ let ap=0 let crit=0 let crit_d=0 let buffap=1 let puncture=0 let puncture_damage=0 let burn_count=0 let burn_value=0 let stun_time=0 let stun_ratto=0 let frost_time=0 let frost_ratto=0 // 汇总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; // 不再在这里减少duration,改为在update中按时间减少 } } if(view.DEBUFF_DEATKS.length>0) { for (let i = view.DEBUFF_DEATKS.length - 1; i >= 0; i--) { DEBUFF_DEATK += view.DEBUFF_DEATKS[i].value; // 不再在这里减少duration,改为在update中按时间减少 } } let BUFF_AP=(100-DEBUFF_DEATK+BUFF_ATK+dmg)/100 //buff区 总加成 puncture =view.puncture puncture_damage=view.puncture_damage ap=view.ap*buffap*BUFF_AP*SkillSet[uuid].ap/100 crit=view.crit crit_d=view.crit_d burn_count=view.burn_count burn_value=view.burn_value stun_time=view.stun_time stun_ratto=view.stun_ratto frost_time=view.frost_time frost_ratto=view.frost_ratto return {ap,crit,crit_d,puncture,puncture_damage,burn_count,burn_value,stun_time,stun_ratto,frost_time,frost_ratto} } }