From 23751fbdf385f3318c9d165fd722bb7a57e04f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sat, 20 Dec 2025 10:15:23 -0600 Subject: [PATCH] feat: dynamic dispersion --- .../src/core/tankopedia/characteristics.ts | 86 ++++++++++--------- .../core/tankopedia/characteristicsOrder.ts | 9 +- .../core/tankopedia/computeCharacteristics.ts | 1 + .../src/core/tankopedia/tankState.ts | 5 ++ 4 files changed, 52 insertions(+), 49 deletions(-) diff --git a/packages/website-ue/src/core/tankopedia/characteristics.ts b/packages/website-ue/src/core/tankopedia/characteristics.ts index dc92dc064..9259327d7 100644 --- a/packages/website-ue/src/core/tankopedia/characteristics.ts +++ b/packages/website-ue/src/core/tankopedia/characteristics.ts @@ -2,6 +2,7 @@ import { ShellUpgrageSingleChange_AttributeName, TankAttributeChange_AttributeName, } from "@protos/blitz_static_tank_upgrade_single_stage"; +import type { TankState } from "./tankState"; export type CharacteristicOutput = number | null; @@ -11,6 +12,7 @@ type Characteristic = (helpers: { attributeSafe: (name: TankAttributeChange_AttributeName) => number | null; shell: (name: ShellUpgrageSingleChange_AttributeName) => number; shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null; + state: TankState; }) => CharacteristicOutput; export type CharacteristicName = keyof typeof characteristics; @@ -22,26 +24,32 @@ export enum GunType { } export const characteristics = { - clip_size({ attribute }) { - return attribute( - TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE - ); - }, - - gun_type({ attributeSafe, characteristic }) { + gun_type({ attributeSafe, attribute }) { const isPump = attributeSafe(TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP) ?? 0; if (isPump === 1) return GunType.AutoReloader; - const clipSize = characteristic("clip_size")!; + const clipSize = attribute( + TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE + ); if (clipSize === 1) return GunType.Regular; return GunType.AutoLoader; }, + clip_size({ attribute, characteristic }) { + const gunType = characteristic("gun_type")!; + + if (gunType === GunType.Regular) return null; + + return attribute( + TankAttributeChange_AttributeName.ATTRIBUTE_NAME_CLIP_SIZE + ); + }, + damage({ shell }) { return shell( ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE @@ -106,7 +114,6 @@ export const characteristics = { case GunType.AutoReloader: { return -Infinity; - break; } default: @@ -158,40 +165,47 @@ export const characteristics = { ); }, - dispersion_still({ attribute }) { + speed_forward({ attribute }) { return attribute( + TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED + ); + }, + + speed_backward({ attribute }) { + return attribute( + TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED + ); + }, + + dispersion({ attribute, characteristic, state }) { + const base = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_ANGLE ); - }, - - dispersion_moving({ attribute }) { - return attribute( + const movement = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_MOVEMENT ); - }, - - dispersion_hull_traversing({ attribute }) { - return attribute( + const vehicleRotation = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_VEHICLE_ROTATION ); - }, - - dispersion_turret_traversing({ attribute }) { - return attribute( + const turretRotation = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_TURRET_ROTATION ); - }, - - dispersion_shooting({ attribute }) { - return attribute( + const afterShot = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_AFTER_SHOT ); - }, - - dispersion_gun_damaged({ attribute }) { - return attribute( + const gunDamaged = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_DISPERSION_FACTOR_WHILE_GUN_DAMAGED ); + const maxSpeed = characteristic("speed_forward") as number; + + return ( + (state.isGunDamaged ? gunDamaged : 1) * + (base + + (state.speed / maxSpeed) * movement + + (state.isHullTraversing ? vehicleRotation : 0) + + (state.isTurretTraversing ? turretRotation : 0) + + (state.isShooting ? afterShot : 0)) + ); }, gun_depression({ attributeSafe }) { @@ -210,18 +224,6 @@ export const characteristics = { ); }, - speed_forward({ attribute }) { - return attribute( - TankAttributeChange_AttributeName.ATTRIBUTE_NAME_FORWARD_MAX_SPEED - ); - }, - - speed_backward({ attribute }) { - return attribute( - TankAttributeChange_AttributeName.ATTRIBUTE_NAME_BACKWARD_MAX_SPEED - ); - }, - engine_power({ attribute }) { return attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_ENGINE_POWER diff --git a/packages/website-ue/src/core/tankopedia/characteristicsOrder.ts b/packages/website-ue/src/core/tankopedia/characteristicsOrder.ts index ba6eaf901..7697e5b51 100644 --- a/packages/website-ue/src/core/tankopedia/characteristicsOrder.ts +++ b/packages/website-ue/src/core/tankopedia/characteristicsOrder.ts @@ -44,16 +44,11 @@ export const characteristicsOrder: CharacteristicsOrder = [ { name: "shell_range", units: "m" }, { name: "shell_capacity" }, - { name: "aim_time", units: "s" }, + { name: "aim_time", decimals: 1, units: "s" }, { toy: "aim_time" }, - { name: "dispersion_still", units: "m" }, - { name: "dispersion_moving", units: "m" }, - { name: "dispersion_hull_traversing", units: "m" }, - { name: "dispersion_turret_traversing", units: "m" }, - { name: "dispersion_shooting", units: "m" }, - { name: "dispersion_gun_damaged", units: "m" }, + { name: "dispersion", decimals: 3, units: "m" }, { name: "gun_depression", units: "deg" }, { name: "gun_elevation", units: "deg" }, diff --git a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts index d0aa852db..0fc573eb8 100644 --- a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts +++ b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts @@ -80,6 +80,7 @@ export function computeCharacteristics( attributeSafe, shell, shellSafe, + state, }); computed[name] = value; } diff --git a/packages/website-ue/src/core/tankopedia/tankState.ts b/packages/website-ue/src/core/tankopedia/tankState.ts index acc81caa8..6c3f79183 100644 --- a/packages/website-ue/src/core/tankopedia/tankState.ts +++ b/packages/website-ue/src/core/tankopedia/tankState.ts @@ -2,4 +2,9 @@ export interface TankState { stage: number; shell: number; + speed: number; + isHullTraversing: boolean; + isTurretTraversing: boolean; + isShooting: boolean; + isGunDamaged: boolean; }