/** * The debriefing table of a settled battle, in the shape of `stat_get_exp()` (aces.exe 0x1053b70, * which serializes the battle's SessionStatsNet; online the battle server fills it). The client's * settlement patch puts it in `debriefingResult.exp` in place of the empty local statistics. * * Root and every `aircrafts.`: * num:i wp:i exp:i tbl{ noBonusWp noBonusExp premAccWp premAccExp premModExp boosterWp boosterExp } * tblTotal{ ... } wpTotal:i expTotal:i sessionTime:r battleTime:r * Root only: result:i activity:r expFree:i expSkillBonusTotal:i expSkillBonusLevel:i * investUnitName:t expInvestUnit:i expInvestUnitTotal:i * Vehicle only: expSkillBonus:i investModuleName:t expInvestModule:i expInvestModuleTotal:i * expInvestUnit:i expInvestUnitTotal:i * Invest<...> is what reached the researched modification / vehicle, Invest<...>Total all RP for * modification / vehicle research (battle-rp-investment.ts). * (key names from the strings of 0x1053b70, 0xf86c10 and 0xf89f90). */ import { emptyBlock, setParam, type BlkBlock } from '@wto/blk'; import { emptyRowRewards, type BattleRewards, type RewardRow, type RowRewards } from './battle-rewards.ts'; import type { BattleRpResult } from './battle-rp-investment.ts'; /** STATS_RESULT_* script constants, registered by aces.exe 0x17db810 (SUCCESS 1, FAIL 2). */ const STATS_RESULT_SUCCESS = 1; const STATS_RESULT_FAIL = 2; /** Battle awards (streaks) of the battle, shown in the root-only row "Unlocks" (debriefingFull.nut). */ export interface UnlockRewards { readonly count: number; readonly wp: number; readonly exp: number; } /** * `compensation`: the premium account's expense compensation, the root-only row * "ExpensesCompensation" (debriefingFull.nut). */ export function debriefingTable(name: string, rewards: BattleRewards, research: BattleRpResult, unlocks: UnlockRewards, compensation: number): BlkBlock { const root = emptyBlock(name); const rootRows = new Map(); for (const vehicle of rewards.vehicles) { for (const [row, amounts] of vehicle.rows) { const sum = rootRows.get(row) ?? emptyRowRewards(); for (const key of Object.keys(sum) as (keyof RowRewards)[]) sum[key] += amounts[key]; rootRows.set(row, sum); } } setParam(root, 'result', { type: 'int', value: rewards.win ? STATS_RESULT_SUCCESS : STATS_RESULT_FAIL }); setParam(root, 'activity', { type: 'real', value: rewards.activity }); setParam(root, 'sessionTime', { type: 'real', value: rewards.sessionTime }); setParam(root, 'battleTime', { type: 'real', value: rewards.battleTime }); if (unlocks.count > 0) { rootRows.set('Unlocks', { ...emptyRowRewards(), count: unlocks.count, noBonusWp: unlocks.wp, noBonusExp: unlocks.exp }); } if (compensation > 0) rootRows.set('ExpensesCompensation', { ...emptyRowRewards(), count: 1, noBonusWp: compensation }); writeRows(root, rootRows, rewards.wpTotal + unlocks.wp + compensation, rewards.expTotal + unlocks.exp); setParam(root, 'expFree', { type: 'int', value: rewards.expFree }); setParam(root, 'expSkillBonusTotal', { type: 'int', value: rewards.vehicles.reduce((sum, v) => sum + v.skillBonusExp, 0) }); setParam(root, 'expSkillBonusLevel', { type: 'int', value: rewards.skillBonusLevel }); for (const branch of research.branches) { setParam(root, `investUnitName${branch.type}`, { type: 'string', value: branch.unit }); setParam(root, `expInvestUnit${branch.type}`, { type: 'int', value: branch.invested }); setParam(root, `expInvestUnitTotal${branch.type}`, { type: 'int', value: branch.total }); } const aircrafts = emptyBlock('aircrafts'); for (const vehicle of rewards.vehicles) { const block = emptyBlock(vehicle.vehicle); setParam(block, 'sessionTime', { type: 'real', value: vehicle.sessionTime }); setParam(block, 'battleTime', { type: 'real', value: vehicle.sessionTime }); writeRows(block, vehicle.rows, vehicle.wpTotal, vehicle.expTotal); setParam(block, 'expSkillBonus', { type: 'int', value: vehicle.skillBonusExp }); setParam(block, 'expSkillBonusTotal', { type: 'int', value: vehicle.skillBonusExp }); // expInvestModule < expInvestModuleTotal marks the modification as finished (debriefingFull.nut expModuleCapped). const unit = research.units.find((entry) => entry.unit === vehicle.vehicle); setParam(block, 'investModuleName', { type: 'string', value: unit?.invModuleName ?? '' }); setParam(block, 'expInvestModule', { type: 'int', value: unit?.invModuleExp ?? 0 }); setParam(block, 'expInvestModuleTotal', { type: 'int', value: unit?.moduleTotal ?? 0 }); setParam(block, 'expInvestUnit', { type: 'int', value: unit?.invUnitExp ?? 0 }); setParam(block, 'expInvestUnitTotal', { type: 'int', value: unit?.unitTotal ?? 0 }); aircrafts.blocks.push(block); } root.blocks.push(aircrafts); return root; } function writeRows(block: BlkBlock, rows: ReadonlyMap, wpTotal: number, expTotal: number): void { const total: RowRewards = emptyRowRewards(); for (const [row, amounts] of rows) { setParam(block, `num${row}`, { type: 'int', value: amounts.count }); setParam(block, `wp${row}`, { type: 'int', value: amounts.noBonusWp + amounts.premAccWp + amounts.boosterWp }); setParam(block, `exp${row}`, { type: 'int', value: amounts.noBonusExp + amounts.premAccExp + amounts.premModExp + amounts.boosterExp }); block.blocks.push(rowTable(`tbl${row}`, amounts)); for (const key of Object.keys(total) as (keyof RowRewards)[]) total[key] += amounts[key]; } setParam(block, 'wpTotal', { type: 'int', value: wpTotal }); setParam(block, 'expTotal', { type: 'int', value: expTotal }); block.blocks.push(rowTable('tblTotal', total)); } function rowTable(name: string, amounts: RowRewards): BlkBlock { const table = emptyBlock(name); setParam(table, 'noBonusWp', { type: 'int', value: amounts.noBonusWp }); setParam(table, 'noBonusExp', { type: 'int', value: amounts.noBonusExp }); setParam(table, 'premAccWp', { type: 'int', value: amounts.premAccWp }); setParam(table, 'premAccExp', { type: 'int', value: amounts.premAccExp }); setParam(table, 'premModExp', { type: 'int', value: amounts.premModExp }); setParam(table, 'boosterWp', { type: 'int', value: amounts.boosterWp }); setParam(table, 'boosterExp', { type: 'int', value: amounts.boosterExp }); return table; }