Skip to content

Commit 3cc77d1

Browse files
committed
Attempt to show crafted/enhanced items' masterwork stat in Compare/ItemPopup views
1 parent 88e990e commit 3cc77d1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/app/item-popup/ItemSocketsWeapons.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { t } from 'app/i18next-t';
22
import { statsMs } from 'app/inventory/store/stats';
33
import { useD2Definitions } from 'app/manifest/selectors';
4+
import {
5+
D2PlugCategoryByStatHash,
6+
weaponMasterworkY2SocketTypeHash,
7+
} from 'app/search/d2-known-values';
48
import { useSetting } from 'app/settings/hooks';
59
import { AppIcon, faGrid, faList } from 'app/shell/icons';
610
import { isKillTrackerSocket } from 'app/utils/item-utils';
711
import { getSocketsByIndexes, getWeaponSockets } from 'app/utils/socket-utils';
812
import { LookupTable } from 'app/utils/util-types';
913
import clsx from 'clsx';
1014
import { ItemCategoryHashes, StatHashes } from 'data/d2/generated-enums';
15+
import { maxBy } from 'es-toolkit';
1116
import { useSelector } from 'react-redux';
1217
import { DimItem, DimSocket } from '../inventory/item-types';
1318
import { wishListSelector } from '../wishlists/selectors';
@@ -45,6 +50,40 @@ export default function ItemSocketsWeapons({
4550
// Improve this when we use iterator-helpers
4651
const mods = [...modSocketsByCategory.values()].flat();
4752

53+
if (item.crafted) {
54+
const y2MasterworkSocket = item.sockets?.allSockets.find(
55+
(socket) => socket.socketDefinition.socketTypeHash === weaponMasterworkY2SocketTypeHash,
56+
);
57+
const plugSet = y2MasterworkSocket?.plugSet;
58+
if (y2MasterworkSocket && plugSet) {
59+
// const plug = y2MasterworkSocket?.plugSet?.plugs.find(
60+
// (p) => p.plugDef.plug.plugCategoryHash === PlugCategoryHashes.V400PlugsWeaponsMasterworks,
61+
// );
62+
const mwHash = item.masterworkInfo?.stats?.find((s) => s.isPrimary)?.hash || 0;
63+
const newCategory =
64+
mwHash in D2PlugCategoryByStatHash
65+
? D2PlugCategoryByStatHash[mwHash as keyof typeof D2PlugCategoryByStatHash]
66+
: null;
67+
let fullMasterworkPlug = newCategory
68+
? maxBy(
69+
plugSet.plugs.filter((p) => p.plugDef.plug.plugCategoryHash === newCategory),
70+
(plugOption) => plugOption.plugDef.investmentStats[0]?.value,
71+
)
72+
: null;
73+
if (fullMasterworkPlug) {
74+
fullMasterworkPlug = {
75+
...fullMasterworkPlug,
76+
plugDef: { ...fullMasterworkPlug.plugDef, iconWatermark: '' },
77+
};
78+
y2MasterworkSocket.plugged = fullMasterworkPlug;
79+
y2MasterworkSocket.plugOptions = [fullMasterworkPlug];
80+
y2MasterworkSocket.visibleInGame = true;
81+
y2MasterworkSocket.reusablePlugItems = [];
82+
y2MasterworkSocket.isPerk = true;
83+
}
84+
}
85+
}
86+
4887
const keyStats =
4988
item.stats &&
5089
!item.itemCategoryHashes.includes(ItemCategoryHashes.Sword) &&

src/app/search/d2-known-values.ts

+13
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ export const D2WeaponStatHashByName = {
139139
accuracy: StatHashes.Accuracy,
140140
};
141141

142+
export const D2PlugCategoryByStatHash = {
143+
[StatHashes.Accuracy]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatAccuracy,
144+
[StatHashes.BlastRadius]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatBlastRadius,
145+
[StatHashes.ChargeTime]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatChargeTime,
146+
[StatHashes.Impact]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatDamage,
147+
[StatHashes.DrawTime]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatDrawTime,
148+
[StatHashes.Handling]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatHandling,
149+
[StatHashes.Speed]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatProjectileSpeed,
150+
[StatHashes.Range]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatRange,
151+
[StatHashes.ReloadSpeed]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatReload,
152+
[StatHashes.Stability]: PlugCategoryHashes.V400PlugsWeaponsMasterworksStatStability,
153+
};
154+
142155
export const swordStatsByName = {
143156
swingspeed: StatHashes.SwingSpeed,
144157
guardefficiency: StatHashes.GuardEfficiency,

0 commit comments

Comments
 (0)