技能组件修改,由skillcom统一负责动画,只负责动画
This commit is contained in:
@@ -21,58 +21,40 @@ export class Skill extends ecs.Entity {
|
||||
this.remove(SkillCom);
|
||||
super.destroy();
|
||||
}
|
||||
load(pos: Vec3 = Vec3.ZERO,group:number,parent:Node,uuid:number=1001,
|
||||
ap:number =10,t_pos:Vec3 = null,is_crit:boolean=false,crit_add:number=0,hp:number=0,lv:number=1)
|
||||
{
|
||||
var path = "game/skills/"+SkillSet[uuid].sp_name;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
console.log("load skill pos:",pos)
|
||||
var node = instantiate(prefab);
|
||||
if(SkillSet[uuid].with){node.parent = parent;t_pos=v3(0,0)}
|
||||
if(!SkillSet[uuid].with){node.parent = parent.parent;}
|
||||
|
||||
node.setPosition(pos)
|
||||
var sv = node.getComponent(SkillCom);
|
||||
if(group==BoxSet.MONSTER) {
|
||||
sv.scale=-1
|
||||
node.setScale(v3(sv.scale*node.scale.x,node.scale.y));
|
||||
}
|
||||
// let angle=0
|
||||
// if(SkillSet[uuid].angle){
|
||||
// angle = Math.atan2(t_pos.y,t_pos.x) * 180 / Math.PI;
|
||||
// if(t_pos.x<0){
|
||||
// angle+=180
|
||||
// }
|
||||
// }
|
||||
// sv.angle = angle;
|
||||
// console.log(group+" "+SkillSet[uuid].name+"angle:"+angle)
|
||||
sv.s_uuid = uuid;
|
||||
sv.s_name = SkillSet[uuid].name;
|
||||
sv.hero = SkillSet[uuid].hero;
|
||||
sv.lv=lv
|
||||
sv.ap = ap*SkillSet[uuid].ap/100; // 技能伤害
|
||||
sv.def = ap*SkillSet[uuid].def/100; // 技能伤害
|
||||
sv.apup = ap*SkillSet[uuid].apup/100; // 伤害增量
|
||||
sv.hp = hp*SkillSet[uuid].hp/100; // 回复hp增量
|
||||
sv.mhp = SkillSet[uuid].mhp/100; // hpmax增量 %
|
||||
sv.shield =SkillSet[uuid].shield; // 护甲增量
|
||||
sv.cd = SkillSet[uuid].cd;
|
||||
sv.tg = SkillSet[uuid].tg;
|
||||
sv.debtime = SkillSet[uuid].debtime;
|
||||
sv.debuff = SkillSet[uuid].debuff;
|
||||
sv.depb = SkillSet[uuid].depb;
|
||||
sv.derate = SkillSet[uuid].derate;
|
||||
sv.is_crit=is_crit
|
||||
sv.crit_add=crit_add
|
||||
// node.setScale(v3(node.scale.x*scale,node.scale.y))
|
||||
sv.speed=SkillSet[uuid].speed;
|
||||
sv.in_time=SkillSet[uuid].in;
|
||||
|
||||
sv.t_pos = t_pos; // 目标增量
|
||||
sv.type = SkillSet[uuid].type;
|
||||
sv.box_tag= BoxSet.SKILL_TAG;
|
||||
sv.box_group=group
|
||||
// console.log("load skill :",sv)
|
||||
this.add(sv);
|
||||
load(
|
||||
startPos: Vec3, // 起始位置
|
||||
group: number, // 阵营
|
||||
parent: Node, // 父节点
|
||||
uuid: number, // 技能ID
|
||||
targetPos: Vec3 // 目标位置
|
||||
) {
|
||||
const config = SkillSet[uuid];
|
||||
if (!config) return;
|
||||
|
||||
// 加载预制体
|
||||
const path = `game/skills/${config.sp_name}`;
|
||||
const prefab = oops.res.get(path, Prefab);
|
||||
const node = instantiate(prefab);
|
||||
|
||||
// 设置节点属性
|
||||
node.parent = parent;
|
||||
node.setPosition(startPos);
|
||||
|
||||
// 添加技能组件
|
||||
const skillComp = node.getComponent(SkillCom);
|
||||
this.add(skillComp);
|
||||
|
||||
// 初始化技能参数
|
||||
skillComp.animType = config.AnimType;
|
||||
skillComp.endType = config.endType;
|
||||
skillComp.speed = config.speed;
|
||||
skillComp.duration = config.in;
|
||||
skillComp.startPos = startPos.clone();
|
||||
skillComp.targetPos = targetPos.clone();
|
||||
skillComp.prefabName = config.sp_name;
|
||||
skillComp.group = group;
|
||||
|
||||
// 初始化动画名称
|
||||
skillComp.animName = config.animName; // 从配置获取动画名称
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,57 +7,117 @@ import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/
|
||||
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('SkillView', false)
|
||||
@ecs.register('SkillCom')
|
||||
export class SkillCom extends CCComp {
|
||||
s_uuid:number = 0;
|
||||
s_name:string = "";
|
||||
hero:number = 0;
|
||||
speed:number = 200;
|
||||
scale:number = 1;
|
||||
lv:number = 1;
|
||||
ap:number = 10;
|
||||
def:number = 10;
|
||||
apup:number = 0;//
|
||||
mhp:number = 0;
|
||||
hp:number = 0; //治疗总量
|
||||
shield:number = 0;//护甲总量
|
||||
cd:number = 1;
|
||||
debuff:number = 0;
|
||||
debtime:number = 0;
|
||||
depb:number = 0;
|
||||
derate:number = 0;
|
||||
atk_count:number = 0;
|
||||
is_crit:boolean = false;
|
||||
crit_add: number = 0;//暴击伤害加成
|
||||
angle:number = 0;
|
||||
t_pos:Vec3 = v3(0,0,0); // 目标增量
|
||||
is_destroy:boolean = false;
|
||||
box_group:number = 0;
|
||||
box_tag:number=0;
|
||||
type:number = 1;
|
||||
run:number = 0;
|
||||
tg:number = 3;
|
||||
in_time:number = 0.3; // 不动技能持续时间
|
||||
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.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()
|
||||
|
||||
if(smc.mission.pause) return;
|
||||
this.toDestroy();
|
||||
}
|
||||
toDestroy() {
|
||||
if(this.is_destroy){
|
||||
@@ -71,6 +131,12 @@ export class SkillCom extends CCComp {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
143
assets/script/game/skills/SkillSystem.ts
Normal file
143
assets/script/game/skills/SkillSystem.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { _decorator, Vec3, v3, tween } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { SkillCom } from "./SkillCom";
|
||||
import { SkillSet, AnimType, endType } from "../common/config/SkillSet";
|
||||
import { Animation, sp } from "cc";
|
||||
|
||||
/** 技能运动系统 */
|
||||
@ecs.register('SkillSystem')
|
||||
export class SkillSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(SkillCom);
|
||||
}
|
||||
|
||||
|
||||
|
||||
update(entity: ecs.Entity) {
|
||||
const skill = entity.get(SkillCom);
|
||||
if (!skill || skill.is_destroy) return;
|
||||
|
||||
this.updateSkillMovement(skill);
|
||||
this.checkDestroy(skill);
|
||||
}
|
||||
|
||||
private updateSkillMovement(skill: SkillCom) {
|
||||
switch(skill.animType) {
|
||||
case AnimType.linear:
|
||||
this.linearMove(skill);
|
||||
break;
|
||||
case AnimType.parabolic:
|
||||
this.bezierMove(skill);
|
||||
break;
|
||||
case AnimType.fixed:
|
||||
this.fixedMove(skill);
|
||||
break;
|
||||
default:
|
||||
console.warn(`未知运动类型: ${skill.animType}`);
|
||||
}
|
||||
}
|
||||
|
||||
private checkDestroy(skill: SkillCom) {
|
||||
let shouldDestroy = false;
|
||||
|
||||
switch(skill.endType) {
|
||||
case endType.animationEnd:
|
||||
// 同时检测普通动画和Spine动画
|
||||
const anim = skill.node.getComponent(Animation);
|
||||
const spine = skill.node.getComponentInChildren(sp.Skeleton);
|
||||
|
||||
if (anim) {
|
||||
const state = anim.getState(skill.animName);
|
||||
shouldDestroy = state?.isPlaying === false;
|
||||
}
|
||||
else if (spine) {
|
||||
shouldDestroy = spine.animation === 'end';
|
||||
}
|
||||
break;
|
||||
case endType.timeEnd:
|
||||
skill.duration -= this.dt;
|
||||
shouldDestroy = skill.duration <= 0;
|
||||
break;
|
||||
case endType.distanceEnd:
|
||||
shouldDestroy = skill.targetPos &&
|
||||
Vec3.distance(skill.node.position, skill.targetPos) < 10;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shouldDestroy) {
|
||||
skill.is_destroy = true;
|
||||
skill.node.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private linearMove(skill: SkillCom) {
|
||||
if (!skill.targetPos) return;
|
||||
|
||||
// 计算移动方向
|
||||
const dir = skill.targetPos.clone().subtract(skill.node.position).normalize();
|
||||
|
||||
// 计算新位置
|
||||
const newPos = skill.node.position.clone().add(
|
||||
dir.multiplyScalar(skill.speed * this.dt)
|
||||
);
|
||||
|
||||
// 更新位置和角度
|
||||
skill.node.setPosition(newPos);
|
||||
|
||||
// 自动处理距离销毁
|
||||
if (skill.endType === endType.distanceEnd) {
|
||||
const remaining = Vec3.distance(newPos, skill.targetPos);
|
||||
if (remaining < 10) {
|
||||
skill.is_destroy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bezierMove(skill: SkillCom) {
|
||||
if (!skill.targetPos) return;
|
||||
|
||||
// 计算控制点(拱顶位置)
|
||||
const startPos = skill.startPos;
|
||||
const endPos = skill.targetPos;
|
||||
const controlHeight = Math.max(startPos.y, endPos.y) + 200;
|
||||
const controlPos = v3(
|
||||
(startPos.x + endPos.x) / 2,
|
||||
controlHeight
|
||||
);
|
||||
|
||||
// 计算当前进度
|
||||
skill.duration += this.dt * skill.speed;
|
||||
const t = skill.duration / skill.inTime;
|
||||
|
||||
// 使用二阶贝塞尔曲线公式计算位置
|
||||
const newPos = this.twoBezier(t, startPos, controlPos, endPos);
|
||||
|
||||
skill.node.setPosition(newPos);
|
||||
|
||||
// 自动结束判断
|
||||
if (t >= 1) {
|
||||
skill.is_destroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private fixedMove(skill: SkillCom) {
|
||||
// 仅处理时间结束逻辑
|
||||
skill.duration += this.dt * skill.speed;
|
||||
|
||||
// 示例:在固定位置播放动画
|
||||
if (skill.endType === endType.timeEnd && skill.duration >= skill.inTime) {
|
||||
skill.is_destroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
9
assets/script/game/skills/SkillSystem.ts.meta
Normal file
9
assets/script/game/skills/SkillSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "02c5af20-5daa-4384-bcc4-c4c73d827ab7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user