refactor(repo)!: move apps, shared packages, and patch definitions
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.
This commit is contained in:
1 parent
9c813ccf7d
commit
930ea07630
476 files changed
+275
-251
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Free repair over time: a damaged vehicle that is not repaired for silver lions becomes intact
|
||||
* again after its full repair time (the stat card's "full repair time", repair-rules.ts
|
||||
* fullRepairHours), part by part: the hangar shows (1 - hp) x the full time as what is left
|
||||
* (shop_time_until_repair, aces.exe 2.61.0.37 0x17a5040).
|
||||
*
|
||||
* The client never raises hp itself, so the local server does it whenever it hands out or
|
||||
* changes a profile: hp grows by the hours since it was last set / the full repair time (with the
|
||||
* crew the vehicle has now), and the damage is cleared once hp reaches 1. The pace following the
|
||||
* current crew and the linear growth are inferred from the client's timer formula; whether a
|
||||
* vehicle keeps repairing while it is in a battle was not looked into (it does here).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import {
|
||||
clearVehicleDamage,
|
||||
damagedVehicles,
|
||||
damageTime,
|
||||
setVehicleDamage,
|
||||
vehicleCondition,
|
||||
} from '../profile/profile-vehicle-condition.ts';
|
||||
import { TICKS_PER_HOUR, type ServerTime } from '../profile/server-time.ts';
|
||||
import type { RepairRules } from './repair-rules.ts';
|
||||
|
||||
export function repairVehiclesOverTime(profile: BlkBlock, rules: RepairRules, now: ServerTime): void {
|
||||
for (const vehicle of damagedVehicles(profile)) {
|
||||
const condition = vehicleCondition(profile, vehicle)!;
|
||||
const since = damageTime(profile, vehicle);
|
||||
const fullHours = rules.fullRepairHours(profile, vehicle);
|
||||
if (fullHours <= 0) {
|
||||
clearVehicleDamage(profile, vehicle);
|
||||
continue;
|
||||
}
|
||||
if (since === undefined || since > now) {
|
||||
setVehicleDamage(profile, vehicle, condition.hp, condition.lastGameMode, now);
|
||||
continue;
|
||||
}
|
||||
const hours = Number(now - since) / Number(TICKS_PER_HOUR);
|
||||
const hp = condition.hp + hours / fullHours;
|
||||
if (hp >= 1) clearVehicleDamage(profile, vehicle);
|
||||
else if (hp > condition.hp) setVehicleDamage(profile, vehicle, hp, condition.lastGameMode, now);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Vehicle repair costs, computed as the client computes them so that what the player is charged
|
||||
* is what the hangar shows (game data: game-data/datasets/vehicle-repair.ts).
|
||||
*
|
||||
* - Full repair cost (wp_get_repair_cost_by_mode, aces.exe 2.61.0.37 0x10517b0): the price
|
||||
* table's aircrafts/<vehicle>/repair/<mode>/cost (repairCost<Mode>) x (1 + the repair cost
|
||||
* coefficients of the modifications the player has, 0x964900), truncated. The stat card shows it
|
||||
* x avgRepairMul (warpoints.blk, 1.0).
|
||||
* - Current repair cost of a damaged vehicle (wp_get_repair_cost -> getAircraftRepairCost
|
||||
* 0x90e0b0): max(1, (1 - hp) x full cost in the mode it was damaged in (lastGameMode)); 0 when
|
||||
* intact or when the full cost is 0 (reserve vehicles). The client would also cap the full cost
|
||||
* at repairCostPerMin x a play time of its own (feature repairCostUsesPlayTime, a per-vehicle
|
||||
* table at EconomicState+0xe838 whose source was not found; the local server never fills it),
|
||||
* so the battle settlement puts the lifetime rule into hp instead (battle/battle-repair.ts).
|
||||
* - Full repair time (shop_get_full_repair_time_by_mode; 0x937330 with the mode it was damaged in),
|
||||
* in hours; the hangar shows (1 - hp) x it as the time until the free repair is done
|
||||
* (shop_time_until_repair 0x17a5040) and never counts down by itself (repair/repair-over-time.ts):
|
||||
* - A crew has the vehicle as its current one: repairTimeHrs<Mode> x the cost's modification
|
||||
* factor (0x964750 multiplies by 0x964900 when the time is positive) x a crew multiplier.
|
||||
* The multiplier is 1 unless the vehicle's rank is at most repair_ranks/rank<q> of the crew's
|
||||
* groundService/repairRank level q (0x95d7b0). Otherwise it runs from 1/low to 1/high of
|
||||
* crew_parameters/mechanic/hangarRepairSpeed (no data file has it: the client default (1, 3),
|
||||
* 0x95cee0) over f = groundService/repair level / its maximum, plus, when the skill uses
|
||||
* specializations, the share of specialization<k>_add up to the crew's specialization with the
|
||||
* vehicle (0x95d200); f spans 0..2 then, else 0..1 (table at 0x72b6e00).
|
||||
* - No crew has it: repairTimeHrsNoCrew<Mode> x the factor, or repairTimeHrs<Mode> x the factor x
|
||||
* rTimeNoCrewMul when the vehicle has no no-crew time (0x964e30, warpoints.blk at 0x5c).
|
||||
* Inferred: the skill entry's two fields the client divides (+0xc / +0x10) are the level and the
|
||||
* maximum level, the rank compared is the vehicle's tech tree rank (0x9523b0), and a crew with
|
||||
* no repairRank level bought has the skill's min_skill_level.
|
||||
*/
|
||||
import { findBlock, findParam, type BlkBlock } from '@wto/blk';
|
||||
import {
|
||||
REPAIR_MODES,
|
||||
type CrewRepairSkill,
|
||||
type RepairMode,
|
||||
type VehicleRepair,
|
||||
type VehicleRepairData,
|
||||
} from '../game-data/datasets/vehicle-repair.ts';
|
||||
import { skillLevel, specializationOf } from '../profile/profile-crew-skills.ts';
|
||||
import { allCrews } from '../profile/profile-crews.ts';
|
||||
import { ownsModification } from '../profile/profile-modifications.ts';
|
||||
import { vehicleCondition } from '../profile/profile-vehicle-condition.ts';
|
||||
import type { TechTree } from '../research/tech-tree.ts';
|
||||
|
||||
/** crew_parameters/mechanic/hangarRepairSpeed default (aces.exe 2.61.0.37 0x95cee0). */
|
||||
const HANGAR_REPAIR_SPEED = { low: 1, high: 3 } as const;
|
||||
/** The smallest repair speed the client allows (0x937330, constant at 0x7296ba0). */
|
||||
const MIN_REPAIR_SPEED = 0.001;
|
||||
const CREW_SKILL_PAGE = 'groundService';
|
||||
|
||||
/** lastGameMode / the client's EGD index: 1 arcade, 2 historical, 3 simulation. */
|
||||
export function repairModeOf(lastGameMode: number): RepairMode {
|
||||
return REPAIR_MODES[lastGameMode - 1] ?? 'Arcade';
|
||||
}
|
||||
|
||||
export function gameModeIndexOf(mode: RepairMode): number {
|
||||
return REPAIR_MODES.indexOf(mode) + 1;
|
||||
}
|
||||
|
||||
export class RepairRules {
|
||||
readonly #vehicles: ReadonlyMap<string, VehicleRepair>;
|
||||
readonly #noCrewTimeMul: number;
|
||||
readonly #crewSkill: CrewRepairSkill;
|
||||
readonly #techTree: TechTree;
|
||||
|
||||
constructor(data: VehicleRepairData, techTree: TechTree) {
|
||||
this.#vehicles = new Map(data.vehicles.map((vehicle) => [vehicle.name, vehicle]));
|
||||
this.#noCrewTimeMul = data.noCrewTimeMul;
|
||||
this.#crewSkill = data.crewSkill;
|
||||
this.#techTree = techTree;
|
||||
}
|
||||
|
||||
/** The vehicle's repair data; undefined for vehicles that repair for free. */
|
||||
vehicle(name: string): VehicleRepair | undefined {
|
||||
return this.#vehicles.get(name);
|
||||
}
|
||||
|
||||
fullCost(profile: BlkBlock, vehicle: string, mode: RepairMode): number {
|
||||
const data = this.#vehicles.get(vehicle);
|
||||
if (!data) return 0;
|
||||
return Math.trunc(data.cost[mode] * this.#modFactor(profile, data, mode));
|
||||
}
|
||||
|
||||
/** Repair cost per minute of lifetime, scaled by the same modification factor as the full cost (inferred). */
|
||||
costPerMinute(profile: BlkBlock, vehicle: string, mode: RepairMode): number {
|
||||
const data = this.#vehicles.get(vehicle);
|
||||
if (!data) return 0;
|
||||
return data.costPerMin[mode] * this.#modFactor(profile, data, mode);
|
||||
}
|
||||
|
||||
currentCost(profile: BlkBlock, vehicle: string): number {
|
||||
const condition = vehicleCondition(profile, vehicle);
|
||||
if (!condition || condition.hp >= 1) return 0;
|
||||
const full = this.fullCost(profile, vehicle, repairModeOf(condition.lastGameMode));
|
||||
if (full < 1) return 0;
|
||||
return Math.max(1, Math.trunc((1 - condition.hp) * full));
|
||||
}
|
||||
|
||||
/** Hours a free repair from wreck to intact takes in the vehicle's damage mode; 0 when it has no time. */
|
||||
fullRepairHours(profile: BlkBlock, vehicle: string): number {
|
||||
const data = this.#vehicles.get(vehicle);
|
||||
const condition = vehicleCondition(profile, vehicle);
|
||||
if (!data || !condition) return 0;
|
||||
const mode = repairModeOf(condition.lastGameMode);
|
||||
const factor = this.#modFactor(profile, data, mode);
|
||||
const scaled = (hours: number) => (hours > 0 ? hours * factor : hours);
|
||||
const crew = allCrews(profile).find((candidate) => currentVehicleOf(candidate) === vehicle);
|
||||
if (crew) return Math.max(0, scaled(data.timeHours[mode]) * this.#crewTimeMultiplier(crew, vehicle));
|
||||
const noCrew = scaled(data.noCrewTimeHours[mode]);
|
||||
if (noCrew >= 0) return noCrew;
|
||||
return Math.max(0, scaled(data.timeHours[mode]) * Math.max(1, this.#noCrewTimeMul));
|
||||
}
|
||||
|
||||
#crewTimeMultiplier(crew: BlkBlock, vehicle: string): number {
|
||||
const skill = this.#crewSkill;
|
||||
const qualification = Math.max(skill.minQualification, skillLevel(crew, CREW_SKILL_PAGE, 'repairRank'));
|
||||
const coveredRank = (skill.ranksByQualification[qualification - 1] ?? 0) > 0 ? skill.ranksByQualification[qualification - 1]! : qualification;
|
||||
const rank = this.#techTree.vehicle(vehicle)?.rank ?? Number.POSITIVE_INFINITY;
|
||||
if (rank > coveredRank) return 1;
|
||||
const slow = 1 / HANGAR_REPAIR_SPEED.low;
|
||||
const fast = 1 / HANGAR_REPAIR_SPEED.high;
|
||||
const span = skill.usesSpecializations ? 2 : 1;
|
||||
const level = skill.maxLevel > 0 ? skillLevel(crew, CREW_SKILL_PAGE, 'repair') / skill.maxLevel : 0;
|
||||
const progress = (skill.usesSpecializations ? specializationShare(skill, specializationOf(crew, vehicle)) : 0) + level;
|
||||
const multiplier = progress <= 0 ? slow : progress < span ? slow + (progress * (fast - slow)) / span : fast;
|
||||
return 1 / Math.max(MIN_REPAIR_SPEED, 1 / multiplier);
|
||||
}
|
||||
|
||||
#modFactor(profile: BlkBlock, data: VehicleRepair, mode: RepairMode): number {
|
||||
let factor = 1;
|
||||
for (const [mod, coefs] of Object.entries(data.modCoefs)) {
|
||||
if (ownsModification(profile, data.name, mod)) factor += coefs[mode];
|
||||
}
|
||||
return factor;
|
||||
}
|
||||
}
|
||||
|
||||
/** Share of specialization<k>_add up to the crew's specialization (0 none, 1 expert, 2 ace; 0x95d200). */
|
||||
function specializationShare(skill: CrewRepairSkill, specialization: number): number {
|
||||
const adds = skill.specializationAdds;
|
||||
const total = adds.reduce((sum, add) => sum + add, 0);
|
||||
if (total === 0) return 0;
|
||||
const reached = adds.reduce((sum, add, index) => sum + (index <= specialization ? add : 0), 0);
|
||||
return reached / total;
|
||||
}
|
||||
|
||||
function currentVehicleOf(crew: BlkBlock): string | undefined {
|
||||
const current = findParam(findBlock(crew, 'aircrafts') ?? crew, 'current')?.value;
|
||||
return current?.type === 'string' && current.value.length > 0 ? current.value : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user