From 1ad7b70c45f14afefca593dfcbabd1e27638125b Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 5 Feb 2026 10:12:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(game):=20=E4=BF=AE=E5=A4=8D=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E4=BC=A4=E5=AE=B3=E5=BA=94=E7=94=A8=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=8B=B1=E9=9B=84=E6=94=BB=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SkillView.apply_damage 中添加实体存在性安全检查,防止目标实体已销毁时访问属性 - 使用可选链操作符安全获取施法者和目标名称,避免日志记录时崩溃 - 将所有英雄的基础攻击速度(as)统一调整为 1,以平衡游戏性 --- assets/script/game/common/config/heroSet.ts | 14 +++++++------- assets/script/game/skill/SkillView.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/assets/script/game/common/config/heroSet.ts b/assets/script/game/common/config/heroSet.ts index 18c9969f..fdb76c49 100644 --- a/assets/script/game/common/config/heroSet.ts +++ b/assets/script/game/common/config/heroSet.ts @@ -148,37 +148,37 @@ export const CanSelectHeros: Record = { export const HeroInfo: Record = { // ========== 英雄角色 ========== - 5001:{uuid:5001,name:"盾战士",icon:"1001",path:"hk1", fac:FacSet.HERO, kind:1,as:1.5, + 5001:{uuid:5001,name:"盾战士",icon:"1001",path:"hk1", fac:FacSet.HERO, kind:1,as:1, type:HType.warrior,lv:1,hp:300,mp:200,def:5,ap:25,speed:120,skills:[6001,6004], rangeType: SkillRange.Melee, buff:[],tal:[],info:"盾战士"}, - 5002:{uuid:5002,name:"奥术法师",icon:"1001",path:"hm2", fac:FacSet.HERO, kind:2,as:1.5, + 5002:{uuid:5002,name:"奥术法师",icon:"1001",path:"hm2", fac:FacSet.HERO, kind:2,as:1, type:HType.mage,lv:1,hp:150,mp:135,def:0,ap:40,speed:95,skills:[6003,6101], rangeType: SkillRange.Long, buff:[],tal:[],info:"奥术法师"}, - 5003:{uuid:5003,name:"射手",icon:"1001",path:"ha1", fac:FacSet.HERO, kind:2,as:1.2, + 5003:{uuid:5003,name:"射手",icon:"1001",path:"ha1", fac:FacSet.HERO, kind:2,as:1, type:HType.remote,lv:1,hp:180,mp:80,def:0,ap:30,speed:140,skills:[6002,6100], rangeType: SkillRange.Long, buff:[],tal:[],info:"射手"}, - 5005:{uuid:5005,name:"牧师",icon:"1001",path:"hh1", fac:FacSet.HERO, kind:2,as:1.5, + 5005:{uuid:5005,name:"牧师",icon:"1001",path:"hh1", fac:FacSet.HERO, kind:2,as:1, type:HType.mage,lv:1,hp:160,mp:135,def:0,ap:25,speed:100,skills:[6003,6100], rangeType: SkillRange.Mid, buff:[],tal:[],info:"牧师"}, - 5004:{uuid:5004,name:"火焰法师",icon:"1001",path:"hm1", fac:FacSet.HERO, kind:2,as:1.5, + 5004:{uuid:5004,name:"火焰法师",icon:"1001",path:"hm1", fac:FacSet.HERO, kind:2,as:1, type:HType.mage,lv:1,hp:150,mp:140,def:0,ap:45,speed:90,skills:[6003,6101], rangeType: SkillRange.Mid, buff:[],tal:[],info:"火焰法师"}, - 5006:{uuid:5006,name:"召唤法师",icon:"1001",path:"hz1", fac:FacSet.HERO, kind:2,as:1.5, + 5006:{uuid:5006,name:"召唤法师",icon:"1001",path:"hz1", fac:FacSet.HERO, kind:2,as:1, type:HType.support,lv:1,hp:200,mp:145,def:0,ap:20,speed:105,skills:[6003,6101], rangeType: SkillRange.Mid, buff:[],tal:[],info:"召唤法师"}, - 5007:{uuid:5007,name:"刺客",icon:"1001",path:"hc1", fac:FacSet.HERO, kind:1,as:1.2, + 5007:{uuid:5007,name:"刺客",icon:"1001",path:"hc1", fac:FacSet.HERO, kind:1,as:1, type:HType.assassin,lv:1,hp:140,mp:60,def:0,ap:50,speed:180,skills:[6001,6004], rangeType: SkillRange.Melee, buff:[],tal:[],info:"刺客"}, diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index c0d24a1a..c580a769 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -153,6 +153,8 @@ export class SkillView extends CCComp { //伤害应用 apply_damage(target:HeroViewComp,is_range:boolean=false){ if(target == null) return; + // 安全检查:如果目标实体已不存在,直接返回 + if (!target.ent) return; if (!this.SConf) return; // 对于非持续碰撞类型的技能,在造成伤害后立即关闭碰撞检测 @@ -161,7 +163,12 @@ export class SkillView extends CCComp { this.collider.enabled = false; mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf.name}] 伤害后关闭碰撞检测`); } - mLogger.log(this.debugMode, 'SkillView', `[skillView] 伤害 [${this.group}][${this.sData.caster.ent.get(HeroAttrsComp).hero_name}][${this.sData.caster.ent.eid}]的 [${this.SConf.name}]对 [${target.box_group}][ ${target.ent.get(HeroAttrsComp).hero_name}][${target.ent.eid}]`); + + // 安全获取名称,防止实体销毁导致的空指针异常 + const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? "未知施法者"; + const targetName = target.ent.get(HeroAttrsComp)?.hero_name ?? "未知目标"; + + mLogger.log(this.debugMode, 'SkillView', `[skillView] 伤害 [${this.group}][${casterName}][${this.sData.casterEid}]的 [${this.SConf.name}]对 [${target.box_group}][ ${targetName}][${target.ent.eid}]`); // if(this.sData.hit_count > this.SConf.hit_num) return 不能超出 最大伤害数量 // 使用伤害队列系统处理伤害 DamageQueueHelper.addDamageToEntity(