refactor(技能系统): 重构技能系统以使用s_uuid作为主键并优化技能施放逻辑

- 将HeroSkillsComp中的技能数组改为以s_uuid为键的对象存储
- 修改CSRequestComp使用s_uuid替代skillIndex
- 优化SkillCastSystem和SACastSystem的施放逻辑
- 为SMoveDataComp添加rePos方法处理技能位置计算
- 移除未使用的SDataComSystem代码
This commit is contained in:
2025-10-31 10:47:05 +08:00
parent b38e63e200
commit 2b3b80b308
11 changed files with 230 additions and 96 deletions

View File

@@ -6,7 +6,7 @@ import { SkillSet } from "../common/config/SkillSet";
* 单个技能的运行时数据
*/
export interface SkillSlot {
uuid: number; // 技能配置ID
s_uuid: number; // 技能配置ID
cd: number; // 当前CD时间递减
cd_max: number; // 最大CD时间
cost: number; // MP消耗
@@ -31,7 +31,7 @@ export class HeroSkillsComp extends ecs.Comp {
// ==================== 技能槽位列表 ====================
/** 技能槽位数组最多4个技能 */
skills: SkillSlot[] = [];
skills: Record<number, SkillSlot> = {};
// ==================== 辅助方法 ====================
@@ -47,14 +47,13 @@ export class HeroSkillsComp extends ecs.Comp {
console.warn(`[HeroSkills] 技能配置不存在: ${s_uuid}`);
continue;
}
this.skills.push({
uuid: config.uuid,
cd: 0, // 初始CD为0可立即施放
this.skills[s_uuid]={
s_uuid: config.uuid,
cd: 0,
cd_max: config.cd,
cost: config.cost,
level: 1
});
level: 1,
}
}
}
@@ -67,30 +66,31 @@ export class HeroSkillsComp extends ecs.Comp {
console.warn(`[HeroSkills] 技能配置不存在: ${s_uuid}`);
return;
}
this.skills.push({
uuid: config.uuid,
this.skills[s_uuid] = {
s_uuid: config.uuid,
cd: 0,
cd_max: config.cd,
cost: config.cost,
level: 1
});
};
}
/**
* 获取指定索引的技能
* 获取指定s_uuid的技能
*/
getSkill(index: number): SkillSlot | null {
return this.skills[index] ?? null;
getSkill(s_uuid: number): SkillSlot | null {
return this.skills[s_uuid] ?? null;
}
/**
* 检查技能是否可施放
* 检查技能是否可施放(通过索引)
* @param index 技能索引
* @param currentMp 当前MP值
*/
canCast(index: number, currentMp: number): boolean {
const skill = this.getSkill(index);
canCast(s_uuid: number, currentMp: number): boolean {
const skill = this.getSkill(s_uuid);
if (!skill) return false;
// 检查CD和MP
@@ -98,11 +98,35 @@ export class HeroSkillsComp extends ecs.Comp {
}
/**
* 重置技能CD开始冷却
* 检查技能是否可施放通过s_uuid
* @param s_uuid 技能配置ID
* @param currentMp 当前MP值
*/
canCastByUuid(s_uuid: number, currentMp: number): boolean {
const skill = this.getSkill(s_uuid);
if (!skill) return false;
// 检查CD和MP
return skill.cd <= 0 && currentMp >= skill.cost;
}
/**
* 重置技能CD开始冷却通过索引
* @param index 技能索引
*/
resetCD(index: number) {
const skill = this.getSkill(index);
resetCD(s_uuid: number) {
const skill = this.getSkill(s_uuid);
if (skill) {
skill.cd = skill.cd_max;
}
}
/**
* 重置技能CD开始冷却通过s_uuid
* @param s_uuid 技能配置ID
*/
resetCDByUuid(s_uuid: number) {
const skill = this.getSkill(s_uuid);
if (skill) {
skill.cd = skill.cd_max;
}
@@ -113,7 +137,8 @@ export class HeroSkillsComp extends ecs.Comp {
* @param dt 时间增量
*/
updateCDs(dt: number) {
for (const skill of this.skills) {
for (const s_uuid in this.skills) {
const skill = this.skills[Number(s_uuid)];
if (skill.cd > 0) {
skill.cd -= dt;
if (skill.cd < 0) {
@@ -128,15 +153,15 @@ export class HeroSkillsComp extends ecs.Comp {
*/
getReadySkills(currentMp: number): number[] {
const ready: number[] = [];
for (let i = 0; i < this.skills.length; i++) {
if (this.canCast(i, currentMp)) {
ready.push(i);
for (const s_uuid in this.skills) {
if (this.canCastByUuid(Number(s_uuid), currentMp)) {
ready.push(Number(s_uuid));
}
}
return ready;
}
reset() {
this.skills = [];
this.skills = {};
}
}