Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
230 lines
9.6 KiB
TypeScript
230 lines
9.6 KiB
TypeScript
/**
|
|
* Prices the local player's combat events: the one place battle rewards are computed.
|
|
*
|
|
* The in-battle banner and the settlement use the same two steps, so what the banner shows is
|
|
* what the settlement pays:
|
|
* 1. baseReward(vehicle, event, victim group): Silver Lions and Research Points of the event
|
|
* before the destroyed unit's class factor (sent to the client at launch, `bannerParams`);
|
|
* 2. x class factor of the victim's expClass (warpoints.blk / rank.blk units{}), x aiKillK when
|
|
* the victim is not a player, x damage points for naval damage.
|
|
* The formula and the source of every factor are in tuning/battle-economy.jsonc.
|
|
*/
|
|
import type { BattleEconomyData, EconomyDifficulty, VehicleEconomy } from '../game-data/datasets/battle-economy.ts';
|
|
import type { ModeDifficulty } from '../game-modes/catalogue/game-mode-declaration.ts';
|
|
import { SCORED_EVENTS, VICTIM_GROUPS, type BattleEconomyTuning, type ScoredEvent, type VictimGroup } from './battle-economy-tuning.ts';
|
|
|
|
/** EXP_EVENT_* codes the LocalMP host reports (gui.vromfs.bin globalScripts/expEventConsts.nut). */
|
|
export const ExpEvent = {
|
|
CAPTURE_ZONE: 2,
|
|
KILL: 5,
|
|
KILL_GROUND: 6,
|
|
ASSIST: 9,
|
|
CRITICAL_HIT: 10,
|
|
HIT: 13,
|
|
UNIT_DAMAGE: 24,
|
|
SEVERE_DAMAGE: 35,
|
|
KILL_HUMAN: 39,
|
|
} as const;
|
|
|
|
/** Debriefing rows (`stat_get_exp()` `num<Row>`/`wp<Row>`/`exp<Row>`, aces.exe 0x1053b70) an event lands in. */
|
|
export type DebriefingRow =
|
|
| 'AirKills' | 'GroundKills' | 'NavalKills' | 'HumanKills' | 'FriendlyKills'
|
|
| 'Assist' | 'AirSevereDamage' | 'ShipSevereDamage' | 'Critical' | 'Hit'
|
|
| 'Captures' | 'AwardDamage';
|
|
|
|
/** What the client reports for one combat event (patches/gui/battle/record-local-battle-awards). */
|
|
export interface CombatEventFact {
|
|
readonly code: number;
|
|
readonly expClass: string;
|
|
readonly victimIsPlayer: boolean;
|
|
readonly friendly: boolean;
|
|
readonly damage: number;
|
|
}
|
|
|
|
export interface PricedEvent {
|
|
readonly row: DebriefingRow;
|
|
/** How much the row's counter grows: 1, or the damage points for AwardDamage. */
|
|
readonly count: number;
|
|
readonly wp: number;
|
|
readonly exp: number;
|
|
}
|
|
|
|
export interface RewardPair {
|
|
readonly wp: number;
|
|
readonly exp: number;
|
|
}
|
|
|
|
/**
|
|
* Launch-time parameters of the in-battle banner (`battle.awards` of the launch message):
|
|
* vehicles.<name>["<code>:<group>"] = [wp, exp] before the class factor; capture uses the group
|
|
* "own". The client multiplies by slClass/rpClass of the victim's expClass, by aiKillK for a
|
|
* victim that is not a player, by the damage points for naval damage, and shows a friendly kill as
|
|
* -wp x friendlyKillPenaltyMul.
|
|
*/
|
|
export interface BannerParams {
|
|
readonly vehicles: Readonly<Record<string, Readonly<Record<string, readonly [number, number]>>>>;
|
|
readonly groups: Readonly<Record<string, VictimGroup>>;
|
|
readonly slClass: Readonly<Record<string, number>>;
|
|
readonly rpClass: Readonly<Record<string, number>>;
|
|
readonly aiKillK: number;
|
|
readonly friendlyKillPenaltyMul: number;
|
|
}
|
|
|
|
export interface RewardMultipliers {
|
|
readonly silverLions: number;
|
|
readonly researchPoints: number;
|
|
}
|
|
|
|
export function economyDifficulty(difficulty: ModeDifficulty): EconomyDifficulty {
|
|
return difficulty === 'arcade' ? 'arcade' : difficulty === 'realistic' ? 'historical' : 'simulation';
|
|
}
|
|
|
|
export class BattleEconomy {
|
|
readonly data: BattleEconomyData;
|
|
readonly #tuning: BattleEconomyTuning;
|
|
readonly #multipliers: RewardMultipliers;
|
|
readonly #premiumVehicles: ReadonlySet<string>;
|
|
|
|
/** `premiumVehicles`: vehicles the client counts as special (isUnitSpecial: costGold > 0 or premPackAir). */
|
|
constructor(
|
|
data: BattleEconomyData,
|
|
tuning: BattleEconomyTuning,
|
|
multipliers: RewardMultipliers,
|
|
premiumVehicles: ReadonlySet<string>,
|
|
) {
|
|
this.data = data;
|
|
this.#tuning = tuning;
|
|
this.#multipliers = multipliers;
|
|
this.#premiumVehicles = premiumVehicles;
|
|
}
|
|
|
|
/** Premium vehicles earn the talisman research bonus without a talisman (scripts/airinfo.nut hasTalisman). */
|
|
isPremiumVehicle(name: string): boolean {
|
|
return this.#premiumVehicles.has(name);
|
|
}
|
|
|
|
get multipliers(): RewardMultipliers {
|
|
return this.#multipliers;
|
|
}
|
|
|
|
vehicle(name: string): VehicleEconomy | undefined {
|
|
return this.data.vehicles[name];
|
|
}
|
|
|
|
victimGroup(expClass: string): VictimGroup {
|
|
return this.#tuning.victimGroups.get(expClass) ?? 'ground';
|
|
}
|
|
|
|
/** Reward of one event before the victim's class factor; undefined for an event that pays nothing. */
|
|
baseReward(vehicle: string, difficulty: EconomyDifficulty, code: number, group: VictimGroup): RewardPair | undefined {
|
|
const economy = this.vehicle(vehicle);
|
|
if (!economy) return undefined;
|
|
const score = this.#score(code, group);
|
|
if (score === undefined) return undefined;
|
|
const reference = this.#tuning.referenceScore[code === ExpEvent.UNIT_DAMAGE ? 'naval' : group];
|
|
return {
|
|
wp: this.data.killSilverLions * economy.rewardMul[difficulty] * (score / reference) * this.#multipliers.silverLions,
|
|
exp: score * economy.expMul * this.#multipliers.researchPoints,
|
|
};
|
|
}
|
|
|
|
price(vehicle: string, difficulty: EconomyDifficulty, fact: CombatEventFact): PricedEvent | undefined {
|
|
const economy = this.vehicle(vehicle);
|
|
if (!economy) return undefined;
|
|
const isCapture = fact.code === ExpEvent.CAPTURE_ZONE;
|
|
const group = isCapture ? this.victimGroup(economy.unitClass) : this.victimGroup(fact.expClass);
|
|
const row = debriefingRow(fact, group);
|
|
const base = this.baseReward(vehicle, difficulty, fact.code, group);
|
|
if (!row || !base) return undefined;
|
|
const count = fact.code === ExpEvent.UNIT_DAMAGE ? Math.max(0, Math.trunc(fact.damage)) : 1;
|
|
const ai = isCapture || fact.victimIsPlayer ? 1 : this.data.aiKillK;
|
|
const slClass = isCapture ? 1 : this.data.silverLionsClassFactors[fact.expClass] ?? 1;
|
|
const rpClass = isCapture ? 1 : this.data.researchClassFactors[fact.expClass] ?? 1;
|
|
if (fact.friendly) {
|
|
return { row: 'FriendlyKills', count: 1, wp: -Math.round(base.wp * slClass * ai * this.#tuning.friendlyKillPenaltyMul), exp: 0 };
|
|
}
|
|
return {
|
|
row,
|
|
count,
|
|
wp: Math.round(base.wp * slClass * ai * count),
|
|
exp: Math.round(base.exp * rpClass * ai * count),
|
|
};
|
|
}
|
|
|
|
bannerParams(vehicles: Iterable<string>, difficulty: EconomyDifficulty): BannerParams {
|
|
const table: Record<string, Record<string, [number, number]>> = {};
|
|
for (const name of vehicles) {
|
|
const economy = this.vehicle(name);
|
|
if (!economy || table[name]) continue;
|
|
const entries: Record<string, [number, number]> = {};
|
|
for (const code of Object.values(ExpEvent)) {
|
|
const groups: readonly (VictimGroup | 'own')[] = code === ExpEvent.CAPTURE_ZONE ? ['own'] : ['ground', 'air', 'naval', 'human'];
|
|
for (const group of groups) {
|
|
const priceGroup = group === 'own' ? this.victimGroup(economy.unitClass) : group;
|
|
const base = this.baseReward(name, difficulty, code, priceGroup);
|
|
if (base) entries[`${code}:${group}`] = [base.wp, base.exp];
|
|
}
|
|
}
|
|
table[name] = entries;
|
|
}
|
|
return {
|
|
vehicles: table,
|
|
groups: Object.fromEntries(this.#tuning.victimGroups),
|
|
slClass: this.data.silverLionsClassFactors,
|
|
rpClass: this.data.researchClassFactors,
|
|
aiKillK: this.data.aiKillK,
|
|
friendlyKillPenaltyMul: this.#tuning.friendlyKillPenaltyMul,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* The scoreboard score of each combat event, for the mission settings block customScoreParams
|
|
* that the native LocalMP bridge reads (native/wto-net/src/local_mp_scores.c lists the keys):
|
|
* the official mission scores of tuning/battle-economy.jsonc, and aiKillK for victims that are
|
|
* not players, as in the rewards.
|
|
*/
|
|
missionScores(): Readonly<Record<string, number>> {
|
|
const scores: Record<string, number> = {};
|
|
for (const group of VICTIM_GROUPS) {
|
|
for (const event of SCORED_EVENTS) scores[`wtoScore_${event}_${group}`] = this.#tuning.eventScores[group][event];
|
|
scores[`wtoScore_capture_${group}`] = this.#tuning.captureZoneScore[group];
|
|
}
|
|
scores.wtoScore_damagePerPoint = this.#tuning.navalDamageScorePerPoint;
|
|
scores.wtoScore_aiMul = this.data.aiKillK;
|
|
return scores;
|
|
}
|
|
|
|
#score(code: number, group: VictimGroup): number | undefined {
|
|
const scored = (event: ScoredEvent): number => this.#tuning.eventScores[group][event];
|
|
switch (code) {
|
|
case ExpEvent.KILL:
|
|
case ExpEvent.KILL_GROUND:
|
|
case ExpEvent.KILL_HUMAN: return scored('kill');
|
|
case ExpEvent.ASSIST: return scored('assist');
|
|
case ExpEvent.CRITICAL_HIT: return scored('criticalHit');
|
|
case ExpEvent.HIT: return scored('hit');
|
|
case ExpEvent.SEVERE_DAMAGE: return scored('severeDamage');
|
|
case ExpEvent.CAPTURE_ZONE: return this.#tuning.captureZoneScore[group];
|
|
case ExpEvent.UNIT_DAMAGE: return this.#tuning.navalDamageScorePerPoint;
|
|
default: return undefined;
|
|
}
|
|
}
|
|
}
|
|
|
|
function debriefingRow(fact: CombatEventFact, group: VictimGroup): DebriefingRow | undefined {
|
|
switch (fact.code) {
|
|
case ExpEvent.KILL:
|
|
case ExpEvent.KILL_GROUND:
|
|
case ExpEvent.KILL_HUMAN:
|
|
if (fact.friendly) return 'FriendlyKills';
|
|
return group === 'air' ? 'AirKills' : group === 'naval' ? 'NavalKills' : group === 'human' ? 'HumanKills' : 'GroundKills';
|
|
case ExpEvent.ASSIST: return 'Assist';
|
|
case ExpEvent.CRITICAL_HIT: return 'Critical';
|
|
case ExpEvent.HIT: return 'Hit';
|
|
case ExpEvent.SEVERE_DAMAGE: return group === 'naval' ? 'ShipSevereDamage' : 'AirSevereDamage';
|
|
case ExpEvent.CAPTURE_ZONE: return 'Captures';
|
|
case ExpEvent.UNIT_DAMAGE: return 'AwardDamage';
|
|
default: return undefined;
|
|
}
|
|
}
|