fix(game): 修复技能伤害应用时的空指针异常并调整英雄攻速

- 在 SkillView.apply_damage 中添加实体存在性安全检查,防止目标实体已销毁时访问属性
- 使用可选链操作符安全获取施法者和目标名称,避免日志记录时崩溃
- 将所有英雄的基础攻击速度(as)统一调整为 1,以平衡游戏性
This commit is contained in:
panw
2026-02-05 10:12:36 +08:00
parent 49b4bef033
commit 1ad7b70c45
2 changed files with 15 additions and 8 deletions

View File

@@ -148,37 +148,37 @@ export const CanSelectHeros: Record<number, number[]> = {
export const HeroInfo: Record<number, heroInfo> = {
// ========== 英雄角色 ==========
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:"刺客"},

View File

@@ -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(