refactor(技能系统): 移除技能MP消耗相关逻辑

技能系统不再需要处理MP消耗,简化了技能施放和检查逻辑
This commit is contained in:
walkpan
2026-01-02 23:10:44 +08:00
parent 7d947db6b5
commit 2c7a628921
3 changed files with 25 additions and 33 deletions

View File

@@ -12,7 +12,6 @@ export interface SkillSlot {
s_uuid: number; // 技能配置ID
cd: number; // 当前CD时间递减
cd_max: number; // 最大CD时间
cost: number; // MP消耗
level: number; // 技能等级(预留)
dis: number; // 攻击距离
hset: HSSet; // 技能设定, 0:普通攻击, 1:一般技能, 2:必杀技
@@ -66,7 +65,6 @@ export class HeroSkillsComp extends ecs.Comp {
s_uuid: config.uuid,
cd: 0,
cd_max: cdMax,
cost: config.cost,
level: 1,
dis: Number(config.dis),
hset: hset,
@@ -97,7 +95,6 @@ export class HeroSkillsComp extends ecs.Comp {
s_uuid: config.uuid,
cd: 0,
cd_max: config.cd,
cost: config.cost,
level: 1,
dis: Number(config.dis),
hset: hset,
@@ -126,14 +123,13 @@ export class HeroSkillsComp extends ecs.Comp {
/**
* 检查技能是否可施放通过s_uuid
* @param s_uuid 技能配置ID
* @param currentMp 当前MP值
*/
canCast(s_uuid: number, currentMp: number): boolean {
canCast(s_uuid: number): boolean {
const skill = this.getSkill(s_uuid);
if (!skill) return false;
// 检查CD和MP
return skill.cd <= 0 && currentMp >= skill.cost;
// 检查CD
return skill.cd <= 0;
}
/**
@@ -172,10 +168,10 @@ export class HeroSkillsComp extends ecs.Comp {
/**
* 获取所有可施放的技能索引
*/
getReadySkills(currentMp: number): number[] {
getReadySkills(): number[] {
const ready: number[] = [];
for (const s_uuid in this.skills) {
if (this.canCast(Number(s_uuid), currentMp)) {
if (this.canCast(Number(s_uuid))) {
ready.push(Number(s_uuid));
}
}
@@ -208,11 +204,10 @@ export class HeroSkillsComp extends ecs.Comp {
/**
* 获取可施放技能中的最远攻击距离
* @param mp 当前MP值
* @returns 最远攻击距离如果没有可用技能返回0
*/
getMaxSkillDistance(mp: number): number {
const readySkills = this.getReadySkills(mp);
getMaxSkillDistance(): number {
const readySkills = this.getReadySkills();
if (readySkills.length === 0) return 0;
let maxDistance = 0;
@@ -227,11 +222,10 @@ export class HeroSkillsComp extends ecs.Comp {
/**
* 获取可施放技能中的最近攻击距离
* @param mp 当前MP值
* @returns 最近攻击距离如果没有可用技能返回0
*/
getMinSkillDistance(mp: number): number {
const readySkills = this.getReadySkills(mp);
getMinSkillDistance(): number {
const readySkills = this.getReadySkills();
if (readySkills.length === 0) return 0;
let minDistance = Number.MAX_VALUE;

View File

@@ -47,7 +47,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
if (!heroAttrs.is_atking) return;
const readySkills = skills.getReadySkills(heroAttrs.mp);
const readySkills = skills.getReadySkills();
if (readySkills.length === 0) return;
// 选择第一个可施放的技能(支持伤害/治疗/护盾)
@@ -89,9 +89,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
if (castSucess) {
// 🔥 怪物不消耗蓝
if (heroAttrs.fac !== FacSet.MON) {
// 使用 add_mp 确保 MP 不会变成负数,并触发相关更新
heroAttrs.add_mp(-skill.cost, true);
// 手动更新技能距离缓存,因为 HeroAttrSystem 无法检测到跨帧的 MP 变化
// 手动更新技能距离缓存
heroAttrs.updateSkillDistanceCache(skills);
}
skills.resetCD(skill.s_uuid);
@@ -134,8 +132,8 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
return false;
}
// 检查CD和MP
if (!skills.canCast(s_uuid, heroAttrs.mp)) {
// 检查CD
if (!skills.canCast(s_uuid)) {
return false;
}