aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/experimentation.ts
blob: d81fb3dc696c5b5668c0747e6794b8525c12fef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import typedHypixelApi from 'typed-hypixel-api'
import { ExperimentationGame as ApiExperimentationGame } from 'typed-hypixel-api/build/responses/skyblock/_profile_member'
import * as constants from '../../constants.js'

export interface ExperimentationGame {
	/** `superpairs`, `chronomatron` or `ultrasequencer`.  */
	id: string
	last_attempt: number | undefined
	last_claimed: number | undefined
	types: {
		attempts: number
		claims: number
		best_score: number
	}[]
}

const EXPERIMENTATION_GAME_IDS = {
	pairings: 'superpairs',
	simon: 'chronomatron',
	numbers: 'ultrasequencer'
} as const

// this should be in skyblock-constants, but i don't expect hypixel to add new experimentation games
const EXPERIMENTATION_GAME_TYPES_COUNT: Record<typeof EXPERIMENTATION_GAME_IDS[keyof typeof EXPERIMENTATION_GAME_IDS], number> = {
	superpairs: 6,
	chronomatron: 5,
	ultrasequencer: 3
}

export interface Experimentation {
	games: ExperimentationGame[]
}

function cleanGame(apiId: string, game: ApiExperimentationGame | undefined): ExperimentationGame {
	const gameId = EXPERIMENTATION_GAME_IDS[apiId]

	if (!game)
		game = {}

	const types: ExperimentationGame['types'] = []

	for (let i = 0; i < EXPERIMENTATION_GAME_TYPES_COUNT[gameId]; i++) {
		const type_attempts = game[`attempts_${i}`] ?? 0
		const type_claims = game[`claims_${i}`] ?? 0
		const type_best_score = game[`best_score_${i}`] ?? 0

		types.push({
			attempts: type_attempts,
			claims: type_claims,
			best_score: type_best_score
		})
	}

	return {
		id: gameId,
		last_attempt: game.last_attempt || undefined,
		last_claimed: game.last_claimed || undefined,
		types
	}
}

export async function cleanExperimentation(data: typedHypixelApi.SkyBlockProfileMember): Promise<Experimentation> {
	return {
		games: [
			cleanGame('pairings', data.experimentation?.pairings),
			cleanGame('simon', data.experimentation?.simon),
			cleanGame('numbers', data.experimentation?.numbers)
		]
	}
}