diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-13 16:30:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 16:30:27 -0500 |
commit | ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f (patch) | |
tree | 600846dd4804c487d16d33dd99ad4073d815e8f3 /src/database.ts | |
parent | c0d03a8d0c1e75967f48cb27d9c55bc4707af22c (diff) | |
download | skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.gz skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.bz2 skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.zip |
Slayer leaderboard (#4)
* add slayers to constants
* Compiled TS into JS
* change units to also show up when only changing one constant item
* Compiled TS into JS
* add slayer leaderboards
* remove debugging stuff
Diffstat (limited to 'src/database.ts')
-rw-r--r-- | src/database.ts | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/database.ts b/src/database.ts index 9e81f5b..3f44b39 100644 --- a/src/database.ts +++ b/src/database.ts @@ -13,6 +13,7 @@ import { shuffle, sleep } from './util' import NodeCache from 'node-cache' import Queue from 'queue-promise' import { debug } from '.' +import { slayerLevels } from './cleaners/skyblock/slayers' // don't update the user for 3 minutes const recentlyUpdated = new NodeCache({ @@ -77,6 +78,23 @@ function getMemberSkillAttributes(member: CleanMember): StringNumber { return skillAttributes } +function getMemberSlayerAttributes(member: CleanMember): StringNumber { + const slayerAttributes: StringNumber = { + slayer_total_xp: member.slayers.xp, + slayer_total_kills: member.slayers.kills, + } + + for (const slayer of member.slayers.bosses) { + slayerAttributes[`slayer_${slayer.name}_total_xp`] = slayer.xp + slayerAttributes[`slayer_${slayer.name}_total_kills`] = slayer.kills + for (const tier of slayer.tiers) { + slayerAttributes[`slayer_${slayer.name}_${tier.tier}_kills`] = tier.kills + } + } + + return slayerAttributes +} + function getMemberLeaderboardAttributes(member: CleanMember): StringNumber { // if you want to add a new leaderboard for member attributes, add it here (and getAllLeaderboardAttributes) return { @@ -89,6 +107,9 @@ function getMemberLeaderboardAttributes(member: CleanMember): StringNumber { // skill leaderboards ...getMemberSkillAttributes(member), + // slayer leaderboards + ...getMemberSlayerAttributes(member), + fairy_souls: member.fairy_souls.total, first_join: member.first_join, purse: member.purse, @@ -115,6 +136,25 @@ export async function fetchAllLeaderboardsCategorized(): Promise<{ [ category: s return categorizedLeaderboards } +/** Fetch the raw names for the slayer leaderboards */ +export async function fetchSlayerLeaderboards(): Promise<string[]> { + const rawSlayerNames = await constants.fetchSlayers() + let leaderboardNames: string[] = [ + 'slayer_total_xp', + 'slayer_total_kills' + ] + + // we use the raw names (zombie, spider, wolf) instead of the clean names (revenant, tarantula, sven) because the raw names are guaranteed to never change + for (const slayerNameRaw of rawSlayerNames) { + leaderboardNames.push(`slayer_${slayerNameRaw}_total_xp`) + leaderboardNames.push(`slayer_${slayerNameRaw}_total_kills`) + for (let slayerTier = 1; slayerTier <= slayerLevels; slayerTier ++) { + leaderboardNames.push(`slayer_${slayerNameRaw}_${slayerTier}_kills`) + } + } + + return leaderboardNames +} /** Fetch the names of all the leaderboards */ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { @@ -128,6 +168,9 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { // skill leaderboards ...(await constants.fetchSkills()).map(value => `skill_${value}`), + // slayer leaderboards + ...await fetchSlayerLeaderboards(), + 'fairy_souls', 'first_join', 'purse', @@ -265,6 +308,7 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu await constants.addCollections(member.collections.map(coll => coll.name)) await constants.addSkills(member.skills.map(skill => skill.name)) await constants.addZones(member.visited_zones.map(zone => zone.name)) + await constants.addSlayers(member.slayers.bosses.map(s => s.raw_name)) if (debug) console.log('done constants..') @@ -306,14 +350,14 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu if (debug) console.log('added member to leaderboards', member.username, leaderboardAttributes) } -const queue = new Queue({ +const leaderboardUpdateQueue = new Queue({ concurrent: 1, interval: 500 }) /** Queue an update for the member's leaderboard data on the server if applicable */ export async function queueUpdateDatabaseMember(member: CleanMember, profile: CleanFullProfile): Promise<void> { - queue.enqueue(async() => await updateDatabaseMember(member, profile)) + leaderboardUpdateQueue.enqueue(async() => await updateDatabaseMember(member, profile)) } |