refactor(skill): 重构技能数据结构并支持技能等级
- 将 HeroAttrsComp 中的技能数组和独立 CD 映射重构为统一的 HSkillInfo 对象记录 - 在 SDataCom 中新增 skill_lv 字段,并在 Skill 加载时传入技能等级 - 更新 Hero 和 Monster 初始化逻辑以适配新的技能数据结构 - 修改 SCastSystem 以传递技能等级并影响技能效果 - 更新 heroSet 配置,将 skills 字段类型改为 Record<number, HSkillInfo>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { Attrs } from "../common/config/HeroAttrs";
|
||||
import { BuffConf } from "../common/config/SkillSet";
|
||||
import { HeroDisVal, HType } from "../common/config/heroSet";
|
||||
import { HeroDisVal, HSkillInfo, HType } from "../common/config/heroSet";
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||
import { FightSet } from "../common/config/GameSet";
|
||||
@@ -26,10 +26,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
shield_max: number = 0; // 最大护盾值
|
||||
|
||||
// ==================== 攻击属性 (补充) ====================
|
||||
skills: number[] = [];
|
||||
skill_max_cds: Record<number, number> = {};
|
||||
skill_cds: Record<number, number> = {};
|
||||
skill_lvs:Record<number, number> = {};
|
||||
skills: Record<number, HSkillInfo> = {};
|
||||
// ==================== 特殊属性 ====================
|
||||
critical: number = 0; // 暴击率
|
||||
freeze_chance: number = 0; // 冰冻概率
|
||||
@@ -159,72 +156,57 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.dirty_shield = true;
|
||||
}
|
||||
updateCD(dt: number){
|
||||
for (const skillId of this.skills) {
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) {
|
||||
this.skill_cds[skillId] = 0;
|
||||
for (const key in this.skills) {
|
||||
const skill = this.skills[key];
|
||||
if (!skill) continue;
|
||||
if (skill.cd <= 0) {
|
||||
skill.ccd = 0;
|
||||
continue;
|
||||
}
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
if (currentCd >= maxCd) {
|
||||
this.skill_cds[skillId] = maxCd;
|
||||
if (skill.ccd >= skill.cd) {
|
||||
skill.ccd = skill.cd;
|
||||
continue;
|
||||
}
|
||||
this.skill_cds[skillId] = Math.min(maxCd, currentCd + dt);
|
||||
skill.ccd = Math.min(skill.cd, skill.ccd + dt);
|
||||
}
|
||||
}
|
||||
isFrost(): boolean {
|
||||
return this.frost_end_time > 0
|
||||
}
|
||||
setSkills(skills: number[], cds: number[]) {
|
||||
this.skills = [];
|
||||
this.skill_max_cds = {};
|
||||
this.skill_cds = {};
|
||||
if (!skills) return;
|
||||
const len = skills.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const skillId = skills[i];
|
||||
if (!skillId) continue;
|
||||
const cd = cds[i] ?? cds[0] ?? 0;
|
||||
const maxCd = Math.max(0, cd);
|
||||
this.skills.push(skillId);
|
||||
this.skill_max_cds[skillId] = maxCd;
|
||||
this.skill_cds[skillId] = maxCd;
|
||||
}
|
||||
getSkillLevel(skillId: number): number {
|
||||
if (!skillId) return 1;
|
||||
return this.skills[skillId]?.lv ?? 1;
|
||||
}
|
||||
|
||||
getSkillIds(): number[] {
|
||||
return [...this.skills];
|
||||
return Object.values(this.skills).map(skill => skill.uuid);
|
||||
}
|
||||
|
||||
isSkillReady(skillId: number): boolean {
|
||||
if (!skillId) return false;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) return true;
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
return currentCd >= maxCd;
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill) return false;
|
||||
if (skill.cd <= 0) return true;
|
||||
return skill.ccd >= skill.cd;
|
||||
}
|
||||
|
||||
triggerSkillCD(skillId: number) {
|
||||
if (!skillId) return;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) {
|
||||
this.skill_cds[skillId] = 0;
|
||||
return;
|
||||
}
|
||||
this.skill_cds[skillId] = 0;
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill) return;
|
||||
skill.ccd = 0;
|
||||
}
|
||||
|
||||
getSkillCdProgress(skillId: number): number {
|
||||
if (!skillId) return 1;
|
||||
const maxCd = this.skill_max_cds[skillId] ?? 0;
|
||||
if (maxCd <= 0) return 1;
|
||||
const currentCd = this.skill_cds[skillId] ?? maxCd;
|
||||
return Math.max(0, Math.min(1, currentCd / maxCd));
|
||||
const skill = this.skills[skillId];
|
||||
if (!skill || skill.cd <= 0) return 1;
|
||||
return Math.max(0, Math.min(1, skill.ccd / skill.cd));
|
||||
}
|
||||
|
||||
getDisplaySkillCdProgress(): number {
|
||||
const displaySkillId = this.skills[1] ?? this.skills[0] ?? 0;
|
||||
const skillIds = this.getSkillIds();
|
||||
const displaySkillId = skillIds[1] ?? skillIds[0] ?? 0;
|
||||
return this.getSkillCdProgress(displaySkillId);
|
||||
}
|
||||
|
||||
@@ -282,9 +264,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.shield_max = 0;
|
||||
|
||||
// 重置新增属性
|
||||
this.skills = [];
|
||||
this.skill_max_cds = {};
|
||||
this.skill_cds = {};
|
||||
this.skills = {};
|
||||
this.critical = 0;
|
||||
this.freeze_chance = 0;
|
||||
this.back_chance = 0;
|
||||
|
||||
Reference in New Issue
Block a user