142 lines
4.5 KiB
TypeScript
142 lines
4.5 KiB
TypeScript
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact,Vec3, tween, math} 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 { BoxSet } from "../common/config/BoxSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { AnimType, endType } from "../common/config/SkillSet";
|
|
|
|
|
|
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;
|
|
t_pos:Vec3 = v3(0,0,0); // 目标增量
|
|
is_destroy:boolean = false;
|
|
enemys:any = [];
|
|
animType: number = 0; // 运动类型
|
|
endType: number = 0; // 结束类型
|
|
inTime: number = 0; // 持续时间
|
|
startPos: Vec3 = v3(); // 起始位置
|
|
targetPos: Vec3 = v3(); // 目标位置
|
|
duration: number = 0; // 技能持续时间
|
|
prefabName: string = ""; // 预制体名称
|
|
group:number = 0; //阵营
|
|
animName: string = ""; // 动画名称
|
|
|
|
|
|
start() {
|
|
oops.message.on(GameEvent.MissionEnd, this.doDestroy, this);
|
|
this.node.active = true;
|
|
|
|
// 根据动画类型开始相应的运动
|
|
this.startMovement();
|
|
}
|
|
|
|
private startMovement() {
|
|
switch(this.animType) {
|
|
case AnimType.linear:
|
|
this.startLinearMove();
|
|
break;
|
|
case AnimType.parabolic:
|
|
this.startBezierMove();
|
|
break;
|
|
case AnimType.fixed:
|
|
this.startFixedMove();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private startLinearMove() {
|
|
if (!this.targetPos) return;
|
|
|
|
const duration = Vec3.distance(this.node.position, this.targetPos) / this.speed;
|
|
|
|
tween(this.node)
|
|
.to(duration, { position: this.targetPos })
|
|
.call(() => {
|
|
if (this.endType === endType.distanceEnd) {
|
|
this.is_destroy = true;
|
|
}
|
|
})
|
|
.start();
|
|
}
|
|
|
|
private startBezierMove() {
|
|
if (!this.targetPos) return;
|
|
|
|
const startPos = this.node.position;
|
|
const endPos = this.targetPos;
|
|
const controlPos = v3(
|
|
(startPos.x + endPos.x) / 2,
|
|
Math.max(startPos.y, endPos.y) + 200
|
|
);
|
|
|
|
const duration = Vec3.distance(startPos, endPos) / this.speed;
|
|
|
|
tween(this.node)
|
|
.to(duration, {}, {
|
|
onUpdate: (target, ratio) => {
|
|
const pos = this.twoBezier(ratio, startPos, controlPos, endPos);
|
|
this.node.setPosition(pos);
|
|
}
|
|
})
|
|
.call(() => this.is_destroy = true)
|
|
.start();
|
|
}
|
|
|
|
private startFixedMove() {
|
|
if (this.endType === endType.timeEnd) {
|
|
tween(this.node)
|
|
.delay(this.inTime)
|
|
.call(() => this.is_destroy = true)
|
|
.start();
|
|
}
|
|
}
|
|
|
|
private twoBezier(t: number, p1: Vec3, cp: Vec3, p2: Vec3): Vec3 {
|
|
const x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
|
|
const y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
|
|
return v3(x, y, 0);
|
|
}
|
|
|
|
to_console(value:any,value2:any=null,value3:any=null){
|
|
console.log("["+this.s_name+this.s_uuid+"]:",value,value2,value3)
|
|
}
|
|
|
|
update(deltaTime: number) {
|
|
if(smc.mission.pause) return;
|
|
this.toDestroy();
|
|
}
|
|
toDestroy() {
|
|
if(this.is_destroy){
|
|
this.ent.destroy()
|
|
}
|
|
}
|
|
doDestroy(){
|
|
this.is_destroy=true
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.is_destroy=false
|
|
this.node.destroy();
|
|
this.animType = 0;
|
|
this.endType = 0;
|
|
this.speed = 0;
|
|
this.inTime = 0;
|
|
this.startPos.set();
|
|
this.targetPos.set();
|
|
}
|
|
|
|
} |