Files
WT-Offline/packages/local-service/src/matching/battle-launch-notify.ts
T
N0VAN0M4LY 7c27d09f78 fix(battle): calculate LocalMP rewards in the local service
The LocalMP host has no battle server, and the previous bridge filled the
gap by computing money in the client: the native ledger wrote invented
amounts into SessionStatsNet, the spawn patch derived reward rates from
warpoints.blk, and the settlement patch summed and rescaled the result.
Rewards came out as zero or several orders of magnitude too high.

Now the client reports facts and the local service prices them.

Native (wto_ws.dll):
- local_mp_ledger.c is removed together with its SessionStatsNet
  offsets and four signatures (43 -> 39).
- local_mp_awards.c raises the HUD script event wtoLocalMpExpEvent for
  every combat event of the local player (event code, victim expClass
  and name, player or AI victim, friendly, naval damage). The DataBlock
  helpers and the HUD event queue are resolved from call sites inside
  GameSaveData::addScoreMessage, which already has a signature.

GUI patches:
- record-local-battle-awards records events and lives in nestdb and
  raises the stock InBattleReward banner from launch-time parameters.
- report-local-battle-settlement sends only facts and rebuilds the
  debriefing from the settled table; failures show the stock error box.
- use-settled-debriefing-stats makes gatherDebriefingResult read that
  table instead of the empty stat_get_exp().
- pass-spawn-modifications-blk no longer computes economy factors.

Local service:
- battle-economy dataset reads every reward factor from wpcost.blk,
  warpoints.blk and rank.blk; tuning/battle-economy.jsonc holds the
  mission score per event with its source (official values where
  published, otherwise marked).
- battle-economy.ts is the single pricing function, shared by the
  banner parameters and the settlement; battle-rewards.ts adds battle
  time, timed award, win/defeat bonus, activity, premium account,
  talisman, skill bonus and free research points; the debriefing table
  has the stat_get_exp() layout and travels in EULT_SESSION_RESULT.
- Crews earn skill points from the battle's research points.
- A battle left before it ends counts as a defeat.

Verified: npm run typecheck, check-gui (35 patches), check-patches,
check-offsets, native build. Not yet run in game.
2026-11-28 04:42:27 +08:00

83 lines
3.4 KiB
TypeScript

/**
* The `mrpc.generic_notify` message that starts a local battle (`from: "wto_battle"`,
* `func: "launch"`), received by the client's launch script patch
* (gui-patches/battle/launch-local-battle-from-queue).
*
* - `mission`: the complete mission settings for `select_training_mission`, as a typed tree
* `{ p: [[name, type, value], ...], b: [[name, node], ...] }` with type "t", "i", "r" or "b".
* Matching notifications are JSON, which cannot tell 1 from 1.0; the engine reads ints and reals
* with typed getters, so the type travels with every value. Repeated blocks stay separate.
* - `lobby`: the session lobby settings the client's own room scripts read during the battle
* (game mode and both sides' countries).
* - `battle`: what the client keeps for this battle (session id for the settlement, extra slots,
* and `awards`, the parameters of the in-battle reward banner, battle-economy.ts BannerParams).
*/
import type { BlkBlock, BlkValue } from '@wto/blk';
import type { BannerParams } from '../battle/battle-economy.ts';
import type { BattleLaunchPlan } from '../battle/battle-matchmaker.ts';
import { battleMissionSettings } from '../battle/battle-mission-settings.ts';
type WireParam = readonly [name: string, type: 't' | 'i' | 'r' | 'b', value: string | number | boolean];
interface WireBlock {
readonly p: readonly WireParam[];
readonly b: ReadonlyArray<readonly [name: string, block: WireBlock]>;
}
export interface BattleLaunchNotify extends Record<string, unknown> {
readonly from: 'wto_battle';
readonly func: 'launch';
readonly mission: WireBlock;
readonly lobby: Readonly<Record<string, unknown>>;
readonly battle: Readonly<Record<string, unknown>>;
}
export function battleLaunchNotify(plan: BattleLaunchPlan, awards: BannerParams): BattleLaunchNotify {
return {
from: 'wto_battle',
func: 'launch',
mission: toWire(battleMissionSettings(plan)),
lobby: {
game_mode_id: plan.modeId,
game_mode_name: plan.modeName,
economicName: plan.economicName,
symmetricTeams: plan.symmetricTeams,
country_allies: plan.countriesAllies.map(withCountryPrefix),
country_axis: plan.countriesAxis.map(withCountryPrefix),
mission: { name: plan.missionName, difficulty: plan.difficulty },
},
battle: {
sessionId: plan.sessionId,
modeName: plan.modeName,
economicName: plan.economicName,
country: plan.country,
missionName: plan.missionName,
extraBattleSlots: plan.extraBattleSlots,
randomUnits: plan.randomUnits,
randomUnitsEventName: plan.randomUnitsEventName ?? '',
awards,
},
};
}
function toWire(block: BlkBlock): WireBlock {
return {
p: block.params.map((param) => [param.name, ...wireValue(param.name, param.value)] as const),
b: block.blocks.map((child) => [child.name, toWire(child)] as const),
};
}
function wireValue(name: string, value: BlkValue): readonly ['t' | 'i' | 'r' | 'b', string | number | boolean] {
switch (value.type) {
case 'string': return ['t', value.value];
case 'int': return ['i', value.value];
case 'real': return ['r', value.value];
case 'bool': return ['b', value.value];
default: throw new Error(`mission settings parameter ${name} has type ${value.type}, which the launch message cannot carry`);
}
}
function withCountryPrefix(country: string): string {
return country.startsWith('country_') ? country : `country_${country}`;
}