From be4884d28afca96c38680a24eb26d3fbd99f2c21 Mon Sep 17 00:00:00 2001 From: walkpan Date: Sun, 22 Mar 2026 13:35:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=8B=B1=E9=9B=84=E6=8A=80=E8=83=BD):?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84=E6=8A=80=E8=83=BD=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E5=A4=9A=E6=8A=80=E8=83=BD=E5=92=8C?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=86=B7=E5=8D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 HeroAttrsComp 中的单一攻击/技能ID重构为技能数组,支持多个技能 - 为每个技能添加独立的冷却计时和最大冷却时间 - 修改 SCastSystem 以支持多技能选择和冷却检查 - 更新 HeroViewComp 显示当前展示技能的冷却进度 - 统一英雄和怪物初始化技能的方式,使用 setSkills 方法 - 移除 heroSet 配置中的 as/ss 字段,改为 cds 数组 - 修改 Skill 实体加载,传递 HeroAttrsComp 用于技能伤害计算 --- assets/script/game/common/config/heroSet.ts | 84 ++++++++-------- assets/script/game/hero/Hero.ts | 12 +-- assets/script/game/hero/HeroAttrsComp.ts | 101 +++++++++++++------- assets/script/game/hero/HeroViewComp.ts | 2 +- assets/script/game/hero/Mon.ts | 8 +- assets/script/game/hero/SCastSystem.ts | 33 ++++--- assets/script/game/skill/Skill.ts | 7 +- 7 files changed, 134 insertions(+), 113 deletions(-) diff --git a/assets/script/game/common/config/heroSet.ts b/assets/script/game/common/config/heroSet.ts index 0f7d41c6..789f1939 100644 --- a/assets/script/game/common/config/heroSet.ts +++ b/assets/script/game/common/config/heroSet.ts @@ -62,8 +62,6 @@ export interface heroInfo { kind?: number; // 未使用 lv: number; // 英雄等级 cards_lv?: number; // 卡片等级 - as: number; // 攻击间隔(越小越快) - ss:number; // 技能间隔 type: HType; // 攻击定位(近战/中程/远程) hp: number; // 生命值上限 ap: number; // 攻击力 @@ -92,48 +90,48 @@ export interface heroInfo { export const HeroInfo: Record = { // ========== 近战英雄 ========== - 5001:{uuid:5001,name:"盾战士",path:"hk1", fac:FacSet.HERO,cards_lv:1,lv:1,as:0.75,ss:5,type:HType.Melee,hp:450,ap:25,speed:180, - skills:[6001,6301],info:"近战,魔法盾 坦克"}, - 5002:{uuid:5002,name:"圣骑士",path:"hk3", fac:FacSet.HERO,cards_lv:3,lv:1,as:0.75,ss:5,type:HType.Melee,hp:1350,ap:75,speed:180, - skills:[6001,6305],info:"近战,群体护盾 坦克"}, - 5003:{uuid:5003,name:"风行剑士",path:"hk4", fac:FacSet.HERO,cards_lv:2,lv:1,as:1.1,ss:5,type:HType.Melee,hp:500,ap:100,speed:180, - skills:[6001,6014],info:"近战,闪击 近战dps"}, - 5004:{uuid:5004,name:"刺客",path:"hc1", fac:FacSet.HERO,cards_lv:4,lv:1,as:1.1,ss:5,type:HType.Melee,hp:1000,ap:200,speed:180, - skills:[6001,6104],info:"近战,火焰击 近战dps"}, - // 5005:{uuid:5005,name:"自然骑士",path:"hk2", fac:FacSet.HERO,cards_lv:4,lv:1,as:1.1,ss:5,type:HType.Melee,hp:1000,ap:200,speed:180, - // skills:[6001,6302],info:"治疗近战,火焰击 近战dps"}, + 5001:{uuid:5001,name:"盾战士",path:"hk1", fac:FacSet.HERO,cards_lv:1,lv:1,type:HType.Melee,hp:450,ap:25,speed:180, + skills:[6001,6301],slvs:[1,1],cds:[0.75,5],info:"近战,魔法盾 坦克"}, + 5002:{uuid:5002,name:"圣骑士",path:"hk3", fac:FacSet.HERO,cards_lv:3,lv:1,type:HType.Melee,hp:1350,ap:75,speed:180, + skills:[6001,6305],slvs:[1,1],cds:[0.75,5],info:"近战,群体护盾 坦克"}, + 5003:{uuid:5003,name:"风行剑士",path:"hk4", fac:FacSet.HERO,cards_lv:2,lv:1,type:HType.Melee,hp:500,ap:100,speed:180, + skills:[6001,6014],slvs:[1,1],cds:[1.1,5],info:"近战,闪击 近战dps"}, + 5004:{uuid:5004,name:"刺客",path:"hc1", fac:FacSet.HERO,cards_lv:4,lv:1,type:HType.Melee,hp:1000,ap:200,speed:180, + skills:[6001,6104],slvs:[1,1],cds:[1.1,5],info:"近战,火焰击 近战dps"}, + // 5005:{uuid:5005,name:"自然骑士",path:"hk2", fac:FacSet.HERO,cards_lv:4,lv:1,type:HType.Melee,hp:1000,ap:200,speed:180, + // skills:[6001,6302],slvs:[1,1],cds:[1.1,5],info:"治疗近战,火焰击 近战dps"}, // ========== 法师英雄 ========== - 5101:{uuid:5101,name:"奥术法师",path:"hm2", fac:FacSet.HERO,cards_lv:1,lv:1,as:1.4,ss:5,type:HType.Long,hp:150,ap:60,speed:100, - skills:[6005,6012],info:"冰球,冰锥 远法dps"}, - 5102:{uuid:5012,name:"火焰法师",path:"hm1", fac:FacSet.HERO,cards_lv:2,lv:1,as:1.4,ss:5,type:HType.Long,hp:300,ap:120,speed:100, - skills:[6004,6013],info:"火击,火球 远法dps"}, - 5103:{uuid:5013,name:"冰法法师",path:"hm4", fac:FacSet.HERO,cards_lv:3,lv:1,as:1.4,ss:5,type:HType.Long,hp:450,ap:180,speed:100, - skills:[6003,6012],info:"冰击,冰锥 远法dps"}, - 5104:{uuid:5104,name:"寒霜术士",path:"hm4", fac:FacSet.HERO,cards_lv:4,lv:1,as:1.4,ss:5,type:HType.Long,hp:600,ap:240,speed:100, - skills:[6012,6202],info:"冰锥,冰刺 远法dps"}, - 5105:{uuid:5105,name:"炎爆法师",path:"hm3", fac:FacSet.HERO,cards_lv:5,lv:1,as:1.4,ss:5,type:HType.Long,hp:750,ap:300,speed:100, - skills:[6013,6201],info:"火球,陨石术 远法dps" }, + 5101:{uuid:5101,name:"奥术法师",path:"hm2", fac:FacSet.HERO,cards_lv:1,lv:1,type:HType.Long,hp:150,ap:60,speed:100, + skills:[6005,6012],slvs:[1,1],cds:[1.4,5],info:"冰球,冰锥 远法dps"}, + 5102:{uuid:5012,name:"火焰法师",path:"hm1", fac:FacSet.HERO,cards_lv:2,lv:1,type:HType.Long,hp:300,ap:120,speed:100, + skills:[6004,6013],slvs:[1,1],cds:[1.4,5],info:"火击,火球 远法dps"}, + 5103:{uuid:5013,name:"冰法法师",path:"hm4", fac:FacSet.HERO,cards_lv:3,lv:1,type:HType.Long,hp:450,ap:180,speed:100, + skills:[6003,6012],slvs:[1,1],cds:[1.4,5],info:"冰击,冰锥 远法dps"}, + 5104:{uuid:5104,name:"寒霜术士",path:"hm4", fac:FacSet.HERO,cards_lv:4,lv:1,type:HType.Long,hp:600,ap:240,speed:100, + skills:[6012,6202],slvs:[1,1],cds:[1.4,5],info:"冰锥,冰刺 远法dps"}, + 5105:{uuid:5105,name:"炎爆法师",path:"hm3", fac:FacSet.HERO,cards_lv:5,lv:1,type:HType.Long,hp:750,ap:300,speed:100, + skills:[6013,6201],slvs:[1,1],cds:[1.4,5],info:"火球,陨石术 远法dps" }, // ========== 远程英雄 ========== - 5201:{uuid:5201,name:"射手",path:"ha1", fac:FacSet.HERO,cards_lv:1,lv:1,as:1.3,ss:5,type:HType.Long,hp:150,ap:60,speed:120, - skills:[6002,6011],info:"普通射击,暴射 远dps"}, + 5201:{uuid:5201,name:"射手",path:"ha1", fac:FacSet.HERO,cards_lv:1,lv:1,type:HType.Long,hp:150,ap:60,speed:120, + skills:[6002,6011],slvs:[1,1],cds:[1.3,5],info:"普通射击,暴射 远dps"}, - 5202:{uuid:5202,name:"游侠",path:"ha2", fac:FacSet.HERO,cards_lv:3,lv:1,as:1.3,ss:5,type:HType.Long,hp:450,ap:180,speed:120, - skills:[6011,6101],info:"暴射,光箭 远dps"}, + 5202:{uuid:5202,name:"游侠",path:"ha2", fac:FacSet.HERO,cards_lv:3,lv:1,type:HType.Long,hp:450,ap:180,speed:120, + skills:[6011,6101],slvs:[1,1],cds:[1.3,5],info:"暴射,光箭 远dps"}, // ========== 腐竹英雄 ========== - 5301:{uuid:5301,name:"牧师",path:"hh1", fac:FacSet.HERO,cards_lv:1,lv:1,as:1,ss:5,type:HType.Long,hp:150,ap:20,speed:100, - skills:[6012,6302],info:"冰锥1,治疗 远辅助" }, + 5301:{uuid:5301,name:"牧师",path:"hh1", fac:FacSet.HERO,cards_lv:1,lv:1,type:HType.Long,hp:150,ap:20,speed:100, + skills:[6012,6302],slvs:[1,1],cds:[1,5],info:"冰锥1,治疗 远辅助" }, - 5302:{uuid:5302,name:"战地医师",path:"hz1", fac:FacSet.HERO,cards_lv:2,lv:1,as:1,ss:5,type:HType.Mid,hp:300,ap:40,speed:100, - skills:[6012,6304],info:"冰锥1,群体治疗 远辅助"}, + 5302:{uuid:5302,name:"战地医师",path:"hz1", fac:FacSet.HERO,cards_lv:2,lv:1,type:HType.Mid,hp:300,ap:40,speed:100, + skills:[6012,6304],slvs:[1,1],cds:[1,5],info:"冰锥1,群体治疗 远辅助"}, - 5303:{uuid:5303,name:"守护祭司",path:"ha3", fac:FacSet.HERO,cards_lv:4,lv:1,as:1,ss:5,type:HType.Mid,hp:600,ap:80,speed:100, - skills:[6002,6004],info:"普通射击,单体攻击buff 射手辅助"}, - 5304:{uuid:5304,name:"秘法精灵",path:"ha3", fac:FacSet.HERO,cards_lv:6,lv:1,as:1,ss:5,type:HType.Long,hp:900,ap:120,speed:100, - skills:[6002,6105],info:"普通射击,群体攻击buff 射手辅助"}, + 5303:{uuid:5303,name:"守护祭司",path:"ha3", fac:FacSet.HERO,cards_lv:4,lv:1,type:HType.Mid,hp:600,ap:80,speed:100, + skills:[6002,6004],slvs:[1,1],cds:[1,5],info:"普通射击,单体攻击buff 射手辅助"}, + 5304:{uuid:5304,name:"秘法精灵",path:"ha3", fac:FacSet.HERO,cards_lv:6,lv:1,type:HType.Long,hp:900,ap:120,speed:100, + skills:[6002,6105],slvs:[1,1],cds:[1,5],info:"普通射击,群体攻击buff 射手辅助"}, @@ -151,20 +149,20 @@ export const HeroInfo: Record = { //============== 兽人系列 =============== // 1. 基础近战型 - 6001:{uuid:6001,name:"兽人战士",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:0.65,ss:10,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],info:""}, + 6001:{uuid:6001,name:"兽人战士",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],slvs:[1,1],cds:[0.65,10],info:""}, // 2. 快速突击型 - 6002:{uuid:6002,name:"兽人斥候",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:0.65,ss:10,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],info:""}, + 6002:{uuid:6002,name:"兽人斥候",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],slvs:[1,1],cds:[0.65,10],info:""}, // 3. 重型坦克型 - 6003:{uuid:6003,name:"兽人卫士",path:"mo3", fac:FacSet.MON,cards_lv:1,lv:1,as:2,ss:10,type:HType.Melee,hp:350,ap:30,speed:120,skills:[6001,6003],info:""}, + 6003:{uuid:6003,name:"兽人卫士",path:"mo3", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:350,ap:30,speed:120,skills:[6001,6003],slvs:[1,1],cds:[2,10],info:""}, // 4. 远程骚扰型 - 6004:{uuid:6004,name:"兽人射手",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:1.5,ss:10,type:HType.Long,hp:80,ap:45,speed:80,skills:[6001,6003],info:""}, + 6004:{uuid:6004,name:"兽人射手",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Long,hp:80,ap:45,speed:80,skills:[6001,6003],slvs:[1,1],cds:[1.5,10],info:""}, // 5. 特殊机制型 - 6005:{uuid:6005,name:"兽人自爆兵",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:0.65,ss:10,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],info:""}, - 6006:{uuid:6006,name:"兽人召唤师",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:1,ss:10,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],info:""}, - 6007:{uuid:6007,name:"兽人祭司",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:1,ss:10,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],info:""}, - 6008:{uuid:6008,name:"兽人图腾师",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,as:1,ss:10,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],info:""}, + 6005:{uuid:6005,name:"兽人自爆兵",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:120,ap:12,speed:180,skills:[6001,6003],slvs:[1,1],cds:[0.65,10],info:""}, + 6006:{uuid:6006,name:"兽人召唤师",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],slvs:[1,1],cds:[1,10],info:""}, + 6007:{uuid:6007,name:"兽人祭司",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],slvs:[1,1],cds:[1,10],info:""}, + 6008:{uuid:6008,name:"兽人图腾师",path:"mo1", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:80,ap:20,speed:80,skills:[6001,6003],slvs:[1,1],cds:[1,10],info:""}, // 6. 精英/BOSS型 - 6009:{uuid:6009,name:"兽人首领(BOSS)",path:"mo4", fac:FacSet.MON,cards_lv:1,lv:1,as:1,ss:10,type:HType.Melee,hp:1500,ap:20,speed:100,skills:[6002,6004],info:""}, + 6009:{uuid:6009,name:"兽人首领(BOSS)",path:"mo4", fac:FacSet.MON,cards_lv:1,lv:1,type:HType.Melee,hp:1500,ap:20,speed:100,skills:[6002,6004],slvs:[1,1],cds:[1,10],info:""}, }; diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index 09bfc690..0fcf179b 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -79,15 +79,9 @@ export class Hero extends ecs.Entity { model.ap = hero.ap*model.lv; model.hp= model.hp_max = hero.hp*model.lv; model.speed = hero.speed; - model.a_cd_max=hero.as - model.s_cd_max=hero.ss - // 初始化技能信息数组 - if(hero.skills[0]) model.atk_id=hero.skills[0]*model.lv - let s_lv=hero.skills[model.lv]?model.lv:1 - if(hero.skills[s_lv]) { - model.skill_id=hero.skills[s_lv] - } - model.updateSkillDistanceCache(model.skill_id || model.atk_id); + model.setSkills(hero.skills, hero.cds); + model.skill_lvs=hero.slvs + model.updateSkillDistanceCache(); // 初始化 buff/debuff 系统 model.initAttrs(); diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index e9e00308..947befcc 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -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 = {}; + skill_cds: Record = {}; + skill_lvs:Record = {}; // ==================== 特殊属性 ==================== 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; // 重置脏标签 diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 53c52a6b..6bd7ddba 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -164,7 +164,7 @@ export class HeroViewComp extends CCComp { } public cd_show(){ - this.top_node.getChildByName("cd").getComponent(ProgressBar).progress = this.model.s_cd/this.model.s_cd_max; + this.top_node.getChildByName("cd").getComponent(ProgressBar).progress = this.model.getDisplaySkillCdProgress(); } /** 显示护盾 */ diff --git a/assets/script/game/hero/Mon.ts b/assets/script/game/hero/Mon.ts index 5903906c..8225c460 100644 --- a/assets/script/game/hero/Mon.ts +++ b/assets/script/game/hero/Mon.ts @@ -141,12 +141,8 @@ export class Monster extends ecs.Entity { if(!model.is_boss){ model.is_kalami = true; } - model.a_cd_max=hero.as - model.s_cd_max=hero.ss - // ✅ 初始化技能数据(迁移到 HeroSkillsComp) - if(hero.skills[0]) model.atk_id=hero.skills[0] - if(hero.skills[1]) model.skill_id=hero.skills[1] - model.updateSkillDistanceCache(model.skill_id || model.atk_id); + model.setSkills(hero.skills, hero.cds); + model.updateSkillDistanceCache(); //根据刷怪控制脚本对ap和hp进行加强 diff --git a/assets/script/game/hero/SCastSystem.ts b/assets/script/game/hero/SCastSystem.ts index 204f047c..454a6ac1 100644 --- a/assets/script/game/hero/SCastSystem.ts +++ b/assets/script/game/hero/SCastSystem.ts @@ -56,15 +56,13 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate const type = heroAttrs.type as HType; const maxRange = this.resolveMaxCastRange(heroAttrs, type); const target = this.findNearestEnemyInRange(heroAttrs, heroView, maxRange); - const skillCandidates = [heroAttrs.skill_id, heroAttrs.atk_id]; + const skillCandidates = this.buildSkillCandidates(heroAttrs.getSkillIds()); const selfEid = heroView.ent?.eid; for (const s_uuid of skillCandidates) { if (!s_uuid) continue; const config = SkillSet[s_uuid]; if (!config) continue; - const isMainSkill = s_uuid === heroAttrs.skill_id; - if (isMainSkill && !heroAttrs.can_skill) continue; - if (!isMainSkill && !heroAttrs.can_atk) continue; + if (!heroAttrs.isSkillReady(s_uuid)) continue; if (this.isSelfSkill(config.TGroup)) { if (typeof selfEid !== "number") continue; return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] }; @@ -91,8 +89,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate heroView.playReady(config.readyAnm); //播放角色攻击动画 heroView.playSkillAnm(config.act); - const isMainSkill = s_uuid === heroAttrs.skill_id; - + // 优先使用技能配置的前摇时间,否则使用全局默认值 // 注意:这里仍然是基于时间的延迟,受帧率波动影响。 // 若需精确同步,建议在动画中添加帧事件并在 HeroViewComp 中监听。 @@ -103,32 +100,34 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate if (castPlan.isFriendly) { const friendlyTargets = this.resolveFriendlyTargets(castPlan.targetEids, heroAttrs.fac); if (friendlyTargets.length === 0) return; - this.applyPrimaryEffect(s_uuid, config, heroView, friendlyTargets, null); + this.applyPrimaryEffect(s_uuid, config, heroView,heroAttrs, friendlyTargets, null); this.applyExtraEffects(config, friendlyTargets); return; } - this.applyPrimaryEffect(s_uuid, config, heroView, [], castPlan.targetPos); + this.applyPrimaryEffect(s_uuid, config, heroView,heroAttrs, [], castPlan.targetPos); }, delay); - if (isMainSkill) { - heroAttrs.triggerSkillCD(); - } else { - heroAttrs.triggerAtkCD(); - } + heroAttrs.triggerSkillCD(s_uuid); } - private createSkillEntity(s_uuid: number, caster: HeroViewComp, targetPos: Vec3) { + private buildSkillCandidates(skillIds: number[]): number[] { + if (!skillIds || skillIds.length === 0) return []; + if (skillIds.length === 1) return [skillIds[0]]; + return [...skillIds.slice(1), skillIds[0]]; + } + + private createSkillEntity(s_uuid: number, caster: HeroViewComp,cAttrsComp: HeroAttrsComp, targetPos: Vec3) { if (!caster.node || !caster.node.isValid) return; const parent = caster.node.parent; if (!parent) return; const skill = ecs.getEntity(Skill); - skill.load(caster.node.position.clone(), parent, s_uuid, targetPos.clone(), caster, 0); + skill.load(caster.node.position.clone(), parent, s_uuid, targetPos.clone(), caster,cAttrsComp, 0); } - private applyPrimaryEffect(s_uuid: number, config: SkillConfig, heroView: HeroViewComp, targets: HeroViewComp[], targetPos: Vec3 | null) { + private applyPrimaryEffect(s_uuid: number, config: SkillConfig, heroView: HeroViewComp, cAttrsComp: HeroAttrsComp,targets: HeroViewComp[], targetPos: Vec3 | null) { const kind = config.kind ?? SkillKind.Damage; if (kind === SkillKind.Damage) { if (config.ap <= 0 || !targetPos) return; - this.createSkillEntity(s_uuid, heroView, targetPos); + this.createSkillEntity(s_uuid, heroView,cAttrsComp, targetPos); return; } for (const target of targets) { diff --git a/assets/script/game/skill/Skill.ts b/assets/script/game/skill/Skill.ts index c9a7a1ca..963ea66f 100644 --- a/assets/script/game/skill/Skill.ts +++ b/assets/script/game/skill/Skill.ts @@ -101,9 +101,8 @@ export class Skill extends ecs.Entity { this.addComponents(SMoveDataComp); } load(startPos: Vec3, parent: Node, s_uuid: number, targetPos: Vec3, - caster:HeroViewComp,ext_dmg:number=0) { + caster:HeroViewComp,cAttrsComp:HeroAttrsComp, ext_dmg:number=0) { const config = SkillSet[s_uuid]; - if (!config) { mLogger.error(this.debugMode, 'Skill', "[Skill] 技能配置不存在:", s_uuid); return; @@ -196,8 +195,6 @@ export class Skill extends ecs.Entity { const sTimeCom = this.get(StimeDataComp); if (sTimeCom) this.remove(StimeDataComp); } - - let cAttrsComp=caster.ent.get(HeroAttrsComp) // 初始化数据组件 let sDataCom = this.get(SDataCom); if (!sDataCom) { @@ -210,7 +207,7 @@ export class Skill extends ecs.Entity { const addCrt = config.crt ?? 0; const addFrz = config.frz ?? 0; const addBck = config.bck ?? 0; - sDataCom.Attrs[Attrs.ap] = cAttrsComp.ap; + sDataCom.Attrs[Attrs.ap] = cAttrsComp.ap*config.ap; sDataCom.Attrs[Attrs.critical] = cAttrsComp.critical + addCrt; sDataCom.Attrs[Attrs.freeze_chance] = cAttrsComp.freeze_chance + addFrz; sDataCom.Attrs[Attrs.back_chance] = cAttrsComp.back_chance + addBck;