Skip to content

Commit

Permalink
Merge pull request #29 from dragoni7/21-have-exotic-items-equip-last-…
Browse files Browse the repository at this point in the history
…when-equipping

21 have exotic items equip last when equipping
  • Loading branch information
dragoni7 authored Aug 26, 2024
2 parents af985d9 + b7d5234 commit 5319cf9
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/features/armor/components/ArmorConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import ArmorIcon from '../../../components/ArmorIcon';
import { updateLoadoutArmorMods } from '../../../store/LoadoutReducer';
import { DestinyArmor, Plug } from '../../../types/d2l-types';
import { DestinyArmor } from '../../../types/d2l-types';
import ArmorModSelector from './ArmorModSelector';
import { getSelectedModsBySlot, getModsBySlot } from '../util';
import { ManifestArmorMod, ManifestArmorStatMod } from '../../../types/manifest-types';
Expand Down
7 changes: 1 addition & 6 deletions src/features/armor/components/ArmorModSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Box } from '@mui/system';
import { Plug } from '../../../types/d2l-types';
import { ManifestArmorMod, ManifestArmorStatMod } from '../../../types/manifest-types';

interface ModSelectorProps {
Expand All @@ -13,11 +12,7 @@ const ArmorModSelector: React.FC<ModSelectorProps> = ({ selected, mods, onSelect
<Box
className="armor-mod-slot"
style={{
backgroundImage: `url(${
mods.find((mod) => {
return mod.itemHash === selected.itemHash;
})?.icon
})`,
backgroundImage: `url(${selected.icon})`,
}}
>
<div className="submenu-grid">
Expand Down
119 changes: 3 additions & 116 deletions src/features/loadouts/components/EquipLoadout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Backdrop, Box, Button, Container, Grid, Paper, Tooltip } from '@mui/material';
import { Backdrop, Box, Button, Grid, Paper, Tooltip } from '@mui/material';
import { store } from '../../../store';
import { useState } from 'react';
import { EquipResult } from '../types';
import { STATUS } from '../constants';
import { ArmorEquipper } from '../util/armorEquipper';
import { DestinyArmor, SubclassConfig } from '../../../types/d2l-types';
import React from 'react';
import { SubclassEquipper } from '../util/subclassEquipper';
import { ManifestArmorMod, ManifestArmorStatMod } from '../../../types/manifest-types';
import { DAMAGE_TYPE } from '../../../lib/bungie_api/constants';
import LoadingBorder from './LoadingBorder';
import FadeIn from './FadeIn';
import { equipLoadout } from '../util/loadoutUtils';

const EquipLoadout: React.FC = () => {
const [processing, setProcessing] = useState<any[]>([]);
Expand All @@ -34,45 +30,8 @@ const EquipLoadout: React.FC = () => {
) {
setOpen(true);
setEquipping(true);
const armorEquipper = new ArmorEquipper();
const tempEquipped: any[] = [];
const tempResults: EquipResult[][] = [];

await armorEquipper.setCharacter(loadout.characterId);

await processArmor(
tempEquipped,
armorEquipper,
tempResults,
loadout.helmet,
loadout.helmetMods
);
await processArmor(
tempEquipped,
armorEquipper,
tempResults,
loadout.gauntlets,
loadout.gauntletMods
);
await processArmor(
tempEquipped,
armorEquipper,
tempResults,
loadout.chestArmor,
loadout.chestArmorMods
);
await processArmor(
tempEquipped,
armorEquipper,
tempResults,
loadout.legArmor,
loadout.legArmorMods
);

const subclassEquipper = new SubclassEquipper();
subclassEquipper.setCharacter(loadout.characterId);

await processSubclass(tempEquipped, subclassEquipper, tempResults, loadout.subclassConfig);
await equipLoadout(loadout, setProcessing, setEquipStep, setResults);

setEquipStep('Finished');
setEquipping(false);
Expand All @@ -81,78 +40,6 @@ const EquipLoadout: React.FC = () => {
}
};

const processArmor = async (
tempEquipped: DestinyArmor[],
equipper: ArmorEquipper,
tempResults: EquipResult[][],
armor: DestinyArmor,
armorMods: { [key: number]: ManifestArmorMod | ManifestArmorStatMod }
) => {
tempEquipped.push(armor);
setProcessing(tempEquipped);
setEquipStep('Equipping ' + armor.name + ' ...');
await equipper.equipArmor(armor);
setEquipStep('Inserting Mods in ' + armor.name + '...');
await equipper.equipArmorMods(armorMods);
tempResults.push(equipper.getResult());
setResults(tempResults);
};

const processSubclass = async (
tempEquipped: any[],
equipper: SubclassEquipper,
tempResults: EquipResult[][],
subclassConfig: SubclassConfig
) => {
tempEquipped.push(subclassConfig.subclass);
setProcessing(tempEquipped);

setEquipStep('Equipping ' + subclassConfig.subclass.name + ' ...');
await equipper.equipSubclass(subclassConfig.subclass);

setEquipStep('Equipping Super ...');
await equipper.equipSubclassAbility(subclassConfig.super, 0);

if (subclassConfig.classAbility) {
setEquipStep('Equipping Class Ability...');
await equipper.equipSubclassAbility(subclassConfig.classAbility, 1);
}

if (subclassConfig.movementAbility) {
setEquipStep('Equipping Movement Ability...');
await equipper.equipSubclassAbility(subclassConfig.movementAbility, 2);
}

if (subclassConfig.meleeAbility) {
setEquipStep('Equipping Melee Ability...');
await equipper.equipSubclassAbility(subclassConfig.meleeAbility, 3);
}

if (subclassConfig.grenade) {
setEquipStep('Equipping Grenade Ability...');
await equipper.equipSubclassAbility(subclassConfig.grenade, 4);
}

setEquipStep('Equipping Aspects ...');

let aspectIndex = subclassConfig.damageType === DAMAGE_TYPE.KINETIC ? 7 : 5;

await equipper.equipSubclassAspect(subclassConfig.aspects[0], aspectIndex);
await equipper.equipSubclassAspect(subclassConfig.aspects[1], aspectIndex + 1);

setEquipStep('Equipping Fragments ...');

let fragmentIndex = subclassConfig.damageType === DAMAGE_TYPE.KINETIC ? 9 : 7;

for (let i = 0; i < subclassConfig.fragments.length; i++) {
await equipper.equipSubclassFragments(subclassConfig.fragments[i], fragmentIndex + i);
}

const result = equipper.getResult();
tempResults.push(result);
setResults(tempResults);
};

return (
<Box>
<Button variant="contained" onClick={onEquipLoadout}>
Expand Down
6 changes: 3 additions & 3 deletions src/features/loadouts/components/LoadingBorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ interface LoadingBorderProps {
const LoadingBorder: React.FC<LoadingBorderProps> = ({ armor, size }) => {
const [border, api] = useSpring(
() => ({
from: { border: '3px solid rgba(195, 195, 195, 0)' },
from: { border: '4px solid rgba(21, 165, 224, 0)' },
to: async (next) => {
await next({ border: '3px solid rgba(195, 195, 195, 1)' });
await next({ border: '3px solid rgba(195, 195, 195, 0)' });
await next({ border: '4px solid rgba(21, 165, 224, 1)' });
await next({ border: '4px solid rgba(21, 165, 224, 0)' });
},
loop: true,

Expand Down
4 changes: 4 additions & 0 deletions src/features/loadouts/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { armor } from '../types';

export enum STATUS {
SUCCESS = 1,
FAIL = 0,
}

export const ARMOR_ARRAY: armor[] = ['helmet', 'gauntlets', 'chestArmor', 'legArmor'];
6 changes: 6 additions & 0 deletions src/features/loadouts/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export type EquipResult = {
message: string;
subject: any;
};

export type armor = 'helmet' | 'gauntlets' | 'chestArmor' | 'legArmor';

export type armorMods = 'helmetMods' | 'gauntletMods' | 'chestArmorMods' | 'legArmorMods';

export type setState = (value: React.SetStateAction<any | string[]>) => void;
15 changes: 8 additions & 7 deletions src/features/loadouts/util/armorEquipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,27 @@ export class ArmorEquipper extends Equipper {
this.result.push(result);
}

public async equipArmorMods(mods: {
[key: number]: ManifestArmorMod | ManifestArmorStatMod;
}): Promise<void> {
public async equipArmorMods(
mods: [string, ManifestArmorMod | ManifestArmorStatMod][]
): Promise<void> {
const armor = this.result[0].subject;

if (!armor) return;

for (let i = 0; i < 5; i++) {
for (const [index, mod] of mods) {
const i = Number(index);
const result = {
status: STATUS.SUCCESS,
message: '',
subject: mods[i],
subject: mod,
};

if (i === 4 && armor.artifice === false) continue;

const response = await insertSocketPlugFreeRequest(
armor.instanceHash,
{
plugItemHash: String(mods[i].itemHash),
plugItemHash: String(mod.itemHash),
socketArrayType: 0,
socketIndex: i === 4 && armor.artifice === true ? 11 : i,
},
Expand All @@ -157,7 +158,7 @@ export class ArmorEquipper extends Equipper {

if (response) result.message = response.data.ErrorStatus.replace(/([a-z])([A-Z])/g, '$1 $2');

this.result.push(result);
this.result[i + 1] = result;
}
}
}
11 changes: 0 additions & 11 deletions src/features/loadouts/util/loadoutService.ts

This file was deleted.

Loading

0 comments on commit 5319cf9

Please sign in to comment.