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/skyblock/slayers.ts | |
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/skyblock/slayers.ts')
-rw-r--r-- | src/cleaners/skyblock/slayers.ts | 36 |
1 files changed, 30 insertions, 6 deletions
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 } |