-
-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10706 from DestinyItemManager/perksdupe
RFC: is:perksdupe
- Loading branch information
Showing
7 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DimItem } from 'app/inventory/item-types'; | ||
|
||
/** | ||
* A Perks can be populated with a bunch of items, and can then answer questions | ||
* such as: | ||
* 1. Are there any items that have (at least) all the same perks (in the same | ||
* columns) as the input item? This covers both exactly-identical perk sets, | ||
* as well as items that are perk-subsets of the input item (e.g. there may | ||
* be another item that has all the same perks, plus some extra options in | ||
* some columns). | ||
*/ | ||
export class PerksSet { | ||
// A map from item ID to a list of columns, each of which has a set of perkHashes | ||
mapping = new Map<string, Set<number>[]>(); | ||
|
||
insert(item: DimItem) { | ||
this.mapping.set(item.id, makePerksSet(item)); | ||
} | ||
|
||
hasPerkDupes(item: DimItem) { | ||
const perksSet = makePerksSet(item); | ||
|
||
for (const [id, set] of this.mapping) { | ||
if (id === item.id) { | ||
continue; | ||
} | ||
|
||
if (perksSet.every((column) => set.some((otherColumn) => column.isSubsetOf(otherColumn)))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
function makePerksSet(item: DimItem) { | ||
return item | ||
.sockets!.allSockets.filter((s) => s.isPerk && s.socketDefinition.defaultVisible) | ||
.map((s) => new Set(s.plugOptions.map((p) => p.plugDef.hash))); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters