Skip to content

Commit

Permalink
Merge pull request #10886 from DestinyItemManager/generated-stat-hashes
Browse files Browse the repository at this point in the history
Use generated enums for stats in D1 code
  • Loading branch information
bhollis authored Jan 9, 2025
2 parents 7fe6295 + 0b60832 commit bea67fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/app/destiny1/loadout-builder/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ export async function getSetBucketsStep(
[BucketHashes.Ghost]: ghost,
},
stats: {
144602215: {
hash: 144602215,
[StatHashes.Intellect]: {
hash: StatHashes.Intellect,
value: 0,
name: 'Intellect',
description: '',
icon: intellectIcon,
},
1735777505: {
hash: 1735777505,
[StatHashes.Discipline]: {
hash: StatHashes.Discipline,
value: 0,
name: 'Discipline',
description: '',
icon: disciplineIcon,
},
4244567218: {
hash: 4244567218,
[StatHashes.Strength]: {
hash: StatHashes.Strength,
value: 0,
name: 'Strength',
description: '',
Expand All @@ -152,9 +152,9 @@ export async function getSetBucketsStep(
const pieces = Object.values(set.armor);
set.setHash = genSetHash(pieces);
calcArmorStats(pieces, set.stats, scaleType);
const tiersString = `${tierValue(set.stats[144602215].value)}/${tierValue(
set.stats[1735777505].value,
)}/${tierValue(set.stats[4244567218].value)}`;
const tiersString = `${tierValue(set.stats[StatHashes.Intellect].value)}/${tierValue(
set.stats[StatHashes.Discipline].value,
)}/${tierValue(set.stats[StatHashes.Strength].value)}`;

tiersSet.add(tiersString);

Expand Down
40 changes: 20 additions & 20 deletions src/app/destiny1/loadout-builder/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { D1BucketHashes, D1_StatHashes } from 'app/search/d1-known-values';
import { isEmpty, mapValues, uniqBy } from 'app/utils/collections';
import { itemCanBeEquippedBy } from 'app/utils/item-utils';
import { BucketHashes } from 'data/d2/generated-enums';
import { BucketHashes, StatHashes } from 'data/d2/generated-enums';
import { maxBy } from 'es-toolkit';
import { D1Item } from '../../inventory/item-types';
import { D1Store, DimStore } from '../../inventory/store-types';
Expand All @@ -25,9 +25,9 @@ function getBonusType(armorpiece: D1ItemWithNormalStats): string {
return '';
}
return (
(armorpiece.normalStats[144602215].bonus > 0 ? 'int ' : '') +
(armorpiece.normalStats[1735777505].bonus > 0 ? 'dis ' : '') +
(armorpiece.normalStats[4244567218].bonus > 0 ? 'str' : '')
(armorpiece.normalStats[StatHashes.Intellect].bonus > 0 ? 'int ' : '') +
(armorpiece.normalStats[StatHashes.Discipline].bonus > 0 ? 'dis ' : '') +
(armorpiece.normalStats[StatHashes.Strength].bonus > 0 ? 'str' : '')
);
}

Expand Down Expand Up @@ -66,32 +66,32 @@ export function calcArmorStats(
scaleTypeArg: 'base' | 'scaled',
) {
for (const armor of pieces) {
const int = armor.item.normalStats![144602215];
const dis = armor.item.normalStats![1735777505];
const str = armor.item.normalStats![4244567218];
const int = armor.item.normalStats![StatHashes.Intellect];
const dis = armor.item.normalStats![StatHashes.Discipline];
const str = armor.item.normalStats![StatHashes.Strength];

const scaleType = armor.item.tier === 'Rare' ? 'base' : scaleTypeArg;

// Mark of the Sunforged, Stormcaller Bond and Nightstalker cloak have special fixed stats
// that do not scale correctly as the scaling is currently implemented.
// See https://github.com/DestinyItemManager/DIM/issues/5191 for details
if ([2820418554, 2122538507, 2300914892].includes(armor.item.hash)) {
stats[144602215].value += int.base;
stats[StatHashes.Intellect].value += int.base;
} else {
stats[144602215].value += int[scaleType];
stats[1735777505].value += dis[scaleType];
stats[4244567218].value += str[scaleType];
stats[StatHashes.Intellect].value += int[scaleType];
stats[StatHashes.Discipline].value += dis[scaleType];
stats[StatHashes.Strength].value += str[scaleType];
}

switch (armor.bonusType) {
case 'int':
stats[144602215].value += int.bonus;
stats[StatHashes.Intellect].value += int.bonus;
break;
case 'dis':
stats[1735777505].value += dis.bonus;
stats[StatHashes.Discipline].value += dis.bonus;
break;
case 'str':
stats[4244567218].value += str.bonus;
stats[StatHashes.Strength].value += str.bonus;
break;
}
}
Expand Down Expand Up @@ -120,12 +120,12 @@ export function getBestArmor(
fullMode = false,
) {
const statHashes = [
{ stats: [144602215, 1735777505], type: 'intdis' },
{ stats: [144602215, 4244567218], type: 'intstr' },
{ stats: [1735777505, 4244567218], type: 'disstr' },
{ stats: [144602215], type: 'int' },
{ stats: [1735777505], type: 'dis' },
{ stats: [4244567218], type: 'str' },
{ stats: [StatHashes.Intellect, StatHashes.Discipline], type: 'intdis' },
{ stats: [StatHashes.Intellect, StatHashes.Strength], type: 'intstr' },
{ stats: [StatHashes.Discipline, StatHashes.Strength], type: 'disstr' },
{ stats: [StatHashes.Intellect], type: 'int' },
{ stats: [StatHashes.Discipline], type: 'dis' },
{ stats: [StatHashes.Strength], type: 'str' },
];
const armor: Partial<Record<ArmorTypes, ItemWithBonus[]>> = {};
let best: { item: D1ItemWithNormalStats; bonusType: string }[] = [];
Expand Down

0 comments on commit bea67fe

Please sign in to comment.