Skip to content

Commit a6fa761

Browse files
committed
refactor: remove redundant upgrade handling logic and streamline optimizer cost calculations
1 parent 6a0277e commit a6fa761

File tree

7 files changed

+98
-93
lines changed

7 files changed

+98
-93
lines changed

components/account/Misc/class-specific/GenericUpgradeOptimizer.jsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const GenericUpgradeOptimizer = ({
8282
// const [MasterclassReductionCheckbox, masterClassReduction] = useCheckbox('Masterclass reduction');
8383
const [masterClassReduction, setMasterClassReduction] = useLocalStorage({
8484
key: `${resourceKey}:genericUpgradeOptimizer:masterClassReduction`,
85-
defaultValue: getLegendTalentBonus(account, 23)
85+
defaultValue: getLegendTalentBonus(account, 23) ?? 0
8686
});
8787
const [resourcePerHour, setResourcePerHour] = useLocalStorage({
8888
key: `${resourceKey}:genericUpgradeOptimizer:resourcePerHour`,
@@ -92,7 +92,6 @@ const GenericUpgradeOptimizer = ({
9292
return obj;
9393
})()
9494
});
95-
const remainingReductedUpgrades = Math.max(0, getLegendTalentBonus(account, 23) - account?.accountOptions?.[480]);
9695
// Add a separate state for the raw input string for each resource
9796
const [resourcePerHourInput, setResourcePerHourInput] = useState(() => {
9897
const obj = {};
@@ -110,17 +109,6 @@ const GenericUpgradeOptimizer = ({
110109
});
111110
const valueCommitDebouncersRef = useRef({});
112111

113-
useEffect(() => {
114-
setResourcePerHourInput(
115-
Object.fromEntries(
116-
Object.entries(resourcePerHour).map(([key, value]) => [
117-
key,
118-
value !== undefined && value !== null && value !== '' ? Number(value).toLocaleString() : ''
119-
])
120-
)
121-
);
122-
}, [resourcePerHour]);
123-
124112
useEffect(() => () => {
125113
Object.values(valueCommitDebouncersRef.current).forEach(fn => fn?.cancel?.());
126114
}, []);
@@ -132,7 +120,6 @@ const GenericUpgradeOptimizer = ({
132120
return getOptimizedUpgradesFn(character, account, category, maxToUse, {
133121
onlyAffordable,
134122
masterClassReduction: isNaN(masterClassReduction) ? 0 : masterClassReduction,
135-
forceLegendTalent: false,
136123
resourcePerHour: optimizationMethod === 'rph' ? resourcePerHour : undefined,
137124
getResourceType
138125
});
@@ -149,18 +136,14 @@ const GenericUpgradeOptimizer = ({
149136
// Group consecutive upgrades of the same type while preserving order
150137
const consolidatedUpgrades = [];
151138
let currentGroup = null;
152-
const currentLevels = {};
153139
optimizedUpgrades.forEach((upgrade, index) => {
154140
const upgradeName = upgrade.name;
155-
// Determine the start level for this group
156141
const startLevel = currentGroup && currentGroup.name === upgradeName
157142
? currentGroup.startLevel
158-
: (currentLevels[upgradeName] ?? upgrade.level);
143+
: upgrade.level;
159144
if (!currentGroup || currentGroup.name !== upgradeName) {
160145
if (currentGroup) {
161-
// After finishing a group, update the current level and push
162146
currentGroup.finalLevel = currentGroup.startLevel + currentGroup.sequence.length - 1;
163-
currentLevels[currentGroup.name] = currentGroup.finalLevel;
164147
consolidatedUpgrades.push(currentGroup);
165148
}
166149
// Start new group
@@ -178,7 +161,6 @@ const GenericUpgradeOptimizer = ({
178161
// Push the last group
179162
if (currentGroup) {
180163
currentGroup.finalLevel = currentGroup.startLevel + currentGroup.sequence.length - 1;
181-
currentLevels[currentGroup.name] = currentGroup.finalLevel;
182164
consolidatedUpgrades.push(currentGroup);
183165
}
184166
// Calculate combined stats for each group
@@ -497,12 +479,6 @@ const GenericUpgradeOptimizer = ({
497479
<Tooltip title={tooltipText}> <IconInfoCircleFilled size={16} /> </Tooltip>
498480
<Stack>
499481
<AffordableCheckboxEl />
500-
{/*<Stack direction={'row'} alignItems={'center'}>*/}
501-
{/* /!*<MasterclassReductionCheckbox/>*!/*/}
502-
{/* <Tooltip*/}
503-
{/* title={`${remainingReductedUpgrades} reduced-cost upgrades remaining (legend talent)`}><IconInfoCircleFilled*/}
504-
{/* size={16}/></Tooltip>*/}
505-
{/*</Stack>*/}
506482
</Stack>
507483
<Divider sx={{ my: 1 }} flexItem orientation={'vertical'} />
508484
{resourceUsage.map((resource) => {
@@ -589,7 +565,7 @@ const GenericUpgradeOptimizer = ({
589565
</Dialog>
590566
)}
591567

592-
<Typography variant="h6">Recommended Upgrade Sequence</Typography>
568+
<Typography variant="h6" data-testid="optimizer-heading">Recommended Upgrade Sequence</Typography>
593569
{displayUpgrades.length > 0 ? (
594570
viewMode === 'grid' ? (
595571
<Stack direction="row" gap={2} flexWrap="wrap">

components/account/Worlds/World7/spelunking/UpgradeOptimizer.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,14 @@ const UpgradeOptimizer = ({ character, account }) => {
182182
// Group consecutive upgrades of the same type while preserving order
183183
const consolidatedUpgrades = [];
184184
let currentGroup = null;
185-
const currentLevels = {};
186185
optimizedUpgrades.forEach((upgrade, index) => {
187186
const upgradeName = upgrade.name;
188-
// Determine the start level for this group
189187
const startLevel = currentGroup && currentGroup.name === upgradeName
190188
? currentGroup.startLevel
191-
: (currentLevels[upgradeName] ?? upgrade.level);
189+
: upgrade.level;
192190
if (!currentGroup || currentGroup.name !== upgradeName) {
193191
if (currentGroup) {
194-
// After finishing a group, update the current level and push
195192
currentGroup.finalLevel = currentGroup.startLevel + currentGroup.sequence.length - 1;
196-
currentLevels[currentGroup.name] = currentGroup.finalLevel;
197193
consolidatedUpgrades.push(currentGroup);
198194
}
199195
// Start new group
@@ -211,7 +207,6 @@ const UpgradeOptimizer = ({ character, account }) => {
211207
// Push the last group
212208
if (currentGroup) {
213209
currentGroup.finalLevel = currentGroup.startLevel + currentGroup.sequence.length - 1;
214-
currentLevels[currentGroup.name] = currentGroup.finalLevel;
215210
consolidatedUpgrades.push(currentGroup);
216211
}
217212
// Calculate combined stats for each group

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parsers/compass.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const parseCompass = (compassRaw, charactersData, accountData, serverVars) => {
104104
}
105105
}, {});
106106

107-
const maps = getFilteredPortals()?.map(({ mapIndex, mapName }, index) => {
107+
const maps = getFilteredPortals()?.map(({ mapIndex, mapName }) => {
108108
const availablePortals = mapPortals?.[mapIndex];
109109
const portals = availablePortals.map((_, portalIndex) => {
110110
const costQuantity = getPortalCostQuantity(mapIndex, portalIndex);
@@ -663,10 +663,6 @@ export const getOptimizedUpgrades = (character, account, category = 'damage', ma
663663
upgrades,
664664
forceLegendTalent
665665
}) => getUpgradeCost(upgrades, index, account?.serverVars, account, forceLegendTalent),
666-
applyUpgrade: (upgrade, upgradesArr) => upgradesArr.map(u => u.index === upgrade.index ? {
667-
...u,
668-
level: u.level + 1
669-
} : u),
670666
updateResourcesAfterUpgrade: (resources, upgrade, resourceNames, cost) => {
671667
const dustType = dustNames[upgrade.x3];
672668
const resource = resources.find(r => r.name === dustType);

0 commit comments

Comments
 (0)