You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/mx/tools/CombatDamageTrace.ts

36 lines
1.1 KiB

3 weeks ago
/**
* 战斗扣血链路诊断(Release 真机用 console.warn,便于抖音开发者工具截图)。
* 验证完成后可 setCombatDamageTraceEnabled(false) 或删本模块。
*/
const TAG = '[DMG-TRACE]';
let _enabled = false;
let _logCount = 0;
const MAX_LOGS = 120;
const THROTTLE_MS = 250;
const _throttle = new Map<string, number>();
export function setCombatDamageTraceEnabled(enabled: boolean): void {
_enabled = enabled;
if (!enabled) _throttle.clear();
}
export function resetCombatDamageTrace(): void {
_logCount = 0;
_throttle.clear();
}
export function traceCombatDamage(stage: string, detail?: Record<string, unknown>): void {
if (!_enabled || _logCount >= MAX_LOGS) return;
const entityKey = String(
detail?.target ?? detail?.victim ?? detail?.entity ?? detail?.caster ?? '',
);
const throttleKey = `${stage}:${entityKey}`;
const now = Date.now();
const last = _throttle.get(throttleKey) ?? 0;
if (now - last < THROTTLE_MS) return;
_throttle.set(throttleKey, now);
_logCount++;
console.log(TAG, stage);
}