penetration_groups_upgrades

This commit is contained in:
TrèsAbhi committed 2025-12-14 21:38:18 -06:00
1 parent 67da59ef41
commit 6830df01fa
2 files changed
+46 -8

No files matched your search

@@ -1,4 +1,5 @@
import { import {
PenetrationGroupUpgrade,
StageParameters, StageParameters,
TankAttributeChange_AttributeName, TankAttributeChange_AttributeName,
TankAttributeChange_Modifier, TankAttributeChange_Modifier,
@@ -6,12 +7,11 @@ import {
import { times } from "lodash-es"; import { times } from "lodash-es";
function patch(change: StageParameters, base: StageParameters) { 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"); throw new Error("Change stage number must be 1 greater than base");
} }
for (const attribute of change.attributes) { for (const attribute of change.attributes) {
const oldValue = base.attributes[attribute.attribute_name].value;
let newValue: number; let newValue: number;
switch (attribute.modifier) { switch (attribute.modifier) {
@@ -20,7 +20,7 @@ function patch(change: StageParameters, base: StageParameters) {
break; break;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: case TankAttributeChange_Modifier.MODIFIER_MULTIPLY:
case TankAttributeChange_Modifier.MODIFIER_ADD: { case TankAttributeChange_Modifier.MODIFIER_ADD:
if (!(attribute.attribute_name in base)) { if (!(attribute.attribute_name in base)) {
throw new Error( throw new Error(
`Missing attribute ${ `Missing attribute ${
@@ -28,15 +28,16 @@ function patch(change: StageParameters, base: StageParameters) {
} to modify` } to modify`
); );
} }
}
const oldValue = base.attributes[attribute.attribute_name]!.value;
case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: { case TankAttributeChange_Modifier.MODIFIER_MULTIPLY: {
newValue = oldValue * attribute.value; newValue = oldValue! * attribute.value;
break; break;
} }
case TankAttributeChange_Modifier.MODIFIER_ADD: { case TankAttributeChange_Modifier.MODIFIER_ADD: {
newValue = oldValue + attribute.value; newValue = oldValue! + attribute.value;
break; break;
} }
@@ -54,6 +55,42 @@ function patch(change: StageParameters, base: StageParameters) {
value: newValue, 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( export function aggregateStages(
@@ -68,7 +105,8 @@ export function aggregateStages(
/** /**
* 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
* setting it to stage 0 below and if the bug's been fixed, throw an error * 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) { if (attributes.stage_number === 0 && import.meta.env.DEV) {
@@ -18,7 +18,7 @@ function Content({ id }: { id: string }) {
const stage = Tankopedia.use((state) => state.stage); const stage = Tankopedia.use((state) => state.stage);
const attributes = useMemo( const aggregatedStages = useMemo(
() => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage), () => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage),
[stage] [stage]
); );