Skip to content
Merged

Deploy #1785

60 changes: 34 additions & 26 deletions apps/frontend/components/journal/get-difficulties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { difficultyMap } from '@/data/difficulty';
import {
difficultyHeroic,
difficultyLookingForRaid,
difficultyMap,
difficultyMythic,
difficultyNormal,
difficultyTimewalking,
difficultyWorld,
} from '@/data/difficulty';
import { Difficulty } from '@/enums/difficulty';
import type { JournalDataEncounterItemAppearance, JournalDataInstance } from '@/types/data/journal';

const raidSizeInstances: Set<number> = new Set([
Expand All @@ -15,18 +24,18 @@ const raidSizeInstances: Set<number> = new Set([

export function getDifficulties(
instance: JournalDataInstance,
appearance: JournalDataEncounterItemAppearance,
appearance: JournalDataEncounterItemAppearance
): [string[], string[]] {
if (!appearance.difficulties) {
return [[], []];
}

const ret: [string[], string[]] = [[], []];
if (raidSizeInstances.has(instance.id)) {
const normal10 = appearance.difficulties.includes(3);
const normal25 = appearance.difficulties.includes(4);
const heroic10 = appearance.difficulties.includes(5);
const heroic25 = appearance.difficulties.includes(6);
const normal10 = appearance.difficulties.includes(Difficulty.RaidLegacy10Normal);
const normal25 = appearance.difficulties.includes(Difficulty.RaidLegacy10Heroic);
const heroic10 = appearance.difficulties.includes(Difficulty.RaidLegacy25Normal);
const heroic25 = appearance.difficulties.includes(Difficulty.RaidLegacy25Heroic);

if (normal10 && normal25 && heroic10 && heroic25) {
ret[0].push('N', 'H');
Expand Down Expand Up @@ -57,30 +66,29 @@ export function getDifficulties(
ret[1].push('25 Heroic');
}
} else {
// LFR Legacy, LFR Raid
if ([7, 17].some((id) => appearance.difficulties.indexOf(id) >= 0)) {
ret[0].push(difficultyMap[17].shortName);
ret[1].push(difficultyMap[17].name);
if (difficultyWorld.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidWorld].shortName);
ret[1].push(difficultyMap[Difficulty.RaidWorld].name);
}
// Normal Dungeon, 10 Normal, 25 Normal, 40 Normal, Normal Raid
if ([1, 3, 4, 9, 14].some((id) => appearance.difficulties.indexOf(id) >= 0)) {
ret[0].push(difficultyMap[14].shortName);
ret[1].push(difficultyMap[14].name);
if (difficultyLookingForRaid.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidLookingForRaid].shortName);
ret[1].push(difficultyMap[Difficulty.RaidLookingForRaid].name);
}
// Heroic Dungeon, 10 Heroic, 25 Heroic, Heroic Raid
if ([2, 5, 6, 15].some((id) => appearance.difficulties.indexOf(id) >= 0)) {
ret[0].push(difficultyMap[15].shortName);
ret[1].push(difficultyMap[15].name);
if (difficultyNormal.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidNormal].shortName);
ret[1].push(difficultyMap[Difficulty.RaidNormal].name);
}
// Mythic Dungeon, Mythic Keystone, Mythic Raid
if ([23, 8, 16].some((id) => appearance.difficulties.indexOf(id) >= 0)) {
ret[0].push(difficultyMap[16].shortName);
ret[1].push(difficultyMap[16].name);
if (difficultyHeroic.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidHeroic].shortName);
ret[1].push(difficultyMap[Difficulty.RaidHeroic].name);
}
// Timewalking Dungeon, Timewalking Raid
if ([24, 33].some((id) => appearance.difficulties.indexOf(id) >= 0)) {
ret[0].push(difficultyMap[33].shortName);
ret[1].push(difficultyMap[33].name);
if (difficultyMythic.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidMythic].shortName);
ret[1].push(difficultyMap[Difficulty.RaidMythic].name);
}
if (difficultyTimewalking.some((id) => appearance.difficulties.includes(id))) {
ret[0].push(difficultyMap[Difficulty.RaidTimewalking].shortName);
ret[1].push(difficultyMap[Difficulty.RaidTimewalking].name);
}
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { difficultyMap, journalDifficultyOrder } from '@/data/difficulty';
import { wowthingData } from '@/shared/stores/data';
import { userState } from '@/user-home/state/user';
import type { Difficulty } from '@/types';
import type { DifficultyData } from '@/types';

let { difficulty, instanceId }: { difficulty: Difficulty; instanceId: number } = $props();
let { difficulty, instanceId }: { difficulty: DifficultyData; instanceId: number } = $props();

let instance = $derived(wowthingData.static.instanceById.get(instanceId));

Expand Down
174 changes: 93 additions & 81 deletions apps/frontend/components/vendors/VendorsGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import IntersectionObserver from 'svelte-intersection-observer';

import { pvpCurrencies } from '@/data/currencies';
import { AppearanceModifier } from '@/enums/appearance-modifier';
import { Faction } from '@/enums/faction';
import { PlayableClass, PlayableClassMask } from '@/enums/playable-class';
Expand All @@ -9,6 +10,7 @@
import { wowthingData } from '@/shared/stores/data';
import { ThingData } from '@/types/vendors';
import { lazyState } from '@/user-home/state/lazy';
import { getNumberKeyedEntries } from '@/utils/get-number-keyed-entries';
import getPercentClass from '@/utils/get-percent-class';
import { applyBonusIds } from '@/utils/items/apply-bonus-ids';
import type { ManualDataVendorGroup } from '@/types/data/manual';
Expand Down Expand Up @@ -49,93 +51,103 @@
let anyHorde = false;
let anyNormal = false;

for (const thing of showAll ? group.sells : group.sellsFiltered) {
const bonusIds = thing.bonusIds || [];
const thingKey = `${thing.type}|${thing.id}|${bonusIds.join(',')}`;
const [userHas, lookupType, lookupId] = lazyState.vendors.userHas[thingKey] || [];
if (showAll || (useShowCollected && userHas) || (useShowUncollected && !userHas)) {
const thingData = new ThingData(thing, userHas, lookupId, lookupType);

thingData.bonusIds = bonusIds;
thingData.quality =
thing.quality || wowthingData.items.items[thing.id]?.quality || 0;

if (thing.type === RewardType.Mount) {
thingData.linkType = 'spell';
thingData.linkId = wowthingData.static.mountById.get(thing.id)?.spellId;
} else if (thing.type === RewardType.Pet) {
thingData.linkType = 'npc';
thingData.linkId = wowthingData.static.petById.get(thing.id)?.creatureId;
} else {
thingData.linkType = 'item';
thingData.linkId = thing.id;

if (bonusIds.length > 0) {
thingData.extraParams['bonus'] = bonusIds
.filter((bonusId) => bonusId < 999999)
.map((bonusId) => bonusId.toString())
.join(':');
}

if (thing.classMask in PlayableClassMask) {
thingData.classId =
PlayableClass[
PlayableClassMask[thing.classMask] as keyof typeof PlayableClass
];
const hideGroup =
!browserState.current.vendors.showPvp &&
group.sells.some((vendorItem) =>
getNumberKeyedEntries(vendorItem.costs).some(([currencyId]) =>
pvpCurrencies.has(currencyId)
)
);

if (!hideGroup) {
for (const thing of showAll ? group.sells : group.sellsFiltered) {
const bonusIds = thing.bonusIds || [];
const thingKey = `${thing.type}|${thing.id}|${bonusIds.join(',')}`;
const [userHas, lookupType, lookupId] = lazyState.vendors.userHas[thingKey] || [];
if (showAll || (useShowCollected && userHas) || (useShowUncollected && !userHas)) {
const thingData = new ThingData(thing, userHas, lookupId, lookupType);

thingData.bonusIds = bonusIds;
thingData.quality =
thing.quality || wowthingData.items.items[thing.id]?.quality || 0;

if (thing.type === RewardType.Mount) {
thingData.linkType = 'spell';
thingData.linkId = wowthingData.static.mountById.get(thing.id)?.spellId;
} else if (thing.type === RewardType.Pet) {
thingData.linkType = 'npc';
thingData.linkId = wowthingData.static.petById.get(thing.id)?.creatureId;
} else {
thingData.classId = 0;
}

const item = wowthingData.items.items[thingData.linkId];
if (!item) {
console.warn('Invalid item', group.name, thingData.linkId);
continue;
}

const withBonusIds = applyBonusIds(bonusIds, {
itemLevel: item.itemLevel,
quality: thingData.quality,
});
thingData.quality = withBonusIds.quality;

const appearanceKeys = Object.keys(item?.appearances || {}).map((n) =>
parseInt(n)
);
let modifier = thing.appearanceModifier;
if (appearanceKeys.length === 1 || !appearanceKeys.includes(modifier)) {
modifier = appearanceKeys[0];
thingData.linkType = 'item';
thingData.linkId = thing.id;

if (bonusIds.length > 0) {
thingData.extraParams['bonus'] = bonusIds
.filter((bonusId) => bonusId < 999999)
.map((bonusId) => bonusId.toString())
.join(':');
}

if (thing.classMask in PlayableClassMask) {
thingData.classId =
PlayableClass[
PlayableClassMask[thing.classMask] as keyof typeof PlayableClass
];
} else {
thingData.classId = 0;
}

const item = wowthingData.items.items[thingData.linkId];
if (!item) {
console.warn('Invalid item', group.name, thingData.linkId);
continue;
}

const withBonusIds = applyBonusIds(bonusIds, {
itemLevel: item.itemLevel,
quality: thingData.quality,
});
thingData.quality = withBonusIds.quality;

const appearanceKeys = Object.keys(item?.appearances || {}).map((n) =>
parseInt(n)
);
let modifier = thing.appearanceModifier;
if (appearanceKeys.length === 1 || !appearanceKeys.includes(modifier)) {
modifier = appearanceKeys[0];
}

if (group.overrideDifficulty === 14) {
modifier = AppearanceModifier.Normal;
} else if (group.overrideDifficulty === 15) {
modifier = AppearanceModifier.Heroic;
} else if (group.overrideDifficulty === 16) {
modifier = AppearanceModifier.Mythic;
} else if (group.overrideDifficulty === 17) {
modifier = AppearanceModifier.LookingForRaid;
}

if (modifier === AppearanceModifier.Mythic) {
thingData.difficulty = 'M';
} else if (modifier === AppearanceModifier.Heroic) {
thingData.difficulty = 'H';
} else if (modifier === AppearanceModifier.LookingForRaid) {
thingData.difficulty = 'L';
} else if (modifier === AppearanceModifier.Normal && group.showNormalTag) {
thingData.difficulty = 'N';
}
}

if (group.overrideDifficulty === 14) {
modifier = AppearanceModifier.Normal;
} else if (group.overrideDifficulty === 15) {
modifier = AppearanceModifier.Heroic;
} else if (group.overrideDifficulty === 16) {
modifier = AppearanceModifier.Mythic;
} else if (group.overrideDifficulty === 17) {
modifier = AppearanceModifier.LookingForRaid;
if (thing.faction === Faction.Alliance) {
anyAlliance = true;
} else if (thing.faction === Faction.Horde) {
anyHorde = true;
} else {
anyNormal = true;
}

if (modifier === AppearanceModifier.Mythic) {
thingData.difficulty = 'M';
} else if (modifier === AppearanceModifier.Heroic) {
thingData.difficulty = 'H';
} else if (modifier === AppearanceModifier.LookingForRaid) {
thingData.difficulty = 'L';
} else if (modifier === AppearanceModifier.Normal && group.showNormalTag) {
thingData.difficulty = 'N';
}
retThings.push(thingData);
}

if (thing.faction === Faction.Alliance) {
anyAlliance = true;
} else if (thing.faction === Faction.Horde) {
anyHorde = true;
} else {
anyNormal = true;
}

retThings.push(thingData);
}
}

Expand Down
Loading
Loading