From 63dd22fb8821ca02106f64bd0752dc6fb7ea6b69 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 3 Feb 2026 14:40:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E5=91=BD=E5=90=8DLogger?= =?UTF-8?q?=E7=B1=BB=E5=B9=B6=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将Logger类重命名为mLogger以符合命名规范 - 新增error方法用于统一错误输出 - 在多个组件中替换console.log/warn/error为mLogger的对应方法 - 为多个组件添加debugMode属性以控制模块级日志开关 - 新增HeroMasterComp组件框架 --- assets/script/game/common/Logger.ts | 14 +++++- .../script/game/common/SingletonModuleComp.ts | 28 ++++++----- assets/script/game/hero/Hero.ts | 13 +++-- assets/script/game/hero/HeroAtkSystem.ts | 40 +++++++--------- assets/script/game/hero/HeroAttrsComp.ts | 22 +++++---- assets/script/game/hero/HeroMasterComp.ts | 38 +++++++++++++++ .../script/game/hero/HeroMasterComp.ts.meta | 9 ++++ assets/script/game/hero/HeroSkills.ts | 8 +++- assets/script/game/hero/HeroViewComp.ts | 22 +++------ assets/script/game/hero/TalComp.ts | 27 +++++++---- assets/script/game/map/CardController.ts | 8 +++- assets/script/game/map/MissionCardComp.ts | 47 ++++++++++++++----- assets/script/game/map/MissionComp.ts | 23 +++++---- assets/script/game/map/MissionMonComp.ts | 8 +++- assets/script/game/map/RogueConfig.ts | 3 +- assets/script/game/skill/SkillView.ts | 22 +++------ 16 files changed, 215 insertions(+), 117 deletions(-) create mode 100644 assets/script/game/hero/HeroMasterComp.ts create mode 100644 assets/script/game/hero/HeroMasterComp.ts.meta diff --git a/assets/script/game/common/Logger.ts b/assets/script/game/common/Logger.ts index 31479be0..ff425897 100644 --- a/assets/script/game/common/Logger.ts +++ b/assets/script/game/common/Logger.ts @@ -1,4 +1,4 @@ -export class Logger { +export class mLogger { /** 总开关:控制所有日志输出 */ public static GLOBAL_ENABLED: boolean = true; @@ -25,4 +25,16 @@ export class Logger { console.warn(`[${tag}]`, ...args); } } + + /** + * 统一错误输出 + * @param enable 单独开关(模块级开关) + * @param tag 标签(通常是类名或模块名) + * @param args 错误内容 + */ + public static error(enable: boolean, tag: string, ...args: any[]) { + if (this.GLOBAL_ENABLED && enable) { + console.error(`[${tag}]`, ...args); + } + } } diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 3389fe12..9f9ba2c4 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -11,6 +11,7 @@ import { Attrs, GameScoreStats } from "./config/HeroAttrs"; import { count, time } from "console"; import { getLevelExp } from "../map/RogueConfig"; import { FightSet } from "./config/GameSet"; +import { mLogger } from "./Logger"; /** * 用远程数据覆盖本地数据(统一方法) * @param remoteData 远程数据(云端或本地调试) @@ -32,6 +33,8 @@ interface CloudData { /** 游戏模块 */ @ecs.register('SingletonModule') export class SingletonModuleComp extends ecs.Comp { + private debugMode: boolean = false; + /** 游戏初始化模块 */ initialize: Initialize = null!; /** 游戏地图 */ @@ -165,7 +168,7 @@ export class SingletonModuleComp extends ecs.Comp { this.vmdata.collection.talents[id] = 0; } this.vmdata.collection.talents[id]++; - console.log(`[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`); + mLogger.log(this.debugMode, 'SMC', `[SMC] 记录天赋获取: ID=${id}, 次数=${this.vmdata.collection.talents[id]}`); oops.message.dispatchEvent(GameEvent.UpdateCollection); } @@ -178,7 +181,7 @@ export class SingletonModuleComp extends ecs.Comp { this.vmdata.collection.skill.uuid = id; } this.vmdata.collection.skill.count++; - console.log(`[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`); + mLogger.log(this.debugMode, 'SMC', `[SMC] 记录技能获取: ID=${id}, 次数=${this.vmdata.collection.skill.count}`); oops.message.dispatchEvent(GameEvent.UpdateCollection); } /** @@ -190,7 +193,7 @@ export class SingletonModuleComp extends ecs.Comp { this.vmdata.collection.friend.uuid = id; } this.vmdata.collection.friend.count++; - console.log(`[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`); + mLogger.log(this.debugMode, 'SMC', `[SMC] 记录好友获取: ID=${id}, 次数=${this.vmdata.collection.friend.count}`); oops.message.dispatchEvent(GameEvent.UpdateCollection); } @@ -219,7 +222,7 @@ export class SingletonModuleComp extends ecs.Comp { // 更新下一级所需经验 h.exp_max = getLevelExp(h.lv); - console.log(`[SMC] 升级! Lv.${h.lv - 1} -> Lv.${h.lv}, 下级所需: ${h.exp_max}`); + mLogger.log(this.debugMode, 'SMC', `[SMC] 升级! Lv.${h.lv - 1} -> Lv.${h.lv}, 下级所需: ${h.exp_max}`); } if (isLevelUp) { @@ -230,6 +233,7 @@ export class SingletonModuleComp extends ecs.Comp { vmAdd() { VM.add(this.vmdata, "data"); + // mLogger.log(this.debugMode, 'SMC', "[MissionComp]局内数据初始化",smc.vmdata.mission_data) } reset() { for (var key in this.vmdata) { @@ -256,16 +260,16 @@ export class SingletonModuleComp extends ecs.Comp { let gemeDate=this.getGameDate() WxCloudApi.save(gemeDate).then((result) => { - console.log('云端保存') + mLogger.log(this.debugMode, 'SMC', '云端保存') if(result.result.code === 200) { - console.log("保存成功",result.result) + mLogger.log(this.debugMode, 'SMC', "保存成功",result.result) return true } else { - console.warn(`[SMC]: 游戏数据增加失败: ${result.result.msg}`); + mLogger.warn(this.debugMode, 'SMC', `[SMC]: 游戏数据增加失败: ${result.result.msg}`); return false } }).catch((error) => { - console.error(`[SMC]: 增加游戏数据异常:`, error); + mLogger.error(this.debugMode, 'SMC', `[SMC]: 增加游戏数据异常:`, error); return false }); return true @@ -274,15 +278,15 @@ export class SingletonModuleComp extends ecs.Comp { WxCloudApi.get().then(async (result) => { if(result.result.code === 200) { let data=result.result.data - console.log(`[SMC]: 获取游戏数据成功:`, result.result); + mLogger.log(this.debugMode, 'SMC', `[SMC]: 获取游戏数据成功:`, result.result); this.overrideLocalDataWithRemote(data) return true } else { - console.warn(`[SMC]: 游戏数据增加失败`); + mLogger.warn(this.debugMode, 'SMC', `[SMC]: 游戏数据增加失败`); return false } }).catch((error) => { - console.error(`[SMC]: 获取游戏数据异常:`, error); + mLogger.error(this.debugMode, 'SMC', `[SMC]: 获取游戏数据异常:`, error); }); } public async overrideLocalDataWithRemote(CloudData) { @@ -303,7 +307,7 @@ export class SingletonModuleComp extends ecs.Comp { } } catch (error) { - console.error(`[SMC]: 数据覆盖失败:`, error); + mLogger.error(this.debugMode, 'SMC', `[SMC]: 数据覆盖失败:`, error); } } getGameDate(){ diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index eafbf1f5..60ebf516 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -13,6 +13,8 @@ import { getNeAttrs, getAttrs ,Attrs} from "../common/config/HeroAttrs"; import { HeroSkillsComp } from "./HeroSkills"; import { HeroMoveComp } from "./HeroMove"; import { TalComp } from "./TalComp"; +import { mLogger } from "../common/Logger"; +import { HeroMasterComp } from "./HeroMasterComp"; /** 角色实体 */ @ecs.register(`Hero`) @@ -33,6 +35,7 @@ export class Hero extends ecs.Entity { destroy(): void { // 如果是主角,清理全局引用 if (smc.role === this) { + console.log(`[Hero] 主角销毁,清除 smc.role`); smc.role = null; } @@ -92,7 +95,9 @@ export class Hero extends ecs.Entity { // 只有主角才挂载天赋组件 if (is_master) { smc.role = this; // 记录主角实体引用 + console.log(`[Hero] 主角创建,设置 smc.role, uuid=${uuid}`); this.add(TalComp); + this.add(HeroMasterComp) const talComp = this.get(TalComp); if (talComp) { talComp.init(uuid); @@ -156,9 +161,9 @@ export class HeroLifecycleSystem extends ecs.ComblockSystem // 英雄实体创建时的特殊处理 const heroAttrs = e.get(HeroAttrsComp); if (heroAttrs) { - console.log(`英雄进入世界: ${heroAttrs.hero_name}`); + mLogger.log(heroAttrs.debugMode, 'HeroLifecycle', `英雄进入世界: ${heroAttrs.hero_name}`); } else { - console.log(`英雄进入世界: 实体ID ${e.eid}`); + mLogger.log(true, 'HeroLifecycle', `英雄进入世界: 实体ID ${e.eid}`); } } @@ -166,9 +171,9 @@ export class HeroLifecycleSystem extends ecs.ComblockSystem // 英雄实体销毁时的清理工作 const heroAttrs = e.get(HeroAttrsComp); if (heroAttrs) { - console.log(`英雄离开世界: ${heroAttrs.hero_name}`); + mLogger.log(heroAttrs.debugMode, 'HeroLifecycle', `英雄离开世界: ${heroAttrs.hero_name}`); } else { - console.log(`英雄离开世界: 实体ID ${e.eid}`); + mLogger.log(true, 'HeroLifecycle', `英雄离开世界: 实体ID ${e.eid}`); } } } \ No newline at end of file diff --git a/assets/script/game/hero/HeroAtkSystem.ts b/assets/script/game/hero/HeroAtkSystem.ts index ad2652fd..041bbe91 100644 --- a/assets/script/game/hero/HeroAtkSystem.ts +++ b/assets/script/game/hero/HeroAtkSystem.ts @@ -12,7 +12,7 @@ import { oops } from "db://oops-framework/core/Oops"; import { GameEvent } from "../common/config/GameEvent"; -import { Logger } from "../common/Logger"; +import { mLogger } from "../common/Logger"; /** 最终伤害数据接口 * 用于封装一次攻击计算的所有结果数据 @@ -43,14 +43,6 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd private debugMode: boolean = false; // 是否启用调试模式 - private debugLog(...args: any[]): void { - Logger.log(this.debugMode, 'HeroAtkSystem', ...args); - } - - private debugWarn(...args: any[]): void { - Logger.warn(this.debugMode, 'HeroAtkSystem', ...args); - } - /** * 过滤器:处理拥有伤害队列的实体 */ @@ -85,7 +77,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd damageQueue.processedCount++; // 如果目标已死亡,停止处理后续伤害 if (TAttrsComp.is_dead) { - this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 已死亡,停止处理剩余伤害`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] ${TAttrsComp.hero_name} 已死亡,停止处理剩余伤害`); damageQueue.clear(); // 清空剩余伤害 break; } @@ -96,7 +88,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd e.remove(DamageQueueComp); if (processedCount > 0) { - this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 伤害队列处理完成,共处理 ${processedCount} 个伤害事件`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] ${TAttrsComp.hero_name} 伤害队列处理完成,共处理 ${processedCount} 个伤害事件`); } } } @@ -164,7 +156,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]-TAttrsComp.Attrs[Attrs.CRITICAL_RES]); // 计算基础伤害 let damage = this.dmgCount(damageEvent,TAttrsComp); - this.debugLog("[HeroAtkSystem] dmgCount",damage) + mLogger.log(this.debugMode, 'HeroAtkSystem', "[HeroAtkSystem] dmgCount",damage) if (isCrit) { // 暴击伤害计算 // 使用施法者的暴击伤害加成属性(damageEvent.Attrs 快照) @@ -175,11 +167,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd CAttrsComp?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff } - this.debugLog("[HeroAtkSystem] after crit",damage) + mLogger.log(this.debugMode, 'HeroAtkSystem', "[HeroAtkSystem] after crit",damage) // 护盾吸收 const shieldResult = this.absorbShield(TAttrsComp, damage); damage = shieldResult.remainingDamage; - this.debugLog("[HeroAtkSystem] after shield",damage) + mLogger.log(this.debugMode, 'HeroAtkSystem', "[HeroAtkSystem] after shield",damage) // 显示护盾吸收飘字 if (shieldResult.absorbedDamage > 0 && targetView) { targetView.shield_tip(shieldResult.absorbedDamage); @@ -197,7 +189,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM const casterName = CAttrsComp?.hero_name || "未知"; - this.debugLog(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`); //反伤判定 并应用到施法者 this.check_thorns(TAttrsComp, caster, damage); @@ -229,7 +221,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd targetView.scheduleRevive(1.0); } - this.debugLog(`[HeroAtkSystem] Hero waiting to revive! Lives left: ${TAttrsComp.Attrs[Attrs.REVIVE_COUNT]}`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] Hero waiting to revive! Lives left: ${TAttrsComp.Attrs[Attrs.REVIVE_COUNT]}`); return reDate; } @@ -240,7 +232,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd if (TAttrsComp.is_master&&TAttrsComp.Attrs[Attrs.REVIVE_COUNT] <= 0) { smc.mission.stop_mon_action = true; oops.message.dispatchEvent(GameEvent.HeroDead, { hero_uuid: TAttrsComp.hero_uuid}); - this.debugLog("[HeroAtkSystem] Hero died, stopping monster action (spawn/move)"+TAttrsComp.Attrs[Attrs.REVIVE_COUNT]); + mLogger.log(this.debugMode, 'HeroAtkSystem', "[HeroAtkSystem] Hero died, stopping monster action (spawn/move)"+TAttrsComp.Attrs[Attrs.REVIVE_COUNT]); } this.doDead(target); @@ -250,7 +242,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd } } - this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`); reDate.damage=damage; @@ -330,11 +322,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd const TAttrs=TAttrsComp.Attrs; let sConf = SkillSet[damageEvent.s_uuid]; if (!sConf) return 0; - this.debugLog(`[HeroAtkSystem] 伤害处理对象`,CAttrs,TAttrs); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 伤害处理对象`,CAttrs,TAttrs); // 2. 计算原始物理伤害和魔法伤害 // 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外伤害) / 100 * 额外伤害比例 let apBase = (sConf.ap||0)*(CAttrs[Attrs.AP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio; - this.debugLog(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]},} + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]},} 额外伤害:${damageEvent.ext_dmg}, 额外伤害比例:${damageEvent.dmg_ratio}`); // 易伤 let DMG_INVUL = TAttrs[Attrs.DMG_INVUL]||0 @@ -351,7 +343,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd total = Math.floor(total * damageRatio); - if (this.debugMode) console.log(`[HeroAtkSystem] 最终伤害: ${total} (Base: ${apBase}, Def: ${DMG_RED}%, Invul: ${DMG_INVUL}%, Ratio: ${damageRatio})`); + if (this.debugMode) mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 最终伤害: ${total} (Base: ${apBase}, Def: ${DMG_RED}%, Invul: ${DMG_INVUL}%, Ratio: ${damageRatio})`); return total; } @@ -467,7 +459,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd private absorbShield(TAttrsComp: HeroAttrsComp, damage: number): {remainingDamage: number, absorbedDamage: number} { if (TAttrsComp.shield <= 0) { - this.debugLog("[HeroAtkSystem] 护盾值小于等于0,无法吸收伤害"); + mLogger.log(this.debugMode, 'HeroAtkSystem', "[HeroAtkSystem] 护盾值小于等于0,无法吸收伤害"); return {remainingDamage: damage, absorbedDamage: 0}; }; @@ -478,7 +470,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0; } TAttrsComp.dirty_shield = true; - this.debugLog(`[HeroAtkSystem] 护盾值完全吸收伤害 ${damage}`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 护盾值完全吸收伤害 ${damage}`); return {remainingDamage: 0, absorbedDamage: damage}; } else { const absorbedDamage = TAttrsComp.shield; @@ -486,7 +478,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd TAttrsComp.shield = 0; TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0; TAttrsComp.dirty_shield = true; - this.debugLog(`[HeroAtkSystem] 护盾值部分吸收伤害 ${absorbedDamage}`); + mLogger.log(this.debugMode, 'HeroAtkSystem', `[HeroAtkSystem] 护盾值部分吸收伤害 ${absorbedDamage}`); return {remainingDamage, absorbedDamage}; } } diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index cbe552de..06526063 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -7,7 +7,10 @@ import { HeroInfo, AttrSet } from "../common/config/heroSet"; import { HeroSkillsComp } from "./HeroSkills"; import { smc } from "../common/SingletonModuleComp"; import { AttrCards, PotionCards } from "../common/config/AttrSet"; - +import { mLogger } from "../common/Logger"; +import { _decorator } from "cc"; + +const { property } = _decorator; interface talTrigger{ value:number @@ -15,6 +18,9 @@ interface talTrigger{ } @ecs.register('HeroAttrs') export class HeroAttrsComp extends ecs.Comp { + @property({ tooltip: "是否启用调试日志" }) + public debugMode: boolean = false; + Ebus:any=null! // ==================== 角色基础信息 ==================== hero_uuid: number = 1001; @@ -95,7 +101,7 @@ export class HeroAttrsComp extends ecs.Comp { const uuid = args; const attrCard = AttrCards[uuid]; if (attrCard) { - console.log(`[HeroAttrs] 使用属性卡: ${attrCard.desc}`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 使用属性卡: ${attrCard.desc}`); // 构造 BuffConf,默认使用 BType.VALUE,永久生效 (time: 0) const buffConf: BuffConf = { buff: attrCard.attr, @@ -117,7 +123,7 @@ export class HeroAttrsComp extends ecs.Comp { // 1. 尝试从 PotionCards 获取 (新版药水) const potion = PotionCards[itemId]; if (potion) { - console.log(`[HeroAttrs] 使用药水: ${potion.desc}`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 使用药水: ${potion.desc}`); const buffConf: BuffConf = { buff: potion.attr, value: potion.value, @@ -140,7 +146,7 @@ export class HeroAttrsComp extends ecs.Comp { const newLv = args.lv; if (newLv > this.lv) { - console.log(`[HeroAttrs] 英雄升级处理: Lv.${this.lv} -> Lv.${newLv}`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 英雄升级处理: Lv.${this.lv} -> Lv.${newLv}`); this.lv = newLv; // === 属性成长逻辑 (示例: 固定数值成长) === @@ -249,7 +255,7 @@ export class HeroAttrsComp extends ecs.Comp { this.hp = Math.max(0, Math.min(this.hp, this.Attrs[Attrs.HP_MAX])); this.dirty_hp = true; // ✅ 仅标记需要更新 smc.updateHeroInfo(this); - // console.log(`[HeroAttrs] HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] HP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldHp.toFixed(1)} -> ${this.hp.toFixed(1)}`); } add_mp(value:number,isValue:boolean){ const oldMp = this.mp; @@ -267,7 +273,7 @@ export class HeroAttrsComp extends ecs.Comp { this.mp += addValue; this.mp = Math.max(0, Math.min(this.mp, this.Attrs[Attrs.MP_MAX])); this.dirty_mp = true; // ✅ 仅标记需要更新 - console.log(`[HeroAttrs] MP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldMp.toFixed(1)} -> ${this.mp.toFixed(1)}`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] MP变更: ${this.hero_name}, 变化=${addValue.toFixed(1)}, ${oldMp.toFixed(1)} -> ${this.mp.toFixed(1)}`); } add_shield(value:number,isValue:boolean){ const oldShield = this.shield; @@ -392,7 +398,7 @@ export class HeroAttrsComp extends ecs.Comp { const [val, count] = smc.global_attrs[attrIndex]; const globalAdd = val * count; totalRatio += globalAdd; - // console.log(`[HeroAttrs] 全局加成: ${this.hero_name} Attr=${attrIndex} Val=${val} Count=${count} Add=${globalAdd}%`); + // mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 全局加成: ${this.hero_name} Attr=${attrIndex} Val=${val} Count=${count} Add=${globalAdd}%`); } // 4. 根据属性类型计算最终值 @@ -411,7 +417,7 @@ export class HeroAttrsComp extends ecs.Comp { this.clampSingleAttr(attrIndex); if (oldVal !== this.Attrs[attrIndex]) { - console.log(`[HeroAttrs] 属性重算: ${this.hero_name}, 属性ID=${attrIndex}, ${oldVal} -> ${this.Attrs[attrIndex]} (Base=${baseVal}, Add=${totalValue-baseVal}, Ratio=${totalRatio}%)`); + mLogger.log(this.debugMode, 'HeroAttrs', `[HeroAttrs] 属性重算: ${this.hero_name}, 属性ID=${attrIndex}, ${oldVal} -> ${this.Attrs[attrIndex]} (Base=${baseVal}, Add=${totalValue-baseVal}, Ratio=${totalRatio}%)`); } } diff --git a/assets/script/game/hero/HeroMasterComp.ts b/assets/script/game/hero/HeroMasterComp.ts new file mode 100644 index 00000000..6cffec7a --- /dev/null +++ b/assets/script/game/hero/HeroMasterComp.ts @@ -0,0 +1,38 @@ +import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; +import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; +import { GameEvent } from "../common/config/GameEvent"; +import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs"; +import { BuffConf, SkillRange } from "../common/config/SkillSet"; +import { HeroInfo, AttrSet } from "../common/config/heroSet"; +import { HeroSkillsComp } from "./HeroSkills"; +import { smc } from "../common/SingletonModuleComp"; +import { AttrCards, PotionCards } from "../common/config/AttrSet"; +import { mLogger } from "../common/Logger"; +import { _decorator } from "cc"; + + + +@ecs.register('HeroMaster') +export class HeroMasterComp extends ecs.Comp { + public debugMode: boolean = false; + + onLoad() { + + } + + onDestroy() { + + } + + + reset() { + // 重置为初始状态 + + } + + + +} + + + diff --git a/assets/script/game/hero/HeroMasterComp.ts.meta b/assets/script/game/hero/HeroMasterComp.ts.meta new file mode 100644 index 00000000..b2374fe8 --- /dev/null +++ b/assets/script/game/hero/HeroMasterComp.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "ddc7102d-a082-4e1c-a527-6493347f2c1b", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/script/game/hero/HeroSkills.ts b/assets/script/game/hero/HeroSkills.ts index 498758a9..0ab3c71a 100644 --- a/assets/script/game/hero/HeroSkills.ts +++ b/assets/script/game/hero/HeroSkills.ts @@ -5,6 +5,10 @@ import { Attrs } from "../common/config/HeroAttrs"; import { HeroInfo } from "../common/config/heroSet"; import { HSSet, SkillSet } from "../common/config/SkillSet"; import { HeroAttrsComp } from "./HeroAttrsComp"; +import { mLogger } from "../common/Logger"; +import { _decorator } from "cc"; + +const { property } = _decorator; /** * ==================== 技能槽位数据 ==================== @@ -35,6 +39,8 @@ export interface SkillSlot { */ @ecs.register('HeroSkills') export class HeroSkillsComp extends ecs.Comp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; // ==================== 技能槽位列表 ==================== /** 技能槽位数组(最多4个技能) */ @@ -101,7 +107,7 @@ export class HeroSkillsComp extends ecs.Comp { addSkill(s_uuid: number, hset: HSSet=HSSet.skill) { const config = SkillSet[s_uuid]; if (!config) { - console.warn(`[HeroSkills] 技能配置不存在: ${s_uuid}`); + mLogger.warn(this.debugMode, 'HeroSkills', `[HeroSkills] 技能配置不存在: ${s_uuid}`); return; } this.skills[s_uuid] = { diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 4463ff8d..82310937 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -1,7 +1,7 @@ import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Tween, Color, BoxCollider2D, UITransform} from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; -import { Logger } from "../common/Logger"; +import { mLogger } from "../common/Logger"; import { HeroSpine } from "./HeroSpine"; import { BoxSet, FacSet } from "../common/config/GameSet"; import { smc } from "../common/SingletonModuleComp"; @@ -28,16 +28,8 @@ export interface BuffInfo { @ecs.register('HeroView', false) // 定义ECS 组件 export class HeroViewComp extends CCComp { @property({ tooltip: "是否启用调试日志" }) - private debugMode: boolean = true; // 是否启用调试模式 + private debugMode: boolean = false; // 是否启用调试模式 - // 添加条件日志方法 - private debugLog(...args: any[]): void { - Logger.log(this.debugMode, 'HeroViewComp', ...args); - } - - private debugWarn(...args: any[]): void { - Logger.warn(this.debugMode, 'HeroViewComp', ...args); - } // ==================== View 层属性(表现相关)==================== as: HeroSpine = null! status:String = "idle" @@ -55,7 +47,7 @@ export class HeroViewComp extends CCComp { get model() { // 🔥 修复:添加安全检查,防止ent为null时的访问异常 if (!this.ent) { - this.debugWarn("[HeroViewComp] ent is null, returning null for model"); + mLogger.warn(this.debugMode, 'HeroViewComp', "[HeroViewComp] ent is null, returning null for model"); return null; } return this.ent.get(HeroAttrsComp); @@ -196,7 +188,7 @@ export class HeroViewComp extends CCComp { // 不再基于血量是否满来决定显示状态,只更新进度条 let hp=this.model.hp; let hp_max=this.model.Attrs[Attrs.HP_MAX]; - // this.debugLog("hp_show",hp,hp_max) + // mLogger.log(this.debugMode, 'HeroViewComp', "hp_show",hp,hp_max) let targetProgress = hp / hp_max; let hpNode = this.top_node.getChildByName("hp"); @@ -224,7 +216,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]; - this.debugLog("mp_show",mp,mp_max) + mLogger.log(this.debugMode, 'HeroViewComp', "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; @@ -425,7 +417,7 @@ export class HeroViewComp extends CCComp { realDead(){ // 🔥 修复:添加model安全检查,防止实体销毁过程中的空指针异常 if (!this.model) { - this.debugWarn("[HeroViewComp] realDead called but model is null, skipping"); + mLogger.warn(this.debugMode, 'HeroViewComp', "[HeroViewComp] realDead called but model is null, skipping"); return; } if(this.model.fac === FacSet.HERO){ @@ -501,7 +493,7 @@ export class HeroViewComp extends CCComp { playSkillEffect(skill_id:number) { let skill = SkillSet[skill_id] - this.debugLog('[heroview] skill_id'+skill_id,skill) + mLogger.log(this.debugMode, 'HeroViewComp', '[heroview] skill_id'+skill_id,skill) if (!skill) return; switch(skill.act){ case "max": diff --git a/assets/script/game/hero/TalComp.ts b/assets/script/game/hero/TalComp.ts index d05a3f64..2d561494 100644 --- a/assets/script/game/hero/TalComp.ts +++ b/assets/script/game/hero/TalComp.ts @@ -1,3 +1,5 @@ +import { _decorator } from "cc"; +import { mLogger } from "../common/Logger"; import { basename } from "path/win32"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; @@ -8,6 +10,8 @@ import { TalAttrs, talConf, TalEffet, TalTarget, TriType} from "../common/config import { HeroAttrsComp } from "./HeroAttrsComp"; import { HeroViewComp } from "./HeroViewComp"; +const { property } = _decorator; + /** * 天赋槽位接口定义 * 描述单个天赋的数据结构 @@ -42,6 +46,9 @@ export interface TalSlot { */ @ecs.register('TalComp', true) export class TalComp extends ecs.Comp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; + /** 英雄视图组件引用,运行时获取以避免循环引用 */ private heroView: any = null; @@ -80,7 +87,7 @@ export class TalComp extends ecs.Comp { */ private onUseTalentCard(event: string, args: any) { const uuid = args as number; - console.log(`[TalComp] 收到天赋选择事件,添加天赋 ID: ${uuid}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp] 收到天赋选择事件,添加天赋 ID: ${uuid}`); this.addTal(uuid); } @@ -91,7 +98,7 @@ export class TalComp extends ecs.Comp { // 只有当前实体是主角时才处理(虽然TalComp只挂载在主角上,但为了安全起见可以再确认,或者直接处理) // GameEvent.CanUpdateLv 事件参数 { lv: number } - console.log(`[TalComp] 监听到升级事件,当前等级: ${args.lv}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp] 监听到升级事件,当前等级: ${args.lv}`); // 更新升级类型的天赋进度 (默认每次升级触发一次,val=1) this.updateCur(TriType.LUP, 1); @@ -109,7 +116,7 @@ export class TalComp extends ecs.Comp { addTal(uuid: number,v_add:number = 0,c_add:number = 0,t_add:number = 0) { // 检查天赋是否已存在 if (this.Tals[uuid]) { - console.log(`[TalComp]天赋已存在,执行叠加逻辑 ID:${uuid}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp]天赋已存在,执行叠加逻辑 ID:${uuid}`); const tConf = talConf[uuid]; if (tConf) { // 叠加效果数值 @@ -121,7 +128,7 @@ export class TalComp extends ecs.Comp { // 获取天赋配置 const tConf = talConf[uuid]; if (!tConf) { - console.error(`[TalComp]天赋配置不存在,天赋ID:${uuid}`); + mLogger.error(this.debugMode, 'TalComp', `[TalComp]天赋配置不存在,天赋ID:${uuid}`); return; } @@ -143,7 +150,7 @@ export class TalComp extends ecs.Comp { desc: tConf.desc, cur: 0, // 当前累积值初始为0 }; - console.log(`[TalComp]添加天赋成功,天赋ID:${uuid}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp]添加天赋成功,天赋ID:${uuid}`); } checkTal() { @@ -157,7 +164,7 @@ export class TalComp extends ecs.Comp { for (let uuid in this.Tals) { const talent = this.Tals[uuid]; if (talent.cur >= (talent.Trigger - talent.Trigger_add)) { // 修复触发条件,累积值达到或超过触发阈值时触发 - console.log(`[TalComp]天赋触发,天赋ID:${uuid}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp]天赋触发,天赋ID:${uuid}`); // 重置累积值 talent.cur = 0; // 添加到触发列表 @@ -180,7 +187,7 @@ export class TalComp extends ecs.Comp { updateVal(uuid: number, val: number) { // 检查天赋是否存在 if (!this.Tals[uuid]) { - console.error(`[TalComp]天赋不存在,天赋ID:${uuid}`); + mLogger.error(this.debugMode, 'TalComp', `[TalComp]天赋不存在,天赋ID:${uuid}`); return; } @@ -191,7 +198,7 @@ export class TalComp extends ecs.Comp { updateTrigger(uuid: number, val: number) { // 检查天赋是否存在 if (!this.Tals[uuid]) { - console.error(`[TalComp]天赋不存在,天赋ID:${uuid}`); + mLogger.error(this.debugMode, 'TalComp', `[TalComp]天赋不存在,天赋ID:${uuid}`); return; } @@ -225,7 +232,7 @@ export class TalComp extends ecs.Comp { checkTrigger(uuid:number){ const talent = this.Tals[uuid]; if (talent.cur >= (talent.Trigger - talent.Trigger_add)) { // 修复触发条件,累积值达到或超过触发阈值时触发 - console.log(`[TalComp]天赋触发,天赋ID:${uuid}`); + mLogger.log(this.debugMode, 'TalComp', `[TalComp]天赋触发,天赋ID:${uuid}`); for(let i=0;i<(talent.count+talent.count_add);i++){ this.doTriggerTal(talent.uuid); } @@ -242,7 +249,7 @@ export class TalComp extends ecs.Comp { doTriggerTal(uuid: number) { // 检查天赋是否存在 if (!this.Tals[uuid]) { - console.error(`[TalComp]天赋不存在,天赋ID:${uuid}`); + mLogger.error(this.debugMode, 'TalComp', `[TalComp]天赋不存在,天赋ID:${uuid}`); return; } const talent = this.Tals[uuid]; diff --git a/assets/script/game/map/CardController.ts b/assets/script/game/map/CardController.ts index 47185d20..6b846ac1 100644 --- a/assets/script/game/map/CardController.ts +++ b/assets/script/game/map/CardController.ts @@ -2,12 +2,16 @@ import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { smc } from "../common/SingletonModuleComp"; +import { mLogger } from "../common/Logger"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('CardControllerComp') @ecs.register('CardController', false) export class CardControllerComp extends CCComp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; + touch_time:number = 0 in_touch:boolean = false bbg:any=null @@ -16,11 +20,11 @@ export class CardControllerComp extends CCComp { protected onLoad(): void { } start() { - console.log("CardControllerComp start",this.node) + mLogger.log(this.debugMode, 'CardController', "CardControllerComp start",this.node) this.page_init() } onAdded(args:any){ - console.log("CardControllerComp onAdded",args) + mLogger.log(this.debugMode, 'CardController', "CardControllerComp onAdded",args) smc.map.MapView.scene.mapLayer.node.getChildByName("loading").active=false; } protected update(dt: number): void { diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 36402798..23d9a2c1 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -1,3 +1,4 @@ +import { mLogger } from "../common/Logger"; import { _decorator, Label, Node, tween, Vec3, Color, Sprite, Tween, SpriteAtlas, resources } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; @@ -24,6 +25,9 @@ interface ICardEvent { @ccclass('MissionCardComp') @ecs.register('MissionCard', false) export class MissionCardComp extends CCComp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; + /** 视图层逻辑代码分离演示 */ @property(Node) card1:Node = null! @@ -376,7 +380,7 @@ export class MissionCardComp extends CCComp { // 加载图集 resources.load("gui/uicons", SpriteAtlas, (err, atlas) => { if (err) { - console.error("[MissionCardComp] Failed to load uicons atlas", err); + mLogger.error(this.debugMode, 'MissionCard', "[MissionCardComp] Failed to load uicons atlas", err); return; } this.uiconsAtlas = atlas; @@ -395,7 +399,7 @@ export class MissionCardComp extends CCComp { } selectCard(e: any, index: string) { - console.log("selectCard", index) + mLogger.log(this.debugMode, 'MissionCard', "selectCard", index) let _index = parseInt(index); // 如果已经选择过,则不再处理 if (this.hasSelected) return; @@ -406,7 +410,7 @@ export class MissionCardComp extends CCComp { if (selectedData && selectedCardNode) { this.hasSelected = true; - console.log("选择卡片:", selectedData.name, "类型:", selectedData.type); + mLogger.log(this.debugMode, 'MissionCard', "选择卡片:", selectedData.name, "类型:", selectedData.type); // 未选中的卡片缩小 const cards = [this.card1, this.card2, this.card3, this.card4]; @@ -432,7 +436,24 @@ export class MissionCardComp extends CCComp { .call(() => { // 根据类型直接操作 smc.role (如果是主角) // 确保只影响主角,避免广播事件导致所有实体生效 - const role = smc.role; + let role = smc.role; + + // 容错处理:如果 smc.role 为空,尝试通过 ECS 查询查找主角 + if (!role) { + console.warn("[MissionCard] smc.role 为空,尝试查找主角实体..."); + // @ts-ignore + const entities = ecs.query(ecs.allOf(HeroAttrsComp)); + for (const e of entities) { + const attrs = e.get(HeroAttrsComp); + if (attrs && attrs.is_master) { + role = e; + smc.role = e; // 修复 smc.role 引用 + console.log("[MissionCard] 成功找回主角实体并修复 smc.role"); + break; + } + } + } + if (role) { switch (selectedData.type) { case CardType.Talent: @@ -441,10 +462,10 @@ export class MissionCardComp extends CCComp { const talComp = role.get(TalComp); if (talComp) { const beforeCount = Object.keys(talComp.Tals).length; - console.log(`[MissionCard] Talent Before: Count=${beforeCount}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Talent Before: Count=${beforeCount}`); talComp.addTal(selectedData.uuid); const afterCount = Object.keys(talComp.Tals).length; - console.log(`[MissionCard] Talent After: Count=${afterCount}, Added=${selectedData.uuid}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Talent After: Count=${afterCount}, Added=${selectedData.uuid}`); } break; case CardType.Skill: @@ -453,10 +474,10 @@ export class MissionCardComp extends CCComp { const skillComp = role.get(HeroSkillsComp); if (skillComp) { const beforeCount = Object.keys(skillComp.skills).length; - console.log(`[MissionCard] Skill Before: Count=${beforeCount}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Skill Before: Count=${beforeCount}`); skillComp.addSkill(selectedData.uuid); const afterCount = Object.keys(skillComp.skills).length; - console.log(`[MissionCard] Skill After: Count=${afterCount}, Added=${selectedData.uuid}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Skill After: Count=${afterCount}, Added=${selectedData.uuid}`); } break; case CardType.Partner: @@ -470,7 +491,7 @@ export class MissionCardComp extends CCComp { const potion = PotionCards[selectedData.uuid]; if (potion) { const beforeVal = attrsComp.Attrs[potion.attr] || 0; - console.log(`[MissionCard] Potion Before: Attr[${potion.attr}]=${beforeVal}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Potion Before: Attr[${potion.attr}]=${beforeVal}`); const buffConf: BuffConf = { buff: potion.attr, @@ -482,7 +503,7 @@ export class MissionCardComp extends CCComp { attrsComp.addBuff(buffConf); smc.updateHeroInfo(attrsComp); - console.log(`[MissionCard] Potion Applied: ${potion.desc}, Value=${potion.value}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Potion Applied: ${potion.desc}, Value=${potion.value}`); oops.gui.toast(potion.desc); } } @@ -500,7 +521,7 @@ export class MissionCardComp extends CCComp { if (roleAttrs) { roleBefore = roleAttrs.Attrs[attrCard.attr] || 0; } - console.log(`[MissionCard] Attr Before: Global=${globalBefore}, Hero=${roleBefore}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Attr Before: Global=${globalBefore}, Hero=${roleBefore}`); if (!smc.global_attrs[attrCard.attr]) { smc.global_attrs[attrCard.attr] = [0, 0]; @@ -516,7 +537,7 @@ export class MissionCardComp extends CCComp { smc.updateHeroInfo(attrsComp); const roleAfter = attrsComp.Attrs[attrCard.attr] || 0; - console.log(`[MissionCard] Attr After: Global=${current[0]}, Hero=${roleAfter}`); + mLogger.log(this.debugMode, 'MissionCard', `[MissionCard] Attr After: Global=${current[0]}, Hero=${roleAfter}`); } oops.gui.toast(attrCard.desc); } @@ -542,7 +563,7 @@ export class MissionCardComp extends CCComp { /** 看广告关闭 Lock */ watchAdCloseLock() { // TODO: 此处接入 IAA 广告 SDK - console.log("播放激励视频广告..."); + mLogger.log(this.debugMode, 'MissionCard', "播放激励视频广告..."); // 模拟广告播放成功回调 this.isLocked = false; diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index f791b713..8a196149 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -10,6 +10,7 @@ import { HeroViewComp } from "../hero/HeroViewComp"; import { UIID } from "../common/config/GameUIConfig"; import { SkillView } from "../skill/SkillView"; import { FightSet, getLevelRewardType, CardType, FacSet } from "../common/config/GameSet"; +import { mLogger } from "../common/Logger"; const { ccclass, property } = _decorator; @@ -19,6 +20,9 @@ const { ccclass, property } = _decorator; @ccclass('MissionComp') @ecs.register('MissionComp', false) export class MissionComp extends CCComp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; + // VictoryComp:any = null; // reward:number = 0; // reward_num:number = 0; @@ -84,7 +88,7 @@ export class MissionComp extends CCComp { // 升级奖励触发 onLevelUp(event: string, args: any) { - console.log(`[MissionComp] 英雄升级到 ${args.lv} 级!`); + mLogger.log(this.debugMode, 'MissionComp', `[MissionComp] 英雄升级到 ${args.lv} 级!`); this.call_cards(args.lv) // 获取当前等级对应的奖励类型 @@ -96,7 +100,7 @@ export class MissionComp extends CCComp { call_cards(lv:number){ const rewardType = getLevelRewardType(lv); - console.log(`[MissionComp] 触发奖励选择, 类型: ${rewardType}`); + mLogger.log(this.debugMode, 'MissionComp', `[MissionComp] 触发奖励选择, 类型: ${rewardType}`); // 默认每级都触发属性选择 oops.message.dispatchEvent(GameEvent.AttrSelect); @@ -119,7 +123,7 @@ export class MissionComp extends CCComp { } showLevelUpReward() { // TODO: 显示三选一技能/属性奖励界面 - console.log("[MissionComp] 显示升级奖励界面 (TODO)"); + mLogger.log(this.debugMode, 'MissionComp', "[MissionComp] 显示升级奖励界面 (TODO)"); } //奖励发放 @@ -128,7 +132,7 @@ export class MissionComp extends CCComp { } do_mon_dead(event:any,data:any){ - // console.log("[MissionComp] do_mon_dead",event,data) + // mLogger.log(this.debugMode, 'MissionComp', "[MissionComp] do_mon_dead",event,data) smc.vmdata.mission_data.mon_num-- // 计算并增加经验 // data 应该是怪物组件或包含怪物信息的对象 @@ -219,7 +223,7 @@ do_ad(){ // smc.mission.play = false; smc.mission.pause = true; // oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false}) - console.log("[MissionComp] open_Victory",is_hero_dead,this.revive_times) + mLogger.log(this.debugMode, 'MissionComp', "[MissionComp] open_Victory",is_hero_dead,this.revive_times) oops.gui.open(UIID.Victory,{ victory:false, rewards:this.rewards, @@ -232,13 +236,13 @@ do_ad(){ onReviveSuccess() { if (this.revive_times > 0) { this.revive_times--; - console.log(`[MissionComp] 玩家复活,剩余次数: ${this.revive_times}`); + mLogger.log(this.debugMode, 'MissionComp', `[MissionComp] 玩家复活,剩余次数: ${this.revive_times}`); } } fight_end(){ - // console.log("任务结束") + // mLogger.log(this.debugMode, 'MissionComp', "任务结束") // 延迟0.5秒后执行任务结束逻辑 this.scheduleOnce(() => { smc.mission.play=false @@ -247,7 +251,7 @@ do_ad(){ } mission_end(){ - // console.log("[MissionComp] mission_end") + // mLogger.log(this.debugMode, 'MissionComp', "[MissionComp] mission_end") // 合并 FightEnd 逻辑:清理组件、停止游戏循环 smc.mission.play=false this.cleanComponents() @@ -273,6 +277,7 @@ do_ad(){ this.spawnedSpecialIndices.clear(); // 重置特殊刷怪记录 // 重置全局属性加成和主角引用 (确保新一局数据干净) + console.log(`[MissionComp] data_init 重置 smc.role 为 null`); smc.role = null; // 重置英雄数据,确保新一局是初始状态 @@ -301,7 +306,7 @@ do_ad(){ }; - // console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data) + // mLogger.log(this.debugMode, 'MissionComp', "[MissionComp]局内数据初始化",smc.vmdata.mission_data) } private cleanComponents() { diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index 361cf0e1..d434397b 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -1,4 +1,5 @@ import { _decorator, v3, Vec3 } from "cc"; +import { mLogger } from "../common/Logger"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { Monster } from "../hero/Mon"; @@ -16,7 +17,10 @@ const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MissionMonCompComp') @ecs.register('MissionMonComp', false) -export class MissionMonCompComp extends CCComp { +export class MissionMonCompComp extends CCComp { + @property({ tooltip: "是否启用调试日志" }) + private debugMode: boolean = false; + // 刷怪队列 (主要用于特殊事件插队) private MonQueue: Array<{ uuid: number, @@ -82,7 +86,7 @@ export class MissionMonCompComp extends CCComp { this.MonQueue = [] this.spawnCount = 0 - console.log("[MissionMonComp] Starting Wave System (15-min Cycle)"); + mLogger.log(this.debugMode, 'MissionMonComp', "[MissionMonComp] Starting Wave System (15-min Cycle)"); } protected update(dt: number): void { diff --git a/assets/script/game/map/RogueConfig.ts b/assets/script/game/map/RogueConfig.ts index 08869a44..dc9fa290 100644 --- a/assets/script/game/map/RogueConfig.ts +++ b/assets/script/game/map/RogueConfig.ts @@ -12,6 +12,7 @@ */ import { HeroInfo } from "../common/config/heroSet"; +import { mLogger } from "../common/Logger"; /** * 怪物类型枚举 @@ -283,7 +284,7 @@ function applyGrowthFormula(baseStat: number, waveFactor: number, growthType: Gr export function getMonAttr(stage: number, uuid: number, monType: MonType = MonType.NORMAL, timeInSeconds: number = 0): MonAttrs { const baseMonster = HeroInfo[uuid]; if (!baseMonster) { - console.warn(`[RogueConfig] 未找到怪物ID: ${uuid}`); + mLogger.warn(true, 'RogueConfig', `[RogueConfig] 未找到怪物ID: ${uuid}`); return { hp: 100, mp: 100, ap: 10, def: 0, speed: 100 }; } diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index 597fa8ad..3183f94c 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -7,7 +7,7 @@ import { SDataCom } from "./SDataCom"; import { Attrs } from "../common/config/HeroAttrs"; import { HeroAttrsComp } from "../hero/HeroAttrsComp"; import { DamageQueueHelper } from "../hero/DamageQueueComp"; -import { Logger } from "../common/Logger"; +import { mLogger } from "../common/Logger"; const { ccclass, property } = _decorator; @@ -24,14 +24,6 @@ export class SkillView extends CCComp { @property({ tooltip: "是否启用调试日志" }) private debugMode: boolean = false; - private debugLog(...args: any[]): void { - Logger.log(this.debugMode, 'SkillView', ...args); - } - - private debugWarn(...args: any[]): void { - Logger.warn(this.debugMode, 'SkillView', ...args); - } - anim:Animation=null; group:number=0; SConf:SkillConfig=null; @@ -75,10 +67,10 @@ export class SkillView extends CCComp { const targetView = oCol.getComponent(HeroViewComp); const targetName = targetView?.ent?.get(HeroAttrsComp)?.hero_name ?? '非英雄对象'; const targetEid = targetView?.ent?.eid ?? '未知EID'; - this.debugLog(`[skillView] 碰撞1 [${this.sData.caster.box_group}][${casterName}][${casterEid}]的[${seCol.group}]:[${this.SConf.name}][${this.ent.eid}]碰撞了 [${oCol.group}]:[ ${targetName}][${targetEid}]`); + mLogger.log(this.debugMode, 'SkillView', `[skillView] 碰撞1 [${this.sData.caster.box_group}][${casterName}][${casterEid}]的[${seCol.group}]:[${this.SConf.name}][${this.ent.eid}]碰撞了 [${oCol.group}]:[ ${targetName}][${targetEid}]`); // 基本空值与同组过滤 if (!this.sData || !this.SConf) { - this.debugWarn('[SkillView] onBeginContact 缺少 sData 或 SConf,忽略此次碰撞'); + mLogger.warn(this.debugMode, 'SkillView', '[SkillView] onBeginContact 缺少 sData 或 SConf,忽略此次碰撞'); return; } if (oCol.group === seCol.group) return; @@ -86,7 +78,7 @@ export class SkillView extends CCComp { if (!targetView) return; // 🔥 方案A:防御性检查 - 在获取model前强制检查ent是否存在 if (!targetView.ent) { - console.warn('[SkillView] onBeginContact targetView.ent为空,实体已销毁,忽略此次碰撞'); + mLogger.warn(this.debugMode, 'SkillView', '[SkillView] onBeginContact targetView.ent为空,实体已销毁,忽略此次碰撞'); return; } let model = targetView.ent.get(HeroAttrsComp); @@ -110,7 +102,7 @@ export class SkillView extends CCComp { // 开启碰撞检测 if(this.collider) { this.collider.enabled = true; - this.debugLog(`[SkillView] [${this.SConf?.name}] 第${this.attackFrameCount}次攻击帧开启碰撞检测`); + mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] 第${this.attackFrameCount}次攻击帧开启碰撞检测`); } // let dis=this.node.getComponent(UITransform).width/2 @@ -167,9 +159,9 @@ export class SkillView extends CCComp { // 这样可以避免同一帧内的重复伤害 if(this.SConf.EType !== EType.collision && this.collider) { this.collider.enabled = false; - this.debugLog(`[SkillView] [${this.SConf.name}] 伤害后关闭碰撞检测`); + mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf.name}] 伤害后关闭碰撞检测`); } - this.debugLog(`[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}]`); + 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}]`); // if(this.sData.hit_count > this.SConf.hit_num) return 不能超出 最大伤害数量 // 使用伤害队列系统处理伤害 DamageQueueHelper.addDamageToEntity(