Files
blitzkit/packages/website-ue/src/core/tankopedia/aggregateParameters.ts
T

202 lines
6.0 KiB
TypeScript
Raw Normal View History

2026-04-28 21:22:50 -05:00
import type { TankCatalogComponent } from "@blitzkit/closed/protos/game/proto/legacy/blitz_static_tank_component";
2026-04-14 20:34:28 -05:00
import { StandardSinglePrice } from "@protos/game/proto/legacy/blitz_static_standard_single_price";
import { PenetrationGroup } from "@protos/game/proto/legacy/blitz_static_tank_penetration_group";
2025-12-13 23:35:38 -06:00
import {
2025-12-14 21:38:18 -06:00
PenetrationGroupUpgrade,
2025-12-18 12:59:12 -06:00
PitchLimit,
2025-12-14 22:00:45 -06:00
ShellUpgrade,
2026-04-14 20:34:28 -05:00
ShellUpgradeSingleChange,
2025-12-13 23:35:38 -06:00
StageParameters,
2026-04-28 21:22:50 -05:00
TankAttributeChange,
2025-12-13 23:35:38 -06:00
TankAttributeChange_AttributeName,
TankAttributeChange_Modifier,
2025-12-18 12:59:12 -06:00
VisualChanges,
2026-04-14 20:34:28 -05:00
} from "@protos/game/proto/legacy/blitz_static_tank_upgrade_single_stage";
2025-12-13 23:35:38 -06:00
2025-12-18 13:08:42 -06:00
function patch(stage0: StageParameters, stage1: StageParameters) {
2026-04-28 21:22:50 -05:00
if (stage1.number !== ++stage0.number) {
2025-12-13 23:35:38 -06:00
throw new Error("Change stage number must be 1 greater than base");
}
2025-12-18 13:08:42 -06:00
for (const attribute1 of stage1.attributes) {
let value1: number;
2025-12-13 23:35:38 -06:00
2025-12-18 13:08:42 -06:00
switch (attribute1.modifier) {
2025-12-13 23:35:38 -06:00
case TankAttributeChange_Modifier.MODIFIER_OVERRIDE:
2025-12-18 13:08:42 -06:00
value1 = attribute1.value;
2025-12-13 23:35:38 -06:00
break;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY:
2025-12-14 21:38:18 -06:00
case TankAttributeChange_Modifier.MODIFIER_ADD:
2025-12-18 13:16:20 -06:00
const attribute0 = stage0.attributes.find(
(attribute0) =>
2026-04-14 20:34:28 -05:00
attribute0.attribute_name === attribute1.attribute_name,
2025-12-18 13:16:20 -06:00
);
if (!attribute0) {
2025-12-13 23:35:38 -06:00
throw new Error(
`Missing attribute ${
2025-12-18 13:08:42 -06:00
TankAttributeChange_AttributeName[attribute1.attribute_name]
2026-04-14 20:34:28 -05:00
} (${attribute1.attribute_name}) to modify`,
2025-12-13 23:35:38 -06:00
);
}
2025-12-14 21:38:18 -06:00
2025-12-13 23:35:38 -06:00
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
2025-12-18 13:16:20 -06:00
value1 = attribute0!.value! * attribute1.value;
2025-12-13 23:35:38 -06:00
break;
}
case TankAttributeChange_Modifier.MODIFIER_ADD: {
2025-12-18 13:16:20 -06:00
value1 = attribute0!.value! + attribute1.value;
2025-12-13 23:35:38 -06:00
break;
}
default:
throw new Error(
`Unhandled modified ${
2025-12-18 13:08:42 -06:00
TankAttributeChange_Modifier[attribute1.modifier]
2026-04-14 20:34:28 -05:00
}`,
2025-12-13 23:35:38 -06:00
);
}
2025-12-18 13:08:42 -06:00
const attribute0 = TankAttributeChange.create({
2025-12-13 23:35:38 -06:00
modifier: TankAttributeChange_Modifier.MODIFIER_OVERRIDE,
2025-12-18 13:08:42 -06:00
attribute_name: attribute1.attribute_name,
value: value1,
});
const index0 = stage0.attributes.findIndex(
2026-04-14 20:34:28 -05:00
(attribute) => attribute.attribute_name === attribute1.attribute_name,
2025-12-18 13:08:42 -06:00
);
if (index0 === -1) {
stage0.attributes.push(attribute0);
} else {
stage0.attributes[index0] = attribute0;
}
2025-12-13 23:35:38 -06:00
}
2025-12-14 21:38:18 -06:00
2025-12-18 13:08:42 -06:00
for (const penetrationGroupUpgrade1 of stage1.penetration_groups_upgrades) {
2025-12-19 14:34:17 -06:00
const penetrationGroupUpgrade0 = stage0.penetration_groups_upgrades.find(
2026-04-14 20:34:28 -05:00
(group) => group.tank_part === penetrationGroupUpgrade1.tank_part,
2025-12-14 21:38:18 -06:00
);
2025-12-19 14:34:17 -06:00
if (penetrationGroupUpgrade0) {
penetrationGroupUpgrade0.primary_armor = [
...penetrationGroupUpgrade1.primary_armor,
];
2025-12-14 21:38:18 -06:00
2025-12-19 14:34:17 -06:00
for (const penetrationGroup1 of penetrationGroupUpgrade1.penetration_groups) {
const penetrationGroup0 =
penetrationGroupUpgrade0.penetration_groups.find(
2026-04-14 20:34:28 -05:00
(baseGroup) =>
baseGroup.group_name === penetrationGroup1.group_name,
2025-12-19 14:34:17 -06:00
);
2025-12-14 21:38:18 -06:00
2025-12-19 14:34:17 -06:00
if (penetrationGroup0) {
penetrationGroup0.common_data = penetrationGroup1.common_data;
penetrationGroup0.armor = penetrationGroup1.armor;
} else {
penetrationGroupUpgrade0.penetration_groups.push(
2026-04-14 20:34:28 -05:00
PenetrationGroup.create(penetrationGroup1),
2025-12-19 14:34:17 -06:00
);
}
2025-12-14 21:38:18 -06:00
}
2025-12-19 14:34:17 -06:00
} else {
stage0.penetration_groups_upgrades.push(
2026-04-14 20:34:28 -05:00
PenetrationGroupUpgrade.create(penetrationGroupUpgrade1),
2025-12-19 14:34:17 -06:00
);
2025-12-14 21:38:18 -06:00
}
}
2025-12-14 22:00:45 -06:00
2025-12-18 13:08:42 -06:00
if (stage1.modules_upgrades.length > 0) {
2025-12-14 22:00:45 -06:00
throw new Error("Modules upgrades not implemented");
}
2025-12-18 13:08:42 -06:00
for (const shellUpgrades1 of stage1.shells_upgrades) {
let shellUpgrades0 = stage0.shells_upgrades.find(
2026-04-14 20:34:28 -05:00
(baseShell) => baseShell.shell_id === shellUpgrades1.shell_id,
2025-12-14 22:00:45 -06:00
);
2025-12-18 15:07:04 -06:00
if (shellUpgrades0) {
shellUpgrades0.shell_type = shellUpgrades1.shell_type;
2025-12-14 22:00:45 -06:00
2025-12-18 15:07:04 -06:00
for (const changedShellUpgrade of shellUpgrades1.changes) {
const shellUpgrade0 = shellUpgrades0.changes.find(
(baseShellUpgrade) =>
baseShellUpgrade.attribute_name ===
2026-04-14 20:34:28 -05:00
changedShellUpgrade.attribute_name,
2025-12-14 22:00:45 -06:00
);
2025-12-18 15:07:04 -06:00
if (shellUpgrade0) {
shellUpgrade0.value = changedShellUpgrade.value;
} else {
shellUpgrades0.changes.push(
2026-04-14 20:34:28 -05:00
ShellUpgradeSingleChange.create(changedShellUpgrade),
2025-12-18 15:07:04 -06:00
);
}
}
shellUpgrades0.silver_price =
shellUpgrades1.silver_price === undefined
? undefined
: StandardSinglePrice.create(shellUpgrades1.silver_price);
} else {
stage0.shells_upgrades.push(ShellUpgrade.create(shellUpgrades1));
}
2025-12-14 22:00:45 -06:00
}
2025-12-18 12:59:12 -06:00
2025-12-18 13:08:42 -06:00
if (stage1.pump_reload_times.length > 0) {
2025-12-19 15:17:45 -06:00
stage0.pump_reload_times = [...stage1.pump_reload_times];
}
2025-12-18 13:08:42 -06:00
if (stage1.pitch_limits_up.length > 0 && stage0.pitch_limits_up.length > 0) {
2025-12-18 12:59:12 -06:00
throw new Error("Pitch limits not implemented");
}
2025-12-18 13:08:42 -06:00
for (const pitchLimitUp1 of stage1.pitch_limits_up) {
stage0.pitch_limits_up.push(PitchLimit.create(pitchLimitUp1));
2025-12-18 12:59:12 -06:00
}
if (
2025-12-18 13:08:42 -06:00
stage1.pitch_limits_down.length > 0 &&
stage0.pitch_limits_down.length > 0
2025-12-18 12:59:12 -06:00
) {
throw new Error("Pitch limits not implemented");
}
2025-12-18 13:08:42 -06:00
for (const pitchLimitDown1 of stage1.pitch_limits_down) {
stage0.pitch_limits_down.push(PitchLimit.create(pitchLimitDown1));
2025-12-18 12:59:12 -06:00
}
2025-12-18 13:08:42 -06:00
for (const visualChange1 of stage1.visual_changes) {
const visualChange0 = stage0.visual_changes.find(
2025-12-18 12:59:12 -06:00
(baseVisualChange) =>
2026-04-14 20:34:28 -05:00
baseVisualChange.tank_part === visualChange1.tank_part,
2025-12-18 12:59:12 -06:00
);
2025-12-18 13:08:42 -06:00
if (visualChange0) {
visualChange0.name = visualChange1.name;
2025-12-18 12:59:12 -06:00
} else {
2025-12-18 13:08:42 -06:00
stage0.visual_changes.push(VisualChanges.create(visualChange1));
2025-12-18 12:59:12 -06:00
}
}
2025-12-13 23:35:38 -06:00
}
2026-04-28 21:22:50 -05:00
export function aggregateParameters(
tank: TankCatalogComponent,
upgrades: Record<string, number>,
2025-12-13 23:35:38 -06:00
) {
2026-04-28 21:22:50 -05:00
const stage0 = StageParameters.create({});
2025-12-13 23:35:38 -06:00
2026-04-28 21:22:50 -05:00
for (const line of tank.upgrade_lines) {
const stage = upgrades[line.name];
2025-12-13 23:35:38 -06:00
2026-04-28 21:22:50 -05:00
stage0.number = 0;
for (let i = 0; i < stage; i++) {
patch(stage0, line.stages[i]);
}
2025-12-13 23:35:38 -06:00
}
2025-12-18 13:08:42 -06:00
return stage0;
2025-12-13 23:35:38 -06:00
}