Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 55 additions & 19 deletions src/hooks/deadlockApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ItemsApi } from 'deadlock_api_client/apis/items-api';

Check failure on line 1 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/apis/items-api' or its corresponding type declarations.

Check failure on line 1 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/apis/items-api' or its corresponding type declarations.
import { HeroesApi } from 'deadlock_api_client/apis/heroes-api';

Check failure on line 2 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/apis/heroes-api' or its corresponding type declarations.

Check failure on line 2 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/apis/heroes-api' or its corresponding type declarations.
import type { Item, Ability, HashMapItemSlotTypeVecMapModCostBonusValueInner } from 'deadlock_api_client/models';

Check failure on line 3 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/models' or its corresponding type declarations.

Check failure on line 3 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/models' or its corresponding type declarations.
import type { DeadlockUpgradeItem, DeadlockAbilityItem, AbilityTier, InvestmentTracks } from '../components/types';
Expand All @@ -17,15 +17,46 @@
return true;
};

/**
* Parse a property value string into a number, returning null if non-numeric.
*/
const parsePropertyValue = (val: string | null | undefined): number | null => {
if (val === null || val === undefined) return null;
const parsed = parseFloat(val);
return isNaN(parsed) ? null : parsed;
};

/**
* Map raw properties to our normalized shape, translating negative offensive debuffs
* applied to enemies into explicit debuff stats (e.g., FireRateSlow) and aligning
* buffs to calculation-friendly keys.
*/
const parseProperties = (
propertiesRaw: Record<string, unknown>,
renamedKeysTracker?: Map<string, string>
) => {
return Object.entries(propertiesRaw)
.map(([name, rawProp]) => {
const prop = rawProp as { value?: string; bonus?: string; usage_flags?: string[] };
const amount = parsePropertyValue(prop?.value);
if (amount === null) return null;

const isEnemyApplied = prop?.usage_flags?.includes('ConditionallyEnemyApplied');

// Convert negative BonusFireRate applied to enemies into FireRateSlow
if (name === 'BonusFireRate' && amount < 0 && isEnemyApplied) {
if (renamedKeysTracker) renamedKeysTracker.set(name, 'FireRateSlow');
return { name: 'FireRateSlow', amount: Math.abs(amount) };
}

// Treat BuffBaseWeaponPct as standard WeaponPower so theorycrafting captures the self-buff
if (name === 'BuffBaseWeaponPct') {
if (renamedKeysTracker) renamedKeysTracker.set(name, 'WeaponPower');
return { name: 'WeaponPower', amount };
}

return { name, amount };
})
.filter((entry): entry is { name: string; amount: number } => entry !== null);
};

/**
* Transform raw Deadlock API items into our normalized EquipmentItem shape.
*
Expand All @@ -40,16 +71,10 @@
.filter(isShopableUpgrade)
.map(item => {
// Safe cast: isShopableUpgrade guarantees these fields exist
const upgrade = item as import('deadlock_api_client/models').Upgrade;

Check failure on line 74 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/models' or its corresponding type declarations.

Check failure on line 74 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Cannot find module 'deadlock_api_client/models' or its corresponding type declarations.

const propertiesRaw = upgrade.properties ?? {};
const properties = Object.entries(propertiesRaw)
.map(([name, prop]) => {
const amount = parsePropertyValue(prop.value);
if (amount === null) return null;
return { name, amount };
})
.filter((entry): entry is { name: string; amount: number } => entry !== null);
const properties = parseProperties(propertiesRaw);

const isStreetBrawl = upgrade.cost === 9999;
return {
Expand Down Expand Up @@ -79,13 +104,8 @@
.filter(ability => ability.upgrades && ability.upgrades.length === 3)
.map(ability => {
const propertiesRaw = ability.properties ?? {};
const properties = Object.entries(propertiesRaw)
.map(([name, prop]) => {
const amount = parsePropertyValue(prop.value);
if (amount === null) return null;
return { name, amount };
})
.filter((entry): entry is { name: string; amount: number } => entry !== null);
const renamedKeys = new Map<string, string>();
const properties = parseProperties(propertiesRaw, renamedKeys);

const rawUpgrades = ability.upgrades ?? [];
const descKeys = [
Expand All @@ -104,12 +124,28 @@
const rawUpgrade = rawUpgrades[i];
if (rawUpgrade && rawUpgrade.property_upgrades) {
upgrades[i].modifiers = rawUpgrade.property_upgrades
.map(u => {

Check failure on line 127 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Parameter 'u' implicitly has an 'any' type.

Check failure on line 127 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Parameter 'u' implicitly has an 'any' type.
const amount = parsePropertyValue(u.bonus);
let amount = parsePropertyValue(u.bonus);
if (amount === null) return null;
return { name: u.name, amount };

let name = u.name;

// Apply translations from base properties
if (renamedKeys.has(name)) {
name = renamedKeys.get(name)!;
if (name === 'FireRateSlow') {
amount = Math.abs(amount);
}
}

// Also apply direct translations for upgrade properties that didn't appear in base
if (name === 'BuffBaseWeaponPct') {
name = 'WeaponPower';
}

return { name, amount };
})
.filter((entry): entry is { name: string; amount: number } => entry !== null);

Check failure on line 148 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Parameter 'entry' implicitly has an 'any' type.

Check failure on line 148 in src/hooks/deadlockApi.ts

View workflow job for this annotation

GitHub Actions / check

Parameter 'entry' implicitly has an 'any' type.
}
}

Expand Down
Loading