-
Notifications
You must be signed in to change notification settings - Fork 25
/
heroes.js
199 lines (176 loc) · 5.4 KB
/
heroes.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// God tier reference: https://www.reddit.com/r/btd6/comments/eh47t8/how_hero_xp_works_in_game_v20/
const gHelper = require('../helpers/general.js');
const bHelper = require('./bloons-general');
const heroes = require('../jsons/heroes.json');
const gerrysShop = require('../jsons/geraldos_shop.json');
BASE_XP_TO_GET_LEVEL = [
null, // Slot for non-existent level-0
0,
180,
460,
1000,
1860,
3280,
5180,
8320,
9380,
13620,
16380,
14400,
16650,
14940,
16380,
17820,
19260,
20700,
16470,
17280,
];
LEVELING_MAP_DIFFICULTY_MODIFIERS = {
BEGINNER: 1,
INTERMEDIATE: 1.1,
ADVANCED: 1.2,
EXPERT: 1.3,
};
function accumulatedXpCurve(
startingRound,
mapDifficulty,
energizerAcquiredRound,
mk
) {
mapSpecificLevelingMultiplier =
LEVELING_MAP_DIFFICULTY_MODIFIERS[mapDifficulty.toUpperCase()];
xpGains = [];
for (round = 0; round < 100; round++) {
if (round == 0) {
baseXpGainGain = 0;
} else if (round == 1) {
baseXpGainGain += 40;
} else if (round <= 20) {
baseXpGainGain += 20;
} else if (round <= 50) {
baseXpGainGain += 40;
} else {
baseXpGainGain += 90;
}
energizerFactor = round >= energizerAcquiredRound ? 1.5 : 1;
mkFactor = mk ? 1.1 * 1.05 * 1.08 : 1;
if (round == startingRound - 1) {
xpGains.push(0);
} else if (round < startingRound) {
xpGains.push(null);
} else {
xpGains.push(
baseXpGainGain * mapSpecificLevelingMultiplier * energizerFactor * mkFactor
);
}
}
acc = 0;
return xpGains.map((xpGain) =>
xpGain == null ? null : (acc = acc + xpGain)
);
}
/**
* Returns an array as to how much xp a hero must get (cumulatively) to reach a certain level
* e.g. returned_arr = [null, 0, 9, 180, 640, 1640, 3500, 6780, ...]
* means that you can find the cumulative xp needed to reach level n by simply doing returned_arr[n]
* @param {string} hero
* @returns {Array[int]}
*/
function heroLevelXpRequirements(hero) {
heroSpecificLevelingMultiplier = heroes[hero]['levelModifier'];
if (!heroSpecificLevelingMultiplier) throw `${hero} does not have "levelModifier" entry in heroes.json`;
acc = 0;
return BASE_XP_TO_GET_LEVEL.map((bxp) => {
return bxp == null
? null
: (acc = acc + Math.round(bxp * heroSpecificLevelingMultiplier));
//: (acc = acc + Math.ceil(bxp * heroSpecificLevelingMultiplier));
});
}
function levelingChart(hero, startingRound, mapDifficulty, mk) {
heroXpGains = heroLevelXpRequirements(hero);
accumulatedXp = accumulatedXpCurve(
startingRound,
mapDifficulty,
Infinity, // no energizer
mk
);
return [null].concat(
accumulatedXp.map((axp) => {
if (axp == null) return null;
return heroXpGains.map((txp) => (txp == null ? null : txp - axp));
})
);
}
/**
* Returns an array as to which round a hero will reach which level
* e.g. returned_arr = [null, 7, 9, 11, 14, 19, ...]
* means that you can find the round a hero will reach level n by simply doing returned_arr[n]
* @param {string} hero
* @param {int} startingRound
* @param {string} mapDifficulty
* @param {int} energizerAcquiredRound
* @returns {Array[int]}
*/
function levelingCurve(
hero,
startingRound,
mapDifficulty,
energizerAcquiredRound = Infinity,
mk = false
) {
accumulatedXp = accumulatedXpCurve(
startingRound,
mapDifficulty,
energizerAcquiredRound,
mk
);
return heroLevelXpRequirements(hero).map((txp) => {
if (txp == null) return null;
acquiredRound =
accumulatedXp.findIndex((axp) => {
return axp == null ? false : axp - txp >= 0;
}) + 1;
// findIndex returns -1 if not found, so +1 is 0, which is falsy
return acquiredRound
? acquiredRound
: gHelper.numberAsCost(txp - accumulatedXp[99]);
});
}
function costOfHero(hero, difficulty, numDiscounts, mk) {
const mediumCost = heroes[hero].cost;
if (!mediumCost) throw `${hero} does not have an entry in heroes.json`;
return bHelper.heroDifficultyDiscountPriceMult(mediumCost, difficulty, numDiscounts, mk);
}
function costOfGerryShopItem(item, difficulty) {
const mediumCost = gerrysShop[item];
if (!mediumCost) throw `${item} does not have an entry in geraldos_shop.json`;
return bHelper.roundEven5(bHelper.rawDifficultyMult(mediumCost, difficulty));
}
function isHero(candidate) {
if (!candidate || !gHelper.is_str(candidate)) return false;
return allHeroes().includes(candidate.toLowerCase());
}
function allHeroes() {
const heroes = Aliases.getAliasGroupsFromSameFileAs('EZILI');
return heroes.map((ag) => ag.canonical);
}
function isGerrysShopItem(candidate) {
if (!candidate || !gHelper.is_str(candidate)) return false;
return allGerrysShopItems().includes(candidate.toLowerCase());
}
function allGerrysShopItems() {
const items = Aliases.getAliasGroupsFromSameFileAs('FERTILIZER');
return items.map((ag) => ag.canonical);
}
module.exports = {
levelingCurve,
levelingChart,
costOfHero,
costOfGerryShopItem,
isHero,
allHeroes,
allGerrysShopItems,
isGerrysShopItem,
};