去掉碰撞系统
This commit is contained in:
11
assets/script/game/skill/EcsSkillSystem.ts
Normal file
11
assets/script/game/skill/EcsSkillSystem.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { SkillSystem } from "./SkillSystem";
|
||||
import { SkillAnimationSystem } from "./SkillAnimation";
|
||||
export class EcsSkillSystem extends ecs.System {
|
||||
constructor() {
|
||||
super();
|
||||
this.add(new SkillSystem());
|
||||
this.add(new SkillAnimationSystem());
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/skill/EcsSkillSystem.ts.meta
Normal file
9
assets/script/game/skill/EcsSkillSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ea1f8dae-6593-46bf-b20b-a301b495a434",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
79
assets/script/game/skill/ProjectileComp.ts
Normal file
79
assets/script/game/skill/ProjectileComp.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
9
assets/script/game/skill/ProjectileComp.ts.meta
Normal file
9
assets/script/game/skill/ProjectileComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f563271b-ee28-4cc0-86ec-6947e9fe454e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
55
assets/script/game/skill/SkillAnimation.ts
Normal file
55
assets/script/game/skill/SkillAnimation.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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);
|
||||
|
||||
// 添加伤害标记组件
|
||||
|
||||
}
|
||||
|
||||
// 在角色组件中实现目标查找
|
||||
|
||||
}
|
||||
9
assets/script/game/skill/SkillAnimation.ts.meta
Normal file
9
assets/script/game/skill/SkillAnimation.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8c885682-d6d1-4bca-a06b-edb7e1389c08",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
187
assets/script/game/skill/SkillSystem.ts
Normal file
187
assets/script/game/skill/SkillSystem.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
9
assets/script/game/skill/SkillSystem.ts.meta
Normal file
9
assets/script/game/skill/SkillSystem.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c927f5c9-45cb-4400-8734-c706e615e4a4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user