diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 15:26:55 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 15:26:55 -0600 |
commit | 872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4 (patch) | |
tree | 07b0084c7046c1f3c5fdb278014253a3883e3355 /src/cleaners/skyblock | |
parent | c7af4d49db5d85bfa2bd7c716a950145f70833da (diff) | |
download | skyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.tar.gz skyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.tar.bz2 skyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.zip |
Closes #2
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/member.ts | 5 | ||||
-rw-r--r-- | src/cleaners/skyblock/slayers.ts | 54 |
2 files changed, 58 insertions, 1 deletions
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<CleanBasicMember> { @@ -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 +} |