-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjunkPerkFilter.js
More file actions
444 lines (411 loc) · 18.1 KB
/
junkPerkFilter.js
File metadata and controls
444 lines (411 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
const _ = require('lodash');
const junkPerkPresets = require('./config.js');
/*
Terminology:
4pa - 4-perk-armor: armor with 2 perks in the first column, 2 perks in the second column
5pa - 5-perk-armor: armor with 3 perks in the first column, 2 perks in the second column
combo: perk pair from first and second column traits
ets: equal to specific, equivalent gain or improvement
*/
let _junkPerkMaps = null;
function initJunkPerks(stores) {
if (_junkPerkMaps === null && stores.length > 0) {
dupeReport = [];
// console.log("initJunkPerks-0", stores.length);
_junkPerkMaps = {
legendaryArmor: _.reduce(
stores,
(memo, store) => {
// console.log("initJunkPerks-1", store.items.length);
_.each(store.items, (item) => {
if (
item.bucket.sort == 'Armor' &&
item.tier === 'Legendary' &&
(junkPerkPresets.skipTags.indexOf(item.dimInfo.tag) == -1 ||
junkPerkPresets.skipTags.length == 0)
) {
memo.push(item);
}
});
return memo;
},
[]
),
/* Reason: Unwanted Perk Pair */
unwantedPerkPairs: _.map(junkPerkPresets.unwantedPerkPairs, function(combo) {
return combo.join(',');
}),
wantedPerkPairs: _.map(junkPerkPresets.wantedPerkPairs, function(combo) {
return combo.join(',');
}),
genericEtsPerkNames: _.keys(junkPerkPresets.genericEtsPerks),
statsByClassName: {}
};
/* transform the first and second column to perk-pairs */
_.each(_junkPerkMaps.legendaryArmor, (item) => {
/* Reason: Unique Armor Piece */
const type = item.type;
const name = item.name;
const classType = item.classTypeName;
//precompute all the stats per class name
if (!_.has(_junkPerkMaps.statsByClassName, classType)) {
_junkPerkMaps.statsByClassName[classType] = {
armorCombos: {},
armorPerks: {},
impossiblePerkPairs: {},
perkPairCount: {},
armorPerkCount: {},
itemTypeNameCounts: {},
unwantedPairBcEnhanced: {},
unwantedBcGenericEtsPairs: {}
};
}
const junkPmByClass = _junkPerkMaps.statsByClassName[classType];
if (!_.has(junkPmByClass.itemTypeNameCounts, type)) {
junkPmByClass.itemTypeNameCounts[type] = {};
}
if (!_.has(junkPmByClass.itemTypeNameCounts[type], name)) {
junkPmByClass.itemTypeNameCounts[type][name] = 0;
}
junkPmByClass.itemTypeNameCounts[type][name]++;
/* Transform Native Perks format to simplified format */
const armorPerks = item.sockets.sockets
.filter((socket) => {
return socket.hasRandomizedPlugItems;
})
.map((socket) => {
return socket.plugOptions.map((options) => {
return options.plugItem.displayProperties.name;
});
});
let armorCombos = [];
let flatPerks = [];
if (armorPerks.length) {
armorPerks[0].forEach((firstColumn) => {
flatPerks.push(firstColumn);
armorPerks[1].forEach((secondColumn) => {
armorCombos.push([firstColumn, secondColumn]);
});
});
armorPerks[1].forEach((secondColumn) => {
flatPerks.push(secondColumn);
});
}
/* Armor Perks reason: Unique Perks */
junkPmByClass.armorPerks[item.id] = flatPerks;
/* Armor Combos reason: figuring everything out */
junkPmByClass.armorCombos[item.id] = armorCombos;
});
/* loop over combos to precompute statistics for the filter per class */
_.each(_.keys(_junkPerkMaps.statsByClassName), (classTypeName) => {
const junkPmByClass = _junkPerkMaps.statsByClassName[classTypeName];
_.each(junkPmByClass.armorCombos, (combos, itemId) => {
const isFourPa = combos.length == 4;
const itemInfo = _.find(_junkPerkMaps.legendaryArmor, { id: itemId });
const perks = junkPmByClass.armorPerks[itemId];
const armorType = itemInfo.bucket.type;
// const applicableGenericEtsNames = junkPerkPresets.genericTypeEquivalents
/* Reason: Unique Perk */
_.each(perks, (perkName) => {
if (!_.has(junkPmByClass.armorPerkCount, perkName)) {
junkPmByClass.armorPerkCount[perkName] = 0;
}
junkPmByClass.armorPerkCount[perkName]++;
});
_.each(combos, (combo) => {
const fcPerkTag = combo[0].split(' ')[0];
const scWeapon = combo[1].split(' ')[0];
const comboString = combo.join(',');
let fcPerkName = combo[0];
//console.log("armorType", armorType);
//manipulate the string in this way so I can check for the beginning of the string and avoid catch {{Other}} Rifle parks
if (armorType == 'Chest Armor') {
fcPerkName = fcPerkName.replace('Unflinching ', '');
}
_.each(_junkPerkMaps.genericEtsPerkNames, function(genericEtsPerkName) {
//this check ensures it's only in the beginning (first character) of the perk name
if (fcPerkName.indexOf(genericEtsPerkName) == 0) {
// console.log("fcPerkName", genericEtsPerkName, combo );
var affectedWeapons = junkPerkPresets.genericEtsPerks[genericEtsPerkName];
_.each(affectedWeapons, function(weaponName) {
//return an array of perks that aren't needed bc the equivalent is found
var fcPerkNameEquiv = combo[0].replace(genericEtsPerkName, weaponName);
if (armorType == 'Chest Armor' && genericEtsPerkName == 'Large Arms') {
fcPerkNameEquiv = fcPerkNameEquiv + ' Aim';
}
var equivalentCombo = [fcPerkNameEquiv, combo[1]].join(',');
if (!_.has(junkPmByClass.unwantedBcGenericEtsPairs, equivalentCombo)) {
junkPmByClass.unwantedBcGenericEtsPairs[equivalentCombo] = {
fivePa: 0,
fourPa: 0,
fourPaIDs: [],
fivePaIDs: [],
combo: combo
};
}
var ids =
junkPmByClass.unwantedBcGenericEtsPairs[equivalentCombo][
isFourPa ? 'fourPaIDs' : 'fivePaIDs'
];
if (ids.indexOf(itemId) == -1) {
junkPmByClass.unwantedBcGenericEtsPairs[equivalentCombo][
isFourPa ? 'fourPa' : 'fivePa'
]++;
ids.push(itemId);
}
});
//console.log("combo", combo);
//unwantedBcGenericFastPairs[keyName] = keyName;
}
});
// console.log("junkPmByClass.unwantedBcGenericEtsPairs", junkPmByClass.unwantedBcGenericEtsPairs);
/* Reason: Impossible Perk Pairs */
if (
junkPerkPresets.uniqueWeaponSlots.indexOf(fcPerkTag) > -1 &&
junkPerkPresets.uniqueWeaponSlots.indexOf(scWeapon) > -1 &&
junkPerkPresets.uniqueWeaponSlots.indexOf(fcPerkTag) !=
junkPerkPresets.uniqueWeaponSlots.indexOf(scWeapon)
) {
junkPmByClass.impossiblePerkPairs[comboString] = comboString;
}
/* Reason Duplicate Perk Pair */
if (!_.has(junkPmByClass.perkPairCount, comboString)) {
junkPmByClass.perkPairCount[comboString] = {
fivePa: 0,
fourPa: 0,
fivePaIDs: [],
fourPaIDs: []
};
}
var ids = junkPmByClass.perkPairCount[comboString][isFourPa ? 'fourPaIDs' : 'fivePaIDs'];
if (ids.indexOf(itemId) == -1) {
junkPmByClass.perkPairCount[comboString][isFourPa ? 'fourPa' : 'fivePa']++;
ids.push(itemId);
}
/* Reason: Enhanced Pair
If you have Enhanced {{Perk1}} and {{Perk2}} then you don't need anything with {{Perk1}} {{Perk2}} pair ever
example: Enhanced HC Loader + Special Ammo Finder replaces all HC Loader + Special Ammo Finder combos
Enhanced Perks only affect the first column of the pair
*/
var isEnhancedCombo = combo[0].indexOf('Enhanced') > -1;
if (isEnhancedCombo) {
var normalCombo = _.clone(combo);
normalCombo[0] = normalCombo[0].replace('Enhanced ', '');
var keyName = normalCombo.join(',');
junkPmByClass.unwantedPairBcEnhanced[keyName] = keyName;
}
});
});
junkPmByClass.impossiblePerkPairs = _.map(junkPmByClass.impossiblePerkPairs);
//_junkPerkMaps.statsByClassName[classTypeName] = junkPmByClass;
const pmStats = _.zipObject(
_.keys(junkPmByClass),
_.map(_.keys(junkPmByClass), (keyName) => {
return _.keys(junkPmByClass[keyName]).length;
})
);
console.log('junkPmByClass', classTypeName, pmStats);
});
//console.log("armor items", _junkPerkMaps.itemTypeNameCounts);
const perkMapStats = _.zipObject(
_.keys(_junkPerkMaps),
_.map(_.keys(_junkPerkMaps), (keyName) => {
return _.keys(_junkPerkMaps[keyName]).length;
})
);
console.log('_junkPerkMaps', perkMapStats);
}
return _junkPerkMaps;
}
//return false for opacity 0, return true for opacity 1, opacity 1 means dismantle
function junkPerkFilter(item, dupeReport) {
//console.log("dupeReport", dupeReport.length);
if (item.bucket.sort == 'Armor' && item.tier === 'Legendary') {
//if the item is marked with the tags set to make it skip analyze
if (junkPerkPresets.ignoreTags.indexOf(item.dimInfo.tag) > -1) {
return false;
}
initJunkPerks();
const junkPmByClass = _junkPerkMaps.statsByClassName[item.classTypeName];
const armorCombos = junkPmByClass.armorCombos[item.id];
const hasArmorCombos = !armorCombos || (armorCombos && armorCombos.length === 0);
// look up the count of instance of that item by type/name
const itemTypeNameCount = junkPmByClass.itemTypeNameCounts[item.type][item.name];
// if the item is unique regardless of whether it has combos the preset determines it has to be kept
const isUniqueAlwaysKeep = itemTypeNameCount === 1 && junkPerkPresets.keepUniqueAlways;
// the item is unique but keepUniqueALways set to false so it needs to have combos (perk pairs) to be kept
const isUniqueNeedsComboToKeep =
itemTypeNameCount === 1 && !junkPerkPresets.keepUniqueAlways && !hasArmorCombos;
/*if (item.id == "6917529087059658459") {
console.log("isUniqueAlwaysKeep", isUniqueAlwaysKeep, "isUniqueNeedsComboToKeep", isUniqueNeedsComboToKeep);
}*/
if (isUniqueAlwaysKeep || isUniqueNeedsComboToKeep) {
//console.log("Skipping Unique Item", item.name, 'light:=' + item.Power, item.id, "No Armor Combos Available");
return false;
}
// Only Y1 Armor has no perks to make this array zero so mark it for dismantle
if (hasArmorCombos) {
dupeReport.push({
classText: item.classTypeName,
type: item.bucket.type,
name: item.name,
power: item.basePower,
id: item.id,
reason: 'Reason: No Armor Combos Available',
reasons: []
});
//console.log();
return true;
}
//filter combos to the combos that are wanted
const comboReasons = [];
var isFourPa = armorCombos.length == 4;
const wantedCombos = _.filter(armorCombos, (combo) => {
/* item checks
1. individual perks count - quick lookup - reason: Having a unique wanted perk is alright even if it's with a bad pair rather than losing it
2. preset unwanted perks - quick lookup - reason: Unwanted perk makes the entire pair unwanted
3. preset unwanted pairs - quick lookup - reason: Unwanted Pair are preconfigured by the user
4. preset impossible heavy pairs - quick lookup - reason: Impossible Pair are first column heady second column mismatched heavy
5. perk-pairs count - quick lookup - reason: Other 5PA with the same pair available
5. enhanced-pairs - quick lookup - reason: Other armor with the enhanced version of the perk pair is available
6. multi-tier perks - heavy lookup - reason:
- if you have Light Arms Loader then you don't need HC Loader bc it's just as good
*/
/* Unique Perk */
const fcPerkName = combo[0];
const scPerkName = combo[1];
const fcPerkCount = junkPmByClass.armorPerkCount[fcPerkName];
const scPerkCount = junkPmByClass.armorPerkCount[scPerkName];
/*if (item.id == "6917529086013942993") {
console.log("fcPerkCount", fcPerkCount, fcPerkName, "scPerkCount", scPerkCount, scPerkName);
}*/
if (fcPerkCount == 1 || scPerkCount == 1) {
comboReasons.push('Unique Perk');
return true;
}
/* Explicitly Wanted Pair desipte unwanted Perk */
const comboString = combo.join(',');
const wantedPair = _.indexOf(_junkPerkMaps.wantedPerkPairs, comboString) > -1;
if (wantedPair) {
//TODO fix this logic so it doesn't repeat further down
const perkPairCount = junkPmByClass.perkPairCount[comboString];
if (isFourPa && (perkPairCount.fourPa >= 2 || perkPairCount.fivePa >= 1)) {
comboReasons.push(
'Duplicate Exp. Pair (' + perkPairCount.fourPa + '/' + perkPairCount.fivePa + ')'
);
return false;
}
//if the item is a 5pa then it can only be replaced by another 5pa armor piece
if (!isFourPa && perkPairCount.fivePa >= 2) {
comboReasons.push(
'Dupe Exp. Pair In Other 5PA (' +
perkPairCount.fourPa +
'/' +
perkPairCount.fivePa +
')'
);
return false;
}
//if the particular pair is wanted and it's not an existing dupe in other armor then return true to keep this unique perk pair
comboReasons.push('Explicit Wanted Perk Pair');
return true;
}
/* Unwanted Perk */
const unwantedPerk = _.intersection(junkPerkPresets.unwantedPerks, combo).length > 0;
if (unwantedPerk) {
comboReasons.push('Unwanted Perk');
return false;
}
/* Unwanted Pair */
const unwantedPair = _.indexOf(_junkPerkMaps.unwantedPerkPairs, comboString) > -1;
if (unwantedPair) {
comboReasons.push('Unwanted Perk Pair');
return false;
}
/* Impossible Pair */
const impossiblePair = _.indexOf(junkPmByClass.impossiblePerkPairs, comboString) > -1;
if (impossiblePair) {
comboReasons.push('Impossible Pair');
return false;
}
/* Enhanced Pair - Enhanced version of the perk pair available */
const hasEnhancedPair = _.has(junkPmByClass.unwantedPairBcEnhanced, comboString);
if (hasEnhancedPair) {
comboReasons.push('Enhanced Pair Available');
return false;
}
/* Generic ETS Available */
//TODO: Check if 5PA item to ensure ETS is available in other 5PA only
const hasGenericReplacement = _.has(junkPmByClass.unwantedBcGenericEtsPairs, comboString);
if (hasGenericReplacement) {
const replacementGenericEtsInfo = junkPmByClass.unwantedBcGenericEtsPairs[comboString];
const rplcInfoComboCount =
' - ' +
replacementGenericEtsInfo.combo +
'(' +
replacementGenericEtsInfo.fourPa +
'/' +
replacementGenericEtsInfo.fivePa +
')';
if (isFourPa) {
comboReasons.push('Generic ETS' + rplcInfoComboCount);
return false;
} else if (!isFourPa && replacementGenericEtsInfo.fivePa >= 2) {
comboReasons.push('Generic ETS w 5PA ' + rplcInfoComboCount);
return false;
}
}
/* Duplicate Perk */
const perkPairCount = junkPmByClass.perkPairCount[comboString];
// if the item has a replacement 4pa piece it needs another 4pa or 5pa replacement to be considered a dupe
if (isFourPa && (perkPairCount.fourPa >= 2 || perkPairCount.fivePa >= 1)) {
comboReasons.push(
'Duplicate Pair (' + perkPairCount.fourPa + '/' + perkPairCount.fivePa + ')'
);
return false;
}
//if the item is a 5pa then it can only be replaced by another 5pa armor piece
if (!isFourPa && perkPairCount.fivePa >= 2) {
comboReasons.push(
'Dupe In Other 5PA (' + perkPairCount.fourPa + '/' + perkPairCount.fivePa + ')'
);
return false;
}
//if it passes all these conditions then the perk-pair is wanted
comboReasons.push('Wanted Perk Pair');
return true;
});
/*if (item.id == "6917529086431217491") {
console.log("wantedCombos", wantedCombos, comboReasons);
}*/
// if the item has no wanted combos then it can safely be dismantled
if (wantedCombos.length == 0) {
const lines = [];
_.each(armorCombos, (combo, index) => {
var reason = comboReasons[index];
lines.push({
combo: combo,
reason: reason
});
});
dupeReport.push({
classText: item.classTypeName,
type: item.bucket.type,
name: item.name,
power: item.basePower,
id: item.id,
reason: 'Reason: No Wanted Combos',
reasons: lines
});
return true;
}
}
//console.log("armorCombos", armorCombos, wantedCombos.length);
//if it passes all the conditions the item is wanted (opacity: 0)
return false;
}
module.exports = {
initJunkPerks: initJunkPerks,
junkPerkFilter: junkPerkFilter,
junkPerkConfig: junkPerkPresets
};