refactor(skill): 重构技能移动系统,整合移动逻辑到SMoveComp

将技能移动逻辑从SkillView迁移到SMoveComp,实现统一的移动管理
添加多种移动类型支持(线性、贝塞尔、固定位置)
优化移动参数配置,从SkillView获取攻击偏移量
This commit is contained in:
walkpan
2025-11-01 12:16:21 +08:00
parent ab03e32278
commit d014e63d27
5 changed files with 465 additions and 118 deletions

View File

@@ -3,7 +3,6 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroViewComp } from "../hero/HeroViewComp";
import { DTType, EType, RType, SkillConfig, SkillSet } from "../common/config/SkillSet";
import { BezierMove } from "../BezierMove/BezierMove";
import { BoxSet, FacSet } from "../common/config/BoxSet";
import { SDataCom } from "./SDataCom";
import { SMoveDataComp } from "./SMoveComp";
@@ -24,10 +23,6 @@ export class SkillView extends CCComp {
atk_x: number = 0
@property({ type: CCInteger })
atk_y: number = 0
@property({ type: CCInteger })
runType: RType = 0 //技能运行类型 0-线性 1-贝塞尔 2-开始位置固定 3-目标位置固定
@property({ type: CCInteger })
endType: EType = 0 //
anim:Animation=null;
group:number=0;
@@ -44,87 +39,30 @@ export class SkillView extends CCComp {
collider.group = this.group;
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
const SMove=this.ent.get(SMoveDataComp)
// 计算延长后的目标点坐标
switch(this.runType){
case RType.linear:
SMove.rePos(v3(this.node.position.x + this.atk_x, this.node.position.y + this.atk_y))
this.do_linear(SMove.startPos,SMove.targetPos)
break
case RType.bezier:
this.do_bezier(SMove.startPos,SMove.targetPos)
break
case RType.fixed:
this.do_fixedStart(SMove.startPos,SMove.targetPos)
break
case RType.fixedEnd:
this.do_fixedEnd(SMove.startPos,SMove.targetPos)
break
if(this.node.getComponent(Animation)){
let anim = this.node.getComponent(Animation);
//console.log("[SkillCom]:has anim",anim)
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
}
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
// console.log(this.scale+"碰撞开始 ",seCol,oCol);
if(this.endType!=EType.collision) return
if(this.SConf.EType!=EType.collision) return
let target = oCol.getComponent(HeroViewComp)
let model=target.ent.get(HeroAttrsComp)
if(model.is_dead) return
if(oCol.group!=this.group){
if(target == null) return;
if (!this.SConf) return;
if(this.endType==EType.collision){
if(this.SConf.EType==EType.collision){
this.apply_damage(target)
}
}
}
do_bezier(startPos:Vec3,targetPos:Vec3){
let bm=this.node.getComponent(BezierMove)
this.node.angle +=10
// bm.speed=700
if(this.group==BoxSet.MONSTER) {bm.controlPointSide=-1 }
bm.rotationSmoothness=0.6
bm.moveTo(targetPos)
}
do_linear(startPos:Vec3,targetPos:Vec3){
let bm=this.node.getComponent(BezierMove)
let s_x=startPos.x
let s_y=startPos.y
let t_x=targetPos.x
let t_y=targetPos.y
// 设定目标x
targetPos.x = 400;
if(this.group == BoxSet.MONSTER) {
bm.controlPointSide = -1;
targetPos.x = -400;
}
// 计算斜率
const k = (t_y - s_y) / (t_x - s_x);
// 按直线公式计算新的y
targetPos.y = k * (targetPos.x - s_x) + s_y;
bm.controlPointOffset=0
bm.rotationSmoothness=0.6
bm.moveTo(targetPos);
}
do_fixedEnd(startPos:Vec3,targetPos:Vec3){
this.node.setPosition(targetPos.x > 360?300:targetPos.x,this.node.position.y,0)
this.do_anim()
}
do_fixedStart(startPos:Vec3,targetPos:Vec3){
// console.log("do_fixedStart",startPos,targetPos)
this.node.setPosition(startPos.x,this.node.position.y,0)
this.do_anim()
}
do_anim(){
if(this.node.getComponent(Animation)){
let anim = this.node.getComponent(Animation);
//console.log("[SkillCom]:has anim",anim)
anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
}
onAnimationFinished(){
if(this.endType==EType.animationEnd){
if(this.SConf.EType==EType.animationEnd){
this.ent.destroy()
}
}
@@ -196,7 +134,7 @@ export class SkillView extends CCComp {
this.sData.hit_count++
// 检查技能是否应该销毁
if( this.sData.hit_count>=(this.SConf.hit+ this.sData.Attrs[Attrs.PUNCTURE])&&(this.SConf.DTType!=DTType.range)&&(this.endType!=EType.animationEnd)&&(this.endType!=EType.timeEnd)) this.ent.destroy// 技能命中次数
if( this.sData.hit_count>=(this.SConf.hit+ this.sData.Attrs[Attrs.PUNCTURE])&&(this.SConf.DTType!=DTType.range)&&(this.SConf.EType!=EType.animationEnd)&&(this.SConf.EType!=EType.timeEnd)) this.ent.destroy// 技能命中次数
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {