diff --git a/assets/script/game/hero/HeroAtkSystem.ts b/assets/script/game/hero/HeroAtkSystem.ts index 96c0616e..e85024be 100644 --- a/assets/script/game/hero/HeroAtkSystem.ts +++ b/assets/script/game/hero/HeroAtkSystem.ts @@ -151,7 +151,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]-TAttrsComp.Attrs[Attrs.CRITICAL_RESIST]); // 计算基础伤害 let damage = this.dmgCount(damageEvent,TAttrsComp); - console.log("[HeroAtkSystem] dmgCount",damage) + if (this.debugMode) console.log("[HeroAtkSystem] dmgCount",damage) if (isCrit) { // 暴击伤害计算 // 使用施法者的暴击伤害加成属性(damageEvent.Attrs 快照) @@ -162,10 +162,10 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd CAttrsComp?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff } - console.log("[HeroAtkSystem] after crit",damage) + if (this.debugMode) console.log("[HeroAtkSystem] after crit",damage) // 护盾吸收 damage =Math.floor(this.absorbShield(TAttrsComp, damage)) - console.log("[HeroAtkSystem] after shield",damage) + if (this.debugMode) console.log("[HeroAtkSystem] after shield",damage) if (damage <= 0) return reDate; // 应用伤害到数据层 TAttrsComp.hp -= damage; diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 07e3dffb..f3d8b018 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -26,7 +26,20 @@ export interface BuffInfo { @ccclass('HeroViewComp') // 定义Cocos Creator 组件 @ecs.register('HeroView', false) // 定义ECS 组件 export class HeroViewComp extends CCComp { - private debugMode: boolean = false; // 是否启用调试模式 + private debugMode: boolean = true; // 是否启用调试模式 + + // 添加条件日志方法 + private debugLog(...args: any[]): void { + if (this.debugMode) { + console.log(...args); + } + } + + private debugWarn(...args: any[]): void { + if (this.debugMode) { + console.warn(...args); + } + } // ==================== View 层属性(表现相关)==================== as: HeroSpine = null! status:String = "idle" @@ -44,7 +57,7 @@ export class HeroViewComp extends CCComp { get model() { // 🔥 修复:添加安全检查,防止ent为null时的访问异常 if (!this.ent) { - console.warn("[HeroViewComp] ent is null, returning null for model"); + this.debugWarn("[HeroViewComp] ent is null, returning null for model"); return null; } return this.ent.get(HeroAttrsComp); @@ -161,7 +174,7 @@ export class HeroViewComp extends CCComp { // 不再基于血量是否满来决定显示状态,只更新进度条 let hp=this.model.hp; let hp_max=this.model.Attrs[Attrs.HP_MAX]; - console.log("hp_show",hp,hp_max) + this.debugLog("hp_show",hp,hp_max) this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp / hp_max;; this.scheduleOnce(() => { this.top_node.getChildByName("hp").getChildByName("hpb").getComponent(ProgressBar).progress = hp / hp_max;; @@ -173,7 +186,7 @@ export class HeroViewComp extends CCComp { if(!this.top_node.active) return let mp=this.model.mp; let mp_max=this.model.Attrs[Attrs.MP_MAX]; - console.log("mp_show",mp,mp_max) + this.debugLog("mp_show",mp,mp_max) this.top_node.getChildByName("mp").getComponent(ProgressBar).progress = mp / mp_max; this.scheduleOnce(() => { this.top_node.getChildByName("mp").getChildByName("mpb").getComponent(ProgressBar).progress = mp / mp_max; @@ -331,7 +344,7 @@ export class HeroViewComp extends CCComp { realDead(){ // 🔥 修复:添加model安全检查,防止实体销毁过程中的空指针异常 if (!this.model) { - console.warn("[HeroViewComp] realDead called but model is null, skipping"); + this.debugWarn("[HeroViewComp] realDead called but model is null, skipping"); return; } if(this.model.fac === FacSet.HERO){ @@ -472,3 +485,8 @@ export class HeroViewComp extends CCComp { } } + + + + +