feat: rename

This commit is contained in:
TrèsAbhi committed 2025-12-18 13:08:42 -06:00
1 parent cf8fa4ffb4
commit 6ba6e10108
1 file changed
+77 -72
@@ -6,123 +6,128 @@ import {
ShellUpgrade, ShellUpgrade,
ShellUpgrageSingleChange, ShellUpgrageSingleChange,
StageParameters, StageParameters,
TankAttributeChange,
TankAttributeChange_AttributeName, TankAttributeChange_AttributeName,
TankAttributeChange_Modifier, TankAttributeChange_Modifier,
VisualChanges, VisualChanges,
} from "@protos/blitz_static_tank_upgrade_single_stage"; } from "@protos/blitz_static_tank_upgrade_single_stage";
import { times } from "lodash-es"; import { times } from "lodash-es";
function patch(change: StageParameters, base: StageParameters) { function patch(stage0: StageParameters, stage1: StageParameters) {
if (change.stage_number !== ++base.stage_number) { if (stage1.stage_number !== ++stage0.stage_number) {
throw new Error("Change stage number must be 1 greater than base"); throw new Error("Change stage number must be 1 greater than base");
} }
for (const changedAttribute of change.attributes) { for (const attribute1 of stage1.attributes) {
let newValue: number; let value1: number;
switch (changedAttribute.modifier) { switch (attribute1.modifier) {
case TankAttributeChange_Modifier.MODIFIER_OVERRIDE: case TankAttributeChange_Modifier.MODIFIER_OVERRIDE:
newValue = changedAttribute.value; value1 = attribute1.value;
break; break;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: case TankAttributeChange_Modifier.MODIFIER_MULTIPLY:
case TankAttributeChange_Modifier.MODIFIER_ADD: case TankAttributeChange_Modifier.MODIFIER_ADD:
if (!(changedAttribute.attribute_name in base)) { if (!(attribute1.attribute_name in stage0)) {
throw new Error( throw new Error(
`Missing attribute ${ `Missing attribute ${
TankAttributeChange_AttributeName[changedAttribute.attribute_name] TankAttributeChange_AttributeName[attribute1.attribute_name]
} to modify` } to modify`
); );
} }
const oldValue = const oldValue = stage0.attributes[attribute1.attribute_name]!.value;
base.attributes[changedAttribute.attribute_name]!.value;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: { case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
newValue = oldValue! * changedAttribute.value; value1 = oldValue! * attribute1.value;
break; break;
} }
case TankAttributeChange_Modifier.MODIFIER_ADD: { case TankAttributeChange_Modifier.MODIFIER_ADD: {
newValue = oldValue! + changedAttribute.value; value1 = oldValue! + attribute1.value;
break; break;
} }
default: default:
throw new Error( throw new Error(
`Unhandled modified ${ `Unhandled modified ${
TankAttributeChange_Modifier[changedAttribute.modifier] TankAttributeChange_Modifier[attribute1.modifier]
}` }`
); );
} }
base.attributes[changedAttribute.attribute_name] = { const attribute0 = TankAttributeChange.create({
modifier: TankAttributeChange_Modifier.MODIFIER_OVERRIDE, modifier: TankAttributeChange_Modifier.MODIFIER_OVERRIDE,
attribute_name: changedAttribute.attribute_name, attribute_name: attribute1.attribute_name,
value: newValue, value: value1,
}; });
const index0 = stage0.attributes.findIndex(
(attribute) => attribute.attribute_name === attribute1.attribute_name
);
if (index0 === -1) {
stage0.attributes.push(attribute0);
} else {
stage0.attributes[index0] = attribute0;
}
} }
for (const changedPenetrationGroupUpgrades of change.penetration_groups_upgrades) { for (const penetrationGroupUpgrade1 of stage1.penetration_groups_upgrades) {
if (changedPenetrationGroupUpgrades.primary_armor.length > 0) { if (penetrationGroupUpgrade1.primary_armor.length > 0) {
throw new Error("Primary armor is not empty; implement this"); throw new Error("Primary armor is not empty; implement this");
} }
let basePenetrationGroupUpgrades = base.penetration_groups_upgrades.find( let penetrationGroupUpgrade0 = stage0.penetration_groups_upgrades.find(
(group) => group.tank_part === changedPenetrationGroupUpgrades.tank_part (group) => group.tank_part === penetrationGroupUpgrade1.tank_part
); );
if (!basePenetrationGroupUpgrades) { if (!penetrationGroupUpgrade0) {
basePenetrationGroupUpgrades = PenetrationGroupUpgrade.create({ penetrationGroupUpgrade0 = PenetrationGroupUpgrade.create({
tank_part: changedPenetrationGroupUpgrades.tank_part, tank_part: penetrationGroupUpgrade1.tank_part,
}); });
base.penetration_groups_upgrades.push(basePenetrationGroupUpgrades); stage0.penetration_groups_upgrades.push(penetrationGroupUpgrade0);
} }
for (const changedPenetrationGroup of changedPenetrationGroupUpgrades.penetration_groups) { for (const penetrationGroup1 of penetrationGroupUpgrade1.penetration_groups) {
const basePenetrationGroup = const penetrationGroup0 =
basePenetrationGroupUpgrades.penetration_groups.find( penetrationGroupUpgrade0.penetration_groups.find(
(baseGroup) => (baseGroup) => baseGroup.group_name === penetrationGroup1.group_name
baseGroup.group_name === changedPenetrationGroup.group_name
); );
if (basePenetrationGroup) { if (penetrationGroup0) {
if ( if (penetrationGroup0.common_data !== penetrationGroup1.common_data) {
basePenetrationGroup.common_data !==
changedPenetrationGroup.common_data
) {
throw new Error("Common data is not the same"); throw new Error("Common data is not the same");
} }
basePenetrationGroup.armor = changedPenetrationGroup.armor; penetrationGroup0.armor = penetrationGroup1.armor;
} else { } else {
basePenetrationGroupUpgrades.penetration_groups.push( penetrationGroupUpgrade0.penetration_groups.push(
PenetrationGroup.create(changedPenetrationGroup) PenetrationGroup.create(penetrationGroup1)
); );
} }
} }
} }
if (change.modules_upgrades.length > 0) { if (stage1.modules_upgrades.length > 0) {
throw new Error("Modules upgrades not implemented"); throw new Error("Modules upgrades not implemented");
} }
for (const changedShellUpgrades of change.shells_upgrades) { for (const shellUpgrades1 of stage1.shells_upgrades) {
let baseShellUpgrades = base.shells_upgrades.find( let shellUpgrades0 = stage0.shells_upgrades.find(
(baseShell) => baseShell.shell_id === changedShellUpgrades.shell_id (baseShell) => baseShell.shell_id === shellUpgrades1.shell_id
); );
if (!baseShellUpgrades) { if (!shellUpgrades0) {
baseShellUpgrades = ShellUpgrade.create({ shellUpgrades0 = ShellUpgrade.create({
shell_id: changedShellUpgrades.shell_id, shell_id: shellUpgrades1.shell_id,
}); });
} }
baseShellUpgrades.shell_type = changedShellUpgrades.shell_type; shellUpgrades0.shell_type = shellUpgrades1.shell_type;
for (const changedShellUpgrade of changedShellUpgrades.changes) { for (const changedShellUpgrade of shellUpgrades1.changes) {
const baseShellUpgrade = baseShellUpgrades.changes.find( const baseShellUpgrade = shellUpgrades0.changes.find(
(baseShellUpgrade) => (baseShellUpgrade) =>
baseShellUpgrade.attribute_name === changedShellUpgrade.attribute_name baseShellUpgrade.attribute_name === changedShellUpgrade.attribute_name
); );
@@ -130,51 +135,51 @@ function patch(change: StageParameters, base: StageParameters) {
if (baseShellUpgrade) { if (baseShellUpgrade) {
baseShellUpgrade.value = changedShellUpgrade.value; baseShellUpgrade.value = changedShellUpgrade.value;
} else { } else {
baseShellUpgrades.changes.push( shellUpgrades0.changes.push(
ShellUpgrageSingleChange.create(changedShellUpgrade) ShellUpgrageSingleChange.create(changedShellUpgrade)
); );
} }
} }
baseShellUpgrades.silver_price = shellUpgrades0.silver_price =
changedShellUpgrades.silver_price === undefined shellUpgrades1.silver_price === undefined
? undefined ? undefined
: StandardSinglePrice.create(changedShellUpgrades.silver_price); : StandardSinglePrice.create(shellUpgrades1.silver_price);
} }
if (change.pump_reload_times.length > 0) { if (stage1.pump_reload_times.length > 0) {
throw new Error("Pump reload times not implemented"); throw new Error("Pump reload times not implemented");
} }
if (change.pitch_limits_up.length > 0 && base.pitch_limits_up.length > 0) { if (stage1.pitch_limits_up.length > 0 && stage0.pitch_limits_up.length > 0) {
throw new Error("Pitch limits not implemented"); throw new Error("Pitch limits not implemented");
} }
for (const changePitchLimitUp of change.pitch_limits_up) { for (const pitchLimitUp1 of stage1.pitch_limits_up) {
base.pitch_limits_up.push(PitchLimit.create(changePitchLimitUp)); stage0.pitch_limits_up.push(PitchLimit.create(pitchLimitUp1));
} }
if ( if (
change.pitch_limits_down.length > 0 && stage1.pitch_limits_down.length > 0 &&
base.pitch_limits_down.length > 0 stage0.pitch_limits_down.length > 0
) { ) {
throw new Error("Pitch limits not implemented"); throw new Error("Pitch limits not implemented");
} }
for (const changePitchLimitDown of change.pitch_limits_down) { for (const pitchLimitDown1 of stage1.pitch_limits_down) {
base.pitch_limits_down.push(PitchLimit.create(changePitchLimitDown)); stage0.pitch_limits_down.push(PitchLimit.create(pitchLimitDown1));
} }
for (const changeVisualChange of change.visual_changes) { for (const visualChange1 of stage1.visual_changes) {
const baseVisualChange = base.visual_changes.find( const visualChange0 = stage0.visual_changes.find(
(baseVisualChange) => (baseVisualChange) =>
baseVisualChange.tank_part === changeVisualChange.tank_part baseVisualChange.tank_part === visualChange1.tank_part
); );
if (baseVisualChange) { if (visualChange0) {
baseVisualChange.name = changeVisualChange.name; visualChange0.name = visualChange1.name;
} else { } else {
base.visual_changes.push(VisualChanges.create(changeVisualChange)); stage0.visual_changes.push(VisualChanges.create(visualChange1));
} }
} }
} }
@@ -184,9 +189,9 @@ export function aggregateStages(
stages: StageParameters[], stages: StageParameters[],
stage: number stage: number
) { ) {
const attributes = StageParameters.create(); const stage0 = StageParameters.create();
patch(base, attributes); patch(stage0, base);
/** /**
* Bug in Reforged: base stats are stage 1, so is the first upgrade. Manually * Bug in Reforged: base stats are stage 1, so is the first upgrade. Manually
@@ -195,15 +200,15 @@ export function aggregateStages(
* stage number to -1. * stage number to -1.
*/ */
if (attributes.stage_number === 0 && import.meta.env.DEV) { if (stage0.stage_number === 0 && import.meta.env.DEV) {
throw new Error( throw new Error(
"Base stats are now stage 0. In-game bug fixed, please remove hack." "Base stats are now stage 0. In-game bug fixed, please remove hack."
); );
} }
attributes.stage_number = 0; stage0.stage_number = 0;
times(stage, (index) => patch(stages[index], attributes)); times(stage, (index) => patch(stage0, stages[index]));
return attributes; return stage0;
} }