feat: 引入集中式日志工具类并重构调试日志
- 新增 Logger 类提供统一的日志和警告输出,支持全局和模块级开关 - 重构 SkillView、HeroViewComp 和 HeroAtkSystem 中的调试日志方法,改用 Logger 类 - 在 HeroViewComp 中添加调试模式属性便于编辑器配置 - 统一日志格式为 [标签] + 内容,提高日志可读性和维护性
This commit is contained in:
28
assets/script/game/common/Logger.ts
Normal file
28
assets/script/game/common/Logger.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
export class Logger {
|
||||||
|
/** 总开关:控制所有日志输出 */
|
||||||
|
public static GLOBAL_ENABLED: boolean = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一日志输出
|
||||||
|
* @param enable 单独开关(模块级开关)
|
||||||
|
* @param tag 标签(通常是类名或模块名)
|
||||||
|
* @param args 日志内容
|
||||||
|
*/
|
||||||
|
public static log(enable: boolean, tag: string, ...args: any[]) {
|
||||||
|
if (this.GLOBAL_ENABLED && enable) {
|
||||||
|
console.log(`[${tag}]`, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一警告输出
|
||||||
|
* @param enable 单独开关(模块级开关)
|
||||||
|
* @param tag 标签(通常是类名或模块名)
|
||||||
|
* @param args 警告内容
|
||||||
|
*/
|
||||||
|
public static warn(enable: boolean, tag: string, ...args: any[]) {
|
||||||
|
if (this.GLOBAL_ENABLED && enable) {
|
||||||
|
console.warn(`[${tag}]`, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
assets/script/game/common/Logger.ts.meta
Normal file
9
assets/script/game/common/Logger.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "0d4013a0-024f-4b53-8c1c-d366a381b64d",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@ import { oops } from "db://oops-framework/core/Oops";
|
|||||||
import { GameEvent } from "../common/config/GameEvent";
|
import { GameEvent } from "../common/config/GameEvent";
|
||||||
|
|
||||||
|
|
||||||
|
import { Logger } from "../common/Logger";
|
||||||
|
|
||||||
/** 最终伤害数据接口
|
/** 最终伤害数据接口
|
||||||
* 用于封装一次攻击计算的所有结果数据
|
* 用于封装一次攻击计算的所有结果数据
|
||||||
* @property damage - 最终造成的伤害值(已考虑所有加成和减免)
|
* @property damage - 最终造成的伤害值(已考虑所有加成和减免)
|
||||||
@@ -41,6 +43,14 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
|
|
||||||
private debugMode: boolean = false; // 是否启用调试模式
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤器:处理拥有伤害队列的实体
|
* 过滤器:处理拥有伤害队列的实体
|
||||||
*/
|
*/
|
||||||
@@ -75,9 +85,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
damageQueue.processedCount++;
|
damageQueue.processedCount++;
|
||||||
// 如果目标已死亡,停止处理后续伤害
|
// 如果目标已死亡,停止处理后续伤害
|
||||||
if (TAttrsComp.is_dead) {
|
if (TAttrsComp.is_dead) {
|
||||||
if (this.debugMode) {
|
this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 已死亡,停止处理剩余伤害`);
|
||||||
console.log(`[HeroAtkSystem] ${TAttrsComp.hero_name} 已死亡,停止处理剩余伤害`);
|
|
||||||
}
|
|
||||||
damageQueue.clear(); // 清空剩余伤害
|
damageQueue.clear(); // 清空剩余伤害
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -87,8 +95,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
if (damageQueue.isEmpty()) {
|
if (damageQueue.isEmpty()) {
|
||||||
e.remove(DamageQueueComp);
|
e.remove(DamageQueueComp);
|
||||||
|
|
||||||
if (this.debugMode && processedCount > 0) {
|
if (processedCount > 0) {
|
||||||
console.log(`[HeroAtkSystem] ${TAttrsComp.hero_name} 伤害队列处理完成,共处理 ${processedCount} 个伤害事件`);
|
this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 伤害队列处理完成,共处理 ${processedCount} 个伤害事件`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,7 +164,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]-TAttrsComp.Attrs[Attrs.CRITICAL_RES]);
|
const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]-TAttrsComp.Attrs[Attrs.CRITICAL_RES]);
|
||||||
// 计算基础伤害
|
// 计算基础伤害
|
||||||
let damage = this.dmgCount(damageEvent,TAttrsComp);
|
let damage = this.dmgCount(damageEvent,TAttrsComp);
|
||||||
if (this.debugMode) console.log("[HeroAtkSystem] dmgCount",damage)
|
this.debugLog("[HeroAtkSystem] dmgCount",damage)
|
||||||
if (isCrit) {
|
if (isCrit) {
|
||||||
// 暴击伤害计算
|
// 暴击伤害计算
|
||||||
// 使用施法者的暴击伤害加成属性(damageEvent.Attrs 快照)
|
// 使用施法者的暴击伤害加成属性(damageEvent.Attrs 快照)
|
||||||
@@ -167,11 +175,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
CAttrsComp?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff
|
CAttrsComp?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff
|
||||||
|
|
||||||
}
|
}
|
||||||
if (this.debugMode) console.log("[HeroAtkSystem] after crit",damage)
|
this.debugLog("[HeroAtkSystem] after crit",damage)
|
||||||
// 护盾吸收
|
// 护盾吸收
|
||||||
const shieldResult = this.absorbShield(TAttrsComp, damage);
|
const shieldResult = this.absorbShield(TAttrsComp, damage);
|
||||||
damage = shieldResult.remainingDamage;
|
damage = shieldResult.remainingDamage;
|
||||||
if (this.debugMode) console.log("[HeroAtkSystem] after shield",damage)
|
this.debugLog("[HeroAtkSystem] after shield",damage)
|
||||||
// 显示护盾吸收飘字
|
// 显示护盾吸收飘字
|
||||||
if (shieldResult.absorbedDamage > 0 && targetView) {
|
if (shieldResult.absorbedDamage > 0 && targetView) {
|
||||||
targetView.shield_tip(shieldResult.absorbedDamage);
|
targetView.shield_tip(shieldResult.absorbedDamage);
|
||||||
@@ -187,10 +195,10 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
|
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
|
||||||
if (this.debugMode) {
|
|
||||||
const casterName = CAttrsComp?.hero_name || "未知";
|
const casterName = CAttrsComp?.hero_name || "未知";
|
||||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
this.debugLog(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||||
}
|
|
||||||
//反伤判定 并应用到施法者
|
//反伤判定 并应用到施法者
|
||||||
this.check_thorns(TAttrsComp, caster, damage);
|
this.check_thorns(TAttrsComp, caster, damage);
|
||||||
// 击退判定
|
// 击退判定
|
||||||
@@ -221,7 +229,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
targetView.scheduleRevive(1.0);
|
targetView.scheduleRevive(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[HeroAtkSystem] Hero waiting to revive! Lives left: ${TAttrsComp.Attrs[Attrs.REVIVE_COUNT]}`);
|
this.debugLog(`[HeroAtkSystem] Hero waiting to revive! Lives left: ${TAttrsComp.Attrs[Attrs.REVIVE_COUNT]}`);
|
||||||
return reDate;
|
return reDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +240,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
if (TAttrsComp.is_master&&TAttrsComp.Attrs[Attrs.REVIVE_COUNT] <= 0) {
|
if (TAttrsComp.is_master&&TAttrsComp.Attrs[Attrs.REVIVE_COUNT] <= 0) {
|
||||||
smc.mission.stop_mon_action = true;
|
smc.mission.stop_mon_action = true;
|
||||||
oops.message.dispatchEvent(GameEvent.HeroDead, { hero_uuid: TAttrsComp.hero_uuid});
|
oops.message.dispatchEvent(GameEvent.HeroDead, { hero_uuid: TAttrsComp.hero_uuid});
|
||||||
console.log("[HeroAtkSystem] Hero died, stopping monster action (spawn/move)"+TAttrsComp.Attrs[Attrs.REVIVE_COUNT]);
|
this.debugLog("[HeroAtkSystem] Hero died, stopping monster action (spawn/move)"+TAttrsComp.Attrs[Attrs.REVIVE_COUNT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.doDead(target);
|
this.doDead(target);
|
||||||
@@ -242,7 +250,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.debugMode) console.log(`[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
|
this.debugLog(`[HeroAtkSystem] ${TAttrsComp.hero_name} 受到 ${damage} 点伤害 (暴击: ${isCrit})`);
|
||||||
|
|
||||||
|
|
||||||
reDate.damage=damage;
|
reDate.damage=damage;
|
||||||
@@ -322,11 +330,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
const TAttrs=TAttrsComp.Attrs;
|
const TAttrs=TAttrsComp.Attrs;
|
||||||
let sConf = SkillSet[damageEvent.s_uuid];
|
let sConf = SkillSet[damageEvent.s_uuid];
|
||||||
if (!sConf) return 0;
|
if (!sConf) return 0;
|
||||||
if (this.debugMode) console.log(`[HeroAtkSystem] 伤害处理对象`,CAttrs,TAttrs);
|
this.debugLog(`[HeroAtkSystem] 伤害处理对象`,CAttrs,TAttrs);
|
||||||
// 2. 计算原始物理伤害和魔法伤害
|
// 2. 计算原始物理伤害和魔法伤害
|
||||||
// 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外伤害) / 100 * 额外伤害比例
|
// 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外伤害) / 100 * 额外伤害比例
|
||||||
let apBase = (sConf.ap||0)*(CAttrs[Attrs.AP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio;
|
let apBase = (sConf.ap||0)*(CAttrs[Attrs.AP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio;
|
||||||
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]},}
|
this.debugLog(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]},}
|
||||||
额外伤害:${damageEvent.ext_dmg}, 额外伤害比例:${damageEvent.dmg_ratio}`);
|
额外伤害:${damageEvent.ext_dmg}, 额外伤害比例:${damageEvent.dmg_ratio}`);
|
||||||
// 易伤
|
// 易伤
|
||||||
let DMG_INVUL = TAttrs[Attrs.DMG_INVUL]||0
|
let DMG_INVUL = TAttrs[Attrs.DMG_INVUL]||0
|
||||||
@@ -459,7 +467,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
private absorbShield(TAttrsComp: HeroAttrsComp, damage: number): {remainingDamage: number, absorbedDamage: number} {
|
private absorbShield(TAttrsComp: HeroAttrsComp, damage: number): {remainingDamage: number, absorbedDamage: number} {
|
||||||
|
|
||||||
if (TAttrsComp.shield <= 0) {
|
if (TAttrsComp.shield <= 0) {
|
||||||
console.log("[HeroAtkSystem] 护盾值小于等于0,无法吸收伤害");
|
this.debugLog("[HeroAtkSystem] 护盾值小于等于0,无法吸收伤害");
|
||||||
return {remainingDamage: damage, absorbedDamage: 0};
|
return {remainingDamage: damage, absorbedDamage: 0};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -470,7 +478,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0;
|
TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0;
|
||||||
}
|
}
|
||||||
TAttrsComp.dirty_shield = true;
|
TAttrsComp.dirty_shield = true;
|
||||||
console.log(`[HeroAtkSystem] 护盾值完全吸收伤害 ${damage}`);
|
this.debugLog(`[HeroAtkSystem] 护盾值完全吸收伤害 ${damage}`);
|
||||||
return {remainingDamage: 0, absorbedDamage: damage};
|
return {remainingDamage: 0, absorbedDamage: damage};
|
||||||
} else {
|
} else {
|
||||||
const absorbedDamage = TAttrsComp.shield;
|
const absorbedDamage = TAttrsComp.shield;
|
||||||
@@ -478,7 +486,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
TAttrsComp.shield = 0;
|
TAttrsComp.shield = 0;
|
||||||
TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0;
|
TAttrsComp.Attrs[Attrs.SHIELD_MAX] = 0;
|
||||||
TAttrsComp.dirty_shield = true;
|
TAttrsComp.dirty_shield = true;
|
||||||
console.log(`[HeroAtkSystem] 护盾值部分吸收伤害 ${absorbedDamage}`);
|
this.debugLog(`[HeroAtkSystem] 护盾值部分吸收伤害 ${absorbedDamage}`);
|
||||||
return {remainingDamage, absorbedDamage};
|
return {remainingDamage, absorbedDamage};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +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 { 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 { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
|
import { Logger } from "../common/Logger";
|
||||||
import { HeroSpine } from "./HeroSpine";
|
import { HeroSpine } from "./HeroSpine";
|
||||||
import { BoxSet, FacSet } from "../common/config/GameSet";
|
import { BoxSet, FacSet } from "../common/config/GameSet";
|
||||||
import { smc } from "../common/SingletonModuleComp";
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
@@ -26,19 +27,16 @@ export interface BuffInfo {
|
|||||||
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
|
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
|
||||||
@ecs.register('HeroView', false) // 定义ECS 组件
|
@ecs.register('HeroView', false) // 定义ECS 组件
|
||||||
export class HeroViewComp extends CCComp {
|
export class HeroViewComp extends CCComp {
|
||||||
private debugMode: boolean = false; // 是否启用调试模式
|
@property({ tooltip: "是否启用调试日志" })
|
||||||
|
private debugMode: boolean = true; // 是否启用调试模式
|
||||||
|
|
||||||
// 添加条件日志方法
|
// 添加条件日志方法
|
||||||
private debugLog(...args: any[]): void {
|
private debugLog(...args: any[]): void {
|
||||||
if (this.debugMode) {
|
Logger.log(this.debugMode, 'HeroViewComp', ...args);
|
||||||
console.log(...args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private debugWarn(...args: any[]): void {
|
private debugWarn(...args: any[]): void {
|
||||||
if (this.debugMode) {
|
Logger.warn(this.debugMode, 'HeroViewComp', ...args);
|
||||||
console.warn(...args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// ==================== View 层属性(表现相关)====================
|
// ==================== View 层属性(表现相关)====================
|
||||||
as: HeroSpine = null!
|
as: HeroSpine = null!
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { SDataCom } from "./SDataCom";
|
|||||||
import { Attrs } from "../common/config/HeroAttrs";
|
import { Attrs } from "../common/config/HeroAttrs";
|
||||||
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
||||||
import { DamageQueueHelper } from "../hero/DamageQueueComp";
|
import { DamageQueueHelper } from "../hero/DamageQueueComp";
|
||||||
|
import { Logger } from "../common/Logger";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -24,15 +25,11 @@ export class SkillView extends CCComp {
|
|||||||
private debugMode: boolean = false;
|
private debugMode: boolean = false;
|
||||||
|
|
||||||
private debugLog(...args: any[]): void {
|
private debugLog(...args: any[]): void {
|
||||||
if (this.debugMode) {
|
Logger.log(this.debugMode, 'SkillView', ...args);
|
||||||
console.log(...args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private debugWarn(...args: any[]): void {
|
private debugWarn(...args: any[]): void {
|
||||||
if (this.debugMode) {
|
Logger.warn(this.debugMode, 'SkillView', ...args);
|
||||||
console.warn(...args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
anim:Animation=null;
|
anim:Animation=null;
|
||||||
|
|||||||
Reference in New Issue
Block a user