2017-04-26 23:51:00 +02:00
|
|
|
/* HacknetNode.js */
|
2017-05-17 05:50:32 +02:00
|
|
|
function hacknetNodesInit() {
|
|
|
|
var mult1x = document.getElementById("hacknet-nodes-1x-multiplier");
|
|
|
|
mult1x.addEventListener("click", function() {
|
|
|
|
hacknetNodePurchaseMultiplier = 1;
|
|
|
|
updateHacknetNodesMultiplierButtons();
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
var mult5x = document.getElementById("hacknet-nodes-5x-multiplier");
|
|
|
|
mult5x.addEventListener("click", function() {
|
|
|
|
hacknetNodePurchaseMultiplier = 5;
|
|
|
|
updateHacknetNodesMultiplierButtons();
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
var mult10x = document.getElementById("hacknet-nodes-10x-multiplier");
|
|
|
|
mult10x.addEventListener("click", function() {
|
|
|
|
hacknetNodePurchaseMultiplier = 10;
|
|
|
|
updateHacknetNodesMultiplierButtons();
|
|
|
|
updateHacknetNodesContent();
|
2017-07-25 04:51:03 +02:00
|
|
|
return false;
|
2017-05-17 05:50:32 +02:00
|
|
|
});
|
|
|
|
var multMax = document.getElementById("hacknet-nodes-max-multiplier");
|
|
|
|
multMax.addEventListener("click", function() {
|
|
|
|
hacknetNodePurchaseMultiplier = 0;
|
|
|
|
updateHacknetNodesMultiplierButtons();
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", hacknetNodesInit, false);
|
|
|
|
|
2017-04-26 23:51:00 +02:00
|
|
|
function HacknetNode(name) {
|
|
|
|
this.level = 1;
|
2017-04-27 22:02:58 +02:00
|
|
|
this.ram = 1; //GB
|
2017-07-25 04:51:03 +02:00
|
|
|
this.cores = 1;
|
|
|
|
|
2017-04-26 23:51:00 +02:00
|
|
|
this.name = name;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-26 23:51:00 +02:00
|
|
|
this.totalMoneyGenerated = 0;
|
|
|
|
this.onlineTimeSeconds = 0;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-26 23:51:00 +02:00
|
|
|
this.moneyGainRatePerSecond = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HacknetNode.prototype.updateMoneyGainRate = function() {
|
|
|
|
//How much extra $/s is gained per level
|
2017-04-27 22:02:58 +02:00
|
|
|
var gainPerLevel = CONSTANTS.HacknetNodeMoneyGainPerLevel;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
|
|
|
this.moneyGainRatePerSecond = (this.level * gainPerLevel) *
|
|
|
|
Math.pow(1.035, this.ram-1) *
|
2017-07-13 18:54:29 +02:00
|
|
|
((this.cores + 5) / 6) * Player.hacknet_node_money_mult;
|
2017-04-27 22:02:58 +02:00
|
|
|
if (isNaN(this.moneyGainRatePerSecond)) {
|
2017-05-15 17:13:21 +02:00
|
|
|
this.moneyGainRatePerSecond = 0;
|
|
|
|
dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer");
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-10 19:42:46 +02:00
|
|
|
updateTotalHacknetProduction();
|
2017-04-26 23:51:00 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 23:22:54 +02:00
|
|
|
HacknetNode.prototype.calculateLevelUpgradeCost = function(levels=1) {
|
|
|
|
if (levels < 1) {return 0;}
|
2017-04-27 22:02:58 +02:00
|
|
|
var mult = CONSTANTS.HacknetNodeUpgradeLevelMult;
|
2017-07-25 04:51:03 +02:00
|
|
|
var totalMultiplier = 0; //Summed
|
2017-05-16 23:22:54 +02:00
|
|
|
var currLevel = this.level;
|
|
|
|
for (var i = 0; i < levels; ++i) {
|
2017-07-25 04:51:03 +02:00
|
|
|
totalMultiplier += Math.pow(mult, currLevel);
|
2017-05-16 23:22:54 +02:00
|
|
|
++currLevel;
|
|
|
|
}
|
|
|
|
return CONSTANTS.BaseCostForHacknetNode / 2 * totalMultiplier * Player.hacknet_node_level_cost_mult;
|
2017-04-26 23:51:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 04:51:03 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.getLevelUpgradeCost = function(levels=1) {
|
|
|
|
return this.calculateLevelUpgradeCost(levels);
|
|
|
|
}
|
|
|
|
|
2017-05-16 23:22:54 +02:00
|
|
|
HacknetNode.prototype.purchaseLevelUpgrade = function(levels=1) {
|
|
|
|
var cost = this.calculateLevelUpgradeCost(levels);
|
2017-05-25 14:18:34 +02:00
|
|
|
if (isNaN(cost)) {return false;}
|
2017-06-01 20:55:23 +02:00
|
|
|
if (this.level + levels > CONSTANTS.HacknetNodeMaxLevel) {
|
2017-05-31 02:00:24 +02:00
|
|
|
var diff = Math.max(0, CONSTANTS.HacknetNodeMaxLevel - this.level);
|
|
|
|
return this.purchaseLevelUpgrade(diff);
|
2017-05-16 23:22:54 +02:00
|
|
|
}
|
2017-06-11 00:44:33 +02:00
|
|
|
if (cost > Player.money) {return false;}
|
|
|
|
Player.loseMoney(cost);
|
2017-05-16 23:22:54 +02:00
|
|
|
this.level += levels;
|
2017-04-27 22:02:58 +02:00
|
|
|
this.updateMoneyGainRate();
|
2017-05-25 14:18:34 +02:00
|
|
|
return true;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:54:29 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.upgradeLevel = function(levels=1) {
|
|
|
|
return this.purchaseLevelUpgrade(levels);
|
|
|
|
}
|
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
HacknetNode.prototype.calculateRamUpgradeCost = function() {
|
|
|
|
var numUpgrades = Math.log2(this.ram);
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
//Calculate cost
|
2017-05-16 23:22:54 +02:00
|
|
|
//Base cost of RAM is 50k per 1GB, increased by some multiplier for each time RAM is upgraded
|
|
|
|
var baseCost = this.ram * CONSTANTS.BaseCostFor1GBOfRamHacknetNode;
|
2017-04-27 22:02:58 +02:00
|
|
|
var mult = Math.pow(CONSTANTS.HacknetNodeUpgradeRamMult, numUpgrades);
|
2017-05-16 23:22:54 +02:00
|
|
|
return baseCost * mult * Player.hacknet_node_ram_cost_mult;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 04:51:03 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.getRamUpgradeCost = function() {
|
|
|
|
return this.calculateRamUpgradeCost();
|
|
|
|
}
|
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
HacknetNode.prototype.purchaseRamUpgrade = function() {
|
|
|
|
var cost = this.calculateRamUpgradeCost();
|
2017-05-25 14:18:34 +02:00
|
|
|
if (isNaN(cost)) {return false;}
|
|
|
|
if (cost > Player.money) {return false;}
|
|
|
|
if (this.ram >= CONSTANTS.HacknetNodeMaxRam) {return false;}
|
2017-05-30 22:34:29 +02:00
|
|
|
Player.loseMoney(cost);
|
2017-04-27 07:01:21 +02:00
|
|
|
this.ram *= 2; //Ram is always doubled
|
2017-04-27 22:02:58 +02:00
|
|
|
this.updateMoneyGainRate();
|
2017-05-25 14:18:34 +02:00
|
|
|
return true;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:54:29 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.upgradeRam = function() {
|
|
|
|
return this.purchaseRamUpgrade();
|
|
|
|
}
|
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
HacknetNode.prototype.calculateCoreUpgradeCost = function() {
|
2017-04-27 22:02:58 +02:00
|
|
|
var coreBaseCost = CONSTANTS.BaseCostForHacknetNodeCore;
|
|
|
|
var mult = CONSTANTS.HacknetNodeUpgradeCoreMult;
|
2017-07-13 18:54:29 +02:00
|
|
|
return coreBaseCost * Math.pow(mult, this.cores-1) * Player.hacknet_node_core_cost_mult;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 04:51:03 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.getCoreUpgradeCost = function() {
|
|
|
|
return this.calculateCoreUpgradeCost();
|
|
|
|
}
|
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
HacknetNode.prototype.purchaseCoreUpgrade = function() {
|
|
|
|
var cost = this.calculateCoreUpgradeCost();
|
2017-05-25 14:18:34 +02:00
|
|
|
if (isNaN(cost)) {return false;}
|
|
|
|
if (cost > Player.money) {return false;}
|
2017-07-13 18:54:29 +02:00
|
|
|
if (this.cores >= CONSTANTS.HacknetNodeMaxCores) {return false;}
|
2017-05-30 22:34:29 +02:00
|
|
|
Player.loseMoney(cost);
|
2017-07-13 18:54:29 +02:00
|
|
|
++this.cores;
|
2017-04-27 22:02:58 +02:00
|
|
|
this.updateMoneyGainRate();
|
2017-05-25 14:18:34 +02:00
|
|
|
return true;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:54:29 +02:00
|
|
|
//Wrapper function for Netscript
|
|
|
|
HacknetNode.prototype.upgradeCore = function() {
|
|
|
|
return this.purchaseCoreUpgrade();
|
|
|
|
}
|
|
|
|
|
2017-04-26 23:51:00 +02:00
|
|
|
/* Saving and loading HackNets */
|
|
|
|
HacknetNode.prototype.toJSON = function() {
|
|
|
|
return Generic_toJSON("HacknetNode", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HacknetNode.fromJSON = function(value) {
|
|
|
|
return Generic_fromJSON(HacknetNode, value.data);
|
|
|
|
}
|
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
Reviver.constructors.HacknetNode = HacknetNode;
|
|
|
|
|
|
|
|
|
|
|
|
purchaseHacknet = function() {
|
2017-05-06 08:24:01 +02:00
|
|
|
/* INTERACTIVE TUTORIAL */
|
|
|
|
if (iTutorialIsRunning) {
|
|
|
|
if (currITutorialStep == iTutorialSteps.HacknetNodesIntroduction) {
|
|
|
|
iTutorialNextStep();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
/* END INTERACTIVE TUTORIAL */
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
var cost = getCostOfNextHacknetNode();
|
2017-05-03 06:38:58 +02:00
|
|
|
if (isNaN(cost)) {throw new Error("Cost is NaN"); return;}
|
2017-04-27 22:02:58 +02:00
|
|
|
if (cost > Player.money) {
|
2017-07-13 18:54:29 +02:00
|
|
|
//dialogBoxCreate("You cannot afford to purchase a Hacknet Node!");
|
|
|
|
return false;
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Auto generate a name for the node for now...TODO
|
|
|
|
var numOwned = Player.hacknetNodes.length;
|
|
|
|
var name = "hacknet-node-" + numOwned;
|
|
|
|
var node = new HacknetNode(name);
|
|
|
|
node.updateMoneyGainRate();
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
Player.loseMoney(cost);
|
|
|
|
Player.hacknetNodes.push(node);
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
displayHacknetNodesContent();
|
2017-05-10 19:42:46 +02:00
|
|
|
updateTotalHacknetProduction();
|
2017-07-13 18:54:29 +02:00
|
|
|
return numOwned;
|
2017-05-10 19:42:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 04:51:03 +02:00
|
|
|
//Calculates the total production from all HacknetNodes
|
2017-05-10 19:42:46 +02:00
|
|
|
updateTotalHacknetProduction = function() {
|
|
|
|
var total = 0;
|
|
|
|
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
|
|
|
total += Player.hacknetNodes[i].moneyGainRatePerSecond;
|
|
|
|
}
|
|
|
|
Player.totalHacknetNodeProduction = total;
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getCostOfNextHacknetNode = function() {
|
|
|
|
//Cost increases exponentially based on how many you own
|
|
|
|
var numOwned = Player.hacknetNodes.length;
|
|
|
|
var mult = CONSTANTS.HacknetNodePurchaseNextMult;
|
2017-05-03 06:38:58 +02:00
|
|
|
return CONSTANTS.BaseCostForHacknetNode * Math.pow(mult, numOwned) * Player.hacknet_node_purchase_cost_mult;
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 05:50:32 +02:00
|
|
|
var hacknetNodePurchaseMultiplier = 1;
|
|
|
|
updateHacknetNodesMultiplierButtons = function() {
|
|
|
|
var mult1x = document.getElementById("hacknet-nodes-1x-multiplier");
|
|
|
|
var mult5x = document.getElementById("hacknet-nodes-5x-multiplier");
|
|
|
|
var mult10x = document.getElementById("hacknet-nodes-10x-multiplier");
|
|
|
|
var multMax = document.getElementById("hacknet-nodes-max-multiplier");
|
|
|
|
mult1x.setAttribute("class", "a-link-button");
|
|
|
|
mult5x.setAttribute("class", "a-link-button");
|
|
|
|
mult10x.setAttribute("class", "a-link-button");
|
|
|
|
multMax.setAttribute("class", "a-link-button");
|
|
|
|
if (Player.hacknetNodes.length == 0) {
|
|
|
|
mult1x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
mult5x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
mult10x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
multMax.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else if (hacknetNodePurchaseMultiplier == 1) {
|
|
|
|
mult1x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else if (hacknetNodePurchaseMultiplier == 5) {
|
|
|
|
mult5x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else if (hacknetNodePurchaseMultiplier == 10) {
|
|
|
|
mult10x.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
|
|
|
multMax.setAttribute("class", "a-link-button-inactive");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Calculate the maximum number of times the Player can afford to upgrade
|
|
|
|
//a Hacknet Node's level"
|
|
|
|
getMaxNumberLevelUpgrades = function(nodeObj) {
|
|
|
|
if (nodeObj.calculateLevelUpgradeCost(1) > Player.money) {return 0;}
|
|
|
|
var min = 1;
|
2017-05-30 22:54:26 +02:00
|
|
|
var max = CONSTANTS.HacknetNodeMaxLevel-1;
|
|
|
|
var levelsToMax = CONSTANTS.HacknetNodeMaxLevel - nodeObj.level;
|
2017-07-05 18:49:01 +02:00
|
|
|
if (nodeObj.calculateLevelUpgradeCost(levelsToMax) < Player.money) {
|
|
|
|
return levelsToMax;
|
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-17 05:50:32 +02:00
|
|
|
while (min <= max) {
|
|
|
|
var curr = (min + max) / 2 | 0;
|
2017-07-25 04:51:03 +02:00
|
|
|
if (curr != CONSTANTS.HacknetNodeMaxLevel &&
|
2017-05-17 05:50:32 +02:00
|
|
|
nodeObj.calculateLevelUpgradeCost(curr) < Player.money &&
|
|
|
|
nodeObj.calculateLevelUpgradeCost(curr+1) > Player.money) {
|
2017-05-30 22:54:26 +02:00
|
|
|
return Math.min(levelsToMax, curr);
|
2017-05-17 05:50:32 +02:00
|
|
|
} else if (nodeObj.calculateLevelUpgradeCost(curr) > Player.money) {
|
|
|
|
max = curr - 1;
|
|
|
|
} else if (nodeObj.calculateLevelUpgradeCost(curr) < Player.money) {
|
|
|
|
min = curr + 1;
|
|
|
|
} else {
|
2017-05-30 22:54:26 +02:00
|
|
|
return Math.min(levelsToMax, curr);
|
2017-05-17 05:50:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-16 23:22:54 +02:00
|
|
|
}
|
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Creates Hacknet Node DOM elements when the page is opened
|
|
|
|
displayHacknetNodesContent = function() {
|
|
|
|
//Update Hacknet Nodes button
|
2017-05-06 08:24:01 +02:00
|
|
|
var newPurchaseButton = clearEventListeners("hacknet-nodes-purchase-button");
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
newPurchaseButton.addEventListener("click", function() {
|
|
|
|
purchaseHacknet();
|
|
|
|
return false;
|
|
|
|
});
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-16 23:22:54 +02:00
|
|
|
//Handle Purchase multiplier buttons
|
2017-05-17 05:50:32 +02:00
|
|
|
updateHacknetNodesMultiplierButtons();
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Remove all old hacknet Node DOM elements
|
|
|
|
var hacknetNodesList = document.getElementById("hacknet-nodes-list");
|
|
|
|
while (hacknetNodesList.firstChild) {
|
|
|
|
hacknetNodesList.removeChild(hacknetNodesList.firstChild);
|
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Then re-create them
|
|
|
|
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
|
|
|
createHacknetNodeDomElement(Player.hacknetNodes[i]);
|
|
|
|
}
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update information on all Hacknet Node DOM elements
|
|
|
|
updateHacknetNodesContent = function() {
|
|
|
|
//Set purchase button to inactive if not enough money, and update its price display
|
|
|
|
var cost = getCostOfNextHacknetNode();
|
|
|
|
var purchaseButton = document.getElementById("hacknet-nodes-purchase-button");
|
2017-05-04 22:50:17 +02:00
|
|
|
purchaseButton.innerHTML = "Purchase Hacknet Node - $" + formatNumber(cost, 2);
|
2017-04-27 22:02:58 +02:00
|
|
|
if (cost > Player.money) {
|
|
|
|
purchaseButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
|
|
|
purchaseButton.setAttribute("class", "a-link-button");
|
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Update player's money
|
2017-05-10 19:42:46 +02:00
|
|
|
var moneyElem = document.getElementById("hacknet-nodes-money");
|
2017-07-25 04:51:03 +02:00
|
|
|
moneyElem.innerHTML = "Money: $" + formatNumber(Player.money, 2) + "<br>" +
|
2017-05-15 08:35:09 +02:00
|
|
|
"Total production from all Hacknet Nodes: $" + formatNumber(Player.totalHacknetNodeProduction, 2) + " / second";
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Update information in each owned hacknet node
|
|
|
|
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
|
|
|
updateHacknetNodeDomElement(Player.hacknetNodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Creates a single Hacknet Node DOM element
|
|
|
|
createHacknetNodeDomElement = function(nodeObj) {
|
|
|
|
var nodeName = nodeObj.name;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
var listItem = document.createElement("li");
|
2017-04-27 22:02:58 +02:00
|
|
|
listItem.setAttribute("class", "hacknet-node");
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
var span = document.createElement("span");
|
2017-04-27 22:02:58 +02:00
|
|
|
span.style.display = "inline";
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
var buttonDiv = document.createElement("div");
|
|
|
|
buttonDiv.setAttribute("class", "hacknet-node-button-div");
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
//Text
|
|
|
|
var txt = document.createElement("p");
|
2017-04-27 22:02:58 +02:00
|
|
|
//txt.setAttribute("id", "hacknet-node-text-" + nodeName);
|
|
|
|
txt.id = "hacknet-node-text-" + nodeName;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 07:01:21 +02:00
|
|
|
//Upgrade buttons
|
|
|
|
var upgradeLevelButton = document.createElement("a");
|
|
|
|
var upgradeRamButton = document.createElement("a");
|
|
|
|
var upgradeCoreButton = document.createElement("a");
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//upgradeLevelButton.setAttribute("id", "hacknet-node-upgrade-level-" + nodeName);
|
|
|
|
upgradeLevelButton.id = "hacknet-node-upgrade-level-" + nodeName;
|
2017-04-27 07:01:21 +02:00
|
|
|
upgradeLevelButton.setAttribute("class", "a-link-button-inactive");
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeLevelButton.addEventListener("click", function() {
|
2017-05-17 05:50:32 +02:00
|
|
|
var numUpgrades = hacknetNodePurchaseMultiplier;
|
|
|
|
if (hacknetNodePurchaseMultiplier == 0) {
|
|
|
|
numUpgrades = getMaxNumberLevelUpgrades(nodeObj);
|
|
|
|
}
|
|
|
|
nodeObj.purchaseLevelUpgrade(numUpgrades);
|
2017-04-27 22:02:58 +02:00
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
//upgradeRamButton.setAttribute("id", "hacknet-node-upgrade-ram-" + nodeName);
|
|
|
|
upgradeRamButton.id = "hacknet-node-upgrade-ram-" + nodeName;
|
2017-04-27 07:01:21 +02:00
|
|
|
upgradeRamButton.setAttribute("class", "a-link-button-inactive");
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeRamButton.addEventListener("click", function() {
|
|
|
|
nodeObj.purchaseRamUpgrade();
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
//upgradeCoreButton.setAttribute("id", "hacknet-node-upgrade-core-" + nodeName);
|
|
|
|
upgradeCoreButton.id = "hacknet-node-upgrade-core-" + nodeName;
|
2017-04-27 07:01:21 +02:00
|
|
|
upgradeCoreButton.setAttribute("class", "a-link-button-inactive");
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeCoreButton.addEventListener("click", function() {
|
|
|
|
nodeObj.purchaseCoreUpgrade();
|
|
|
|
updateHacknetNodesContent();
|
|
|
|
return false;
|
|
|
|
});
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Put all the components together in the li element
|
|
|
|
span.appendChild(txt);
|
|
|
|
buttonDiv.appendChild(upgradeLevelButton);
|
|
|
|
buttonDiv.appendChild(upgradeRamButton);
|
|
|
|
buttonDiv.appendChild(upgradeCoreButton);
|
|
|
|
span.appendChild(buttonDiv);
|
|
|
|
listItem.appendChild(span);
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
document.getElementById("hacknet-nodes-list").appendChild(listItem);
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Set the text and stuff inside the DOM element
|
|
|
|
updateHacknetNodeDomElement(nodeObj);
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
//Updates information on a single hacknet node DOM element
|
|
|
|
updateHacknetNodeDomElement = function(nodeObj) {
|
2017-04-27 07:01:21 +02:00
|
|
|
var nodeName = nodeObj.name;
|
2017-04-27 22:02:58 +02:00
|
|
|
var txt = document.getElementById("hacknet-node-text-" + nodeName);
|
|
|
|
if (txt == null) {throw new Error("Cannot find text element");}
|
|
|
|
txt.innerHTML = "Node name: " + nodeName + "<br>" +
|
2017-07-25 04:51:03 +02:00
|
|
|
"Production: $" + formatNumber(nodeObj.totalMoneyGenerated, 2) +
|
|
|
|
" ($" + formatNumber(nodeObj.moneyGainRatePerSecond, 2) + " / second) <br>" +
|
|
|
|
"Level: " + nodeObj.level + "<br>" +
|
|
|
|
"RAM: " + nodeObj.ram + "GB<br>" +
|
2017-07-13 18:54:29 +02:00
|
|
|
"Cores: " + nodeObj.cores;
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-16 00:22:17 +02:00
|
|
|
//Upgrade level
|
2017-04-27 22:02:58 +02:00
|
|
|
var upgradeLevelButton = document.getElementById("hacknet-node-upgrade-level-" + nodeName);
|
|
|
|
if (upgradeLevelButton == null) {throw new Error("Cannot find upgrade level button element");}
|
2017-05-16 00:22:17 +02:00
|
|
|
if (nodeObj.level >= CONSTANTS.HacknetNodeMaxLevel) {
|
|
|
|
upgradeLevelButton.innerHTML = "MAX LEVEL";
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeLevelButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
2017-05-17 05:50:32 +02:00
|
|
|
var multiplier = 0;
|
|
|
|
if (hacknetNodePurchaseMultiplier == 0) {
|
|
|
|
//Max
|
|
|
|
multiplier = getMaxNumberLevelUpgrades(nodeObj);
|
|
|
|
} else {
|
2017-05-31 02:00:24 +02:00
|
|
|
var levelsToMax = CONSTANTS.HacknetNodeMaxLevel - nodeObj.level;
|
|
|
|
multiplier = Math.min(levelsToMax, hacknetNodePurchaseMultiplier);
|
2017-05-17 05:50:32 +02:00
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-17 05:50:32 +02:00
|
|
|
var upgradeLevelCost = nodeObj.calculateLevelUpgradeCost(multiplier);
|
|
|
|
upgradeLevelButton.innerHTML = "Upgrade Hacknet Node Level x" + multiplier +
|
|
|
|
" - $" + formatNumber(upgradeLevelCost, 2);
|
2017-05-16 00:22:17 +02:00
|
|
|
if (upgradeLevelCost > Player.money ) {
|
|
|
|
upgradeLevelButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
|
|
|
upgradeLevelButton.setAttribute("class", "a-link-button");
|
|
|
|
}
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-16 00:22:17 +02:00
|
|
|
//Upgrade RAM
|
2017-04-27 22:02:58 +02:00
|
|
|
var upgradeRamButton = document.getElementById("hacknet-node-upgrade-ram-" + nodeName);
|
|
|
|
if (upgradeRamButton == null) {throw new Error("Cannot find upgrade ram button element");}
|
2017-05-16 00:22:17 +02:00
|
|
|
if (nodeObj.ram >= CONSTANTS.HacknetNodeMaxRam) {
|
|
|
|
upgradeRamButton.innerHTML = "MAX RAM";
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeRamButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
2017-05-16 00:22:17 +02:00
|
|
|
var upgradeRamCost = nodeObj.calculateRamUpgradeCost();
|
|
|
|
upgradeRamButton.innerHTML = "Upgrade Hacknet Node RAM -$" + formatNumber(upgradeRamCost, 2);
|
|
|
|
if (upgradeRamCost > Player.money) {
|
|
|
|
upgradeRamButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
|
|
|
upgradeRamButton.setAttribute("class", "a-link-button");
|
|
|
|
}
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-07-25 04:51:03 +02:00
|
|
|
|
2017-05-16 00:22:17 +02:00
|
|
|
//Upgrade Cores
|
2017-04-27 22:02:58 +02:00
|
|
|
var upgradeCoreButton = document.getElementById("hacknet-node-upgrade-core-" + nodeName);
|
|
|
|
if (upgradeCoreButton == null) {throw new Error("Cannot find upgrade cores button element");}
|
2017-07-13 18:54:29 +02:00
|
|
|
if (nodeObj.cores >= CONSTANTS.HacknetNodeMaxCores) {
|
2017-05-16 00:22:17 +02:00
|
|
|
upgradeCoreButton.innerHTML = "MAX CORES";
|
2017-04-27 22:02:58 +02:00
|
|
|
upgradeCoreButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
2017-05-16 00:22:17 +02:00
|
|
|
var upgradeCoreCost = nodeObj.calculateCoreUpgradeCost();
|
|
|
|
upgradeCoreButton.innerHTML = "Purchase additional CPU Core - $" + formatNumber(upgradeCoreCost, 2);
|
|
|
|
if (upgradeCoreCost > Player.money) {
|
|
|
|
upgradeCoreButton.setAttribute("class", "a-link-button-inactive");
|
|
|
|
} else {
|
|
|
|
upgradeCoreButton.setAttribute("class", "a-link-button");
|
|
|
|
}
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
2017-04-26 23:51:00 +02:00
|
|
|
|
2017-04-27 22:02:58 +02:00
|
|
|
processAllHacknetNodeEarnings = function(numCycles) {
|
2017-05-20 11:27:42 +02:00
|
|
|
var total = 0;
|
2017-04-27 22:02:58 +02:00
|
|
|
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
2017-05-20 11:27:42 +02:00
|
|
|
total += processSingleHacknetNodeEarnings(numCycles, Player.hacknetNodes[i]);
|
2017-04-27 22:02:58 +02:00
|
|
|
}
|
2017-05-20 11:27:42 +02:00
|
|
|
return total;
|
2017-04-27 07:01:21 +02:00
|
|
|
}
|
2017-04-27 22:02:58 +02:00
|
|
|
|
|
|
|
processSingleHacknetNodeEarnings = function(numCycles, nodeObj) {
|
|
|
|
var cyclesPerSecond = 1000 / Engine._idleSpeed;
|
|
|
|
var earningPerCycle = nodeObj.moneyGainRatePerSecond / cyclesPerSecond;
|
|
|
|
if (isNaN(earningPerCycle)) {throw new Error("Calculated Earnings is not a number");}
|
|
|
|
var totalEarnings = numCycles * earningPerCycle;
|
|
|
|
nodeObj.totalMoneyGenerated += totalEarnings;
|
|
|
|
nodeObj.onlineTimeSeconds += (numCycles * (Engine._idleSpeed / 1000));
|
|
|
|
Player.gainMoney(totalEarnings);
|
2017-05-20 11:27:42 +02:00
|
|
|
return totalEarnings;
|
|
|
|
}
|
|
|
|
|
|
|
|
getHacknetNode = function(name) {
|
|
|
|
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
|
|
|
if (Player.hacknetNodes[i].name == name) {
|
2017-05-23 19:49:26 +02:00
|
|
|
return Player.hacknetNodes[i];
|
2017-05-20 11:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2017-07-25 04:51:03 +02:00
|
|
|
}
|