Skip to content

Commit

Permalink
Attempt to show crafted/enhanced items' masterwork stat in Compare/It…
Browse files Browse the repository at this point in the history
…emPopup views
  • Loading branch information
FlaminSarge committed Feb 12, 2025
1 parent b094038 commit 04a2b18
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/app/item-popup/ItemSocketsWeapons.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { t } from 'app/i18next-t';
import { statsMs } from 'app/inventory/store/stats';
import { useD2Definitions } from 'app/manifest/selectors';
import {
D2PlugCategoryByStatHash,
weaponMasterworkY2SocketTypeHash,
} from 'app/search/d2-known-values';
import { useSetting } from 'app/settings/hooks';
import { AppIcon, faGrid, faList } from 'app/shell/icons';
import { isKillTrackerSocket } from 'app/utils/item-utils';
import { getSocketsByIndexes, getWeaponSockets } from 'app/utils/socket-utils';
import { LookupTable } from 'app/utils/util-types';
import clsx from 'clsx';
import { ItemCategoryHashes, StatHashes } from 'data/d2/generated-enums';
import { maxBy } from 'es-toolkit';
import { useSelector } from 'react-redux';
import { DimItem, DimSocket } from '../inventory/item-types';
import { wishListSelector } from '../wishlists/selectors';
Expand Down Expand Up @@ -39,6 +44,40 @@ export default function ItemSocketsWeapons({
return null;
}

if (item.crafted) {
const y2MasterworkSocket = item.sockets?.allSockets.find(
(socket) => socket.socketDefinition.socketTypeHash === weaponMasterworkY2SocketTypeHash,
);
const plugSet = y2MasterworkSocket?.plugSet;
if (y2MasterworkSocket && plugSet) {
// const plug = y2MasterworkSocket?.plugSet?.plugs.find(
// (p) => p.plugDef.plug.plugCategoryHash === PlugCategoryHashes.V400PlugsWeaponsMasterworks,
// );
const mwHash = item.masterworkInfo?.stats?.find((s) => s.isPrimary)?.hash || 0;
const newCategory =
mwHash in D2PlugCategoryByStatHash
? D2PlugCategoryByStatHash[mwHash as keyof typeof D2PlugCategoryByStatHash]
: null;
let fullMasterworkPlug = newCategory
? maxBy(
plugSet.plugs.filter((p) => p.plugDef.plug.plugCategoryHash === newCategory),
(plugOption) => plugOption.plugDef.investmentStats[0]?.value,
)
: null;
if (fullMasterworkPlug) {
fullMasterworkPlug = {
...fullMasterworkPlug,
plugDef: { ...fullMasterworkPlug.plugDef, iconWatermark: '', investmentStats: [] },
};
y2MasterworkSocket.plugged = fullMasterworkPlug;
y2MasterworkSocket.plugOptions = [fullMasterworkPlug];
y2MasterworkSocket.visibleInGame = true;
y2MasterworkSocket.reusablePlugItems = [];
y2MasterworkSocket.isPerk = true;
}
}
}

// Separate out perks from sockets.
const { intrinsicSocket, perks, modSocketsByCategory } = getWeaponSockets(item)!;

Expand Down
13 changes: 13 additions & 0 deletions src/app/search/d2-known-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ export const D2WeaponStatHashByName = {
accuracy: StatHashes.Accuracy,
};

export const D2PlugCategoryByStatHash = {
[StatHashes.Accuracy]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatAccuracy,
[StatHashes.BlastRadius]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatBlastRadius,
[StatHashes.ChargeTime]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatChargeTime,
[StatHashes.Impact]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatDamage,
[StatHashes.DrawTime]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatDrawTime,
[StatHashes.Handling]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatHandling,
[StatHashes.Speed]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatProjectileSpeed,
[StatHashes.Range]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatRange,
[StatHashes.ReloadSpeed]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatReload,
[StatHashes.Stability]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatStability,
};

export const swordStatsByName = {
swingspeed: StatHashes.SwingSpeed,
guardefficiency: StatHashes.GuardEfficiency,
Expand Down

0 comments on commit 04a2b18

Please sign in to comment.