diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 9d68796..94cf9fb 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -5,7 +5,7 @@ import { cleanCoopInvitation, CoopInvitation } from './coopInvitation.js' import { cleanCollections, Collection } from './collections.js' import { cleanInventories, Inventories } from './inventory.js' import { cleanFairySouls, FairySouls } from './fairysouls.js' -import { cleanObjectives, Objective } from './objectives.js' +import { cleanQuests, Quest } from './quests.js' import { CleanFullProfileBasicMembers } from './profile.js' import { cleanProfileStats, StatItem } from './stats.js' import { CleanMinion, cleanMinions } from './minions.js' @@ -39,7 +39,7 @@ interface ExtraCleanMemberFields { minions: CleanMinion[] fairySouls: FairySouls inventories?: Inventories - objectives: Objective[] + quests: Quest[] skills: Skills zones: Zone[] collections: Collection[] @@ -110,8 +110,7 @@ export async function cleanSkyBlockProfileMemberResponse(member: typedHypixelApi minions: await minionsPromise, fairySouls: fairySouls, inventories: inventoriesPromise ? await inventoriesPromise : undefined, - objectives: cleanObjectives(member), - + quests: cleanQuests(member), skills: await skillsPromise, zones: await zonesPromise, diff --git a/src/cleaners/skyblock/objectives.ts b/src/cleaners/skyblock/objectives.ts deleted file mode 100644 index 62f7b8b..0000000 --- a/src/cleaners/skyblock/objectives.ts +++ /dev/null @@ -1,20 +0,0 @@ -import typedHypixelApi from 'typed-hypixel-api' - - -export interface Objective { - name: string - completed: boolean -} - -export function cleanObjectives(data: typedHypixelApi.SkyBlockProfileMember): Objective[] { - const rawObjectives = data?.objectives || {} - const objectives: Objective[] = [] - for (const [name, value] of Object.entries(rawObjectives)) { - - objectives.push({ - name: name, - completed: value.status === 'COMPLETE', - }) - } - return objectives -} diff --git a/src/cleaners/skyblock/quests.ts b/src/cleaners/skyblock/quests.ts new file mode 100644 index 0000000..e3dcc14 --- /dev/null +++ b/src/cleaners/skyblock/quests.ts @@ -0,0 +1,65 @@ +import typedHypixelApi from 'typed-hypixel-api' + +/* +Each quest has a number of attached objectives that must be completed in order for the quest to be counted as complete. Quests show when they started and when they ended. All attached objectives will be in between these times. + +An objective has a number called the "progress". This usually represents how much of the objective item has been collected, so if the objective requires you to collect logs the progress would be the amount collected. If the objective doesn't require you to collect items, this will be 0. + +What we want to know: +- The attached objectives for each quest +- The minimum required progress for each objective for be completed +*/ + +export interface Objective { + id: string + completed: boolean + progress: { + done: number + required: number + } | null +} + +export interface Quest { + id: string + completed: boolean + objectives: Objective +} + +/** A record of objective ids to quest ids */ +let knownAttachedQuests: Record = {} + +export function cleanQuests(data: typedHypixelApi.SkyBlockProfileMember): Quest[] { + for (const [objectiveId, objectiveValue] of Object.entries(data.objectives)) { + if (objectiveId in knownAttachedQuests) + continue + + // here we try to figure out what quests this objective could belong to + let possibleAttachedQuests: string[] = [] + if (objectiveValue.status === 'COMPLETE') { + for (const [questId, questValue] of Object.entries(data.quests)) { + if (questValue.status === 'COMPLETE') { + if ( + objectiveValue.completed_at >= questValue.activated_at + && objectiveValue.completed_at <= questValue.completed_at + ) { + // console.log('objective', objectiveId, 'could belong to quest', questId) + possibleAttachedQuests.push(questId) + } + } + } + } + if (objectiveValue.status === 'ACTIVE') { + for (const [questId, questValue] of Object.entries(data.quests)) { + if (questValue.status === 'ACTIVE') { + possibleAttachedQuests.push(questId) + } + } + } + if (possibleAttachedQuests.length === 1) { + knownAttachedQuests[objectiveId] = possibleAttachedQuests[0] + console.log('Figured out that', objectiveId, 'belongs to quest', possibleAttachedQuests[0]) + } + } + + return [] +} diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index d229bc1..f8b1a7f 100644 --- a/src/hypixelApi.ts +++ b/src/hypixelApi.ts @@ -3,7 +3,6 @@ */ import { shuffle, sleep } from './util.js' import typedHypixelApi from 'typed-hypixel-api' -import { Agent } from 'https' if (!process.env.hypixel_keys) // if there's no hypixel keys in env, run dotenv