aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-03 20:21:56 -0500
committermat <github@matdoes.dev>2022-05-03 20:21:56 -0500
commit15dbc7c3a1f76693cd83198861e94f211dbb1cb1 (patch)
tree2af3b38d94391d1a8e50df8cf3a6721ca17a30c6 /src/cleaners/skyblock
parentfc2003e704aef7bef7248903a3eafd8ffe1dce44 (diff)
downloadskyblock-api-15dbc7c3a1f76693cd83198861e94f211dbb1cb1.tar.gz
skyblock-api-15dbc7c3a1f76693cd83198861e94f211dbb1cb1.tar.bz2
skyblock-api-15dbc7c3a1f76693cd83198861e94f211dbb1cb1.zip
auto update max minion tiers
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r--src/cleaners/skyblock/minions.ts44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/cleaners/skyblock/minions.ts b/src/cleaners/skyblock/minions.ts
index c77b6c5..3067fd0 100644
--- a/src/cleaners/skyblock/minions.ts
+++ b/src/cleaners/skyblock/minions.ts
@@ -1,6 +1,5 @@
import typedHypixelApi from 'typed-hypixel-api'
import * as constants from '../../constants.js'
-import { maxMinion } from '../../hypixel.js'
export interface CleanMinion {
name: string,
@@ -14,19 +13,28 @@ export interface CleanMinion {
*/
export async function cleanMinions(member: typedHypixelApi.SkyBlockProfileMember): Promise<CleanMinion[]> {
const minions: CleanMinion[] = []
- const processedMinionNames: Set<string> = new Set()
+ const processedMinionIds: Set<string> = new Set()
+
+ const maxMinionTiers = await constants.fetchMaxMinionTiers()
+ let updatedMaxMinionTiers = false
for (const minionRaw of member?.crafted_generators ?? []) {
// do some regex magic to get the minion name and level
// examples of potential minion names: CLAY_11, PIG_1, MAGMA_CUBE_4
- const minionName = minionRaw.split(/_\d/)[0].toLowerCase()
+ const minionId = minionRaw.split(/_\d/)[0].toLowerCase()
const minionLevel = parseInt(minionRaw.split(/\D*_/)[1])
- let matchingMinion = minions.find(m => m.name === minionName)
+
+ if (minionLevel > (maxMinionTiers[minionId] ?? -1)) {
+ maxMinionTiers[minionId] = minionLevel
+ updatedMaxMinionTiers = true
+ }
+
+ let matchingMinion = minions.find(m => m.name === minionId)
if (!matchingMinion) {
// if the minion doesnt already exist in the minions array, then create it
matchingMinion = {
- name: minionName,
- levels: new Array(maxMinion).fill(false)
+ name: minionId,
+ levels: new Array(maxMinionTiers[minionId]).fill(false)
}
minions.push(matchingMinion)
}
@@ -36,29 +44,35 @@ export async function cleanMinions(member: typedHypixelApi.SkyBlockProfileMember
// set the minion at that level to true
matchingMinion.levels[minionLevel - 1] = true
- processedMinionNames.add(minionName)
+ processedMinionIds.add(minionId)
}
const allMinionNames = new Set(await constants.fetchMinions())
- for (const minionName of processedMinionNames) {
+ for (const minionName of processedMinionIds) {
if (!allMinionNames.has(minionName)) {
- constants.addMinions(Array.from(processedMinionNames))
+ constants.addMinions(Array.from(processedMinionIds))
break
}
}
- for (const minionName of allMinionNames) {
- if (!processedMinionNames.has(minionName)) {
- processedMinionNames.add(minionName)
+ for (const minionId of allMinionNames) {
+ if (!processedMinionIds.has(minionId)) {
+ processedMinionIds.add(minionId)
minions.push({
- name: minionName,
- levels: new Array(maxMinion).fill(false)
+ name: minionId,
+ levels: new Array(maxMinionTiers[minionId]).fill(false)
})
}
}
- return minions.sort((a, b) => a.name > b.name ? 1 : (a.name < b.name ? -1 : 0))
+ if (updatedMaxMinionTiers) {
+ await constants.addMaxMinionTiers(maxMinionTiers)
+ }
+
+ minions.sort((a, b) => a.name > b.name ? 1 : (a.name < b.name ? -1 : 0))
+
+ return minions
}
/**