refactor: 重命名Logger类并增加错误日志方法

- 将Logger类重命名为mLogger以符合命名规范
- 新增error方法用于统一错误输出
- 在多个组件中替换console.log/warn/error为mLogger的对应方法
- 为多个组件添加debugMode属性以控制模块级日志开关
- 新增HeroMasterComp组件框架
This commit is contained in:
panw
2026-02-03 14:40:02 +08:00
parent 859ab3bc2a
commit 63dd22fb88
16 changed files with 215 additions and 117 deletions

View File

@@ -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};
}
}