refactor(技能系统): 重构技能系统以使用s_uuid作为主键并优化技能施放逻辑
- 将HeroSkillsComp中的技能数组改为以s_uuid为键的对象存储 - 修改CSRequestComp使用s_uuid替代skillIndex - 优化SkillCastSystem和SACastSystem的施放逻辑 - 为SMoveDataComp添加rePos方法处理技能位置计算 - 移除未使用的SDataComSystem代码
This commit is contained in:
@@ -24,7 +24,7 @@ import { CSRequestComp } from "../skill/STagComps";
|
||||
* - 施法检查与执行分离
|
||||
* - 自动处理资源消耗和CD重置
|
||||
*/
|
||||
@ecs.register('SkillCastSystem')
|
||||
// @ecs.register('SkillCastSystem')
|
||||
export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
|
||||
|
||||
/**
|
||||
@@ -38,28 +38,28 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
||||
* 实体进入时触发(即请求施法时)
|
||||
*/
|
||||
entityEnter(e: ecs.Entity): void {
|
||||
const skills = e.get(HeroSkillsComp);
|
||||
const heroModel = e.get(HeroAttrsComp);
|
||||
const skillsComp = e.get(HeroSkillsComp);
|
||||
const heroAttrs = e.get(HeroAttrsComp);
|
||||
const request = e.get(CSRequestComp);
|
||||
const heroView = e.get(HeroViewComp);
|
||||
|
||||
// 1. 验证数据完整性
|
||||
if (!skills || !heroModel || !request || !heroView) {
|
||||
if (!skillsComp || !heroAttrs || !request || !heroView) {
|
||||
console.warn("[SkillCastSystem] 数据不完整,取消施法");
|
||||
e.remove(CSRequestComp);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 获取技能数据
|
||||
const skill = skills.getSkill(request.skillIndex);
|
||||
const skill = skillsComp.getSkill(request.s_uuid);
|
||||
if (!skill) {
|
||||
console.warn(`[SkillCastSystem] 技能索引无效: ${request.skillIndex}`);
|
||||
console.warn(`[SkillCastSystem] 技能索引无效: ${request.s_uuid }`);
|
||||
e.remove(CSRequestComp);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 检查施法条件
|
||||
if (!this.checkCastConditions(skills, heroModel, request.skillIndex)) {
|
||||
if (!this.checkCastConditions(skillsComp, heroAttrs, request.s_uuid)) {
|
||||
e.remove(CSRequestComp);
|
||||
return;
|
||||
}
|
||||
@@ -68,8 +68,8 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
||||
this.executeCast(e, skill, request.targets, heroView);
|
||||
|
||||
// 5. 扣除资源和重置CD
|
||||
heroModel.mp -= skill.cost;
|
||||
skills.resetCD(request.skillIndex);
|
||||
heroAttrs.mp -= skill.cost;
|
||||
skillsComp.resetCD(request.s_uuid);
|
||||
|
||||
// 6. 移除请求标记
|
||||
e.remove(CSRequestComp);
|
||||
@@ -78,19 +78,19 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
||||
/**
|
||||
* 检查施法条件
|
||||
*/
|
||||
private checkCastConditions(skills: HeroSkillsComp, heroModel: HeroAttrsComp, skillIndex: number): boolean {
|
||||
private checkCastConditions(skillsComp: HeroSkillsComp, heroAttrs: HeroAttrsComp, skillIndex: number): boolean {
|
||||
// 检查角色状态
|
||||
if (heroModel.is_dead) {
|
||||
if (heroAttrs.is_dead) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查控制状态(眩晕、冰冻)
|
||||
if (heroModel.isStun() || heroModel.isFrost()) {
|
||||
if (heroAttrs.isStun() || heroAttrs.isFrost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查CD和MP
|
||||
if (!skills.canCast(skillIndex, heroModel.mp)) {
|
||||
if (!skillsComp.canCast(skillIndex, heroAttrs.mp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
||||
this.createSkill(skill.uuid, heroView, targets);
|
||||
}, delay);
|
||||
|
||||
const heroModel = casterEntity.get(HeroAttrsComp);
|
||||
console.log(`[SkillCastSystem] ${heroModel?.hero_name ?? '未知'} 施放技能: ${config.name}`);
|
||||
const heroAttrs = casterEntity.get(HeroAttrsComp);
|
||||
console.log(`[SkillCastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user