Skip to content

Commit

Permalink
Fix: Guess armor Guardian Class
Browse files Browse the repository at this point in the history
  • Loading branch information
chainrez committed Feb 5, 2025
1 parent 96ee532 commit 0a4a04e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
44 changes: 38 additions & 6 deletions src/app/inventory/store/d2-item-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
SOME_OTHER_DUMMY_BUCKET,
THE_FORBIDDEN_BUCKET,
d2MissingIcon,
infusionCategoryHashToClass,
plugCategoryHashToClass,
uniqueEquipBuckets,
} from 'app/search/d2-known-values';
import { lightStats } from 'app/search/search-filter-values';
Expand All @@ -27,6 +29,7 @@ import {
DestinyItemResponse,
DestinyItemSubType,
DestinyItemTooltipNotification,
DestinyItemType,
DestinyObjectiveProgress,
DestinyProfileResponse,
DestinyVendorSaleItemComponent,
Expand Down Expand Up @@ -434,17 +437,46 @@ export function makeItem(
}
}

// we cannot trust the claimed class of redacted items. they all say Titan
const classType = itemDef.redacted
? normalBucket.inArmor
let classType = itemDef.classType;

// we cannot trust the claimed class of redacted items
if (itemDef.redacted) {
classType = normalBucket.inArmor
? itemInstanceData?.isEquipped && owner
? // equipped armor gets marked as that character's class
owner.classType
: // unequipped armor gets marked "no class"
DestinyClass.Classified
: // other items are marked "any class"
DestinyClass.Unknown
: itemDef.classType;
DestinyClass.Unknown;
} else if (
// This whole elseif can go, eventually.
itemDef.classType === DestinyClass.Unknown &&
(itemDef.itemType === DestinyItemType.Armor ||
// Festival masks are head armor in traits but not types.
(itemDef.itemType === DestinyItemType.None &&
itemDef.traitHashes?.includes(TraitHashes.ItemArmorHead)))
) {
// This identifies 4591 armors by infusion category.
classType =
infusionCategoryHashToClass[itemDef.quality!.infusionCategoryHash] ?? DestinyClass.Unknown;

// This identifies the remaining 413 by what class' ornament they are (or look like).
if (classType === DestinyClass.Unknown) {
// If this item has a plug, it can be an ornament (and be identified). If not, find a visually matching ornament.
let plugCheckItem: DestinyInventoryItemDefinition | undefined = itemDef;
if (!itemDef.plug) {
plugCheckItem = Object.values(defs.InventoryItem.getAll()).find(
(i) => i.plug && i.displayProperties.icon === itemDef.displayProperties.icon,
);
}

if (plugCheckItem) {
classType =
plugCategoryHashToClass[plugCheckItem.plug!.plugCategoryHash] ?? DestinyClass.Unknown;
}
}
}

const createdItem: DimItem = {
owner: owner?.id || 'unknown',
Expand Down Expand Up @@ -486,7 +518,7 @@ export function makeItem(
maxStackSize: Math.max(itemDef.inventory!.maxStackSize, 1),
uniqueStack: Boolean(itemDef.inventory!.stackUniqueLabel?.length),
classType,
classTypeNameLocalized: getClassTypeNameLocalized(defs)(itemDef.classType),
classTypeNameLocalized: getClassTypeNameLocalized(defs)(classType),
element,
energy: itemInstanceData.energy ?? null,
lockable: normalBucket.hash !== BucketHashes.Finishers ? item.lockable : true,
Expand Down
44 changes: 43 additions & 1 deletion src/app/search/d2-known-values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CustomStatWeights } from '@destinyitemmanager/dim-api-types';
import { HashLookup } from 'app/utils/util-types';
import { TierType } from 'bungie-api-ts/destiny2';
import { DestinyClass, TierType } from 'bungie-api-ts/destiny2';

import {
BreakerTypeHashes,
Expand Down Expand Up @@ -318,3 +318,45 @@ export const enum ModsWithConditionalStats {
}

export const ARTIFICE_PERK_HASH = 3727270518; // InventoryItem "Artifice Armor"

/** Most armor's Guardian Class can be determined by what it can be infused into */
export const infusionCategoryHashToClass: Record<number, DestinyClass | undefined> = {
3301232851: DestinyClass.Hunter, // hunter head
3853570272: DestinyClass.Hunter, // hunter arms
1814923096: DestinyClass.Hunter, // hunter chest
2542340350: DestinyClass.Hunter, // hunter legs
821835303: DestinyClass.Hunter, // hunter class

3548569221: DestinyClass.Titan, // titan head
3647016162: DestinyClass.Titan, // titan arms
2858080654: DestinyClass.Titan, // titan chest
1462658336: DestinyClass.Titan, // titan legs
4159907129: DestinyClass.Titan, // titan class

1046741990: DestinyClass.Warlock, // warlock head
673964473: DestinyClass.Warlock, // warlock arms
3312934999: DestinyClass.Warlock, // warlock chest
3441938495: DestinyClass.Warlock, // warlock legs
2278270520: DestinyClass.Warlock, // warlock class
};

/** Most remaining armor's Guardian Class can be determined by its ornament category */
export const plugCategoryHashToClass: Record<number, DestinyClass | undefined> = {
1608828634: DestinyClass.Hunter, // armor_skins_hunter_legs
4147546868: DestinyClass.Hunter, // armor_skins_hunter_chest
3952105943: DestinyClass.Hunter, // armor_skins_hunter_head
1392996619: DestinyClass.Hunter, // armor_skins_hunter_class
4060972748: DestinyClass.Hunter, // armor_skins_hunter_arms

454950060: DestinyClass.Hunter, // armor_skins_warlock_head
3281006437: DestinyClass.Hunter, // armor_skins_warlock_legs
3934361071: DestinyClass.Hunter, // armor_skins_warlock_arms
1509135441: DestinyClass.Hunter, // armor_skins_warlock_chest
505602046: DestinyClass.Hunter, // armor_skins_warlock_class

3955281547: DestinyClass.Hunter, // armor_skins_titan_head
3945759584: DestinyClass.Hunter, // armor_skins_titan_chest
2112278838: DestinyClass.Hunter, // armor_skins_titan_legs
3386643992: DestinyClass.Hunter, // armor_skins_titan_arms
2415787951: DestinyClass.Hunter, // armor_skins_titan_class
};

0 comments on commit 0a4a04e

Please sign in to comment.