162 lines
5.4 KiB
TypeScript
162 lines
5.4 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, FacSet } from "../common/config/BoxSet";
|
||
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)
|
||
}
|
||
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)
|
||
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
|
||
SComp.buV = config.buV
|
||
SComp.buC = config.buC
|
||
SComp.buR = config.buR
|
||
SComp.burn_count = ap_data.burn_count
|
||
SComp.burn_value = ap_data.burn_value
|
||
SComp.stun_time = ap_data.stun_time
|
||
SComp.stun_ratto = ap_data.stun_ratto
|
||
SComp.frost_time = ap_data.frost_time
|
||
SComp.frost_ratto = ap_data.frost_ratto
|
||
// 设置技能组件属性
|
||
Object.assign(SComp, {
|
||
s_uuid: uuid,
|
||
dis:config.dis,
|
||
AType: config.AType,
|
||
speed: config.speed,
|
||
atk_count: 0,
|
||
hit_num:config.hit_num, //目前设定 根据技能不一样,几十
|
||
startPos: startPos,
|
||
targetPos: targetPos,
|
||
caster: caster,
|
||
prefabName: config.sp_name,
|
||
group: caster.box_group,
|
||
fac: caster.fac,
|
||
scale: caster.scale,
|
||
animName: config.animName,
|
||
});
|
||
|
||
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}
|
||
}
|
||
}
|