From 872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 14 Feb 2021 15:26:55 -0600 Subject: Closes #2 --- src/cleaners/skyblock/member.ts | 5 +++- src/cleaners/skyblock/slayers.ts | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/cleaners/skyblock/slayers.ts (limited to 'src/cleaners') diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index f0d2cec..b2dc105 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -11,6 +11,7 @@ import { CleanPlayer } from '../player' import { Bank } from './bank' import { cleanVisitedZones, Zone } from './zones' import { cleanCollections, Collection } from './collections' +import { cleanSlayers, Slayer } from './slayers' export interface CleanBasicMember { uuid: string @@ -29,6 +30,7 @@ export interface CleanMember extends CleanBasicMember { skills: Skill[] visited_zones: Zone[] collections: Collection[] + slayers: Slayer[] } export async function cleanSkyBlockProfileMemberResponseBasic(member, included: Included[] = null): Promise { @@ -59,7 +61,8 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu objectives: cleanObjectives(member), skills: cleanSkills(member), visited_zones: cleanVisitedZones(member), - collections: cleanCollections(member) + collections: cleanCollections(member), + slayers: cleanSlayers(member) } } diff --git a/src/cleaners/skyblock/slayers.ts b/src/cleaners/skyblock/slayers.ts new file mode 100644 index 0000000..0fa1a5e --- /dev/null +++ b/src/cleaners/skyblock/slayers.ts @@ -0,0 +1,54 @@ + +const slayerLevels = 4 // number of slayer levels, this might be 5 soon + +type SlayerName = 'spider' | 'zombie' | 'wolf' + +interface SlayerTier { + tier: number, + kills: number +} + +export interface Slayer { + name: SlayerName + xp: number + tiers: SlayerTier[] +} + +export function cleanSlayers(data: any) { + const slayers: Slayer[] = [] + + const slayersDataRaw = data?.slayer_bosses + for (const slayerName in slayersDataRaw) { + const slayerDataRaw = slayersDataRaw[slayerName] + const slayerXp: number = slayerDataRaw.xp + const slayerTiers: SlayerTier[] = [] + for (const slayerDataKey in slayerDataRaw) { + // if a key starts with boss_kills_tier_ (boss_kills_tier_1), get the last number + if (slayerDataKey.startsWith('boss_kills_tier_')) { + const slayerTierRaw = parseInt(slayerDataKey.substr('boss_kills_tier_'.length)) + const slayerTierKills = slayerDataRaw[slayerDataKey] + // add 1 since hypixel is using 0 indexed tiers + const slayerTier = slayerTierRaw + 1 + slayerTiers.push({ + kills: slayerTierKills, + tier: slayerTier + }) + } + } + + // if the slayer tier length is less than the max, add more empty ones + while (slayerTiers.length < slayerLevels) + slayerTiers.push({ + tier: slayerTiers.length + 1, + kills: 0 + }) + + const slayer: Slayer = { + name: slayerName as SlayerName, + tiers: slayerTiers, + xp: slayerXp + } + slayers.push(slayer) + } + return slayers +} -- cgit