aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/itemList.ts
blob: 3a166e3176ccbd9b875be76371b169ea8bb03118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import typedHypixelApi from 'typed-hypixel-api'
import { headIdFromBase64 } from './inventory.js'

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
    headTexture?: string
    vanillaId: string
    tier: string | null
    display: {
        name: string
        glint: boolean
    }
    npcSellPrice: 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,
        headTexture: (item.material === 'SKULL_ITEM' && 'skin' in item) ? headIdFromBase64(item.skin) : undefined,
        vanillaId: item.durability ? `${vanillaId}:${item.durability}` : vanillaId,
        tier: item.tier ?? null,
        display: {
            name: item.name,
            glint: item.glowing ?? false
        },
        npcSellPrice: 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)
    }
}