Files
heros/assets/script/game/skills/Skill.ts
2025-06-20 16:29:11 +08:00

112 lines
3.7 KiB
TypeScript

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 { 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
console.log("[Skill]:node=>",startPos)
// 添加技能组件
const SComp = node.getComponent(SkillCom); // 初始化技能参数
if (!SComp) {
console.error("[Skill] 技能组件获取失败");
return;
}
console.log("[Skill]:caster=>",caster,config.name+"scomp=>",SComp,"fightcon=>",FIGHTCON)
// 确保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;
}
SComp.ap = caster.ap*config.ap/100;
if(caster.fac==0){
if(caster.is_master){
SComp.ap=Math.floor(SComp.ap*(100+FIGHTCON.hero_buff.ATK)/100);
}else{
SComp.ap=Math.floor(SComp.ap*(100+FIGHTCON.friend_buff.ATK)/100);
}
}else{
SComp.ap=Math.floor(SComp.ap*(100-FIGHTCON.enemy_buff.ATK)/100);
}
SComp.ap=(100+dmg)/100*SComp.ap // master 主将 技能额外百分比加成
console.log("[Skill]:caster.box_group=>",caster.box_group,config.name+"scomp.group=>",SComp.group)
// 设置技能组件属性
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);
}
}