refactor(英雄技能): 重构技能系统以支持多技能和独立冷却

- 将 HeroAttrsComp 中的单一攻击/技能ID重构为技能数组,支持多个技能
- 为每个技能添加独立的冷却计时和最大冷却时间
- 修改 SCastSystem 以支持多技能选择和冷却检查
- 更新 HeroViewComp 显示当前展示技能的冷却进度
- 统一英雄和怪物初始化技能的方式,使用 setSkills 方法
- 移除 heroSet 配置中的 as/ss 字段,改为 cds 数组
- 修改 Skill 实体加载,传递 HeroAttrsComp 用于技能伤害计算
This commit is contained in:
walkpan
2026-03-22 13:35:25 +08:00
parent 218703be6b
commit be4884d28a
7 changed files with 134 additions and 113 deletions

View File

@@ -26,10 +26,10 @@ export class HeroAttrsComp extends ecs.Comp {
shield_max: number = 0; // 最大护盾值
// ==================== 攻击属性 (补充) ====================
a_cd: number = 0; // 攻击计时
s_cd: number = 0; // 技能计时
a_cd_max: number = 0; // 攻击CD
s_cd_max: number = 0; // 技能CD
skills: number[] = [];
skill_max_cds: Record<number, number> = {};
skill_cds: Record<number, number> = {};
skill_lvs:Record<number, number> = {};
// ==================== 特殊属性 ====================
critical: number = 0; // 暴击率
freeze_chance: number = 0; // 冰冻概率
@@ -69,10 +69,6 @@ export class HeroAttrsComp extends ecs.Comp {
atk_count: number = 0; // 攻击次数
atked_count: number = 0; // 被攻击次数
killed_count:number=0;
atk_id:number=0; //普通攻击技能id
skill_id:number=0; //技能攻击技能id
can_atk=false
can_skill=false
combat_target_eid: number = -1;
enemy_in_cast_range: boolean = false;
start(){
@@ -162,27 +158,74 @@ export class HeroAttrsComp extends ecs.Comp {
this.shield = Math.max(0, Math.min(this.shield + value, this.shield_max));
this.dirty_shield = true;
}
//======更新cd========//
updateCD(dt: number){
if(this.atk_id !=0&&!this.can_atk){
this.a_cd+=dt
if(this.a_cd >= this.a_cd_max) this.can_atk = true
}
if(this.skill_id !=0&&!this.can_skill){
this.s_cd+=dt
if(this.s_cd >= this.s_cd_max) this.can_skill = true
for (const skillId of this.skills) {
const maxCd = this.skill_max_cds[skillId] ?? 0;
if (maxCd <= 0) {
this.skill_cds[skillId] = 0;
continue;
}
const currentCd = this.skill_cds[skillId] ?? maxCd;
if (currentCd >= maxCd) {
this.skill_cds[skillId] = maxCd;
continue;
}
this.skill_cds[skillId] = Math.min(maxCd, currentCd + dt);
}
}
isFrost(): boolean {
return this.frost_end_time > 0
}
triggerAtkCD() {
this.a_cd = 0;
this.can_atk = false;
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;
}
}
triggerSkillCD() {
this.s_cd = 0;
this.can_skill = false;
getSkillIds(): number[] {
return [...this.skills];
}
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;
}
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;
}
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));
}
getDisplaySkillCdProgress(): number {
const displaySkillId = this.skills[1] ?? this.skills[0] ?? 0;
return this.getSkillCdProgress(displaySkillId);
}
@@ -194,8 +237,7 @@ export class HeroAttrsComp extends ecs.Comp {
* 在技能初始化、新增技能、MP变化时调用
* @param skillsComp 技能组件
*/
public updateSkillDistanceCache(skill_id:number): void {
void skill_id;
public updateSkillDistanceCache(): void {
const rangeType = this.type as HType.Melee | HType.Mid | HType.Long;
const maxRange = HeroDisVal[rangeType];
let minRange = 0;
@@ -240,10 +282,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.shield_max = 0;
// 重置新增属性
this.a_cd = 0;
this.s_cd = 0;
this.a_cd_max = 0;
this.s_cd_max = 0;
this.skills = [];
this.skill_max_cds = {};
this.skill_cds = {};
this.critical = 0;
this.freeze_chance = 0;
this.back_chance = 0;
@@ -273,10 +314,6 @@ export class HeroAttrsComp extends ecs.Comp {
this.atk_count = 0;
this.atked_count = 0;
this.killed_count =0;
this.atk_id = 0;
this.skill_id = 0;
this.can_atk=false
this.can_skill=false
this.combat_target_eid = -1;
this.enemy_in_cast_range = false;
// 重置脏标签