refactor(技能系统): 重构技能系统以使用s_uuid作为主键并优化技能施放逻辑
- 将HeroSkillsComp中的技能数组改为以s_uuid为键的对象存储 - 修改CSRequestComp使用s_uuid替代skillIndex - 优化SkillCastSystem和SACastSystem的施放逻辑 - 为SMoveDataComp添加rePos方法处理技能位置计算 - 移除未使用的SDataComSystem代码
This commit is contained in:
@@ -18,16 +18,16 @@ export class SDataCom extends ecs.Comp {
|
||||
}
|
||||
}
|
||||
|
||||
/** 业务层业务逻辑处理对象 */
|
||||
export class SDataComSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(SDataCom);
|
||||
}
|
||||
// /** 业务层业务逻辑处理对象 */
|
||||
// export class SDataComSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
|
||||
// filter(): ecs.IMatcher {
|
||||
// return ecs.allOf(SDataCom);
|
||||
// }
|
||||
|
||||
entityEnter(e: ecs.Entity): void {
|
||||
// 注:自定义业务逻辑
|
||||
// entityEnter(e: ecs.Entity): void {
|
||||
// // 注:自定义业务逻辑
|
||||
|
||||
|
||||
e.remove(SDataCom);
|
||||
}
|
||||
}
|
||||
// e.remove(SDataCom);
|
||||
// }
|
||||
// }
|
||||
@@ -2,6 +2,7 @@ import { Vec3, v3 } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BezierMove } from "../BezierMove/BezierMove";
|
||||
import { RType, SkillSet } from "../common/config/SkillSet";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
/**
|
||||
* 技能移动数据组件
|
||||
* 存储技能实体的移动相关数据
|
||||
@@ -29,6 +30,21 @@ export class SMoveDataComp extends ecs.Comp {
|
||||
this.direction.set(0, 0, 0);
|
||||
this.autoDestroy = true;
|
||||
}
|
||||
rePos(originalStart:Vec3){
|
||||
if(!originalStart){
|
||||
return
|
||||
}
|
||||
// 计算延长后的目标点坐标
|
||||
const originalTarget = v3(this.targetPos.x, this.targetPos.y + BoxSet.ATK_Y);
|
||||
const direction = new Vec3();
|
||||
Vec3.subtract(direction, originalTarget, originalStart);
|
||||
const distance = direction.length();
|
||||
direction.normalize();
|
||||
const extendedTarget = new Vec3();
|
||||
Vec3.scaleAndAdd(extendedTarget, originalTarget, direction, 720);
|
||||
this.startPos.set(originalStart);
|
||||
this.targetPos.set(extendedTarget);
|
||||
}
|
||||
}
|
||||
|
||||
// /** 业务层业务逻辑处理对象 */
|
||||
|
||||
@@ -12,13 +12,13 @@ import { Vec3 } from "cc";
|
||||
@ecs.register('CSRequest')
|
||||
export class CSRequestComp extends ecs.Comp {
|
||||
/** 技能索引(在 HeroSkillsComp.skills 中的位置) */
|
||||
skillIndex: number = 0;
|
||||
s_uuid: number = 0;
|
||||
|
||||
/** 目标位置数组(由请求者提供) */
|
||||
targets: Vec3[] = [];
|
||||
|
||||
reset() {
|
||||
this.skillIndex = 0;
|
||||
this.s_uuid = 0;
|
||||
this.targets = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { SkillView } from "./SkillView";
|
||||
import { SDataCom } from "./SDataCom";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { SMoveDataComp } from "../skill/SMoveComp";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
|
||||
/** Skill 模块 */
|
||||
@ecs.register(`Skill`)
|
||||
@@ -32,10 +33,12 @@ export class Skill extends ecs.Entity {
|
||||
this.addComponents<SDataCom>();
|
||||
this.addComponents<SMoveDataComp>();
|
||||
}
|
||||
load(startPos: Vec3, parent: Node, uuid: number, targetPos: Vec3,casterAttrs:Attrs[]=[],scale:number=1,fac:FacSet=FacSet.MON,type:HType=HType.warrior,box_group:BoxSet=BoxSet.HERO) {
|
||||
const config = SkillSet[uuid];
|
||||
load(startPos: Vec3, parent: Node, s_uuid: number, targetPos: Vec3,
|
||||
caster:HeroViewComp) {
|
||||
const config = SkillSet[s_uuid];
|
||||
let casterAttrs=caster.ent.get(HeroAttrsComp).Attrs
|
||||
if (!config) {
|
||||
console.error("[Skill] 技能配置不存在:", uuid);
|
||||
console.error("[Skill] 技能配置不存在:", s_uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,32 +56,35 @@ export class Skill extends ecs.Entity {
|
||||
// 设置节点属性
|
||||
node.setPosition(startPos);
|
||||
|
||||
if(fac==FacSet.MON){
|
||||
if(casterAttrs.fac==FacSet.MON){
|
||||
node.scale=v3(node.scale.x*-1,1,1)
|
||||
}else{
|
||||
if(type==HType.warrior){
|
||||
if(scale<0){
|
||||
if(casterAttrs.type==HType.warrior){
|
||||
if(casterAttrs.node.scale<0){
|
||||
node.scale=v3(node.scale.x*-1,node.scale.y,1)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加技能组件
|
||||
const SView = node.getComponent(SkillView); // 初始化技能参数
|
||||
// 初始视图
|
||||
const SView = node.getComponent(SkillView);
|
||||
// 只设置必要的运行时属性,配置信息通过 SkillSet[uuid] 访问
|
||||
// 核心标识
|
||||
SView.s_uuid= uuid
|
||||
SView.group= box_group
|
||||
SView.s_uuid= s_uuid
|
||||
SView.group= caster.box_group
|
||||
|
||||
this.add(SView);
|
||||
|
||||
|
||||
const sDataCom = this.get(SDataCom);
|
||||
// 初始化移动组件
|
||||
const sMoveCom = this.get(SMoveDataComp);
|
||||
sMoveCom.startPos=startPos
|
||||
sMoveCom.targetPos=targetPos
|
||||
sMoveCom.s_uuid=uuid
|
||||
sDataCom.group=box_group
|
||||
sMoveCom.s_uuid=s_uuid
|
||||
|
||||
// 初始化数据组件
|
||||
const sDataCom = this.get(SDataCom);
|
||||
sDataCom.group=caster.box_group
|
||||
sDataCom.caster=caster
|
||||
sDataCom.attrs=casterAttrs
|
||||
sDataCom.s_uuid=uuid
|
||||
sDataCom.s_uuid=s_uuid
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { _decorator, Animation, Collider2D, Contact2DType, Vec3 } from "cc";
|
||||
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";
|
||||
@@ -15,6 +15,11 @@ const { ccclass, property } = _decorator;
|
||||
@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;
|
||||
@@ -29,6 +34,9 @@ export class SkillView extends CCComp {
|
||||
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)
|
||||
@@ -54,6 +62,7 @@ export class SkillView extends CCComp {
|
||||
if (!this.SConf) return;
|
||||
}
|
||||
}
|
||||
|
||||
do_bezier(startPos:Vec3,targetPos:Vec3){
|
||||
let bm=this.node.getComponent(BezierMove)
|
||||
this.node.angle +=10
|
||||
|
||||
Reference in New Issue
Block a user