diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 15:34:54 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 15:34:54 -0600 |
commit | 8a21158dfaa6392ca6f8d7d8c218c69689236765 (patch) | |
tree | 97d61ac10a1dbbe1b11dea78989325d499277d3e /src/cleaners | |
parent | 872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4 (diff) | |
download | skyblock-api-8a21158dfaa6392ca6f8d7d8c218c69689236765.tar.gz skyblock-api-8a21158dfaa6392ca6f8d7d8c218c69689236765.tar.bz2 skyblock-api-8a21158dfaa6392ca6f8d7d8c218c69689236765.zip |
add total slayer xp
Diffstat (limited to 'src/cleaners')
-rw-r--r-- | src/cleaners/skyblock/member.ts | 4 | ||||
-rw-r--r-- | src/cleaners/skyblock/slayers.ts | 36 |
2 files changed, 32 insertions, 8 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index b2dc105..6d419e1 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -11,7 +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' +import { cleanSlayers, Slayer, SlayerData } from './slayers' export interface CleanBasicMember { uuid: string @@ -30,7 +30,7 @@ export interface CleanMember extends CleanBasicMember { skills: Skill[] visited_zones: Zone[] collections: Collection[] - slayers: Slayer[] + slayers: SlayerData } export async function cleanSkyBlockProfileMemberResponseBasic(member, included: Included[] = null): Promise<CleanBasicMember> { diff --git a/src/cleaners/skyblock/slayers.ts b/src/cleaners/skyblock/slayers.ts index 0fa1a5e..dd3881b 100644 --- a/src/cleaners/skyblock/slayers.ts +++ b/src/cleaners/skyblock/slayers.ts @@ -1,7 +1,14 @@ const slayerLevels = 4 // number of slayer levels, this might be 5 soon -type SlayerName = 'spider' | 'zombie' | 'wolf' +const SLAYER_NAMES = { + spider: 'tarantula', + zombie: 'revenant', + wolf: 'sven' +} as const + +type ApiSlayerName = keyof typeof SLAYER_NAMES +type SlayerName = (typeof SLAYER_NAMES)[ApiSlayerName] interface SlayerTier { tier: number, @@ -14,12 +21,24 @@ export interface Slayer { tiers: SlayerTier[] } -export function cleanSlayers(data: any) { +export interface SlayerData { + xp: number + bosses: Slayer[] +} + +export function cleanSlayers(data: any): SlayerData { const slayers: Slayer[] = [] const slayersDataRaw = data?.slayer_bosses - for (const slayerName in slayersDataRaw) { - const slayerDataRaw = slayersDataRaw[slayerName] + + let totalXp = 0 + + for (const slayerNameRaw in slayersDataRaw) { + const slayerDataRaw = slayersDataRaw[slayerNameRaw] + + // convert name provided by api (spider) to the real name (tarantula) + const slayerName: SlayerName = SLAYER_NAMES[slayerDataRaw] + const slayerXp: number = slayerDataRaw.xp const slayerTiers: SlayerTier[] = [] for (const slayerDataKey in slayerDataRaw) { @@ -44,11 +63,16 @@ export function cleanSlayers(data: any) { }) const slayer: Slayer = { - name: slayerName as SlayerName, + name: slayerName, tiers: slayerTiers, xp: slayerXp } slayers.push(slayer) + // add the xp from this slayer to the total xp + totalXp += slayerXp + } + return { + xp: totalXp, + bosses: slayers } - return slayers } |