aboutsummaryrefslogtreecommitdiff
path: root/build/cleaners/skyblock/slayers.js
blob: 8575d4387e8838d9ea3f9078faaf83b74a8eae85 (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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanSlayers = exports.slayerLevels = void 0;
exports.slayerLevels = 5;
const SLAYER_NAMES = {
    spider: 'tarantula',
    zombie: 'revenant',
    wolf: 'sven'
};
function cleanSlayers(data) {
    var _a, _b;
    const slayers = [];
    const slayersDataRaw = data === null || data === void 0 ? void 0 : data.slayer_bosses;
    let totalXp = 0;
    let totalKills = 0;
    for (const slayerNameRaw in slayersDataRaw) {
        const slayerDataRaw = slayersDataRaw[slayerNameRaw];
        // convert name provided by api (spider) to the real name (tarantula)
        const slayerName = SLAYER_NAMES[slayerNameRaw];
        const slayerXp = (_a = slayerDataRaw.xp) !== null && _a !== void 0 ? _a : 0;
        let slayerKills = 0;
        const slayerTiers = [];
        for (const slayerDataKey in slayerDataRaw) {
            // if a key starts with boss_kills_tier_ (boss_kills_tier_1), get the last number
            if (slayerDataKey.startsWith('boss_kills_tier_')) {
                const slayerTierRaw = parseInt(slayerDataKey.substr('boss_kills_tier_'.length));
                const slayerTierKills = (_b = slayerDataRaw[slayerDataKey]) !== null && _b !== void 0 ? _b : 0;
                // add 1 since hypixel is using 0 indexed tiers
                const slayerTier = slayerTierRaw + 1;
                slayerTiers.push({
                    kills: slayerTierKills,
                    tier: slayerTier
                });
                // count up the total number of kills for this slayer
                if (slayerTierKills)
                    slayerKills += slayerTierKills;
            }
        }
        // if the slayer tier length is less than the max, add more empty ones
        while (slayerTiers.length < exports.slayerLevels)
            slayerTiers.push({
                tier: slayerTiers.length + 1,
                kills: 0
            });
        const slayer = {
            name: slayerName,
            raw_name: slayerNameRaw,
            tiers: slayerTiers,
            xp: slayerXp !== null && slayerXp !== void 0 ? slayerXp : 0,
            kills: slayerKills
        };
        slayers.push(slayer);
        // add the xp and kills from this slayer to the total xp
        if (slayerXp)
            totalXp += slayerXp;
        if (slayerKills)
            totalKills += slayerKills;
    }
    return {
        xp: totalXp,
        kills: totalKills,
        bosses: slayers
    };
}
exports.cleanSlayers = cleanSlayers;