hypixel-api-reborn 11.3.3 → 11.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,174 +0,0 @@
1
- const { divide } = require('../../utils');
2
-
3
- /**
4
- * Wool Wars Class
5
- */
6
- class WoolWars {
7
- /**
8
- * Constructor
9
- * @param {Record<string,unknown>} data Data from API
10
- */
11
- constructor(data) {
12
- /**
13
- * Sheep layers, similar to prestige
14
- * @type {number}
15
- */
16
- this.layers = data.progression?.available_layers || 0;
17
- /**
18
- * Wool Wars XP
19
- * @type {number}
20
- */
21
- this.xp = data.progression?.experience || 0;
22
- /**
23
- * Wool Wars Decimal Level
24
- * @type {number}
25
- */
26
- this.exactLevel = WoolWars.convertXPToLevel(this.xp);
27
- /**
28
- * Wool wars level (as shown in game)
29
- * @type {number}
30
- */
31
- this.level = Math.floor(this.exactLevel);
32
- /**
33
- * Coins
34
- * @type {number}
35
- */
36
- this.coins = data.coins || 0;
37
- /**
38
- * Wins
39
- * @type {number}
40
- */
41
- this.wins = data.wins || 0;
42
- /**
43
- * gamesPlayed
44
- * @type {number}
45
- */
46
- this.gamesPlayed = data.games_played || 0;
47
- /**
48
- * woolsPlaced
49
- * @type {number}
50
- */
51
- this.woolsPlaced = data.wool_placed || 0;
52
- /**
53
- * blocksBroken
54
- * @type {number}
55
- */
56
- this.blocksBroken = data.blocks_broken || 0;
57
- /**
58
- * placeBreakRatio
59
- * @type {number}
60
- */
61
- this.placeBreakRatio = divide(this.woolsPlaced, this.blocksBroken);
62
- /**
63
- * kills
64
- * @type {number}
65
- */
66
- this.kills = data.kills || 0;
67
- /**
68
- * deaths
69
- * @type {number}
70
- */
71
- this.deaths = data.deaths || 0;
72
- /**
73
- * KDRatio
74
- * @type {number}
75
- */
76
- this.KDRatio = divide(this.kills, this.deaths);
77
- /**
78
- * assists
79
- * @type {number}
80
- */
81
- this.assists = data.assists || 0;
82
- /**
83
- * powerups
84
- * @type {number}
85
- */
86
- this.powerups = data.powerups_gotten || 0;
87
- /**
88
- * Selected class, or NONE if field isn't present in API for some reason
89
- * @type {'ASSAULT'|'TANK'|'GOLEM'|'SWORDSMAN'|'ENGINEER'|'ARCHER'|'NONE'}
90
- */
91
- this.selectedClass = data.wool_wars?.selected_class || 'NONE';
92
- this.stats = {
93
- assault: WoolWars.generateStatsFor(data.wool_wars?.stats, 'assault'),
94
- tank: WoolWars.generateStatsFor(data.wool_wars?.stats, 'tank'),
95
- golem: WoolWars.generateStatsFor(data.wool_wars?.stats, 'golem'),
96
- swordsman: WoolWars.generateStatsFor(data.wool_wars?.stats, 'swordsman'),
97
- engineer: WoolWars.generateStatsFor(data.wool_wars?.stats, 'engineer'),
98
- archer: WoolWars.generateStatsFor(data.wool_wars?.stats, 'archer')
99
- };
100
- /**
101
- * Owned Cosmetics
102
- * @type {string[]}
103
- */
104
- this.ownedCosmetics = data.packages || [];
105
- /**
106
- * Private Games config
107
- * @type {PrivateGamesConfig}
108
- */
109
- this.privateGamesConfig = data.privategames || {};
110
- }
111
- /**
112
- * Converts XP to Level
113
- * @param {number} exp xp
114
- * @return {number}
115
- */
116
- static convertXPToLevel(exp) {
117
- const minimalExp = [0, 1e3, 3e3, 6e3, 1e4, 15e3];
118
- const baseLevel = minimalExp.length;
119
- const baseExp = minimalExp[minimalExp.length - 1];
120
- const expToLevel100 = 49e4;
121
- if (exp < baseExp) return minimalExp.findIndex((x) => exp < x);
122
- const theoreticalLevel = (exp - baseExp) / 5e3 + baseLevel;
123
- if (100 < theoreticalLevel) return 100 + this.convertXPToLevel(exp - expToLevel100);
124
- return theoreticalLevel;
125
- }
126
- /**
127
- * Generates stats per class/overall
128
- * @param {Record<string, any>} data data
129
- * @param {string} [_class=''] Class
130
- * @return {WoolWarsStats}
131
- */
132
- static generateStatsFor(data, _class) {
133
- // N.B i called it _class instead of class because reserved keyword
134
-
135
- // eslint-disable-next-line no-underscore-dangle
136
- const workingData = (_class ? data?.classes?.[_class] : data) || {};
137
- return {
138
- wins: workingData.wins || 0,
139
- gamesPlayed: workingData.games_played || 0,
140
- woolsPlaced: workingData.wool_placed || 0,
141
- blocksBroken: workingData.blocks_broken || 0,
142
- placeBreakRatio: divide(workingData.wool_placed || 0, workingData.blocks_broken || 0),
143
- kills: workingData.kills || 0,
144
- deaths: workingData.deaths || 0,
145
- KDRatio: divide(workingData.kills, workingData.deaths),
146
- assists: workingData.assists || 0,
147
- powerups: workingData.powerups_gotten || 0
148
- };
149
- }
150
- }
151
- /**
152
- * @typedef {Object} PrivateGamesConfig NB. There could be more fields
153
- * @property {boolean} one_hit_one_kill One hit one kill
154
- * @property {'Enabled'|'Disabled'} rainbow_wool Rainbow wool
155
- * @property {string} health_buff Health Buff
156
- * @property {string} game_speed Game speed
157
- * @property {string} speed Player speed
158
- * @property {'Enabled'|'Disabled'} no_class No class
159
- * @property {boolean} respawn_enable Respawning enabled
160
- */
161
- /**
162
- * @typedef {Object} WoolWarsStats
163
- * @property {number} wins wins
164
- * @property {number} gamesPlayed games played
165
- * @property {number} woolsPlaced wools placed
166
- * @property {number} blocksBroken blocks broken
167
- * @property {number} placeBreakRatio broken blocks to placed wool ratio
168
- * @property {number} kills kills
169
- * @property {number} deaths deaths
170
- * @property {number} KDRatio KDR
171
- * @property {number} assists assists (not included in KDR)
172
- * @property {number} powerups number of powerups picked up
173
- */
174
- module.exports = WoolWars;