import type { BattleSession } from 'db://assets/mx/module/battle'; import { AttrId, AttributeComp, CombatComp } from 'db://assets/mx/module/battle/ecs/Components'; import type { EntityId } from 'db://assets/mx/module/ecs'; import { isAtkDebugWeapon } from './AtkDebugConstants'; import { isDesignDebugEnabled } from './DesignDebug'; const TAG = '[AtkDebug][刀]'; /** ① setupCombat:基础攻击拆解 */ export function logKnifeBaseAttack(info: { entityId: EntityId; weapon1Id: number; composeLevel: number; effectiveLevel: number; heroAtk: number; weaponAtk: number; combatAttack: number; }): void { if (!isDesignDebugEnabled() || !isAtkDebugWeapon(info.weapon1Id)) return; console.log( TAG, '①基础攻击', `entity=${info.entityId}`, `合成Lv=${info.composeLevel}→有效=${info.effectiveLevel}`, `Hero.atk=${info.heroAtk}`, `装备atk=${info.weaponAtk}`, `公式: ${info.heroAtk}×等级系数+${info.weaponAtk}=${info.combatAttack}`, `→ CombatComp.attack=${info.combatAttack}`, ); } /** ② 词条 base_attr 类型1 写入 Mul */ export function logKnifeEntryAttack(info: { entityId: EntityId; weapon1Id: number; entryId: number; entryName: string; stackCount: number; cfgWan: number; scaledWan: number; mulValue: number; }): void { if (!isDesignDebugEnabled() || !isAtkDebugWeapon(info.weapon1Id)) return; console.log( TAG, '②词条攻击Mul', `entity=${info.entityId}`, `entry=${info.entryId}(${info.entryName})`, `叠层=${info.stackCount}`, `配表万分比=${info.cfgWan}`, `scaled=${info.scaledWan}`, `Mul=1+${info.scaledWan}/10000=${info.mulValue}`, '同id合并: 一次 Mul(1+0.3N),非连乘', ); } /** ③ AttributeSystem 最终攻击拆解 */ export function dumpKnifeFinalAttack( session: BattleSession, entityId: EntityId, reason: string, weapon1Id: number | null | undefined, ): void { if (!isDesignDebugEnabled() || !isAtkDebugWeapon(weapon1Id)) return; const combat = session.world.getComponent(entityId, CombatComp); const attr = session.world.getComponent(entityId, AttributeComp); const base = combat?.attack ?? attr?.base[AttrId.Attack] ?? 0; const mods = (attr?.modifiers ?? []).filter(m => m.attr === AttrId.Attack); let add = 0; let mul = 1; let override: number | undefined; for (const m of mods) { if (m.op === 'Add') add += m.value; else if (m.op === 'Mul') mul *= m.value; else if (m.op === 'Override') override = m.value; } const finalAtk = override !== undefined ? override : (base + add) * mul; console.log( TAG, '③最终攻击', reason, `entity=${entityId}`, `base=${base}`, `Add=${add}`, `Mul=${mul}`, override !== undefined ? `Override=${override}` : '', `mods=${mods.length}`, `→ final=${finalAtk}`, ); }