Calculating max purchase takes into account max level for Hacknet Nodes

This commit is contained in:
Daniel Xie 2017-05-30 15:54:26 -05:00
parent 2569a4819d
commit d5ad17c84b

@ -215,20 +215,21 @@ updateHacknetNodesMultiplierButtons = function() {
getMaxNumberLevelUpgrades = function(nodeObj) {
if (nodeObj.calculateLevelUpgradeCost(1) > Player.money) {return 0;}
var min = 1;
var max = 199;
var max = CONSTANTS.HacknetNodeMaxLevel-1;
var levelsToMax = CONSTANTS.HacknetNodeMaxLevel - nodeObj.level;
while (min <= max) {
var curr = (min + max) / 2 | 0;
if (curr != 200 &&
if (curr != CONSTANTS.HacknetNodeMaxLevel &&
nodeObj.calculateLevelUpgradeCost(curr) < Player.money &&
nodeObj.calculateLevelUpgradeCost(curr+1) > Player.money) {
return curr;
return Math.min(levelsToMax, curr);
} else if (nodeObj.calculateLevelUpgradeCost(curr) > Player.money) {
max = curr - 1;
} else if (nodeObj.calculateLevelUpgradeCost(curr) < Player.money) {
min = curr + 1;
} else {
return curr;
return Math.min(levelsToMax, curr);
}
}
}