aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/slayers.ts
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-14 15:26:55 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-14 15:26:55 -0600
commit872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4 (patch)
tree07b0084c7046c1f3c5fdb278014253a3883e3355 /src/cleaners/skyblock/slayers.ts
parentc7af4d49db5d85bfa2bd7c716a950145f70833da (diff)
downloadskyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.tar.gz
skyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.tar.bz2
skyblock-api-872b99eb4376dc9af9f9083a3c4a9e9dd2c7f0a4.zip
Closes #2
Diffstat (limited to 'src/cleaners/skyblock/slayers.ts')
-rw-r--r--src/cleaners/skyblock/slayers.ts54
1 files changed, 54 insertions, 0 deletions
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
+}