diff options
author | mat <github@matdoes.dev> | 2022-03-28 15:30:02 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-03-28 15:30:21 +0000 |
commit | 44a8aebcb40f1d02b93218bcf5ccfa8e87621abb (patch) | |
tree | 94a51903caeea25e322676b178d02047bb615ef7 /src/cleaners/skyblock | |
parent | 8e86d739ae21d24c148276aa67fd0c19aaf37c1c (diff) | |
download | skyblock-api-44a8aebcb40f1d02b93218bcf5ccfa8e87621abb.tar.gz skyblock-api-44a8aebcb40f1d02b93218bcf5ccfa8e87621abb.tar.bz2 skyblock-api-44a8aebcb40f1d02b93218bcf5ccfa8e87621abb.zip |
add item list
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/itemList.ts | 60 | ||||
-rw-r--r-- | src/cleaners/skyblock/pets.ts | 10 |
2 files changed, 67 insertions, 3 deletions
diff --git a/src/cleaners/skyblock/itemList.ts b/src/cleaners/skyblock/itemList.ts new file mode 100644 index 0000000..a534628 --- /dev/null +++ b/src/cleaners/skyblock/itemList.ts @@ -0,0 +1,60 @@ +import typedHypixelApi from 'typed-hypixel-api' + +export interface ItemRequirement { + // idk what these do + // they'll probably be renamed at some point + dungeon: { + type: string + level: number + } +} + +// based on Item from inventory.ts +export interface ItemListItem { + id: string + vanillaId: string + tier: string | null + display: { + name: string + glint: boolean + } + npc_sell_price: number | null + requirements: ItemRequirement | null +} + +export interface ItemListData { + lastUpdated: number + list: ItemListItem[] +} + +function cleanItemRequirements(data: typedHypixelApi.SkyBlockItemsResponse['items'][number]['requirements'] & typedHypixelApi.SkyBlockItemsResponse['items'][number]['catacombs_requirements']): ItemRequirement | null { + if (!data || !data.dungeon) return null + return { + dungeon: { + type: data.dungeon.type, + level: data.dungeon.level + } + } +} + +function cleanItemListItem(item: typedHypixelApi.SkyBlockItemsResponse['items'][number]): ItemListItem { + const vanillaId = item.material.toLowerCase() + return { + id: item.id, + vanillaId: item.durability ? `${vanillaId}:${item.durability}` : vanillaId, + tier: item.tier ?? null, + display: { + name: item.name, + glint: item.glowing ?? false + }, + npc_sell_price: item.npc_sell_price ?? null, + requirements: cleanItemRequirements(item.catacombs_requirements ?? item.requirements) + } +} + +export async function cleanItemListResponse(data: typedHypixelApi.SkyBlockItemsResponse): Promise<ItemListData> { + return { + lastUpdated: data.lastUpdated, + list: data.items.map(cleanItemListItem) + } +}
\ No newline at end of file diff --git a/src/cleaners/skyblock/pets.ts b/src/cleaners/skyblock/pets.ts index d6265e5..4c0fe4a 100644 --- a/src/cleaners/skyblock/pets.ts +++ b/src/cleaners/skyblock/pets.ts @@ -1,6 +1,8 @@ import typedHypixelApi from 'typed-hypixel-api' -import { fetchPets } from '../../constants.js' +import { fetchItemList } from '../../hypixel.js' import { levelFromXpTable } from '../../util.js' +import { fetchPets } from '../../constants.js' +import { ItemListItem } from './itemList.js' // https://hypixel-skyblock.fandom.com/wiki/Module:Pet/LevelingData?action=edit @@ -43,7 +45,7 @@ export interface Pet { level: number tier: typedHypixelApi.Pet['tier'] skin: string | null - item: string | null + item: ItemListItem | null } export interface PetsData { @@ -59,6 +61,8 @@ export async function cleanPets(data: typedHypixelApi.SkyBlockProfileMember): Pr const allPetIds = await fetchPets() const obtainedPetIds: string[] = [] + const itemList = await fetchItemList() + for (const petData of data.pets ?? []) { const xpTable = RARITY_XP_TABLES[petData.tier] const level = levelFromXpTable(petData.exp, xpTable) @@ -69,7 +73,7 @@ export async function cleanPets(data: typedHypixelApi.SkyBlockProfileMember): Pr level, tier: petData.tier, skin: petData.skin ?? null, - item: petData.heldItem + item: petData.heldItem ? (itemList.list.find(i => i.id === petData.heldItem) ?? null) : null } obtainedPetIds.push(pet.id) obtainedPets.push(pet) |