技能内存优化
This commit is contained in:
@@ -20,32 +20,19 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('SkillCom')
|
||||
@ecs.register('SkillCom')
|
||||
export class SkillCom extends CCComp {
|
||||
// 核心标识和配置
|
||||
s_uuid:number = 0;
|
||||
s_name:string = "";
|
||||
hero:number = 0;
|
||||
speed:number = 200;
|
||||
scale:number = 1;
|
||||
angle:number = 0;
|
||||
atk_count:number = 0;
|
||||
hit_num:number=0; // 范围攻击的 伤害个数
|
||||
|
||||
// 运行时状态(必须缓存的)
|
||||
is_destroy:boolean = false;
|
||||
enemys:any = [];
|
||||
AType: number = 0; // 运动类型
|
||||
startPos: Vec3 = v3(); // 起始位置
|
||||
targetPos: Vec3 = v3(); // 目标位置
|
||||
duration: number = 0; // 技能持续时间
|
||||
prefabName: string = ""; // 预制体名称
|
||||
animName: string = "";
|
||||
group:number = 0; //阵营
|
||||
fac:number=0; //阵营
|
||||
caster:any=null;
|
||||
distance_x:number=0;
|
||||
distance_y:number=0;
|
||||
dis:number=0;
|
||||
|
||||
// 战斗相关运行时数据
|
||||
ap:number=0;
|
||||
buV:number=0;
|
||||
buC:number=0;
|
||||
buR:number=0;
|
||||
burn_count:number=0;
|
||||
burn_value:number=0;
|
||||
stun_time:number=0;
|
||||
@@ -55,23 +42,42 @@ export class SkillCom extends CCComp {
|
||||
run_time:number=0;
|
||||
hited_time:number=0;
|
||||
hit_count:number=0;
|
||||
spine:sp.Skeleton=null;
|
||||
anim:Animation=null;
|
||||
tweenInstance:Tween<any> = null;
|
||||
t_end_x:number=0;
|
||||
caster_crit:number=0;
|
||||
caster_crit_d:number=0;
|
||||
puncture:number=0;
|
||||
puncture_damage:number=0;
|
||||
EType:any=null
|
||||
|
||||
// 组件引用
|
||||
spine:sp.Skeleton=null;
|
||||
anim:Animation=null;
|
||||
tweenInstance:Tween<any> = null;
|
||||
private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向
|
||||
|
||||
// 缓存的配置对象(避免重复查找)
|
||||
public skillConfig: any = null;
|
||||
private isInitialized: boolean = false;
|
||||
|
||||
protected onLoad(): void {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private initializeSkillConfig() {
|
||||
if (this.isInitialized) return;
|
||||
|
||||
// 缓存技能配置,避免重复查找
|
||||
this.skillConfig = SkillSet[this.s_uuid];
|
||||
if (!this.skillConfig) {
|
||||
console.error("[SkillCom] 技能配置不存在:", this.s_uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
this.isInitialized = true;
|
||||
console.log("[SkillCom] 技能配置初始化完成:", this.s_uuid, this.skillConfig.name);
|
||||
}
|
||||
|
||||
start() {
|
||||
this.EType=SkillSet[this.s_uuid].EType
|
||||
this.initializeSkillConfig();
|
||||
if (!this.skillConfig) return;
|
||||
this.node.setPosition(this.startPos.x,this.startPos.y,0)
|
||||
if(this.node.getChildByName('anm')){
|
||||
this.spine=this.node.getChildByName('anm').getComponent('sp.Skeleton') as sp.Skeleton;
|
||||
@@ -90,7 +96,7 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
let bm=this.node.getComponent(BezierMove)
|
||||
// //console.log(this.group +"技能 collider ",collider);
|
||||
switch(SkillSet[this.s_uuid].AType){
|
||||
switch(this.skillConfig.AType){
|
||||
case AType.parabolic:
|
||||
this.node.angle +=10
|
||||
// bm.speed=700
|
||||
@@ -152,17 +158,21 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
onAnimationFinished(){
|
||||
console.log("[SkillCom]:onAnimationFinished",this.s_uuid)
|
||||
if(SkillSet[this.s_uuid].EType==EType.timeEnd) return
|
||||
if(SkillSet[this.s_uuid].SType!=SType.damage){
|
||||
if (!this.skillConfig) return;
|
||||
|
||||
if(this.skillConfig.EType==EType.timeEnd) return
|
||||
if(this.skillConfig.SType!=SType.damage){
|
||||
this.to_do_buff()
|
||||
}
|
||||
|
||||
this.is_destroy=true
|
||||
}
|
||||
to_do_buff(){
|
||||
switch(SkillSet[this.s_uuid].SType){
|
||||
if (!this.skillConfig) return;
|
||||
|
||||
switch(this.skillConfig.SType){
|
||||
case SType.shield:
|
||||
this.caster.add_shield(SkillSet[this.s_uuid].buV)
|
||||
this.caster.add_shield(this.skillConfig.buV)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -171,6 +181,7 @@ export class SkillCom extends CCComp {
|
||||
// //console.log("[SkillCom]:onBeginContact hit_count:",this.hit_count,SkillSet[this.s_uuid].hit)
|
||||
// if(this.hit_count > 0&&!is_range) this.ap=this.ap*(50+this.puncture_damage)/100 // 穿刺后 伤害减半,过滤范围伤害
|
||||
if(target == null) return;
|
||||
if (!this.skillConfig) return;
|
||||
let ap=this.ap
|
||||
if(this.hit_count > 0 &&!is_range ){
|
||||
ap=ap*(50+this.puncture_damage)/100
|
||||
@@ -178,20 +189,22 @@ export class SkillCom extends CCComp {
|
||||
target.do_atked(ap,this.caster_crit,this.caster_crit_d,
|
||||
this.burn_count,this.burn_value,
|
||||
this.stun_time,this.stun_ratto,
|
||||
this.frost_time,this.frost_ratto) // ap 及暴击 属性已经在skill.ts 处理
|
||||
this.frost_time,this.frost_ratto,
|
||||
this.skillConfig.AtkedType
|
||||
) // ap 及暴击 属性已经在skill.ts 处理
|
||||
// console.log("[SkillCom]:single_damage t:tp:rtp",this.node.position,this.targetPos,target.node.position)
|
||||
if(SkillSet[this.s_uuid].debuff>0){
|
||||
let debuff=SkillSet[this.s_uuid]
|
||||
if(this.skillConfig.debuff>0){
|
||||
let debuff=this.skillConfig
|
||||
let dev=debuff.deV*(100+this.caster.DEBUFF_VALUE)/100
|
||||
let deR=debuff.deR+this.caster.DEBUFF_UP
|
||||
dev=Math.round(dev*100)/100
|
||||
let deC=debuff.deC+this.caster.DEBUFF_COUNT //dec只作为次数叠加
|
||||
// //console.log("[SkillCom]:debuff",SkillSet[this.s_uuid].name,debuff.debuff,deUP.deV,deUP.deC)
|
||||
// //console.log("[SkillCom]:debuff",this.skillConfig.name,debuff.debuff,deUP.deV,deUP.deC)
|
||||
target.add_debuff(debuff.debuff,dev,deC,deR)
|
||||
}
|
||||
this.hit_count++
|
||||
// console.log("[SkillCom]:碰撞次数:技能次数:穿刺次数",this.hit_count,SkillSet[this.s_uuid].hit,this.puncture)
|
||||
if(this.hit_count>=(SkillSet[this.s_uuid].hit+this.puncture)&&(SkillSet[this.s_uuid].DTType!=DTType.range)&&(SkillSet[this.s_uuid].EType!=EType.animationEnd)&&(SkillSet[this.s_uuid].EType!=EType.timeEnd)) this.is_destroy=true // 技能命中次数
|
||||
// console.log("[SkillCom]:碰撞次数:技能次数:穿刺次数",this.hit_count,this.skillConfig.hit,this.puncture)
|
||||
if(this.hit_count>=(this.skillConfig.hit+this.puncture)&&(this.skillConfig.DTType!=DTType.range)&&(this.skillConfig.EType!=EType.animationEnd)&&(this.skillConfig.EType!=EType.timeEnd)) this.is_destroy=true // 技能命中次数
|
||||
}
|
||||
|
||||
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
@@ -200,8 +213,9 @@ export class SkillCom extends CCComp {
|
||||
let target = oCol.getComponent(HeroViewComp)
|
||||
if(oCol.group!=this.group){
|
||||
if(target == null) return;
|
||||
if (!this.skillConfig) return;
|
||||
// console.log("[SkillCom]:onBeginContact oCol||seCol",oCol.node.position,seCol.node.position)
|
||||
this.single_damage(target,SkillSet[this.s_uuid].DTType==DTType.range?true:false)
|
||||
this.single_damage(target,this.skillConfig.DTType==DTType.range?true:false)
|
||||
// this.ent.destroy()
|
||||
}
|
||||
}
|
||||
@@ -209,7 +223,12 @@ export class SkillCom extends CCComp {
|
||||
|
||||
|
||||
update(deltaTime: number) {
|
||||
let config=SkillSet[this.s_uuid]
|
||||
// 确保配置已初始化(处理 update 可能先于 start 执行的情况)
|
||||
if (!this.isInitialized) {
|
||||
this.initializeSkillConfig();
|
||||
if (!this.skillConfig) return;
|
||||
}
|
||||
|
||||
if(smc.mission.pause) {
|
||||
if(this.spine) this.spine.paused=true
|
||||
if(this.anim) this.anim.pause()
|
||||
@@ -218,16 +237,17 @@ export class SkillCom extends CCComp {
|
||||
if(this.anim) this.anim.resume()
|
||||
if(this.spine) this.spine.paused=false
|
||||
if (!this.node || !this.node.isValid) return;
|
||||
if(config.EType==EType.timeEnd){
|
||||
|
||||
if(this.skillConfig.EType==EType.timeEnd){
|
||||
this.run_time+=deltaTime
|
||||
if(this.run_time>config.in){
|
||||
if(this.run_time>this.skillConfig.in){
|
||||
// //console.log("[SkillCom]: timeEnd destroy",this.s_uuid,this.run_time)
|
||||
this.is_destroy=true
|
||||
}
|
||||
}
|
||||
|
||||
//直线移动
|
||||
// if(this.AType == AType.linear) this.startLinearMove(deltaTime);
|
||||
// if(this.skillConfig.AType == AType.linear) this.startLinearMove(deltaTime);
|
||||
this.toDestroy();
|
||||
}
|
||||
|
||||
@@ -254,11 +274,11 @@ export class SkillCom extends CCComp {
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.is_destroy = false;
|
||||
this.AType = 0;
|
||||
this.speed = 0;
|
||||
this.startPos.set();
|
||||
this.targetPos.set();
|
||||
this.moveDirection = null; // 重置移动方向
|
||||
this.skillConfig = null; // 清除配置缓存
|
||||
this.isInitialized = false; // 重置初始化状态
|
||||
// 先移除所有碰撞回调
|
||||
const collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
|
||||
Reference in New Issue
Block a user