Skip to content

Commit

Permalink
plugged enhanced perks are rollable if their unenhanced is rollable
Browse files Browse the repository at this point in the history
  • Loading branch information
nev-r committed Jun 15, 2024
1 parent 9ef2707 commit a37fffe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app/inventory/item-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export interface DimPlugSet {

/** A precomputed list of plug hashes that can not roll on current versions of the item. */
readonly plugHashesThatCannotRoll: number[];
readonly plugHashesThatCanRoll: number[];
}

export interface DimSocket {
Expand Down
16 changes: 11 additions & 5 deletions src/app/inventory/store/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
PlugCategoryHashes,
SocketCategoryHashes,
} from 'data/d2/generated-enums';
import perkToEnhanced from 'data/d2/trait-to-enhanced-trait.json';
import _ from 'lodash';
import {
DimItem,
DimPlug,
Expand All @@ -51,6 +53,8 @@ import {
// This is called from within d2-item-factory.service.ts
//

const enhancedToPerk = _.mapValues(_.invert(perkToEnhanced), (s) => Number(s));

/**
* Calculate all the sockets we want to display (or make searchable). Sockets represent perks,
* mods, and intrinsic properties of the item. They're really the swiss army knife of item
Expand Down Expand Up @@ -491,13 +495,16 @@ function buildPlug(
: '';

const enabled = destinyItemPlug ? plug.enabled : plug.isEnabled;
const unenhancedVersion = enhancedToPerk[plugDef.hash];
return {
plugDef,
enabled: enabled && (!destinyItemPlug || plug.canInsert),
enableFailReasons: failReasons,
plugObjectives: plugObjectivesData?.[plugHash] || emptyArray(),
stats: null,
cannotCurrentlyRoll: plugSet?.plugHashesThatCannotRoll.includes(plugDef.hash),
cannotCurrentlyRoll:
plugSet?.plugHashesThatCannotRoll.includes(plugDef.hash) &&
!plugSet?.plugHashesThatCanRoll.includes(unenhancedVersion),
};
}

Expand Down Expand Up @@ -785,16 +792,15 @@ function buildCachedDimPlugSet(defs: D2ManifestDefinitions, plugSetHash: number)
}
}
}

const [cant, can] = _.partition(plugs, (p) => plugCannotCurrentlyRoll(plugs, p.plugDef.hash));
const dimPlugSet: DimPlugSet = {
plugs,
hash: plugSetHash,
precomputedEmptyPlugItemHash: defPlugSet.reusablePlugItems.find((p) =>
isKnownEmptyPlugItemHash(p.plugItemHash),
)?.plugItemHash,
plugHashesThatCannotRoll: plugs
.filter((p) => plugCannotCurrentlyRoll(plugs, p.plugDef.hash))
.map((p) => p.plugDef.hash),
plugHashesThatCannotRoll: cant.map((p) => p.plugDef.hash),
plugHashesThatCanRoll: can.map((p) => p.plugDef.hash),
};
reusablePlugSetCache[plugSetHash] = dimPlugSet;

Expand Down

0 comments on commit a37fffe

Please sign in to comment.