From 85b3a261503b074bb052ad814ce436b9eae18f41 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 12 Apr 2022 18:18:09 +0000 Subject: [PATCH 1/2] start working on adding quests --- src/cleaners/skyblock/member.ts | 8 ++-- src/cleaners/skyblock/objectives.ts | 20 -------- src/cleaners/skyblock/profileUpgrades.ts | 38 +++++++++++++++ src/cleaners/skyblock/quests.ts | 61 ++++++++++++++++++++++++ src/hypixelApi.ts | 1 - 5 files changed, 103 insertions(+), 25 deletions(-) delete mode 100644 src/cleaners/skyblock/objectives.ts create mode 100644 src/cleaners/skyblock/profileUpgrades.ts create mode 100644 src/cleaners/skyblock/quests.ts diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 57462ed..6abb169 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -3,7 +3,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' @@ -36,7 +36,7 @@ export interface CleanMember extends CleanBasicMember { minions: CleanMinion[] fairySouls: FairySouls inventories?: Inventories - objectives: Objective[] + quests: Quest[] skills: Skill[] zones: Zone[] collections: Collection[] @@ -99,7 +99,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, collections: cleanCollections(member), @@ -125,7 +125,7 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { minions: CleanMinion[] fairySouls: FairySouls inventories?: Inventories - objectives: Objective[] + quests: Quest[] skills: Skill[] zones: Zone[] collections: Collection[] 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/profileUpgrades.ts b/src/cleaners/skyblock/profileUpgrades.ts new file mode 100644 index 0000000..dc7951f --- /dev/null +++ b/src/cleaners/skyblock/profileUpgrades.ts @@ -0,0 +1,38 @@ +import typedHypixelApi from 'typed-hypixel-api' + +export interface ProfileUpgrade { + id: string +} + +export interface ProfileUpgrades { + upgrades: { + + } +} + +export function cleanBank(data: typedHypixelApi.SkyBlockProfile): Bank { + let history: BankHistoryItem[] = [] + + if (data?.banking?.transactions) { + let bankBalance = Math.round(data.banking.balance * 10) / 10 + // we go in reverse so we can simulate the bank transactions + for (const transaction of data.banking.transactions.sort((a, b) => b.timestamp - a.timestamp)) { + const change = transaction.action === 'DEPOSIT' ? transaction.amount : -transaction.amount + history.push({ + change: Math.round(change * 10) / 10, + total: Math.round(bankBalance * 10) / 10, + timestamp: transaction.timestamp, + name: transaction.initiator_name, + }) + // since we're going in reverse, we remove from the total balance when adding to the history + bankBalance -= change + } + } + + // history.reverse() + + return { + balance: data?.banking?.balance ? Math.round(data.banking.balance * 10) / 10 : undefined, + history + } +} \ No newline at end of file diff --git a/src/cleaners/skyblock/quests.ts b/src/cleaners/skyblock/quests.ts new file mode 100644 index 0000000..126198a --- /dev/null +++ b/src/cleaners/skyblock/quests.ts @@ -0,0 +1,61 @@ +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 +} + +export function cleanQuests(data: typedHypixelApi.SkyBlockProfileMember): Quest[] { + // objective: [ quests ] + const possibleAttachedQuests: Record = {} + for (const [objectiveId, objectiveValue] of Object.entries(data.objectives)) { + possibleAttachedQuests[objectiveId] = [] + // figure out what quests this objective could belong to + 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[objectiveId].push(questId) + } + } + } + } + if (objectiveValue.status === 'ACTIVE') { + for (const [questId, questValue] of Object.entries(data.quests)) { + if (questValue.status === 'ACTIVE') { + console.log('active objective', objectiveId, 'could belong to quest', questId) + possibleAttachedQuests[objectiveId].push(questId) + } + } + } + } + + console.log('possibleAttachedQuests', possibleAttachedQuests) + + + return [] +} diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index 42d4f74..5cd5db1 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 From bd06aa547a4d2b1381f04256dc92cac88e13a2d2 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 12 Apr 2022 23:55:03 +0000 Subject: [PATCH 2/2] quest stuff --- src/cleaners/skyblock/profileUpgrades.ts | 38 ------------------------ src/cleaners/skyblock/quests.ts | 24 ++++++++------- 2 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 src/cleaners/skyblock/profileUpgrades.ts diff --git a/src/cleaners/skyblock/profileUpgrades.ts b/src/cleaners/skyblock/profileUpgrades.ts deleted file mode 100644 index dc7951f..0000000 --- a/src/cleaners/skyblock/profileUpgrades.ts +++ /dev/null @@ -1,38 +0,0 @@ -import typedHypixelApi from 'typed-hypixel-api' - -export interface ProfileUpgrade { - id: string -} - -export interface ProfileUpgrades { - upgrades: { - - } -} - -export function cleanBank(data: typedHypixelApi.SkyBlockProfile): Bank { - let history: BankHistoryItem[] = [] - - if (data?.banking?.transactions) { - let bankBalance = Math.round(data.banking.balance * 10) / 10 - // we go in reverse so we can simulate the bank transactions - for (const transaction of data.banking.transactions.sort((a, b) => b.timestamp - a.timestamp)) { - const change = transaction.action === 'DEPOSIT' ? transaction.amount : -transaction.amount - history.push({ - change: Math.round(change * 10) / 10, - total: Math.round(bankBalance * 10) / 10, - timestamp: transaction.timestamp, - name: transaction.initiator_name, - }) - // since we're going in reverse, we remove from the total balance when adding to the history - bankBalance -= change - } - } - - // history.reverse() - - return { - balance: data?.banking?.balance ? Math.round(data.banking.balance * 10) / 10 : undefined, - history - } -} \ No newline at end of file diff --git a/src/cleaners/skyblock/quests.ts b/src/cleaners/skyblock/quests.ts index 126198a..e3dcc14 100644 --- a/src/cleaners/skyblock/quests.ts +++ b/src/cleaners/skyblock/quests.ts @@ -25,12 +25,16 @@ export interface Quest { objectives: Objective } +/** A record of objective ids to quest ids */ +let knownAttachedQuests: Record = {} + export function cleanQuests(data: typedHypixelApi.SkyBlockProfileMember): Quest[] { - // objective: [ quests ] - const possibleAttachedQuests: Record = {} for (const [objectiveId, objectiveValue] of Object.entries(data.objectives)) { - possibleAttachedQuests[objectiveId] = [] - // figure out what quests this objective could belong to + 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') { @@ -39,7 +43,7 @@ export function cleanQuests(data: typedHypixelApi.SkyBlockProfileMember): Quest[ && objectiveValue.completed_at <= questValue.completed_at ) { // console.log('objective', objectiveId, 'could belong to quest', questId) - possibleAttachedQuests[objectiveId].push(questId) + possibleAttachedQuests.push(questId) } } } @@ -47,15 +51,15 @@ export function cleanQuests(data: typedHypixelApi.SkyBlockProfileMember): Quest[ if (objectiveValue.status === 'ACTIVE') { for (const [questId, questValue] of Object.entries(data.quests)) { if (questValue.status === 'ACTIVE') { - console.log('active objective', objectiveId, 'could belong to quest', questId) - possibleAttachedQuests[objectiveId].push(questId) + possibleAttachedQuests.push(questId) } } } + if (possibleAttachedQuests.length === 1) { + knownAttachedQuests[objectiveId] = possibleAttachedQuests[0] + console.log('Figured out that', objectiveId, 'belongs to quest', possibleAttachedQuests[0]) + } } - console.log('possibleAttachedQuests', possibleAttachedQuests) - - return [] }