去掉了 技能系统,技能由单个精灵独立处理

This commit is contained in:
2025-06-02 20:25:23 +08:00
parent c9a499e38b
commit 3fbfc2ea09
68 changed files with 3923 additions and 11907 deletions

View File

@@ -1,139 +1,139 @@
import { Node, UI, UITransform, Vec3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { HeroViewComp } from "../hero/HeroViewComp";
import { SkillSet, TargetGroup, TargetType } from "../common/config/SkillSet";
import { CdType } from "../common/config/SkillSet";
import { oops } from "db://oops-framework/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { Skill } from "../skills/Skill";
import { SkillCom } from "../skills/SkillCom";
import { AnimType } from "../common/config/SkillSet";
import { BoxSet } from "../common/config/BoxSet";
// import { Node, UI, UITransform, Vec3 } from "cc";
// import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
// import { HeroViewComp } from "../hero/HeroViewComp";
// import { SkillSet, TargetGroup, TargetType } from "../common/config/SkillSet";
// import { CdType } from "../common/config/SkillSet";
// import { oops } from "db://oops-framework/core/Oops";
// import { GameEvent } from "../common/config/GameEvent";
// import { Skill } from "../skills/Skill";
// import { SkillCom } from "../skills/SkillCom";
// import { AnimType } from "../common/config/SkillSet";
// import { BoxSet } from "../common/config/BoxSet";
/** 技能系统 */
@ecs.register('HeroSkillSystem')
export class HeroSkillSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
// export class HeroSkillSystem implements ecs.ISystemUpdate {
// private updateInterval: number = 0.1; // 每0.1秒更新一次
// private accumulator: number = 0;
private _timers: { [key: string]: number } = {};
private _damageQueue: Array<{ timer: number; callback: () => void }> = [];
init(): void {
oops.message.on(GameEvent.FightEnd, this.clear_timer, this);
}
filter(): ecs.IMatcher {
return ecs.allOf(HeroViewComp);
}
update(e: ecs.Entity) {
//return false
// 处理伤害队列
const view = e.get(HeroViewComp);
// 只在攻击状态触发技能
if (view.is_atking &&view.at > view.cd) {
const config = SkillSet[view.atk_skill];
if (!config) return;
this.castSkill(e, view.atk_skill, config);
view.at = 0;
}
// /** 技能系统 */
// @ecs.register('HeroSkillSystem')
// export class HeroSkillSystem extends ecs.ComblockSystem {
// // export class HeroSkillSystem implements ecs.ISystemUpdate {
// // private updateInterval: number = 0.1; // 每0.1秒更新一次
// // private accumulator: number = 0;
// private _timers: { [key: string]: number } = {};
// private _damageQueue: Array<{ timer: number; callback: () => void }> = [];
// init(): void {
// oops.message.on(GameEvent.FightEnd, this.clear_timer, this);
// }
// filter(): ecs.IMatcher {
// return ecs.allOf(HeroViewComp);
// }
// update(e: ecs.Entity) {
// //return false
// // 处理伤害队列
// const view = e.get(HeroViewComp);
// // 只在攻击状态触发技能
// if (view.is_atking &&view.at > view.cd) {
// const config = SkillSet[view.atk_skill];
// if (!config) return;
// this.castSkill(e, view.atk_skill, config);
// view.at = 0;
// }
}
// }
/** 施放技能 */
private castSkill(caster: ecs.Entity, skillId: number, config: typeof SkillSet[keyof typeof SkillSet]) {
const view = caster.get(HeroViewComp);
console.log(view.uuid+"=>"+view.hero_name+"施放技能:"+config.uuid);
if (config.TargetGroup === TargetGroup.Enemy) {
caster.get(HeroViewComp).playSkillEffect(config.uuid);
this.doSkill(caster,config);
}
// /** 施放技能 */
// private castSkill(caster: ecs.Entity, skillId: number, config: typeof SkillSet[keyof typeof SkillSet]) {
// const view = caster.get(HeroViewComp);
// console.log(view.uuid+"=>"+view.hero_name+"施放技能:"+config.uuid);
// if (config.TargetGroup === TargetGroup.Enemy) {
// caster.get(HeroViewComp).playSkillEffect(config.uuid);
// this.doSkill(caster,config);
// }
if (config.TargetGroup === TargetGroup.Ally) {
const targets = this.selectAllyTargets(caster, config);
if (targets.length === 0) return;
// if (config.TargetGroup === TargetGroup.Ally) {
// const targets = this.selectAllyTargets(caster, config);
// if (targets.length === 0) return;
}
if (config.TargetGroup === TargetGroup.Self) {
// }
// if (config.TargetGroup === TargetGroup.Self) {
}
// }
}
private doSkill(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]) {
const view = caster.get(HeroViewComp);
const skillEntity = ecs.getEntity<Skill>(Skill);
const targets = this.selectEnemyTargets(caster, config);
if (targets.length === 0) return;
skillEntity.load(
new Vec3(view.node.position.x, view.node.position.y+BoxSet.ATK_Y, 0), // 起始位置
view.box_group, // 阵营
view.node.parent, // 父节点
config.uuid, // 技能ID
new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置
view
);
console.log("技能:"+config.uuid+"=>"+targets[0]?.get(HeroViewComp).hero_name);
}
// }
// private doSkill(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]) {
// const view = caster.get(HeroViewComp);
// const skillEntity = ecs.getEntity<Skill>(Skill);
// const targets = this.selectEnemyTargets(caster, config);
// if (targets.length === 0) return;
// skillEntity.load(
// new Vec3(view.node.position.x, view.node.position.y+BoxSet.ATK_Y, 0), // 起始位置
// view.box_group, // 阵营
// view.node.parent, // 父节点
// config.uuid, // 技能ID
// new Vec3(targets[0]?.get(HeroViewComp).node.position.x, targets[0]?.get(HeroViewComp).node.position.y, 0), // 目标位置
// view
// );
// console.log("技能:"+config.uuid+"=>"+targets[0]?.get(HeroViewComp).hero_name);
// }
private selectEnemyTargets(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
const casterView = caster.get(HeroViewComp);
const team = casterView.fac;
const isEnemyTeam = team === 0 ? 1 : 0;
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac !== team);
return this.filterFrontRow(candidates, isEnemyTeam);
}
private selectAllyTargets(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
const casterView = caster.get(HeroViewComp);
const team = casterView.fac;
const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac === team);
// 第二阶段:位置/血量等精细筛选
switch(config.TargetType) {
case TargetType.Melee:
return candidates.filter(e => e.get(HeroViewComp).type === 0);
case TargetType.Ranged:
return candidates.filter(e => e.get(HeroViewComp).type === 1);
case TargetType.SupportClass:
return candidates.filter(e => e.get(HeroViewComp).type === 2);
case TargetType.Random:
return this.pickRandomTarget(candidates, config.count || 1);
default:
return candidates;
}
}
// private selectEnemyTargets(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
// const casterView = caster.get(HeroViewComp);
// const team = casterView.fac;
// const isEnemyTeam = team === 0 ? 1 : 0;
// const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac !== team);
// return this.filterFrontRow(candidates, isEnemyTeam);
// }
// private selectAllyTargets(caster: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]): ecs.Entity[] {
// const casterView = caster.get(HeroViewComp);
// const team = casterView.fac;
// const candidates= ecs.query(ecs.allOf(HeroViewComp)).filter(e => e.get(HeroViewComp).fac === team);
// // 第二阶段:位置/血量等精细筛选
// switch(config.TargetType) {
// case TargetType.Melee:
// return candidates.filter(e => e.get(HeroViewComp).type === 0);
// case TargetType.Ranged:
// return candidates.filter(e => e.get(HeroViewComp).type === 1);
// case TargetType.SupportClass:
// return candidates.filter(e => e.get(HeroViewComp).type === 2);
// case TargetType.Random:
// return this.pickRandomTarget(candidates, config.count || 1);
// default:
// return candidates;
// }
// }
/** 筛选最前排单位 */
private filterFrontRow(entities: ecs.Entity[], isEnemyTeam: number): ecs.Entity[] {
// 敌方最前排是x坐标最大的我方最前排是x坐标最小的
const keyPos = isEnemyTeam ?
Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) :
Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x));
// /** 筛选最前排单位 */
// private filterFrontRow(entities: ecs.Entity[], isEnemyTeam: number): ecs.Entity[] {
// // 敌方最前排是x坐标最大的我方最前排是x坐标最小的
// const keyPos = isEnemyTeam ?
// Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) :
// Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x));
return entities.filter(e =>
Math.abs(e.get(HeroViewComp).node.position.x - keyPos) < 10
);
}
// return entities.filter(e =>
// Math.abs(e.get(HeroViewComp).node.position.x - keyPos) < 10
// );
// }
/** 随机选择目标 */
private pickRandomTarget(entities: ecs.Entity[], count: number): ecs.Entity[] {
const shuffled = [...entities].sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
}
// /** 随机选择目标 */
// private pickRandomTarget(entities: ecs.Entity[], count: number): ecs.Entity[] {
// const shuffled = [...entities].sort(() => 0.5 - Math.random());
// return shuffled.slice(0, count);
// }
public clear_timer() {
console.log("clear_timer");
Object.values(this._timers).forEach(clearTimeout);
}
onDestroy() {
Object.values(this._timers).forEach(clearTimeout);
}
// public clear_timer() {
// console.log("clear_timer");
// Object.values(this._timers).forEach(clearTimeout);
// }
// onDestroy() {
// Object.values(this._timers).forEach(clearTimeout);
// }
/** 应用负面状态 */
private applyDebuff(target: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]) {
// 实现debuff逻辑...
}
// /** 应用负面状态 */
// private applyDebuff(target: ecs.Entity, config: typeof SkillSet[keyof typeof SkillSet]) {
// // 实现debuff逻辑...
// }
}
// }

View File

@@ -1,31 +0,0 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
@ecs.register('HeroSkills')
export class HeroSkillsComp extends ecs.Comp {
/** 当前拥有的技能ID列表 */
skills: number[] = [];
/** 技能冷却计时器 [技能ID:剩余冷却时间] */
cooldowns: Map<number, number> = new Map();
/** 技能触发计数器 [技能ID:触发次数] */
counters: Map<number, number> = new Map();
reset() {
this.skills = [];
this.cooldowns.clear();
this.counters.clear();
}
/** 重置指定技能冷却 */
resetCooldown(skillId: number) {
if (this.cooldowns.has(skillId)) {
this.cooldowns.set(skillId, 0);
}
}
/** 重置所有技能冷却 */
resetAllCooldowns() {
this.cooldowns.forEach((value, key) => {
this.cooldowns.set(key, 0);
});
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "42bf4f68-80fe-4b71-88d1-89cbaea575cb",
"files": [],
"subMetas": {},
"userData": {}
}