Skip to content

Commit

Permalink
Merge pull request #31 from dragoni7/16-preset-character-class-items
Browse files Browse the repository at this point in the history
Fixed crash on gathering selected class armor mods. Added selection o…
  • Loading branch information
dragoni7 authored Aug 27, 2024
2 parents 5319cf9 + ea1e47d commit 060e14d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
49 changes: 28 additions & 21 deletions src/features/armor-optimization/generate-permutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ export const generatePermutations = (
armorClass: ArmorBySlot,
selectedExoticItemHash: string | null = null
): DestinyArmor[][] => {
const { helmet, arms, legs, chest } = armorClass;
const { helmet, arms, legs, chest, classItem } = armorClass;

let filteredHelmet = helmet;
let filteredArms = arms;
let filteredLegs = legs;
let filteredChest = chest;
let filteredClass = classItem;

if (selectedExoticItemHash) {
const allItems = [...helmet, ...arms, ...legs, ...chest];
const allItems = [...helmet, ...arms, ...legs, ...chest, ...classItem];
const selectedExoticItems: DestinyArmor[] = allItems.filter(
(item) => Number(item.itemHash) === Number(selectedExoticItemHash)
);
Expand Down Expand Up @@ -54,6 +55,9 @@ export const generatePermutations = (
(item) => Number(item.itemHash) === Number(selectedExoticItemHash)
);
break;
case 'class':
console.log('exotic class item selected');
break;
}
} else {
console.error('Selected exotic items not found!');
Expand All @@ -62,24 +66,27 @@ export const generatePermutations = (

const armorTypes = [filteredHelmet, filteredArms, filteredLegs, filteredChest];

const fakeClassItem: DestinyArmor = {
intellect: 2,
discipline: 2,
resilience: 2,
mobility: 2,
strength: 2,
recovery: 2,
instanceHash: 'fake_class_item',
itemHash: 'fake_class_item',
artifice: true,
masterwork: false,
exotic: false,
class: undefined,
type: 'classItem',
location: -1,
icon: 'https://www.bungie.net/common/destiny2_content/icons/faeea62cd4cfaec3683a0ad84f1fa2ac.jpg',
name: 'Class Item Bonus',
};
// find best class armor to use for permutation
// if additionally class armor filtering is implemented, do so here
let masterworkedClassArmor = undefined;
let artificeMasterworkedClassArmor = undefined;

for (const item of classItem) {
if (masterworkedClassArmor !== undefined && artificeMasterworkedClassArmor !== undefined) break;

if (item.masterwork === true) {
masterworkedClassArmor = item;

if (item.artifice === true) artificeMasterworkedClassArmor = item;
}
}

const bestClassArmor: DestinyArmor =
artificeMasterworkedClassArmor === undefined
? masterworkedClassArmor === undefined
? classItem[0]
: masterworkedClassArmor
: artificeMasterworkedClassArmor;

const heap = new MaxHeap<DestinyArmor[]>((a: DestinyArmor[], b: DestinyArmor[]) => {
const sumStats = (items: DestinyArmor[]) =>
Expand All @@ -104,7 +111,7 @@ export const generatePermutations = (
exoticCount: number
) => {
if (currentTypeIndex === armorTypes.length) {
const modifiedPermutation = [...currentPermutation, fakeClassItem];
const modifiedPermutation = [...currentPermutation, bestClassArmor];
const totalStats = modifiedPermutation.reduce(
(sum: number, item: DestinyArmor) =>
sum +
Expand Down
3 changes: 2 additions & 1 deletion src/features/armor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function getModsBySlot(slot: string): Promise<ManifestArmorMod[]> {
}

export function getSelectedModsBySlot(slot: string): (ManifestArmorMod | ManifestArmorStatMod)[] {
console.log(slot);
switch (slot) {
case 'helmet': {
return store.getState().loadoutConfig.loadout.helmetMods;
Expand All @@ -38,7 +39,7 @@ export function getSelectedModsBySlot(slot: string): (ManifestArmorMod | Manifes
case 'legs': {
return store.getState().loadoutConfig.loadout.legArmorMods;
}
case 'classItem': {
case 'class': {
return store.getState().loadoutConfig.loadout.classArmorMods;
}
default: {
Expand Down

0 comments on commit 060e14d

Please sign in to comment.