From 6830df01fa6c91a0b1881c4601f2f57fcf047089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 14 Dec 2025 21:38:18 -0600 Subject: [PATCH] penetration_groups_upgrades --- .../src/core/blitz/aggregateStages.ts | 52 ++++++++++++++++--- .../src/pages/tanks/[slug]/_index.tsx | 2 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/packages/website-ue/src/core/blitz/aggregateStages.ts b/packages/website-ue/src/core/blitz/aggregateStages.ts index 17b861e83..41bf0b297 100644 --- a/packages/website-ue/src/core/blitz/aggregateStages.ts +++ b/packages/website-ue/src/core/blitz/aggregateStages.ts @@ -1,4 +1,5 @@ import { + PenetrationGroupUpgrade, StageParameters, TankAttributeChange_AttributeName, TankAttributeChange_Modifier, @@ -6,12 +7,11 @@ import { import { times } from "lodash-es"; function patch(change: StageParameters, base: StageParameters) { - if (change.stage_number !== base.stage_number + 1) { + if (change.stage_number !== ++base.stage_number) { throw new Error("Change stage number must be 1 greater than base"); } for (const attribute of change.attributes) { - const oldValue = base.attributes[attribute.attribute_name].value; let newValue: number; switch (attribute.modifier) { @@ -20,7 +20,7 @@ function patch(change: StageParameters, base: StageParameters) { break; case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: - case TankAttributeChange_Modifier.MODIFIER_ADD: { + case TankAttributeChange_Modifier.MODIFIER_ADD: if (!(attribute.attribute_name in base)) { throw new Error( `Missing attribute ${ @@ -28,15 +28,16 @@ function patch(change: StageParameters, base: StageParameters) { } to modify` ); } - } + + const oldValue = base.attributes[attribute.attribute_name]!.value; case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: { - newValue = oldValue * attribute.value; + newValue = oldValue! * attribute.value; break; } case TankAttributeChange_Modifier.MODIFIER_ADD: { - newValue = oldValue + attribute.value; + newValue = oldValue! + attribute.value; break; } @@ -54,6 +55,42 @@ function patch(change: StageParameters, base: StageParameters) { value: newValue, }; } + + for (const changedPenetrationGroupsUpgrade of change.penetration_groups_upgrades) { + if (changedPenetrationGroupsUpgrade.primary_armor.length > 0) { + throw new Error("Primary armor is not empty; implement this"); + } + + let basePenetrationGroupsUpgrade = base.penetration_groups_upgrades.find( + (group) => group.tank_part === changedPenetrationGroupsUpgrade.tank_part + ); + + if (!basePenetrationGroupsUpgrade) { + basePenetrationGroupsUpgrade = PenetrationGroupUpgrade.create({ + tank_part: changedPenetrationGroupsUpgrade.tank_part, + }); + + base.penetration_groups_upgrades.push(basePenetrationGroupsUpgrade); + } + + for (const changedGroup of changedPenetrationGroupsUpgrade.penetration_groups) { + const baseGroup = basePenetrationGroupsUpgrade.penetration_groups.find( + (baseGroup) => baseGroup.group_name === changedGroup.group_name + ); + + if (baseGroup) { + if (baseGroup.common_data !== changedGroup.common_data) { + throw new Error("Common data is not the same"); + } + + baseGroup.armor = changedGroup.armor; + } else { + basePenetrationGroupsUpgrade.penetration_groups.push({ + ...changedGroup, + }); + } + } + } } export function aggregateStages( @@ -68,7 +105,8 @@ export function aggregateStages( /** * Bug in Reforged: base stats are stage 1, so is the first upgrade. Manually * setting it to stage 0 below and if the bug's been fixed, throw an error - * in dev mode to allow clean up in the future. + * in dev mode to allow clean up in the future. Also, update the initial + * stage number to -1. */ if (attributes.stage_number === 0 && import.meta.env.DEV) { diff --git a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx index 41bbd4240..289577e01 100644 --- a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx +++ b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx @@ -18,7 +18,7 @@ function Content({ id }: { id: string }) { const stage = Tankopedia.use((state) => state.stage); - const attributes = useMemo( + const aggregatedStages = useMemo( () => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage), [stage] );