- 将HeroSkillsComp中的技能数组改为以s_uuid为键的对象存储 - 修改CSRequestComp使用s_uuid替代skillIndex - 优化SkillCastSystem和SACastSystem的施放逻辑 - 为SMoveDataComp添加rePos方法处理技能位置计算 - 移除未使用的SDataComSystem代码
116 lines
4.1 KiB
TypeScript
116 lines
4.1 KiB
TypeScript
import { _decorator, Animation, CCInteger, Collider2D, Contact2DType, v3, Vec3 } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
import { DTType, RType, SkillSet } from "../common/config/SkillSet";
|
|
import { BezierMove } from "../BezierMove/BezierMove";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { SDataCom } from "./SDataCom";
|
|
import { SMoveDataComp } from "./SMoveComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('SkillViewComp')
|
|
@ecs.register('SkillView', false)
|
|
export class SkillView extends CCComp {
|
|
/** 视图层逻辑代码分离演示 */
|
|
@property({ type: CCInteger })
|
|
atk_x: number = 0
|
|
@property({ type: CCInteger })
|
|
|
|
atk_y: number = 0
|
|
anim:Animation=null;
|
|
group:number=0;
|
|
SConf:any=null;
|
|
s_uuid:number=1001
|
|
start() {
|
|
this.SConf = SkillSet[this.s_uuid]
|
|
this.anim=this.node.getComponent(Animation)
|
|
this.node.active = true;
|
|
let collider = this.getComponent(Collider2D);
|
|
if(collider) {
|
|
collider.group = this.group;
|
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
const SMove=this.ent.get(SMoveDataComp)
|
|
// 计算延长后的目标点坐标
|
|
SMove.rePos(v3(this.node.position.x + this.atk_x, this.node.position.y + this.atk_y))
|
|
|
|
switch(this.SConf.RType){
|
|
case RType.linear:
|
|
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
|
|
}
|
|
|
|
}
|
|
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
|
// console.log(this.scale+"碰撞开始 ",seCol,oCol);
|
|
if(seCol.node.position.x-oCol.node.position.x > 100 ) return
|
|
let target = oCol.getComponent(HeroViewComp)
|
|
if(oCol.group!=this.group){
|
|
if(target == null) return;
|
|
if (!this.SConf) return;
|
|
}
|
|
}
|
|
|
|
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){
|
|
this.node.setPosition(startPos.x > 360?300: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(){
|
|
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |