开始英雄技能系统,负责英雄技能的释放
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"ver": "4.0.23",
|
"ver": "4.0.23",
|
||||||
"importer": "typescript",
|
"importer": "typescript",
|
||||||
"imported": true,
|
"imported": true,
|
||||||
"uuid": "c927f5c9-45cb-4400-8734-c706e615e4a4",
|
"uuid": "8cc0af1b-f8d6-420f-b1c3-9b1f735a843d",
|
||||||
"files": [],
|
"files": [],
|
||||||
"subMetas": {},
|
"subMetas": {},
|
||||||
"userData": {}
|
"userData": {}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
@ecs.register('BattleMove')
|
@ecs.register('BattleMove')
|
||||||
|
|
||||||
export class BattleMoveComp extends ecs.Comp {
|
export class BattleMoveComp extends ecs.Comp {
|
||||||
/** 移动方向:1向右,-1向左 */
|
/** 移动方向:1向右,-1向左 */
|
||||||
direction: number = 1;
|
direction: number = 1;
|
||||||
|
|||||||
@@ -1,17 +1,8 @@
|
|||||||
/*
|
|
||||||
* @Author: dgflash
|
|
||||||
* @Date: 2021-08-11 16:41:12
|
|
||||||
* @LastEditors: dgflash
|
|
||||||
* @LastEditTime: 2022-07-25 17:05:02
|
|
||||||
*/
|
|
||||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { BattleMoveSystem } from "./BattleMoveSystem";
|
import { BattleMoveSystem } from "./BattleMoveSystem";
|
||||||
import { MoveToSystem } from "./MoveTo";
|
|
||||||
|
|
||||||
export class EcsPositionSystem extends ecs.System {
|
export class EcsPositionSystem extends ecs.System {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.add(new MoveToSystem());
|
|
||||||
this.add(new BattleMoveSystem());
|
this.add(new BattleMoveSystem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* @Author: dgflash
|
|
||||||
* @Date: 2021-08-11 16:41:12
|
|
||||||
* @LastEditors: dgflash
|
|
||||||
* @LastEditTime: 2023-01-19 15:27:24
|
|
||||||
*/
|
|
||||||
import { Node, Vec3 } from "cc";
|
|
||||||
import { Timer } from "../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
||||||
import { Vec3Util } from "../../../../../../extensions/oops-plugin-framework/assets/core/utils/Vec3Util";
|
|
||||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
||||||
|
|
||||||
/** 向目标移动,移动过程中目标位置变化会自动修正移动目标点,直到未修正前移动到目标点停止 */
|
|
||||||
@ecs.register('MoveTo')
|
|
||||||
export class MoveToComp extends ecs.Comp {
|
|
||||||
/** 移动节点 */
|
|
||||||
node: Node = null!;
|
|
||||||
/** 移动方向 */
|
|
||||||
velocity: Vec3 = Vec3Util.zero;
|
|
||||||
/** 移动速度(每秒移动的像素距离) */
|
|
||||||
speed: number = 0;
|
|
||||||
/** 目标实体ECS编号、目标位置 */
|
|
||||||
target: Vec3 | Node | null = null;
|
|
||||||
|
|
||||||
/** 坐标标(默认本地坐标) */
|
|
||||||
ns: number = Node.NodeSpace.LOCAL;
|
|
||||||
/** 偏移距离 */
|
|
||||||
offset: number = 0;
|
|
||||||
/** 偏移向量 */
|
|
||||||
offsetVector: Vec3 | null = null;
|
|
||||||
/** 移动完成回调 */
|
|
||||||
onComplete: Function | null = null;
|
|
||||||
/** 距离变化时 */
|
|
||||||
onChange: Function | null = null;
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.ns = Node.NodeSpace.LOCAL;
|
|
||||||
this.offset = 0;
|
|
||||||
this.target = null;
|
|
||||||
this.offsetVector = null;
|
|
||||||
this.onComplete = null;
|
|
||||||
this.onChange = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ecs.register('VariableMoveTo')
|
|
||||||
class VariableMoveToComponent extends ecs.Comp {
|
|
||||||
/** 延时触发器 */
|
|
||||||
timer: Timer = new Timer();
|
|
||||||
/** 终点备份 */
|
|
||||||
end: Vec3 | null = null;
|
|
||||||
/** 目标位置 */
|
|
||||||
target!: Vec3;
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.end = null;
|
|
||||||
this.timer.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 跟踪移动到目标位置 */
|
|
||||||
export class MoveToSystem extends ecs.ComblockSystem<ecs.Entity> implements ecs.IEntityEnterSystem, ecs.IEntityRemoveSystem, ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(MoveToComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
entityEnter(e: ecs.Entity): void {
|
|
||||||
e.add(VariableMoveToComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
entityRemove(e: ecs.Entity): void {
|
|
||||||
e.remove(VariableMoveToComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity) {
|
|
||||||
let move = e.get(MoveToComp);
|
|
||||||
let mtv = e.get(VariableMoveToComponent);
|
|
||||||
let end: Vec3;
|
|
||||||
|
|
||||||
console.assert(move.speed > 0, "移动速度必须要大于零");
|
|
||||||
|
|
||||||
if (move.target instanceof Node) {
|
|
||||||
end = move.ns == Node.NodeSpace.WORLD ? move.target.worldPosition : move.target.position;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
end = move.target as Vec3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 目标移动后,重计算移动方向与移动到目标点的速度
|
|
||||||
if (mtv.end == null || !mtv.end.strictEquals(end)) {
|
|
||||||
let target = end.clone();
|
|
||||||
if (move.offsetVector) {
|
|
||||||
target = target.add(move.offsetVector); // 这里的问题
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移动方向与移动数度
|
|
||||||
let start = move.ns == Node.NodeSpace.WORLD ? move.node.worldPosition : move.node.position;
|
|
||||||
move.velocity = Vec3Util.sub(target, start).normalize();
|
|
||||||
|
|
||||||
// 移动时间与目标偏位置计算
|
|
||||||
let distance = Vec3.distance(start, target) - move.offset;
|
|
||||||
|
|
||||||
move.onChange?.call(this);
|
|
||||||
|
|
||||||
if (distance - move.offset <= 0) {
|
|
||||||
this.exit(e);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mtv.timer.step = distance / move.speed;
|
|
||||||
mtv.end = end.clone();
|
|
||||||
mtv.target = move.velocity.clone().multiplyScalar(distance).add(start);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (move.speed > 0) {
|
|
||||||
let trans = Vec3Util.mul(move.velocity, move.speed * this.dt);
|
|
||||||
move.node.translate(trans, Node.NodeSpace.LOCAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移动完成事件
|
|
||||||
if (mtv.timer.update(this.dt)) {
|
|
||||||
if (move.ns == Node.NodeSpace.WORLD)
|
|
||||||
move.node.worldPosition = mtv.target;
|
|
||||||
else
|
|
||||||
move.node.position = mtv.target;
|
|
||||||
|
|
||||||
this.exit(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private exit(e: ecs.Entity) {
|
|
||||||
let move = e.get(MoveToComp);
|
|
||||||
move.onComplete?.call(this);
|
|
||||||
e.remove(VariableMoveToComponent);
|
|
||||||
e.remove(MoveToComp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,27 +7,27 @@ import { HeroViewComp } from "./HeroViewComp";
|
|||||||
import { BoxSet } from "../common/config/BoxSet";
|
import { BoxSet } from "../common/config/BoxSet";
|
||||||
import { HeroInfo } from "../common/config/heroSet";
|
import { HeroInfo } from "../common/config/heroSet";
|
||||||
import { Talents } from "../common/config/TalentSet";
|
import { Talents } from "../common/config/TalentSet";
|
||||||
import { SkillsComp } from "../skill/SkillSystem";
|
|
||||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||||
|
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||||
/** 角色实体 */
|
/** 角色实体 */
|
||||||
@ecs.register(`Hero`)
|
@ecs.register(`Hero`)
|
||||||
|
|
||||||
export class Hero extends ecs.Entity {
|
export class Hero extends ecs.Entity {
|
||||||
HeroModel!: HeroModelComp;
|
HeroModel!: HeroModelComp;
|
||||||
HeroView!: HeroViewComp;
|
HeroView!: HeroViewComp;
|
||||||
Skills!: SkillsComp;
|
|
||||||
BattleMove!: BattleMoveComp;
|
BattleMove!: BattleMoveComp;
|
||||||
|
HeroSkills!: HeroSkillsComp;
|
||||||
|
|
||||||
protected init() {
|
protected init() {
|
||||||
this.addComponents<ecs.Comp>(
|
this.addComponents<ecs.Comp>(
|
||||||
SkillsComp,
|
BattleMoveComp,
|
||||||
BattleMoveComp
|
HeroSkillsComp,
|
||||||
|
HeroModelComp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.remove(HeroViewComp);
|
this.remove(HeroViewComp);;
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,6 @@ export class Hero extends ecs.Entity {
|
|||||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,is_call:boolean=false,lv:number=1) {
|
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,is_call:boolean=false,lv:number=1) {
|
||||||
scale = 1
|
scale = 1
|
||||||
let box_group=BoxSet.HERO
|
let box_group=BoxSet.HERO
|
||||||
this.addComponents<ecs.Comp>( HeroModelComp);
|
|
||||||
var path = "game/heros/"+HeroInfo[uuid].path;
|
var path = "game/heros/"+HeroInfo[uuid].path;
|
||||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||||
var node = instantiate(prefab);
|
var node = instantiate(prefab);
|
||||||
@@ -99,13 +98,11 @@ export class Hero extends ecs.Entity {
|
|||||||
this.add(hv);
|
this.add(hv);
|
||||||
|
|
||||||
// 初始化多个技能组件
|
// 初始化多个技能组件
|
||||||
const skills = this.get(SkillsComp);
|
|
||||||
|
|
||||||
// 初始化移动参数
|
// 初始化移动参数
|
||||||
const move = this.get(BattleMoveComp);
|
const move = this.get(BattleMoveComp);
|
||||||
move.direction = 1; // 向右移动
|
move.direction = 1; // 向右移动
|
||||||
move.targetX = 800; // 右边界
|
move.targetX = 800; // 右边界
|
||||||
console.log("hero_init",skills,move);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { HeroViewComp } from "./HeroViewComp";
|
|||||||
import { BoxSet } from "../common/config/BoxSet";
|
import { BoxSet } from "../common/config/BoxSet";
|
||||||
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
||||||
import { HeroInfo } from "../common/config/heroSet";
|
import { HeroInfo } from "../common/config/heroSet";
|
||||||
import { MoveToComp } from "../common/ecs/position/MoveTo";
|
|
||||||
import { Talents } from "../common/config/TalentSet";
|
import { Talents } from "../common/config/TalentSet";
|
||||||
import { MonModelComp } from "./MonModelComp";
|
import { MonModelComp } from "./MonModelComp";
|
||||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||||
@@ -36,7 +35,6 @@ export class Monster extends ecs.Entity {
|
|||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.remove(HeroViewComp);
|
this.remove(HeroViewComp);
|
||||||
this.remove(MoveToComp);
|
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { SkillSystem } from "./SkillSystem";
|
import { HeroSkillSystem } from "./HeroSkillSystem";
|
||||||
import { SkillAnimationSystem } from "./SkillAnimation";
|
|
||||||
export class EcsSkillSystem extends ecs.System {
|
export class EcsSkillSystem extends ecs.System {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.add(new SkillSystem());
|
this.add(new HeroSkillSystem());
|
||||||
this.add(new SkillAnimationSystem());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
assets/script/game/skill/HeroSkillSystem.ts
Normal file
26
assets/script/game/skill/HeroSkillSystem.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Node, Vec3 } from "cc";
|
||||||
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
|
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||||
|
import { HeroSkillsComp } from "./heroSkillsComp";
|
||||||
|
|
||||||
|
|
||||||
|
/** 技能系统 */
|
||||||
|
@ecs.register('HeroSkillSystem')
|
||||||
|
export class HeroSkillSystem extends ecs.ComblockSystem<ecs.Entity> implements ecs.ISystemUpdate {
|
||||||
|
filter(): ecs.IMatcher {
|
||||||
|
return ecs.allOf(HeroSkillsComp, HeroViewComp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
update(e: ecs.Entity) {
|
||||||
|
let skills = e.get(HeroSkillsComp);
|
||||||
|
let view = e.get(HeroViewComp);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"ver": "4.0.23",
|
"ver": "4.0.23",
|
||||||
"importer": "typescript",
|
"importer": "typescript",
|
||||||
"imported": true,
|
"imported": true,
|
||||||
"uuid": "eb55eb50-dace-4e75-8965-3475c0b11835",
|
"uuid": "36448c83-0bd9-495b-806d-6e7d640370e3",
|
||||||
"files": [],
|
"files": [],
|
||||||
"subMetas": {},
|
"subMetas": {},
|
||||||
"userData": {}
|
"userData": {}
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import { Vec3 } from "cc";
|
|
||||||
import { ecs } from "db://oops-framework/libs/ecs/ECS";
|
|
||||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
||||||
|
|
||||||
// 投射物组件
|
|
||||||
@ecs.register('Projectile')
|
|
||||||
export class ProjectileComp extends ecs.Comp {
|
|
||||||
speed: number = 500; // 飞行速度
|
|
||||||
direction: Vec3 = Vec3.RIGHT;// 飞行方向
|
|
||||||
maxDistance: number = 1000; // 最大射程
|
|
||||||
traveled: number = 0; // 已飞行距离
|
|
||||||
penetrate: number = 3; // 穿透次数
|
|
||||||
targets = new Set<ecs.Entity>(); // 已命中目标
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.speed = 500;
|
|
||||||
this.direction.set(Vec3.RIGHT);
|
|
||||||
this.maxDistance = 1000;
|
|
||||||
this.traveled = 0;
|
|
||||||
this.penetrate = 3;
|
|
||||||
this.targets.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 投射物系统
|
|
||||||
@ecs.register('ProjectileSystem')
|
|
||||||
export class ProjectileSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(ProjectileComp, HeroViewComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
|
||||||
const proj = e.get(ProjectileComp);
|
|
||||||
const view = e.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 移动计算
|
|
||||||
const delta = proj.direction.multiplyScalar(proj.speed * this.dt);
|
|
||||||
view.node.position = view.node.position.add(delta);
|
|
||||||
proj.traveled += delta.length();
|
|
||||||
|
|
||||||
// 碰撞检测(使用ECS组件检测)
|
|
||||||
this.checkCollision(e);
|
|
||||||
|
|
||||||
// 超出射程销毁
|
|
||||||
if (proj.traveled >= proj.maxDistance) {
|
|
||||||
e.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private checkCollision(e: ecs.Entity) {
|
|
||||||
const proj = e.get(ProjectileComp);
|
|
||||||
const view = e.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 获取范围内所有敌人
|
|
||||||
// const enemies = ecs.getEntities(HeroViewComp).filter(entity => {
|
|
||||||
// const enemyView = entity.get(HeroViewComp);
|
|
||||||
// return enemyView.boxGroup !== view.boxGroup &&
|
|
||||||
// Vec3.distance(view.node.position, enemyView.node.position) <= 50; // 碰撞半径
|
|
||||||
// });
|
|
||||||
|
|
||||||
// enemies.forEach(enemy => {
|
|
||||||
// if (!proj.targets.has(enemy)) {
|
|
||||||
// this.applyDamage(e, enemy);
|
|
||||||
// proj.targets.add(enemy);
|
|
||||||
// proj.penetrate--;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (proj.penetrate <= 0) {
|
|
||||||
e.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private applyDamage(projectile: ecs.Entity, target: ecs.Entity) {
|
|
||||||
const projView = projectile.get(HeroViewComp);
|
|
||||||
const targetView = target.get(HeroViewComp);
|
|
||||||
// targetView.takeDamage(projView.attack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import { ecs ,} from "db://oops-framework/libs/ecs/ECS";
|
|
||||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
||||||
import { SkillsComp } from "./SkillSystem";
|
|
||||||
import { SkillSet } from "../common/config/SkillSet";
|
|
||||||
import { Node } from "cc";
|
|
||||||
|
|
||||||
// 动画组件
|
|
||||||
@ecs.register('SkillAnimation')
|
|
||||||
export class SkillAnimationComp extends ecs.Comp {
|
|
||||||
prefab: Node | null = null; // 预制体实例
|
|
||||||
damageTriggerTime = 0.3; // 伤害触发时间(秒)
|
|
||||||
elapsed = 0; // 已播放时间
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.prefab?.destroy();
|
|
||||||
this.prefab = null;
|
|
||||||
this.damageTriggerTime = 0.3;
|
|
||||||
this.elapsed = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 动画系统
|
|
||||||
@ecs.register('SkillAnimationSystem')
|
|
||||||
export class SkillAnimationSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(SkillAnimationComp, HeroViewComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
|
||||||
const anim = e.get(SkillAnimationComp);
|
|
||||||
anim.elapsed += this.dt;
|
|
||||||
|
|
||||||
// 伤害触发检测
|
|
||||||
// if (!anim.hitted && anim.elapsed >= anim.hitTime) {
|
|
||||||
// this.applyDamage(e);
|
|
||||||
// anim.hitted = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 更新动画状态
|
|
||||||
// if (anim.elapsed >= anim.duration) {
|
|
||||||
// e.remove(SkillAnimationComp);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private applyDamage(e: ecs.Entity) {
|
|
||||||
const skill = e.get(SkillsComp);
|
|
||||||
const view = e.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 添加伤害标记组件
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在角色组件中实现目标查找
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
import { Node, Vec3 } from "cc";
|
|
||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
||||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
|
||||||
import { SkillSet } from "../common/config/SkillSet";
|
|
||||||
import { SkillAnimationComp } from "./SkillAnimation";
|
|
||||||
import { ProjectileComp } from "./ProjectileComp";
|
|
||||||
|
|
||||||
/** 技能触发组件 */
|
|
||||||
@ecs.register('HerosSkills')
|
|
||||||
export class SkillsComp extends ecs.Comp {
|
|
||||||
/** 技能ID */
|
|
||||||
skillId: number = 0;
|
|
||||||
/** 目标位置/实体 */
|
|
||||||
target: Vec3 | Node | null = null;
|
|
||||||
/** 当前冷却时间 */
|
|
||||||
currentCooldown: number = 0;
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.skillId = 0;
|
|
||||||
this.target = null;
|
|
||||||
this.currentCooldown = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 技能系统 */
|
|
||||||
@ecs.register('SkillSystem')
|
|
||||||
export class SkillSystem extends ecs.ComblockSystem<ecs.Entity> implements ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(SkillsComp, HeroViewComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity) {
|
|
||||||
let skill = e.get(SkillsComp);
|
|
||||||
let view = e.get(HeroViewComp);
|
|
||||||
|
|
||||||
if (this.canCastSkill(skill, view)) {
|
|
||||||
this.castSkill(e, skill);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private canCastSkill(skill: SkillsComp, view: HeroViewComp): boolean {
|
|
||||||
return skill.currentCooldown <= 0 &&
|
|
||||||
view.pw >= view.pwm;
|
|
||||||
}
|
|
||||||
|
|
||||||
private castSkill(entity: ecs.Entity, skill: SkillsComp) {
|
|
||||||
const skillData = SkillSet[skill.skillId];
|
|
||||||
|
|
||||||
// // 创建飞弹实体
|
|
||||||
// const projectile = ecs.createEntity();
|
|
||||||
// const projView = projectile.add(HeroViewComp);
|
|
||||||
// projView.node = instantiate(skillData.prefab);
|
|
||||||
// projView.node.setParent(entity.get(HeroViewComp).node.parent);
|
|
||||||
// projView.node.setPosition(entity.get(HeroViewComp).node.position);
|
|
||||||
|
|
||||||
// // 添加投射物组件
|
|
||||||
// projectile.add(ProjectileComp, {
|
|
||||||
// speed: skillData.speed,
|
|
||||||
// direction: entity.get(HeroViewComp).node.scale.x > 0 ? Vec3.RIGHT : Vec3.LEFT,
|
|
||||||
// maxDistance: skillData.range,
|
|
||||||
// penetrate: skillData.penetrate
|
|
||||||
// });
|
|
||||||
|
|
||||||
// 应用冷却时间
|
|
||||||
skill.currentCooldown = skillData.cooldown;
|
|
||||||
|
|
||||||
// 根据技能类型处理
|
|
||||||
switch(skillData.type) {
|
|
||||||
case 'damage':
|
|
||||||
this.handleDamage(entity, skillData);
|
|
||||||
break;
|
|
||||||
case 'heal':
|
|
||||||
this.handleHeal(entity, skillData);
|
|
||||||
break;
|
|
||||||
case 'projectile':
|
|
||||||
this.castProjectileSkill(entity, skillData);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 播放动画(示例)
|
|
||||||
// entity.get(HeroViewComp).playAnimation(skillData.anim);
|
|
||||||
|
|
||||||
// 触发完成回调
|
|
||||||
entity.remove(SkillsComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleDamage(entity: ecs.Entity, data: any) {
|
|
||||||
const view = entity.get(HeroViewComp);
|
|
||||||
// 实现伤害逻辑...
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleHeal(entity: ecs.Entity, data: any) {
|
|
||||||
const view = entity.get(HeroViewComp);
|
|
||||||
// 实现治疗逻辑...
|
|
||||||
}
|
|
||||||
|
|
||||||
private castProjectileSkill(entity: ecs.Entity, skillData: any) {
|
|
||||||
const view = entity.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 创建飞弹实体
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private exit(e: ecs.Entity) {
|
|
||||||
e.remove(SkillsComp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 动画系统
|
|
||||||
@ecs.register('SkillAnimationSystem')
|
|
||||||
export class SkillAnimationSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(SkillAnimationComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
|
||||||
const anim = e.get(SkillAnimationComp);
|
|
||||||
anim.elapsed += this.dt;
|
|
||||||
|
|
||||||
// 触发伤害检测
|
|
||||||
if (anim.elapsed >= anim.damageTriggerTime) {
|
|
||||||
e.add(DamageLineComp); // 添加伤害区域组件
|
|
||||||
e.remove(SkillAnimationComp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 直线型伤害区域组件
|
|
||||||
@ecs.register('DamageLine')
|
|
||||||
export class DamageLineComp extends ecs.Comp {
|
|
||||||
startPos: Vec3 = new Vec3();
|
|
||||||
direction: Vec3 = Vec3.RIGHT;
|
|
||||||
length: number = 300;
|
|
||||||
width: number = 50;
|
|
||||||
|
|
||||||
reset() {
|
|
||||||
this.startPos.set();
|
|
||||||
this.direction.set(Vec3.RIGHT);
|
|
||||||
this.length = 300;
|
|
||||||
this.width = 50;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 直线伤害系统
|
|
||||||
@ecs.register('DamageLineSystem')
|
|
||||||
export class DamageLineSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
|
||||||
filter(): ecs.IMatcher {
|
|
||||||
return ecs.allOf(DamageLineComp, HeroViewComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
update(e: ecs.Entity): void {
|
|
||||||
const line = e.get(DamageLineComp);
|
|
||||||
const caster = e.get(HeroViewComp);
|
|
||||||
|
|
||||||
// 根据角色朝向调整方向
|
|
||||||
line.direction = caster.node.scale.x > 0 ? Vec3.RIGHT : new Vec3(-1, 0, 0);
|
|
||||||
|
|
||||||
// 获取直线区域内的目标
|
|
||||||
const targets = this.getTargetsInLine(
|
|
||||||
caster.node.worldPosition,
|
|
||||||
line.direction,
|
|
||||||
line.length,
|
|
||||||
line.width,
|
|
||||||
caster.box_group
|
|
||||||
);
|
|
||||||
|
|
||||||
// 应用伤害
|
|
||||||
targets.forEach(target => {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
e.remove(DamageLineComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getTargetsInLine(origin: Vec3, dir: Vec3, length: number, width: number, team: number): ecs.Entity[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
private isInLine(origin: Vec3, dir: Vec3, target: Vec3, length: number, width: number): boolean {
|
|
||||||
return false; // 临时返回值保持类型安全
|
|
||||||
// const toTarget = target.subtract(origin);
|
|
||||||
// const projection = Vec3.project(toTarget, dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
10
assets/script/game/skill/heroSkillsComp.ts
Normal file
10
assets/script/game/skill/heroSkillsComp.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
|
@ecs.register('HeroSkills')
|
||||||
|
export class HeroSkillsComp extends ecs.Comp {
|
||||||
|
/** 移动方向:1向右,-1向左 */
|
||||||
|
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
9
assets/script/game/skill/heroSkillsComp.ts.meta
Normal file
9
assets/script/game/skill/heroSkillsComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.23",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "42bf4f68-80fe-4b71-88d1-89cbaea575cb",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user