From b48a68b8deb3f0ea885acaf4c0399d0207730067 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:14:09 -0600 Subject: [PATCH] vehicle abilities and their characteristics --- .../core/src/blitzkit/api/server/0_base.ts | 2 +- .../src/blitzkit/api/server/11_scripts.ts | 72 +- .../core/src/blitzkit/api/server/1_tanks.ts | 450 ++++++---- .../src/types/augmentAttributeDefinitions.ts | 10 + packages/core/src/types/blitzEffectScript.ts | 12 +- packages/core/src/types/blitzScripts.ts | 2 +- packages/core/src/types/gunDefinitionsList.ts | 1 + packages/core/src/types/index.ts | 5 + .../core/src/types/shellDefinitionsList.ts | 36 +- packages/core/src/types/vehicleAbilityItem.ts | 11 + packages/core/src/types/vehicleDefinitions.ts | 87 +- packages/core/src/types/vehicleFilter.ts | 3 + packages/i18n/strings/en.json | 64 +- .../src/blitzkit/tank_definitions.proto | 17 + .../website/src/config/characteristics.ts | 818 +++++++++++++++++- .../src/config/characteristicsGroups.ts | 258 ++++++ .../src/config/characteristicsPresets.ts | 16 + .../website/src/hooks/useCharacteristics.ts | 41 +- .../src/tankopedia/calculateRankings.ts | 8 +- .../src/tankopedia/sortableCharacteristics.ts | 4 +- packages/website/src/types/characteristics.ts | 5 +- 21 files changed, 1664 insertions(+), 258 deletions(-) create mode 100644 packages/core/src/types/augmentAttributeDefinitions.ts create mode 100644 packages/core/src/types/vehicleAbilityItem.ts create mode 100644 packages/core/src/types/vehicleFilter.ts create mode 100644 packages/website/src/config/characteristicsPresets.ts diff --git a/packages/core/src/blitzkit/api/server/0_base.ts b/packages/core/src/blitzkit/api/server/0_base.ts index 912ee23b8..95a92cd9a 100644 --- a/packages/core/src/blitzkit/api/server/0_base.ts +++ b/packages/core/src/blitzkit/api/server/0_base.ts @@ -87,7 +87,7 @@ export abstract class ServerBlitzKitAPI0 extends AbstractBlitzKitAPI { protected botPattern = /^.+((tutorial_bot(\d+)?)|(TU))$/; - protected stringsI18n: Record> = {}; + private stringsI18n: Record> = {}; protected nationsDir?: string[]; protected tankStringIdMap: Record = {}; protected consumablesCommon: ConsumablesCommon = {}; diff --git a/packages/core/src/blitzkit/api/server/11_scripts.ts b/packages/core/src/blitzkit/api/server/11_scripts.ts index f8647c52b..9f91492cc 100644 --- a/packages/core/src/blitzkit/api/server/11_scripts.ts +++ b/packages/core/src/blitzkit/api/server/11_scripts.ts @@ -1,25 +1,53 @@ -import { ConsumablesCommon, OptionalDevices } from "../../../types"; -import { BlitzEffectScript } from "../../../types/blitzEffectScript"; -import { BlitzScripts } from "../../../types/blitzScripts"; +import type { + BlitzEffectScript, + BlitzScripts, + ConsumablesCommon, + OptionalDevices, +} from "../../../types"; import { AbstractVFS } from "../../vfs"; import { Cache } from "./0_base"; import { ServerBlitzKitAPI10 } from "./10_avatars"; -function assignNormalizedScript( - target: Record, - key: number, - script?: BlitzEffectScript, -) { - if (script === undefined) return; +export abstract class ServerBlitzKitAPI11 extends ServerBlitzKitAPI10 { + // The XML parser keeps switches as text, but the script types declare them as + // booleans + private normalizeSwitches(value: Value): Value { + if (typeof value === "string") { + const lowered = value.toLowerCase(); - if (script["#text"] === "StaticFactorDevice") { - script["#text"] = script.attribute!; + if (lowered === "true") return true as Value; + if (lowered === "false") return false as Value; + } + + if (Array.isArray(value)) + return value.map((child) => this.normalizeSwitches(child)) as Value; + + if (typeof value === "object" && value !== null) { + return Object.fromEntries( + Object.entries(value).map(([key, child]) => [ + key, + this.normalizeSwitches(child), + ]), + ) as Value; + } + + return value; } - target[key] = script; -} + private assignNormalizedScript( + target: Record, + key: number, + script?: BlitzEffectScript, + ) { + if (script === undefined) return; + + if (script["#text"] === "StaticFactorDevice") { + script["#text"] = script.attribute!; + } + + target[key] = this.normalizeSwitches(script); + } -export abstract class ServerBlitzKitAPI11 extends ServerBlitzKitAPI10 { @Cache() async scripts() { const scripts: BlitzScripts = { @@ -35,14 +63,18 @@ export abstract class ServerBlitzKitAPI11 extends ServerBlitzKitAPI10 { for (const key in optionalDevices.root) { const equipment = optionalDevices.root[key]; - assignNormalizedScript(scripts.equipment, equipment.id, equipment.script); + this.assignNormalizedScript( + scripts.equipment, + equipment.id, + equipment.script, + ); } - async function assign( + const assign = async ( vfs: AbstractVFS, dir: string, - target: keyof BlitzScripts, - ) { + target: "consumables" | "provisions", + ) => { const root = `Data/XML/item_defs/vehicles/common/${dir}`; const list = await vfs.text(`${root}/list.xml`); const pattern = //gm; @@ -55,14 +87,14 @@ export abstract class ServerBlitzKitAPI11 extends ServerBlitzKitAPI10 { for (const key in things.root) { const thing = things.root[key]; - assignNormalizedScript( + this.assignNormalizedScript( scripts[target], thing.id, things.root[key].script, ); } } - } + }; await assign(this.vfs, "consumables", "consumables"); await assign(this.vfs, "provisions", "provisions"); diff --git a/packages/core/src/blitzkit/api/server/1_tanks.ts b/packages/core/src/blitzkit/api/server/1_tanks.ts index 546041e8e..7f2fbcb6e 100644 --- a/packages/core/src/blitzkit/api/server/1_tanks.ts +++ b/packages/core/src/blitzkit/api/server/1_tanks.ts @@ -1,9 +1,11 @@ import { + type AugmentAttributeDefinitions, BlitzCrewType, BlitzModuleType, blitzShellKindToBlitzkit, BlitzTankClass, ChassisDefinitionsList, + type ConsumablesVehicleFilter, EngineDefinitionsList, GunDefinitionsList, ShellDefinitionsList, @@ -17,10 +19,13 @@ import { UpgradeProgressionXml, UpgradeProgressionXmlNode, UpgradeProgressionXmlRequirement, + type VehicleAbilityItem, + type VehicleDefinitionGun, VehicleDefinitionList, VehicleDefinitions, } from "@blitzkit/core"; import { + AbilitySource, AssaultRanges, AugmentAttribute, AugmentNode, @@ -33,23 +38,282 @@ import { ModulePosition, ModuleType, ResearchCost, + ShellDefinition, TankDefinitions, TankPrice, TankPriceType, TankType, Unlock, + type VehicleAbility, } from "@blitzkit/protos"; import { Cache, ServerBlitzKitAPI0 } from "./0_base"; -// What an augment attribute shows, by attribute name -interface AugmentAttributeDefinition { - icon: string; - title: string; -} - -type AugmentAttributeDefinitions = Map; - export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 { + // A gun the way a tank's turret or a vehicle ability builds it. `gun` + // overrides the shared gun entry, which is all an ability has + private parseGun( + nation: string, + gunKey: string, + gunList: GunDefinitionsList, + shellList: ShellDefinitionsList, + gun: Partial, + unlocks: GunDefinition["unlocks"], + ) { + const gunListEntry = gunList.shared[gunKey]; + const gunType = + gun.clip === undefined + ? "regular" + : gun.pumpGunMode + ? "auto_reloader" + : "auto_loader"; + const gunClipCount = gunType === "regular" ? 1 : gun.clip!.count; + const shotDispersionFactors = + gun.shotDispersionFactors ?? gunListEntry.shotDispersionFactors; + let assault_ranges: AssaultRanges | undefined; + + if (gun.extras?.trayShell) { + const types = gun.extras.trayShell.kinds.split(" ").map((string) => { + const trimmed = string.trim(); + + if (trimmed in blitzShellKindToBlitzkit) { + return blitzShellKindToBlitzkit[trimmed as ShellKind]; + } + + throw new SyntaxError(`Invalid shell kind: ${trimmed}`); + }); + const sectorNames = Object.keys(gun.extras.trayShell.sectors); + + if (sectorNames.length !== 1 || sectorNames[0] !== "sector") { + throw new SyntaxError("Invalid tray shell sector"); + } + + const sector = gun.extras.trayShell.sectors.sector; + + assault_ranges = { + types, + ranges: sector.map((value) => ({ + factor: value.factor, + distance: value.distance, + })), + }; + } + + return { + id: toUniqueId(nation, gunList.ids[gunKey]), + weight: gunListEntry.weight, + rotation_speed: gunListEntry.rotationSpeed, + name: this.getString(gunListEntry.userString), + tier: gunListEntry.level, + shells: this.parseShells(nation, gunListEntry, shellList), + camouflage_loss: + gun.invisibilityFactorAtShot === undefined + ? 0 + : typeof gun.invisibilityFactorAtShot === "number" + ? gun.invisibilityFactorAtShot + : gun.invisibilityFactorAtShot.at(-1)!, + aim_time: gun.aimingTime ?? gunListEntry.aimingTime, + dispersion_base: + gun.shotDispersionRadius ?? gunListEntry.shotDispersionRadius, + dispersion_damaged: shotDispersionFactors.whileGunDamaged, + dispersion_shot: shotDispersionFactors.afterShot, + dispersion_traverse: shotDispersionFactors.turretRotation, + unlocks, + shell_capacity: gun.maxAmmo ?? gunListEntry.maxAmmo, + assault_ranges, + burst: + gun.burst && gun.burst.count > 1 + ? { + count: gun.burst.count, + interval: 60 / gun.burst.rate, + } + : undefined, + gun_type: + gunType === "regular" + ? { + $case: "regular", + value: { + reload: gun.reloadTime ?? 0, + }, + } + : gunType === "auto_reloader" + ? { + $case: "auto_reloader", + value: { + intra_clip: 60 / gun.clip!.rate, + shell_count: gunClipCount, + shell_reloads: gun.pumpGunReloadTimes!.split(" ").map(Number), + }, + } + : { + $case: "auto_loader", + value: { + intra_clip: 60 / gun.clip!.rate, + clip_reload: gun.reloadTime ?? 0, + shell_count: gunClipCount, + }, + }, + } satisfies GunDefinition; + } + + // The shells a gun fires. Its shots may override a shell's speed, range and + // penetration, and otherwise the shell's own values hold + private parseShells( + nation: string, + gunListEntry: GunDefinitionsList["shared"][string], + shellList: ShellDefinitionsList, + ) { + return Object.keys(gunListEntry.shots ?? {}).map((shellKey) => { + const gunShellEntry = gunListEntry.shots[shellKey]; + const shell = shellList[shellKey]; + + // Newer client data stores shot properties on the shell rather than + // repeating them under every gun's entry + const speed = + typeof gunShellEntry === "string" ? shell.speed : gunShellEntry.speed; + const maxDistance = + typeof gunShellEntry === "string" + ? shell.maxDistance + : gunShellEntry.maxDistance; + const piercingPower = + typeof gunShellEntry === "string" + ? shell.piercingPower + : gunShellEntry.piercingPower; + + const penetrationRaw = piercingPower + .split(" ") + .filter((penetrationString) => penetrationString !== "") + .map(Number); + + return { + id: toUniqueId(nation, shell.id), + name: this.getString(shell.userString), + velocity: speed, + armor_damage: shell.damage.armor, + module_damage: shell.damage.devices, + caliber: shell.caliber, + normalization: shell.normalizationAngle, + ricochet: shell.ricochetAngle, + type: blitzShellKindToBlitzkit[shell.kind], + explosion_radius: + shell.kind === "HIGH_EXPLOSIVE" + ? shell.explosionRadius ?? 0 + : undefined, + icon: shell.icon, + penetration: { + near: penetrationRaw[0], + far: penetrationRaw[1], + }, + range: maxDistance, + acceleration: shell.acceleration, + max_speed: shell.maxSpeed, + } satisfies ShellDefinition; + }); + } + + // A vehicle ability's placeholder gun as `nation:gun`, built like a tank's own + // guns. An ability's gun has no turret, so its shared entry is all its data + private async placeholderGun(reference: string) { + const [nation, gunKey] = reference.trim().split(":"); + const base = `Data/XML/item_defs/vehicles/${nation}/components`; + const { root: gunList } = await this.vfs.xml<{ + root: GunDefinitionsList; + }>(`${base}/guns.xml`); + const { root: shellList } = await this.vfs.xml<{ + root: ShellDefinitionsList; + }>(`${base}/shells.xml`); + const shared = gunList.shared[gunKey]; + + if (shared === undefined) { + throw new Error(`Vehicle ability gun ${reference} is not in guns.xml`); + } + + return this.parseGun(nation, gunKey, gunList, shellList, shared, []); + } + + // The hidden provisions and consumables the game marks as vehicle abilities, + // by the key a tank's `extras` names them with + private vehicleAbilityItems() { + const items = new Map(); + const groups = [ + [AbilitySource.ABILITY_SOURCE_CONSUMABLE, this.consumablesCommon], + [AbilitySource.ABILITY_SOURCE_PROVISION, this.provisionsCommon], + ] as const; + + for (const [source, group] of groups) { + for (const [key, item] of Object.entries(group)) { + if (!("isVehicleAbility" in item)) continue; + + // The names in the filter's `include`, or nothing when it doesn't name tanks + const vehicle = item.vehicleFilter?.include.vehicle; + + items.set(key, { + source, + id: item.id, + vehicleNames: + vehicle !== undefined && "name" in vehicle + ? vehicle.name.trim().split(/\s+/) + : undefined, + gun: item.script?.gun, + }); + } + } + + return items; + } + + // The abilities a tank has, from the hidden items its own `extras` names. + // Guns name none in the game files today, so one is an error, not a gap + private async vehicleAbilitiesOf( + nation: string, + tankKey: string, + root: { + extras?: Record; + turrets0?: Record< + string, + { guns: Record }> } + >; + }, + items: Map, + ) { + const name = `${nation}:${tankKey}`; + + for (const turret of Object.values(root.turrets0 ?? {})) { + for (const gun of Object.values(turret.guns ?? {})) { + for (const key of Object.keys(gun.extras ?? {})) { + if (items.has(key)) { + throw new Error( + `Gun extra ${key} on ${name} is a vehicle ability, which is only linked for tanks`, + ); + } + } + } + } + + const abilities: VehicleAbility[] = []; + + for (const key of Object.keys(root.extras ?? {})) { + const item = items.get(key); + if (item === undefined) continue; + + if (item.vehicleNames && !item.vehicleNames.includes(name)) { + throw new Error( + `${key} is on ${name}, which its vehicle filter does not include`, + ); + } + + abilities.push({ + source: item.source, + id: item.id, + gun: + item.gun === undefined + ? undefined + : await this.placeholderGun(item.gun), + }); + } + + return abilities; + } + private parseResearchCost(raw: number | string) { if (typeof raw === "number") { return { @@ -194,6 +458,7 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 { @Cache() async tanks() { const tankDefinitions = TankDefinitions.create(); + const abilityItems = this.vehicleAbilityItems(); const gameModeNativeNames: Record = {}; @@ -605,6 +870,12 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 { dev_name: tankKey, module_positions, augment_progression, + vehicle_abilities: await this.vehicleAbilitiesOf( + nation, + tankKey, + tankDefinition.root, + abilityItems, + ), roles: {}, camouflages: camouflages, fixed_camouflage: fixedCamouflage, @@ -726,165 +997,20 @@ export abstract class ServerBlitzKitAPI1 extends ServerBlitzKitAPI0 { ), }); - let gunIndex = 0; for (const gunKey in turret.guns) { const gun = turret.guns[gunKey]; - const gunId = toUniqueId(nation, gunList.root.ids[gunKey]); - const gunListEntry = gunList.root.shared[gunKey]; - const gunName = this.getString(gunListEntry.userString); - const gunType = - "clip" in gun - ? gun.pumpGunMode - ? "autoReloader" - : "autoLoader" - : "regular"; - const gunClipCount = gunType === "regular" ? 1 : gun.clip!.count; - const shotDispersionFactors = - gun.shotDispersionFactors ?? gunListEntry.shotDispersionFactors; - let assault_ranges: AssaultRanges | undefined; - - if (gun.extras?.trayShell) { - const types = gun.extras.trayShell.kinds - .split(" ") - .map((string) => { - const trimmed = string.trim(); - - if (trimmed in blitzShellKindToBlitzkit) { - return blitzShellKindToBlitzkit[trimmed as ShellKind]; - } - - throw new SyntaxError(`Invalid shell kind: ${trimmed}`); - }); - const sectorNames = Object.keys(gun.extras.trayShell.sectors); - - if (sectorNames.length !== 1 || sectorNames[0] !== "sector") { - throw new SyntaxError("Invalid tray shell sector"); - } - - const sector = gun.extras.trayShell.sectors.sector; - - assault_ranges = { - types, - ranges: sector.map((value) => ({ - factor: value.factor, - distance: value.distance, - })), - }; - } totalUnlocks.push(gun.unlocks); - - tankDefinitions.tanks[tankId].turrets[turretIndex].guns.push({ - id: gunId, - weight: gunListEntry.weight, - rotation_speed: gunListEntry.rotationSpeed, - name: gunName, - tier: gunListEntry.level, - shells: [], - camouflage_loss: - typeof gun.invisibilityFactorAtShot === "number" - ? gun.invisibilityFactorAtShot - : gun.invisibilityFactorAtShot.at(-1)!, - aim_time: gun.aimingTime ?? gunListEntry.aimingTime, - dispersion_base: - gun.shotDispersionRadius ?? gunListEntry.shotDispersionRadius, - dispersion_damaged: shotDispersionFactors.whileGunDamaged, - dispersion_shot: shotDispersionFactors.afterShot, - dispersion_traverse: shotDispersionFactors.turretRotation, - unlocks: resolveUnlocks( - this.blitzModuleTypeToBlitzkit, - gun.unlocks, + tankDefinitions.tanks[tankId].turrets[turretIndex].guns.push( + this.parseGun( + nation, + gunKey, + gunList.root, + shellList.root, + gun, + resolveUnlocks(this.blitzModuleTypeToBlitzkit, gun.unlocks), ), - shell_capacity: gun.maxAmmo ?? gunListEntry.maxAmmo, - assault_ranges, - burst: - gun.burst && gun.burst.count > 1 - ? { - count: gun.burst.count, - interval: 60 / gun.burst.rate, - } - : undefined, - gun_type: - gunType === "regular" - ? { - $case: "regular", - value: { - reload: gun.reloadTime, - }, - } - : gunType === "autoReloader" - ? { - $case: "auto_reloader", - value: { - intra_clip: 60 / gun.clip!.rate, - shell_count: gunClipCount, - shell_reloads: gun - .pumpGunReloadTimes!.split(" ") - .map(Number), - }, - } - : { - $case: "auto_loader", - value: { - intra_clip: 60 / gun.clip!.rate, - clip_reload: gun.reloadTime, - shell_count: gunClipCount, - }, - }, - } satisfies GunDefinition); - - for (const shellKey in gunListEntry.shots) { - const gunShellEntry = gunListEntry.shots[shellKey]; - const shell = shellList.root[shellKey]; - - // Newer client data stores shot properties on the shell rather - // than repeating them under every gun's entry. - const speed = - typeof gunShellEntry === "string" - ? shell.speed - : gunShellEntry.speed; - const maxDistance = - typeof gunShellEntry === "string" - ? shell.maxDistance - : gunShellEntry.maxDistance; - const piercingPower = - typeof gunShellEntry === "string" - ? shell.piercingPower - : gunShellEntry.piercingPower; - - const shellId = toUniqueId(nation, shell.id); - const shellName = this.getString(shell.userString); - const penetrationRaw = piercingPower - .split(" ") - .filter((penetrationString) => penetrationString !== "") - .map(Number); - - tankDefinitions.tanks[tankId].turrets[turretIndex].guns[ - gunIndex - ].shells.push({ - id: shellId, - name: shellName, - velocity: speed, - armor_damage: shell.damage.armor, - module_damage: shell.damage.devices, - caliber: shell.caliber, - normalization: shell.normalizationAngle, - ricochet: shell.ricochetAngle, - type: blitzShellKindToBlitzkit[shell.kind], - explosion_radius: - shell.kind === "HIGH_EXPLOSIVE" - ? shell.explosionRadius ?? 0 - : undefined, - icon: shell.icon, - penetration: { - near: penetrationRaw[0], - far: penetrationRaw[1], - }, - range: maxDistance, - }); - } - - gunIndex++; + ); } turretIndex++; diff --git a/packages/core/src/types/augmentAttributeDefinitions.ts b/packages/core/src/types/augmentAttributeDefinitions.ts new file mode 100644 index 000000000..ea4c3cdb3 --- /dev/null +++ b/packages/core/src/types/augmentAttributeDefinitions.ts @@ -0,0 +1,10 @@ +// What an augment attribute shows, by attribute name +export interface AugmentAttributeDefinition { + icon: string; + title: string; +} + +export type AugmentAttributeDefinitions = Map< + string, + AugmentAttributeDefinition +>; diff --git a/packages/core/src/types/blitzEffectScript.ts b/packages/core/src/types/blitzEffectScript.ts index 5b94c4b49..54753c12a 100644 --- a/packages/core/src/types/blitzEffectScript.ts +++ b/packages/core/src/types/blitzEffectScript.ts @@ -4,6 +4,14 @@ export type BlitzEffectScript = RSN & { cooldown?: number; duration?: number; + aimingSpeed?: number; + gunDispersionModifier?: number; + activateWithoutDamage?: boolean; + targetOrder?: boolean; + // A placeholder gun the ability fires, as `nation:gun`, and what it resolves to + gun?: string; + allowSwitchAfterKill?: boolean; + allowNonDamagingHits?: boolean; startCooldown?: number; automatic?: boolean; @@ -52,10 +60,6 @@ interface ModuleConstants { modules: Record; } -interface ModulesMaxHPFactorsModules { - ammoBayHealth: number; -} - interface ChangesToHit { crew: number; modules: RSN; diff --git a/packages/core/src/types/blitzScripts.ts b/packages/core/src/types/blitzScripts.ts index c32759054..b0a16ada5 100644 --- a/packages/core/src/types/blitzScripts.ts +++ b/packages/core/src/types/blitzScripts.ts @@ -1,4 +1,4 @@ -import { BlitzEffectScript } from "./blitzEffectScript"; +import type { BlitzEffectScript } from "./blitzEffectScript"; export interface BlitzScripts { consumables: Record; diff --git a/packages/core/src/types/gunDefinitionsList.ts b/packages/core/src/types/gunDefinitionsList.ts index 01bcc957e..7c30d80d6 100644 --- a/packages/core/src/types/gunDefinitionsList.ts +++ b/packages/core/src/types/gunDefinitionsList.ts @@ -5,6 +5,7 @@ export interface GunDefinitionsList { [key: string]: { rotationSpeed: number; weight: number; + reloadTime?: number; shotDispersionFactors: { turretRotation: number; afterShot: number; diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 66a70fc68..28b2e1f96 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -1,5 +1,8 @@ +export * from "./augmentAttributeDefinitions"; export * from "./availableNationsYaml"; +export * from "./blitzEffectScript"; export * from "./blitzModuleType"; +export * from "./blitzScripts"; export * from "./blitzStrings"; export * from "./blitzTankFilterDefinitionCategory"; export * from "./camouflagesXml"; @@ -24,6 +27,8 @@ export * from "./tanksStats"; export * from "./techTreeLayoutYaml"; export * from "./turretDefinitionsList"; export * from "./upgradeProgressionXml"; +export * from "./vehicleAbilityItem"; export * from "./vehicleDefinitionArmor"; export * from "./vehicleDefinitionList"; export * from "./vehicleDefinitions"; +export * from "./vehicleFilter"; diff --git a/packages/core/src/types/shellDefinitionsList.ts b/packages/core/src/types/shellDefinitionsList.ts index b37302e70..c364d9e1e 100644 --- a/packages/core/src/types/shellDefinitionsList.ts +++ b/packages/core/src/types/shellDefinitionsList.ts @@ -1,20 +1,22 @@ -export type ShellDefinitionsList = Record< - string, - { - id: number; - userString: string; - icon: string; - kind: ShellKind; - caliber: number; - damage: { armor: number; devices: number }; - normalizationAngle?: number; - ricochetAngle?: number; - explosionRadius?: number; - speed: number; - maxDistance: number; - piercingPower: string; - } -> & { +// A shell as its shells.xml entry lists it +export interface ShellDefinitionXml { + id: number; + userString: string; + icon: string; + kind: ShellKind; + caliber: number; + damage: { armor: number; devices: number }; + normalizationAngle?: number; + ricochetAngle?: number; + explosionRadius?: number; + speed: number; + maxDistance: number; + acceleration?: number; + maxSpeed?: number; + piercingPower: string; +} + +export type ShellDefinitionsList = Record & { icons: Record; }; diff --git a/packages/core/src/types/vehicleAbilityItem.ts b/packages/core/src/types/vehicleAbilityItem.ts new file mode 100644 index 000000000..566b26add --- /dev/null +++ b/packages/core/src/types/vehicleAbilityItem.ts @@ -0,0 +1,11 @@ +import type { AbilitySource } from "@blitzkit/protos"; + +// A hidden provision or consumable the game marks as a vehicle ability. +// `vehicleNames` is its filter's list of tanks, when it has one +export interface VehicleAbilityItem { + source: AbilitySource; + id: number; + vehicleNames?: string[]; + // The placeholder gun the ability fires, as `nation:gun` + gun?: string; +} diff --git a/packages/core/src/types/vehicleDefinitions.ts b/packages/core/src/types/vehicleDefinitions.ts index 55c9b1ca0..fc11287ae 100644 --- a/packages/core/src/types/vehicleDefinitions.ts +++ b/packages/core/src/types/vehicleDefinitions.ts @@ -78,48 +78,7 @@ export interface VehicleDefinitions { collisionModel: string; }; guns: { - [key: string]: { - unlocks: UnlocksListing; - armor: VehicleDefinitionArmor & { - gun?: - | number - | { - chanceToHitByProjectile: number; - chanceToHitByExplosion: number; - "#text": number; - }; - }; - invisibilityFactorAtShot: number | number[]; - reloadTime: number; - aimingTime?: number; - shotDispersionRadius: number; - shotDispersionFactors?: { - turretRotation: number; - afterShot: number; - whileGunDamaged: number; - }; - maxAmmo: number; - extraPitchLimits?: { - front?: string; - back?: string; - transition?: number | number[]; - }; - pitchLimits?: string | string[]; - pumpGunMode?: boolean; - pumpGunReloadTimes?: string; - clip?: { count: number; rate: number }; - burst?: { count: number; rate: number }; - models: { undamaged: string }; - extras?: { - trayShell?: { - kinds: string; - sectors: Record< - string, - { id: number; distance: number; factor: number }[] - >; - }; - }; - }; + [key: string]: VehicleDefinitionGun; }; }; }; @@ -154,3 +113,47 @@ export type BlitzCrewType = | "loader"; export type UnlocksListing = BlitzModuleType | undefined; + +// A turret gun as its tank lists it, which overrides the shared gun entry +export interface VehicleDefinitionGun { + unlocks: UnlocksListing; + armor: VehicleDefinitionArmor & { + gun?: + | number + | { + chanceToHitByProjectile: number; + chanceToHitByExplosion: number; + "#text": number; + }; + }; + invisibilityFactorAtShot: number | number[]; + reloadTime: number; + aimingTime?: number; + shotDispersionRadius: number; + shotDispersionFactors?: { + turretRotation: number; + afterShot: number; + whileGunDamaged: number; + }; + maxAmmo: number; + extraPitchLimits?: { + front?: string; + back?: string; + transition?: number | number[]; + }; + pitchLimits?: string | string[]; + pumpGunMode?: boolean; + pumpGunReloadTimes?: string; + clip?: { count: number; rate: number }; + burst?: { count: number; rate: number }; + models: { undamaged: string }; + extras?: { + trayShell?: { + kinds: string; + sectors: Record< + string, + { id: number; distance: number; factor: number }[] + >; + }; + }; +} diff --git a/packages/core/src/types/vehicleFilter.ts b/packages/core/src/types/vehicleFilter.ts new file mode 100644 index 000000000..a33dfab5c --- /dev/null +++ b/packages/core/src/types/vehicleFilter.ts @@ -0,0 +1,3 @@ +export interface VehicleFilter { + include?: { vehicle?: { name?: string } | { name?: string }[] }; +} diff --git a/packages/i18n/strings/en.json b/packages/i18n/strings/en.json index 2982567dd..d0ec47e21 100644 --- a/packages/i18n/strings/en.json +++ b/packages/i18n/strings/en.json @@ -61,6 +61,7 @@ "percentage": "{value}%", "deg_s": "{value}°/s", "m_s": "{value}m/s", + "m_s2": "{value}m/s²", "km_h": "{value}km/h", "t": "{value}t", "bhp": "{value}bhp", @@ -180,6 +181,15 @@ "survivability": "Survivability", "concealment": "Concealment", + "steady_aim_system": "Steady aim system", + "burst_mode": "Burst mode", + "combat_frenzy": "Combat frenzy", + "external_ammo_module": "External ammo module", + "ramming_configuration": "Ramming configuration", + "nitro": "Nitro", + "shell_overheat": "Shell overheat", + "auxiliary_weapons": "Auxiliary weapons", + "unguided_rocket": "Unguided rocket", "assault_shells": "Assault shells" }, @@ -267,7 +277,59 @@ "camouflage_on_fire": "On fire", "width": "Width", "height": "Height", - "length": "Length" + "length": "Length", + + "steady_aim_system_duration": "Duration", + "steady_aim_system_aiming_speed": "Aim time", + "steady_aim_system_dispersion": "Dispersion", + "steady_aim_system_activation_condition": "Activates on", + "burst_mode_count": "Shells", + "burst_mode_interval": "First intra-clip", + "burst_mode_penetrations": "Penetrations", + "burst_mode_target_order": "Same target", + "combat_frenzy_reload_bonus": "Reload per stack", + "combat_frenzy_max_stacks": "Max stacks", + "combat_frenzy_keep_stacks": "Keep on kill", + "external_ammo_module_clip_bonus": "Extra shells", + "external_ammo_module_transformation": "Transform time", + "external_ammo_module_timeout": "Timeout", + "external_ammo_module_activation_condition": "Activates on", + "ramming_configuration_damage_bonus": "Damage bonus", + "ramming_configuration_track_damage_bonus": "Track damage bonus", + "ramming_configuration_damage_reduction": "Damage taken", + "nitro_duration": "Heat time", + "nitro_cooling_duration": "Cool time", + "nitro_cooldown": "Cooldown", + "nitro_engine_power": "Engine power", + "nitro_top_speed": "Top speed", + "nitro_rotation_speed": "Hull traverse", + "shell_overheat_boost": "Damage boost", + "shell_overheat_charge_time": "Charge time", + "shell_overheat_activation_delay": "Charge delay", + "shell_overheat_decay_time": "Discharge time", + "shell_overheat_min_speed": "Min speed", + "shell_overheat_max_speed": "Max speed", + "auxiliary_weapons_shots": "Shots", + "auxiliary_weapons_damage": "Damage", + "auxiliary_weapons_penetration": "Penetration", + "auxiliary_weapons_shell_speed": "Shell speed", + "auxiliary_weapons_interval": "Intra-clip", + "auxiliary_weapons_cooldown": "Reload", + "unguided_rocket_count": "Rockets", + "unguided_rocket_damage": "Damage", + "unguided_rocket_penetration": "Penetration", + "unguided_rocket_initial_speed": "Initial speed", + "unguided_rocket_acceleration": "Acceleration", + "unguided_rocket_max_distance": "Range", + "unguided_rocket_intra_clip": "Intra-clip", + "unguided_rocket_container_reload": "Reload" + }, + + "flags": { + "yes": "Yes", + "no": "No", + "on_hit": "On hit", + "on_damage": "On damage" } }, diff --git a/packages/protos/src/blitzkit/tank_definitions.proto b/packages/protos/src/blitzkit/tank_definitions.proto index 1520abb54..2f45e3730 100644 --- a/packages/protos/src/blitzkit/tank_definitions.proto +++ b/packages/protos/src/blitzkit/tank_definitions.proto @@ -45,6 +45,7 @@ message TankDefinition { optional I18nString name_full = 34; repeated ModulePosition module_positions = 35; optional AugmentProgression augment_progression = 36; + repeated VehicleAbility vehicle_abilities = 37; } // Hand-authored cell in the modules screen grid. Tanks without any use the @@ -65,6 +66,20 @@ message AugmentProgression { optional AugmentGroup group = 4; } +// A hidden provision or consumable the tank has, which the game turns into an +// ability. The script itself lives in `scripts.json` under `id`. `gun` is the +// placeholder gun the ability fires, when it fires one +message VehicleAbility { + AbilitySource source = 1; + uint32 id = 2; + optional GunDefinition gun = 3; +} + +enum AbilitySource { + ABILITY_SOURCE_PROVISION = 0; + ABILITY_SOURCE_CONSUMABLE = 1; +} + // TODO: render these differently in the browser enum AugmentNodeType { AUGMENT_NODE_TYPE_COMMON = 0; @@ -253,6 +268,8 @@ message ShellDefinition { optional float ricochet = 11; optional float explosion_radius = 12; uint32 range = 13; + optional float acceleration = 14; + optional float max_speed = 15; } enum ShellType { diff --git a/packages/website/src/config/characteristics.ts b/packages/website/src/config/characteristics.ts index 2fd00084c..2679f3215 100644 --- a/packages/website/src/config/characteristics.ts +++ b/packages/website/src/config/characteristics.ts @@ -4,7 +4,7 @@ import { normalizeBoundingBox, unionBoundingBox, } from "@blitzkit/core"; -import { ShellType, TankClass } from "@blitzkit/protos"; +import { ShellType, TankClass, type GunDefinition } from "@blitzkit/protos"; import type { Vector2Tuple } from "three"; import { shellSlot } from "../tankopedia/augments"; import { hullTraverseSpeed } from "../tankopedia/hullTraverseSpeed"; @@ -15,6 +15,36 @@ import { type Characteristic, } from "../types/characteristics"; +// The reload a gun shows. An auto reloader has no single one, so it shows none +function reloadOf(gun: GunDefinition) { + const type = gun.gun_type; + + if (type?.$case === "regular") return type.value.reload; + if (type?.$case === "auto_loader") return type.value.clip_reload; + + return 0; +} + +// The shells in a gun's clip, or none for a gun without one +function shellsPerClipOf(gun: GunDefinition) { + const type = gun.gun_type; + + if (type?.$case === "auto_loader") return type.value.shell_count; + if (type?.$case === "auto_reloader") return type.value.shell_count; + + return 0; +} + +// The time between a clip's shells, or none for a gun without a clip +function intraClipOf(gun: GunDefinition) { + const type = gun.gun_type; + + if (type?.$case === "auto_loader") return type.value.intra_clip; + if (type?.$case === "auto_reloader") return type.value.intra_clip; + + return 0; +} + /** * peek-a-boo assumes at least this many seconds between shots to account for * peeking out, aiming, and retreating @@ -1358,6 +1388,792 @@ export const characteristics = { }, }, + // Abilities. A tank only gets the ones it has, which is whether the + // protagonist carries the ability's script + steady_aim_system_duration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("SteadyAimSystem"), + + compute({ script, augment }) { + let duration = 0; + + script("protagonist", "SteadyAimSystem", (effect) => { + duration += effect.duration ?? 0; + }); + + augment("SAS_DURATION", (value) => { + duration += value; + }); + + return duration; + }, + }, + + steady_aim_system_aiming_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("SteadyAimSystem"), + + compute({ script, augment }) { + let speed = 0; + + script("protagonist", "SteadyAimSystem", (effect) => { + speed += effect.aimingSpeed ?? 0; + }); + + augment("SAS_AIMING_SPEED", (value) => { + speed += value; + }); + + return speed * 100; + }, + }, + + steady_aim_system_dispersion: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("SteadyAimSystem"), + + compute({ script, augment }) { + let dispersion = 0; + + script("protagonist", "SteadyAimSystem", (effect) => { + dispersion += effect.gunDispersionModifier ?? 0; + }); + + augment("SAS_GUN_DISPERSION", (value) => { + dispersion += value; + }); + + return dispersion * 100; + }, + }, + + steady_aim_system_activation_condition: { + type: CharacteristicType.Enum, + should_render: ({ hasScript }) => hasScript("SteadyAimSystem"), + + compute({ script, augment }) { + let onHit = false; + + script("protagonist", "SteadyAimSystem", (effect) => { + onHit = effect.activateWithoutDamage === true; + }); + + augment("SAS_ALLOW_ACTIVATE_ON_HIT", (value) => { + onHit = value !== 0; + }); + + return onHit ? "on_hit" : "on_damage"; + }, + }, + + burst_mode_count: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("BurstMode"), + + compute({ script }) { + let count = 0; + + script("protagonist", "BurstMode", (effect) => { + count += effect.count ?? 0; + }); + + return count; + }, + }, + + burst_mode_interval: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("BurstMode"), + + compute({ script, augment }) { + let interval = 0; + + script("protagonist", "BurstMode", (effect) => { + interval += effect.burstInterval ?? 0; + }); + + augment("BURST_MODE_INTERVAL", (value) => { + interval += value; + }); + + return interval; + }, + }, + + burst_mode_penetrations: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("BurstMode"), + + compute({ script, augment }) { + let penetrations = 0; + + script("protagonist", "BurstMode", (effect) => { + penetrations += effect.requiredDamagingPenetrations ?? 0; + }); + + augment("BURST_MODE_REQUIRED_PENETRATIONS", (value) => { + penetrations += value; + }); + + return penetrations; + }, + }, + + burst_mode_target_order: { + type: CharacteristicType.Enum, + should_render: ({ hasScript }) => hasScript("BurstMode"), + + compute({ script, augment }) { + let order = false; + + script("protagonist", "BurstMode", (effect) => { + order = effect.targetOrder === true; + }); + + augment("BURST_MODE_TARGET_ORDER", (value) => { + order = value !== 0; + }); + + return order ? "yes" : "no"; + }, + }, + + combat_frenzy_reload_bonus: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("CombatFrenzy"), + + compute({ script, augment }) { + let bonus = 0; + + script("protagonist", "CombatFrenzy", (effect) => { + bonus += effect.reloadSpeedBonusPerStack ?? 0; + }); + + augment("COMBAT_FRENZY_RELOAD_SPEED_BONUS_PER_STACK", (value) => { + bonus += value; + }); + + return bonus * 100; + }, + }, + + combat_frenzy_max_stacks: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("CombatFrenzy"), + + compute({ script, augment }) { + let stacks = 0; + + script("protagonist", "CombatFrenzy", (effect) => { + stacks += effect.maxStacks ?? 0; + }); + + augment("COMBAT_FRENZY_MAX_STACKS", (value) => { + stacks += value; + }); + + return stacks; + }, + }, + + combat_frenzy_keep_stacks: { + type: CharacteristicType.Enum, + should_render: ({ hasScript }) => hasScript("CombatFrenzy"), + + compute({ script, augment }) { + let keep = false; + + script("protagonist", "CombatFrenzy", (effect) => { + keep = effect.allowSwitchAfterKill === true; + }); + + augment("COMBAT_FRENZY_ALLOW_SWITCH_AFTER_KILL", (value) => { + keep = value !== 0; + }); + + return keep ? "yes" : "no"; + }, + }, + + external_ammo_module_clip_bonus: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ExternalAmmoModule"), + + compute({ script }) { + let bonus = 0; + + script("protagonist", "ExternalAmmoModule", (effect) => { + bonus += effect.clipSizeBonus ?? 0; + }); + + return bonus; + }, + }, + + external_ammo_module_transformation: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ExternalAmmoModule"), + + compute({ script }) { + let duration = 0; + + script("protagonist", "ExternalAmmoModule", (effect) => { + duration += effect.transformationDuration ?? 0; + }); + + return duration; + }, + }, + + external_ammo_module_timeout: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ExternalAmmoModule"), + + compute({ script }) { + let timeout = 0; + + script("protagonist", "ExternalAmmoModule", (effect) => { + timeout += effect.transformationTimeOut ?? 0; + }); + + return timeout; + }, + }, + + external_ammo_module_activation_condition: { + type: CharacteristicType.Enum, + should_render: ({ hasScript }) => hasScript("ExternalAmmoModule"), + + compute({ script, augment }) { + let onHit = false; + + script("protagonist", "ExternalAmmoModule", (effect) => { + onHit = effect.allowNonDamagingHits === true; + }); + + augment("EXTERNAL_AMMO_MODULE_ALLOW_NON_DAMAGING_HITS", (value) => { + onHit = value !== 0; + }); + + return onHit ? "on_hit" : "on_damage"; + }, + }, + + ramming_configuration_damage_bonus: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RammingConfiguration"), + + compute({ script, augment }) { + let bonus = 0; + + script("protagonist", "RammingConfiguration", (effect) => { + bonus += effect.rammingDamageBonus ?? 0; + }); + + augment("RAMMING_CONFIGURATION_RAMMING_DAMAGE_BONUS", (value) => { + bonus += value; + }); + + return bonus * 100; + }, + }, + + ramming_configuration_track_damage_bonus: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RammingConfiguration"), + + compute({ script, augment }) { + let bonus = 0; + + script("protagonist", "RammingConfiguration", (effect) => { + bonus += effect.rammingTrackDamageBonus ?? 0; + }); + + augment("RAMMING_CONFIGURATION_RAMMING_TRACK_DAMAGE_BONUS", (value) => { + bonus += value; + }); + + return bonus * 100; + }, + }, + + ramming_configuration_damage_reduction: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RammingConfiguration"), + + compute({ script, augment }) { + let reduction = 0; + + script("protagonist", "RammingConfiguration", (effect) => { + reduction += effect.rammingDamageReduction ?? 0; + }); + + augment("RAMMING_CONFIGURATION_RAMMING_DAMAGE_REDUCTION", (value) => { + reduction += value; + }); + + return reduction * 100; + }, + }, + + nitro_duration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script, augment }) { + let duration = 0; + + script("protagonist", "RechargeableNitro", (effect) => { + duration += effect.duration ?? 0; + }); + + // The augment's heating duration is taken as the nitro duration + augment("RECHARGEABLE_NITRO_HEATING_DURATION", (value) => { + duration += value; + }); + + return duration; + }, + }, + + nitro_cooling_duration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script, augment }) { + let duration = 0; + + script("protagonist", "RechargeableNitro", (effect) => { + duration += effect.coolingDuration ?? 0; + }); + + augment("RECHARGEABLE_NITRO_COOLING_DURATION", (value) => { + duration += value; + }); + + return duration; + }, + }, + + nitro_cooldown: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script }) { + let cooldown = 0; + + script("protagonist", "RechargeableNitro", (effect) => { + cooldown += effect.cooldown ?? 0; + }); + + return cooldown; + }, + }, + + nitro_engine_power: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script, characteristic }): number { + let factor = 1; + + script("protagonist", "RechargeableNitro", (effect) => { + factor *= effect.enginePowerFactor ?? 1; + }); + + return (characteristic("engine_power") as number) * factor; + }, + }, + + nitro_top_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script, augment, characteristic }): number { + let factor = 1; + + script("protagonist", "RechargeableNitro", (effect) => { + factor *= effect.fwdSpeedLimitFactor ?? 1; + }); + + augment("RECHARGEABLE_NITRO_FWD_SPEED_LIMIT_FACTOR", (value) => { + factor += value; + }); + + return (characteristic("speed_forward") as number) * factor; + }, + }, + + nitro_rotation_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("RechargeableNitro"), + + compute({ script, augment, characteristic }): number { + let bonus = 0; + + script("protagonist", "RechargeableNitro", (effect) => { + bonus += effect.rotationSpeedFactor ?? 0; + }); + + augment("RECHARGEABLE_NITRO_ROTATION_SPEED_FACTOR", (value) => { + bonus += value; + }); + + return ( + (characteristic("hull_traverse_speed_medium") as number) * (1 + bonus) + ); + }, + }, + + shell_overheat_boost: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script, augment }) { + let boost = 0; + + script("protagonist", "ShellOverheat", (effect) => { + boost += effect.maxBoostToMinimumAlpha ?? 0; + }); + + augment("SHELL_OVERHEAT_MIN_ALPHA_BOOST", (value) => { + boost += value; + }); + + return boost * 100; + }, + }, + + shell_overheat_charge_time: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script, augment }) { + let time = 0; + + script("protagonist", "ShellOverheat", (effect) => { + time += effect.maxChargeAccumulationTimeFromStart ?? 0; + }); + + augment("SHELL_OVERHEAT_CHARGE_TIME", (value) => { + time += value; + }); + + return time; + }, + }, + + shell_overheat_activation_delay: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script, augment }) { + let delay = 0; + + script("protagonist", "ShellOverheat", (effect) => { + delay += effect.chargeActivationDelay ?? 0; + }); + + augment("SHELL_OVERHEAT_ACTIVATION_DELAY", (value) => { + delay += value; + }); + + return delay; + }, + }, + + shell_overheat_decay_time: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script }) { + let time = 0; + + script("protagonist", "ShellOverheat", (effect) => { + time += effect.decayTimeFromMaxToZero ?? 0; + }); + + return time; + }, + }, + + shell_overheat_min_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script }) { + let speed = 0; + + script("protagonist", "ShellOverheat", (effect) => { + speed += effect.minSpeedForChargeAccumulation ?? 0; + }); + + return speed; + }, + }, + + shell_overheat_max_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("ShellOverheat"), + + compute({ script, augment }) { + let speed = 0; + + script("protagonist", "ShellOverheat", (effect) => { + speed += effect.maxSpeedForChargeAccumulation ?? 0; + }); + + augment("SHELL_OVERHEAT_MAX_TANK_SPEED", (value) => { + speed += value; + }); + + return speed; + }, + }, + + auxiliary_weapons_shots: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script }) { + let count = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + count += gun!.burst!.count; + }); + + return count; + }, + }, + + auxiliary_weapons_damage: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script, augment }) { + let damage = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + damage += gun!.shells[0].armor_damage; + }); + + augment("AUXILLIARY_WEAPONS_GUN_DAMAGE", (value) => { + damage += value; + }); + + return damage; + }, + }, + + auxiliary_weapons_penetration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script }) { + let penetration = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + penetration += gun!.shells[0].penetration!.near; + }); + + return penetration; + }, + }, + + auxiliary_weapons_shell_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script }) { + let speed = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + speed += gun!.shells[0].velocity; + }); + + return speed; + }, + }, + + auxiliary_weapons_interval: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script, augment }) { + let interval = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + interval += gun!.burst!.interval; + }); + + augment("AUXILLIARY_WEAPONS_GUN_BURST_INTERVAL", (value) => { + interval += value; + }); + + return interval; + }, + }, + + auxiliary_weapons_cooldown: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("AuxilliaryWeapons"), + + compute({ script, augment }) { + let cooldown = 0; + + script("protagonist", "AuxilliaryWeapons", (_, gun) => { + cooldown += reloadOf(gun!); + }); + + augment("AUXILLIARY_WEAPONS_GUN_RELOAD_TIME", (value) => { + cooldown += value; + }); + + return cooldown; + }, + }, + + unguided_rocket_count: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script }) { + let count = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + count += shellsPerClipOf(gun!); + }); + + return count; + }, + }, + + unguided_rocket_damage: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script, augment }) { + let damage = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + damage += gun!.shells[0].armor_damage; + }); + + augment("UNGUIDED_ROCKET_DAMAGE", (value) => { + damage += value; + }); + + return damage; + }, + }, + + unguided_rocket_penetration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script }) { + let penetration = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + penetration += gun!.shells[0].penetration!.near; + }); + + return penetration; + }, + }, + + unguided_rocket_initial_speed: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script, augment }) { + let speed = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + speed += gun!.shells[0].velocity; + }); + + augment("UNGUIDED_ROCKET_INITIAL_SPEED", (value) => { + speed += value; + }); + + return speed; + }, + }, + + unguided_rocket_acceleration: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script, augment }) { + // Only the unguided rocket carries an acceleration, so it always exists here + let acceleration = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + acceleration += gun!.shells[0].acceleration!; + }); + + augment("UNGUIDED_ROCKET_ACCELERATION", (value) => { + acceleration += value; + }); + + return acceleration; + }, + }, + + unguided_rocket_max_distance: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script }) { + let distance = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + distance += gun!.shells[0].range; + }); + + return distance; + }, + }, + + unguided_rocket_intra_clip: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script, augment }) { + let reload = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + reload += intraClipOf(gun!); + }); + + augment("UNGUIDED_ROCKET_INTERCLIP_RELOAD", (value) => { + reload += value; + }); + + return reload; + }, + }, + + unguided_rocket_container_reload: { + type: CharacteristicType.Number, + should_render: ({ hasScript }) => hasScript("UnguidedRocket"), + + compute({ script, augment }) { + let reload = 0; + + script("protagonist", "UnguidedRocket", (_, gun) => { + reload += reloadOf(gun!); + }); + + augment("UNGUIDED_ROCKET_CONTAINER_RELOAD", (value) => { + reload += value; + }); + + return reload; + }, + }, + // Compute time only: what the assault shells visualizer is drawn from _assault_distances: { type: CharacteristicType.NumberList, diff --git a/packages/website/src/config/characteristicsGroups.ts b/packages/website/src/config/characteristicsGroups.ts index 78a888727..74b9aeebc 100644 --- a/packages/website/src/config/characteristicsGroups.ts +++ b/packages/website/src/config/characteristicsGroups.ts @@ -1,5 +1,6 @@ import type { CaseType } from "@blitzkit/core"; import type { GunDefinition } from "@blitzkit/protos"; +import { humanBoolean } from "./characteristicsPresets"; import { CharacteristicRanking, type CharacteristicName, @@ -68,6 +69,263 @@ export const characteristicsGroups: CharacteristicsGroup[] = [ // ], // }, + // Abilities, which only show on the tanks that have them + { + name: "steady_aim_system", + sortable: false, + order: [ + { + name: "steady_aim_system_duration", + decimals: 1, + units: "s", + }, + { + name: "steady_aim_system_aiming_speed", + decimals: 1, + units: "percentage", + }, + { + name: "steady_aim_system_dispersion", + ranking: CharacteristicRanking.None, + decimals: 1, + units: "percentage", + }, + { + ...humanBoolean, + + name: "steady_aim_system_activation_condition", + }, + ], + }, + + { + name: "burst_mode", + sortable: false, + order: [ + { + name: "burst_mode_count", + decimals: 0, + }, + { + name: "burst_mode_interval", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "burst_mode_penetrations", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 0, + }, + { + ...humanBoolean, + + name: "burst_mode_target_order", + }, + ], + }, + + { + name: "combat_frenzy", + sortable: false, + order: [ + { + name: "combat_frenzy_reload_bonus", + decimals: 0, + units: "percentage", + }, + { + name: "combat_frenzy_max_stacks", + decimals: 0, + }, + { + ...humanBoolean, + + name: "combat_frenzy_keep_stacks", + }, + ], + }, + + { + name: "external_ammo_module", + sortable: false, + order: [ + { + name: "external_ammo_module_clip_bonus", + decimals: 0, + }, + { + name: "external_ammo_module_transformation", + ranking: CharacteristicRanking.None, + decimals: 1, + units: "s", + }, + { + name: "external_ammo_module_timeout", + ranking: CharacteristicRanking.None, + decimals: 1, + units: "s", + }, + { + ...humanBoolean, + + name: "external_ammo_module_activation_condition", + }, + ], + }, + + { + name: "ramming_configuration", + sortable: false, + order: [ + { + name: "ramming_configuration_damage_bonus", + decimals: 0, + units: "percentage", + }, + { + name: "ramming_configuration_track_damage_bonus", + decimals: 0, + units: "percentage", + }, + { + name: "ramming_configuration_damage_reduction", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 0, + units: "percentage", + }, + ], + }, + + { + name: "nitro", + sortable: false, + order: [ + { + name: "nitro_duration", + decimals: 1, + units: "s", + }, + { + name: "nitro_cooling_duration", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "nitro_cooldown", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "nitro_engine_power", + decimals: 0, + units: "bhp", + }, + { + name: "nitro_top_speed", + decimals: 0, + units: "km_h", + }, + { + name: "nitro_rotation_speed", + decimals: 1, + units: "deg_s", + }, + ], + }, + + { + name: "shell_overheat", + sortable: false, + order: [ + { + name: "shell_overheat_boost", + decimals: 1, + units: "percentage", + }, + { + name: "shell_overheat_charge_time", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "shell_overheat_activation_delay", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "shell_overheat_decay_time", + ranking: CharacteristicRanking.None, + decimals: 1, + units: "s", + }, + { + name: "shell_overheat_min_speed", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 0, + units: "km_h", + }, + { + name: "shell_overheat_max_speed", + ranking: CharacteristicRanking.None, + decimals: 0, + units: "km_h", + }, + ], + }, + + { + name: "auxiliary_weapons", + sortable: false, + order: [ + { name: "auxiliary_weapons_shots", decimals: 0 }, + { name: "auxiliary_weapons_damage", decimals: 0 }, + { name: "auxiliary_weapons_penetration", decimals: 0, units: "mm" }, + { name: "auxiliary_weapons_shell_speed", decimals: 0, units: "m_s" }, + { + name: "auxiliary_weapons_interval", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 2, + units: "s", + }, + { + name: "auxiliary_weapons_cooldown", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 2, + units: "s", + }, + ], + }, + + { + name: "unguided_rocket", + sortable: false, + order: [ + { name: "unguided_rocket_count", decimals: 0 }, + { name: "unguided_rocket_damage", decimals: 0 }, + { name: "unguided_rocket_penetration", decimals: 0, units: "mm" }, + { name: "unguided_rocket_initial_speed", decimals: 0, units: "m_s" }, + { name: "unguided_rocket_acceleration", decimals: 1, units: "m_s2" }, + { name: "unguided_rocket_max_distance", decimals: 0, units: "m" }, + { + name: "unguided_rocket_intra_clip", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + { + name: "unguided_rocket_container_reload", + ranking: CharacteristicRanking.LowerIsBetter, + decimals: 1, + units: "s", + }, + ], + }, + { name: "assault_shells", sortable: false, diff --git a/packages/website/src/config/characteristicsPresets.ts b/packages/website/src/config/characteristicsPresets.ts new file mode 100644 index 000000000..35de6c18b --- /dev/null +++ b/packages/website/src/config/characteristicsPresets.ts @@ -0,0 +1,16 @@ +import { + CharacteristicRanking, + type CharacteristicRenderConfig, +} from "../types/characteristics"; + +// Switches come out as "yes" or "no", or as what the game calls them +export const humanBoolean = { + // Ability values are only comparable to themselves, so nothing is ranked + ranking: CharacteristicRanking.None, + + render({ output, strings }) { + return strings.tanks.characteristics.flags[ + output as keyof typeof strings.tanks.characteristics.flags + ]; + }, +} satisfies Partial; diff --git a/packages/website/src/hooks/useCharacteristics.ts b/packages/website/src/hooks/useCharacteristics.ts index d9abe2fcb..06cd2a5b3 100644 --- a/packages/website/src/hooks/useCharacteristics.ts +++ b/packages/website/src/hooks/useCharacteristics.ts @@ -5,7 +5,12 @@ import { type TankEnvironment, } from "@blitzkit/core"; import type { BlitzEffectScript } from "@blitzkit/core/src/types/blitzEffectScript"; -import { CrewType, type TankDefinition } from "@blitzkit/protos"; +import { + AbilitySource, + CrewType, + type GunDefinition, + type TankDefinition, +} from "@blitzkit/protos"; import { useMemo } from "react"; import { api } from "../api/dynamic"; import { characteristics } from "../config/characteristics"; @@ -51,6 +56,10 @@ export function computeCharacteristics( protagonist: new Map(), antagonist: new Map(), }; + const scriptGunMap: Record> = { + protagonist: new Map(), + antagonist: new Map(), + }; function addScript(side: DuelSide, name: string, script: BlitzEffectScript) { if (!scriptsMap[side].has(name)) { @@ -80,6 +89,25 @@ export function computeCharacteristics( addScript(side, script["#text"], script); } + // A tank's vehicle abilities are hidden provisions or consumables, which + // count like any other script + for (const ability of sideTank.vehicle_abilities) { + const script = + scripts[ + ability.source === AbilitySource.ABILITY_SOURCE_PROVISION + ? "provisions" + : "consumables" + ][ability.id]; + + if (script === undefined) continue; + + addScript(side, script["#text"], script); + + if (ability.gun !== undefined) { + scriptGunMap[side].set(script["#text"], ability.gun); + } + } + for (const index in states[side].equipment) { const choice = states[side].equipment[index]; const id = sideEquipmentPreset.slots[index].options[choice]; @@ -140,20 +168,26 @@ export function computeCharacteristics( // console.log(scriptsMap); + // The gun is the script's placeholder gun when it is a vehicle ability with one function script( side: DuelSide, name: string, - callback: (effect: BlitzEffectScript) => void, + callback: (effect: BlitzEffectScript, gun?: GunDefinition) => void, ) { if (!scriptsMap[side].has(name)) return; const scripts = scriptsMap[side].get(name)!; + const gun = scriptGunMap[side].get(name); for (const script of scripts) { - callback(script); + callback(script, gun); } } + function hasScript(name: string) { + return scriptsMap.protagonist.has(name); + } + const augments = augmentAttributes(tank, states.protagonist); function augment(name: string, callback: (value: number) => void) { @@ -179,6 +213,7 @@ export function computeCharacteristics( characteristic, script, + hasScript, augment, } satisfies CharacteristicContext; diff --git a/packages/website/src/tankopedia/calculateRankings.ts b/packages/website/src/tankopedia/calculateRankings.ts index 05f948363..335ced2be 100644 --- a/packages/website/src/tankopedia/calculateRankings.ts +++ b/packages/website/src/tankopedia/calculateRankings.ts @@ -15,8 +15,12 @@ const characteristicConfigs = new Map< CharacteristicRenderConfig >(); -for (const { order } of characteristicsGroups) { - for (const item of order) { +for (const group of characteristicsGroups) { + // Special groups only some tanks have, so there is no other tank to rank + // them against + if (group.sortable === false) continue; + + for (const item of group.order) { if (!("name" in item)) continue; characteristicConfigs.set(item.name, item); } diff --git a/packages/website/src/tankopedia/sortableCharacteristics.ts b/packages/website/src/tankopedia/sortableCharacteristics.ts index 4dae74abc..9eaeb9aa3 100644 --- a/packages/website/src/tankopedia/sortableCharacteristics.ts +++ b/packages/website/src/tankopedia/sortableCharacteristics.ts @@ -14,7 +14,9 @@ const sortableCharacteristicTypes = new Set([ export const sortableCharacteristics = new Set(); for (const group of characteristicsGroups) { - if (!group.sortable) continue; + // Only groups that are explicitly unsortable are left out, which is different from undefined + // yes, it's meant to be === false and not !sortable + if (group.sortable === false) continue; for (const config of group.order) { if (!("name" in config)) continue; diff --git a/packages/website/src/types/characteristics.ts b/packages/website/src/types/characteristics.ts index 6d6d03e88..e7122efc0 100644 --- a/packages/website/src/types/characteristics.ts +++ b/packages/website/src/types/characteristics.ts @@ -41,7 +41,7 @@ export type Characteristic = { export type CharacteristicScript = ( side: DuelSide, name: string, - effect: (effect: BlitzEffectScript) => void, + effect: (effect: BlitzEffectScript, gun?: GunDefinition) => void, ) => void; export interface CharacteristicContext { @@ -64,10 +64,9 @@ export interface CharacteristicContext { name: CharacteristicName, ): ReturnType; + hasScript(name: string): boolean; script: CharacteristicScript; - // Like scripts, but for each value the installed augments give an attribute, - // named without the `ATTRIBUTE_NAME_` prefix augment(name: string, callback: (value: number) => void): void; }