-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
66 lines (52 loc) · 1.58 KB
/
utils.js
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
const UpgradeCost = {
// example: LEVEL_TEN = cost for an upgrade from level 9 to level 10
LEVEL_ONE: 0,
LEVEL_TWO: 5,
LEVEL_THREE: 20,
LEVEL_FOUR: 50,
LEVEL_FIVE: 150,
LEVEL_SIX: 400,
LEVEL_SEVEN: 1000,
LEVEL_EIGHT: 2000,
LEVEL_NINE: 4000,
LEVEL_TEN: 8000,
LEVEL_ELEVEN: 15000,
LEVEL_TWELVE: 35000,
LEVEL_THIRTEEN: 75000,
LEVEL_FOURTEEN: 100000,
}
const Rarity = {
// number describes how many level upgrades are possible from the basic card
COMMON: 14,
RARE: 12,
EPIC: 9,
LEGENDARY: 6,
CHAMPION: 4
}
class Utils {
static totalCardValue(currentLevel, rarity) {
let cost = 0;
let startLevel = 15 - rarity;
for (let i = startLevel; i < currentLevel; i++) {
cost += Object.values(UpgradeCost)[i].valueOf();
}
if (rarity === Rarity.EPIC && currentLevel >= 7) {
cost -= 600;
} else if (rarity === Rarity.LEGENDARY && currentLevel >= 10) {
cost -= 3000;
}
return cost;
}
static getCorrectLevel(level, rarity) {
// start level of a card = 15 - rarity
// correct level = start level + sent Level - 1
return 15 - rarity + level - 1;
}
static cardValueToString(cards) {
let sortedMap = new Map([...cards.entries()].sort((a, b) => b[1] - a[1]));
let result = "Gold spent per card (in descending order): \n";
sortedMap.forEach((value, name) => result += name + ": " + value + "\n");
return result;
}
}
module.exports = {Utils, Rarity, UpgradeCost}