Skip to content

Commit

Permalink
Merge pull request #103 from dragoni7/fix-auto-equip-required-mods
Browse files Browse the repository at this point in the history
Fix auto equip required mods
  • Loading branch information
dragoni7 authored Sep 19, 2024
2 parents 528208b + a9754ec commit d4e2ec2
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 145 deletions.
17 changes: 8 additions & 9 deletions src/app/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export const Dashboard: React.FC = () => {
return fragments.reduce(
(acc, fragment) => {
if (fragment.itemHash !== 0) {
acc.mobility += fragment.mobilityMod || 0;
acc.resilience += fragment.resilienceMod || 0;
acc.recovery += fragment.recoveryMod || 0;
acc.discipline += fragment.disciplineMod || 0;
acc.intellect += fragment.intellectMod || 0;
acc.strength += fragment.strengthMod || 0;
acc.mobility += fragment.mobilityMod;
acc.resilience += fragment.resilienceMod;
acc.recovery += fragment.recoveryMod;
acc.discipline += fragment.disciplineMod;
acc.intellect += fragment.intellectMod;
acc.strength += fragment.strengthMod;
}
return acc;
},
Expand Down Expand Up @@ -324,15 +324,14 @@ export const Dashboard: React.FC = () => {
statPriority: sharedLoadoutDto.statPriority as StatName[],
characterClass: sharedLoadoutDto.characterClass as CharacterClass,
};
setGeneratingPermutations(true);

const sharedLoadoutPermutation = filterFromSharedLoadout(
decodedLoadoutData,
permutations,
fragmentStatModifications
);
filtered = sharedLoadoutPermutation === null ? null : [sharedLoadoutPermutation];
} else if (permutations && selectedValues) {
setGeneratingPermutations(true);
filtered = filterPermutations(permutations, selectedValues, fragmentStatModifications);
}

Expand Down Expand Up @@ -360,7 +359,7 @@ export const Dashboard: React.FC = () => {
(mod) => mod[(stat + 'Mod') as StatModifiers] === cost
);
if (matchedStatMod !== undefined)
requiredMods.push({ mod: matchedStatMod, equipped: false });
requiredMods.push({ mod: Object.create(matchedStatMod), equipped: false });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadoutCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AbilitiesModification from '../features/subclass/components/AbilitiesModi
import ShareLoadout from '../features/loadouts/components/ShareLoadout';
import { SubclassConfig } from '../types/d2l-types';
import { BackButton } from './BackButton';
import TotalStatsDisplay from '../features/subclass/components/TotalStatsDisplay';
import TotalStatsDisplay from './TotalStatsDisplay';

interface LoadoutCustomizationProps {
onBackClick: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { styled } from '@mui/material/styles';
import { Box, Typography, Grid } from '@mui/material';
import { STATS } from '../../../lib/bungie_api/constants';
import { RootState } from '../../../store';
import { StatName, DestinyArmor } from '../../../types/d2l-types';
import { ManifestArmorStatMod, ManifestStatPlug } from '../../../types/manifest-types';
import { ARMOR_ARRAY, STATS } from '../lib/bungie_api/constants';
import { RootState } from '../store';
import { StatName, DestinyArmor, armorMods } from '../types/d2l-types';
import { ManifestArmorMod, ManifestArmorStatMod, ManifestStatPlug } from '../types/manifest-types';
import { statIcons } from '../util/constants';

const StatsContainer = styled(Box)(({ theme }) => ({
display: 'flex',
Expand Down Expand Up @@ -35,15 +36,6 @@ const StatValue = styled(Typography)({
fontWeight: 'bold',
});

const statIcons: Record<StatName, string> = {
mobility: 'assets/mob.png',
resilience: 'assets/res.png',
recovery: 'assets/rec.png',
discipline: 'assets/disc.png',
intellect: 'assets/int.png',
strength: 'assets/str.png',
};

function isStatsMod(mod: unknown): mod is ManifestArmorStatMod {
return (
typeof mod === 'object' &&
Expand All @@ -70,38 +62,23 @@ const TotalStatsDisplay: React.FC = () => {
strength: 0,
};

// Sum up armor stats
const armorPieces: DestinyArmor[] = [
loadout.helmet,
loadout.gauntlets,
loadout.chestArmor,
loadout.legArmor,
loadout.classArmor,
];
armorPieces.forEach((armor) => {
// add stats from armor + mods
ARMOR_ARRAY.forEach((armor) => {
(STATS as StatName[]).forEach((stat) => {
stats[stat] += Number(armor[stat]) || 0;
stats[stat] +=
loadout[armor][stat] +
(Number(
loadout[(armor + 'Mods') as armorMods][0][`${stat}Mod` as keyof ManifestStatPlug]
) |
0) +
(loadout[armor].artifice
? Number(
loadout[(armor + 'Mods') as armorMods][4][`${stat}Mod` as keyof ManifestStatPlug]
) | 0
: 0);
});
});

// Add stats from armor mods in slot 0
const armorMods = [
loadout.helmetMods[0],
loadout.gauntletsMods[0],
loadout.chestArmorMods[0],
loadout.legArmorMods[0],
loadout.classArmorMods[0],
];

armorMods.forEach((mod) => {
if (isStatsMod(mod)) {
(STATS as StatName[]).forEach((stat) => {
const modStat = `${stat}Mod` as keyof ManifestStatPlug;
stats[stat] += Number(mod[modStat]) || 0;
});
}
});

// Add stats from fragments
loadout.subclassConfig.fragments.forEach((fragment) => {
(STATS as StatName[]).forEach((stat) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ const PermutationsList: React.FC<PermutationsListProps> = ({

useEffect(() => {
if (large) {
setItemsPerPage(5);
} else {
setItemsPerPage(4);
} else {
setItemsPerPage(3);
}
}, [large]);

Expand Down
Loading

0 comments on commit d4e2ec2

Please sign in to comment.