diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 14:07:10 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 14:07:10 -0600 |
commit | eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495 (patch) | |
tree | 39a5e242c360f735e28889da22187b9471ed8dc1 /src/cleaners/skyblock/collections.ts | |
parent | a12f0eaf3349160282bdc9f48cf9f253a154e500 (diff) | |
download | skyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.tar.gz skyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.tar.bz2 skyblock-api-eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495.zip |
add collections
Diffstat (limited to 'src/cleaners/skyblock/collections.ts')
-rw-r--r-- | src/cleaners/skyblock/collections.ts | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts new file mode 100644 index 0000000..a70d7b8 --- /dev/null +++ b/src/cleaners/skyblock/collections.ts @@ -0,0 +1,113 @@ +import { cleanItemId, cleanItemNames, hypixelItemNames } from "./itemId" + +const COLLECTIONS = { + 'farming': [ + 'wheat', + 'carrot', + 'potato', + 'pumpkin', + 'melon_slice', + 'wheat_seeds', + 'red_mushroom', + 'cocoa_beans', + 'cactus', + 'sugar_cane', + 'feather', + 'leather', + 'porkchop', + 'chicken', + 'mutton', + 'rabbit', + 'nether_wart' + ], + 'mining': [ + 'cobblestone', + 'coal', + 'iron_ingot', + 'gold_ingot', + 'diamond', + 'lapis_lazuli', + 'emerald', + 'redstone', + 'quartz', + 'obsidian', + 'glowstone_dust', + 'gravel', + 'ice', + 'netherrack', + 'sand', + 'end_stone' + ], + 'combat': [ + 'rotten_flesh', + 'bone', + 'string', + 'spider_eye', + 'gunpowder', + 'ender_pearl', + 'ghast_tear', + 'slime_ball', + 'blaze_rod', + 'magma_cream' + ], + 'foraging': [ + 'oak_log', + 'spruce_log', + 'birch_log', + 'jungle_log', + 'acacia_log', + 'dark_oak_log' + ], + 'fishing': [ + 'cod', + 'salmon', + 'tropical_fish', + 'pufferfish', + 'prismarine_shard', + 'prismarine_crystals', + 'clay_ball', + 'lily_pad', + 'ink_sac', + 'sponge' + ] +} as const + +export interface Collection { + name: string + xp: number + level: number +} + +export function cleanCollections(data: any): Collection[] { + // collection tiers show up like this: [ GRAVEL_3, GOLD_INGOT_2, MELON_-1, LOG_2:1_7, RAW_FISH:3_-1] + // these tiers are the same for all players in a coop + const playerCollectionTiersRaw: string[] = data?.unlocked_coll_tiers ?? [] + const playerCollectionTiers: { [ key: string ]: number } = {} + + for (const collectionTierNameValueRaw of playerCollectionTiersRaw) { + const [ collectionTierNameRaw, collectionTierValueRaw ] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/) + const collectionName = cleanItemId(collectionTierNameRaw) + // ensure it's at least 0 + const collectionValue: number = Math.max(parseInt(collectionTierValueRaw), 0) + + // if the collection hasn't been checked yet, or the new value is higher than the old, replace it + if (!playerCollectionTiers[collectionName] || collectionValue > playerCollectionTiers[collectionName]) + playerCollectionTiers[collectionName] = collectionValue + } + + // collection names show up like this: { LOG: 49789, LOG:2: 26219, MUSHROOM_COLLECTION: 2923} + // these values are different for each player in a coop + const playerCollectionValuesRaw: { [ key in hypixelItemNames ]: number } = data?.collection ?? {} + const playerCollectionValues: Collection[] = [] + + for (const collectionNameRaw in playerCollectionValuesRaw) { + const collectionValue: number = playerCollectionValuesRaw[collectionNameRaw] + const collectionName = cleanItemId(collectionNameRaw) + playerCollectionValues.push({ + name: collectionName, + xp: collectionValue, + level: playerCollectionTiers[collectionName] + }) + } + return playerCollectionValues +}
\ No newline at end of file |