mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-21 13:45:44 +01:00
Added donate button. Added Netscript functions to get cost of Hacknet Node upgrades
This commit is contained in:
parent
d5be649bbd
commit
be48875ff3
@ -901,6 +901,15 @@
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com/wiki/Changelog" target="_blank"> Changelog </a>
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com" target="_blank">Wiki</a>
|
||||
<a class="a-link-button" style="display:block;", href="https://www.reddit.com/r/bitburner" target="_blank">Subreddit</a>
|
||||
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
||||
<input type="hidden" name="cmd" value="_s-xclick">
|
||||
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYA2Y2VGE75oWct89z//G2YEJKmzx0uDTXNrpje9ThxmUnBLFZCY+I11Pors7lGRvFqo5okwnu41CfYMPHDxpAgyYyQndMX9pWUX0gLfBMm2BaHwsNBCwt34WmpQqj7TGsQ+aw9NbmkxiJltGnOa+6/gy10mPZAA3HxiieLeCKkGgDELMAkGBSsOAwIaBQAwgcQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQI72F1YSzHUd2AgaDMekHU3AKT93Ey9wkB3486bV+ngFSD6VOHrPweH9QATsp+PMe9QM9vmq+s2bGtTbZaYrFqM3M97SnQ0l7IQ5yuOzdZhRdfysu5uJ8dnuHUzq4gLSzqMnZ6/3c+PoHB8AS1nYHU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hbC5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCBXzpWmoBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTcwNzI1MDExODE2WjAjBgkqhkiG9w0BCQQxFgQUNo8efiZ7sk7nwKM/6B6Z7sU8hIIwDQYJKoZIhvcNAQEBBQAEgYB+JB4vZ/r48815/1HF/xK3+rOx7bPz3kAXmbhW/mkoF4OUbzqMeljvDIA9q/BDdlCLtxFOw9XlftTzv0eZCW/uCIiwu5wTzPIfPY1SI8WHe4cJbP2f2EYxIVs8D7OSirbW4yVa0+gACaLLj0rzIzNN8P/5PxgB03D+jwkcJABqng==-----END PKCS7-----
|
||||
">
|
||||
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
|
||||
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
|
||||
</form>
|
||||
|
||||
<a id="save-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Save Game </a>
|
||||
<a id="delete-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Delete Game </a>
|
||||
<a id="export-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Export Game </a>
|
||||
|
972
src/Constants.js
972
src/Constants.js
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ function hacknetNodesInit() {
|
||||
hacknetNodePurchaseMultiplier = 10;
|
||||
updateHacknetNodesMultiplierButtons();
|
||||
updateHacknetNodesContent();
|
||||
return false;
|
||||
return false;
|
||||
});
|
||||
var multMax = document.getElementById("hacknet-nodes-max-multiplier");
|
||||
multMax.addEventListener("click", function() {
|
||||
@ -34,43 +34,48 @@ document.addEventListener("DOMContentLoaded", hacknetNodesInit, false);
|
||||
function HacknetNode(name) {
|
||||
this.level = 1;
|
||||
this.ram = 1; //GB
|
||||
this.cores = 1;
|
||||
|
||||
this.cores = 1;
|
||||
|
||||
this.name = name;
|
||||
|
||||
|
||||
this.totalMoneyGenerated = 0;
|
||||
this.onlineTimeSeconds = 0;
|
||||
|
||||
|
||||
this.moneyGainRatePerSecond = 0;
|
||||
}
|
||||
|
||||
HacknetNode.prototype.updateMoneyGainRate = function() {
|
||||
//How much extra $/s is gained per level
|
||||
var gainPerLevel = CONSTANTS.HacknetNodeMoneyGainPerLevel;
|
||||
|
||||
this.moneyGainRatePerSecond = (this.level * gainPerLevel) *
|
||||
Math.pow(1.035, this.ram-1) *
|
||||
|
||||
this.moneyGainRatePerSecond = (this.level * gainPerLevel) *
|
||||
Math.pow(1.035, this.ram-1) *
|
||||
((this.cores + 5) / 6) * Player.hacknet_node_money_mult;
|
||||
if (isNaN(this.moneyGainRatePerSecond)) {
|
||||
this.moneyGainRatePerSecond = 0;
|
||||
dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer");
|
||||
}
|
||||
|
||||
|
||||
updateTotalHacknetProduction();
|
||||
}
|
||||
|
||||
HacknetNode.prototype.calculateLevelUpgradeCost = function(levels=1) {
|
||||
if (levels < 1) {return 0;}
|
||||
var mult = CONSTANTS.HacknetNodeUpgradeLevelMult;
|
||||
var totalMultiplier = 0; //Summed
|
||||
var totalMultiplier = 0; //Summed
|
||||
var currLevel = this.level;
|
||||
for (var i = 0; i < levels; ++i) {
|
||||
totalMultiplier += Math.pow(mult, currLevel);
|
||||
totalMultiplier += Math.pow(mult, currLevel);
|
||||
++currLevel;
|
||||
}
|
||||
return CONSTANTS.BaseCostForHacknetNode / 2 * totalMultiplier * Player.hacknet_node_level_cost_mult;
|
||||
}
|
||||
|
||||
//Wrapper function for Netscript
|
||||
HacknetNode.prototype.getLevelUpgradeCost = function(levels=1) {
|
||||
return this.calculateLevelUpgradeCost(levels);
|
||||
}
|
||||
|
||||
HacknetNode.prototype.purchaseLevelUpgrade = function(levels=1) {
|
||||
var cost = this.calculateLevelUpgradeCost(levels);
|
||||
if (isNaN(cost)) {return false;}
|
||||
@ -92,7 +97,7 @@ HacknetNode.prototype.upgradeLevel = function(levels=1) {
|
||||
|
||||
HacknetNode.prototype.calculateRamUpgradeCost = function() {
|
||||
var numUpgrades = Math.log2(this.ram);
|
||||
|
||||
|
||||
//Calculate cost
|
||||
//Base cost of RAM is 50k per 1GB, increased by some multiplier for each time RAM is upgraded
|
||||
var baseCost = this.ram * CONSTANTS.BaseCostFor1GBOfRamHacknetNode;
|
||||
@ -100,6 +105,11 @@ HacknetNode.prototype.calculateRamUpgradeCost = function() {
|
||||
return baseCost * mult * Player.hacknet_node_ram_cost_mult;
|
||||
}
|
||||
|
||||
//Wrapper function for Netscript
|
||||
HacknetNode.prototype.getRamUpgradeCost = function() {
|
||||
return this.calculateRamUpgradeCost();
|
||||
}
|
||||
|
||||
HacknetNode.prototype.purchaseRamUpgrade = function() {
|
||||
var cost = this.calculateRamUpgradeCost();
|
||||
if (isNaN(cost)) {return false;}
|
||||
@ -122,6 +132,11 @@ HacknetNode.prototype.calculateCoreUpgradeCost = function() {
|
||||
return coreBaseCost * Math.pow(mult, this.cores-1) * Player.hacknet_node_core_cost_mult;
|
||||
}
|
||||
|
||||
//Wrapper function for Netscript
|
||||
HacknetNode.prototype.getCoreUpgradeCost = function() {
|
||||
return this.calculateCoreUpgradeCost();
|
||||
}
|
||||
|
||||
HacknetNode.prototype.purchaseCoreUpgrade = function() {
|
||||
var cost = this.calculateCoreUpgradeCost();
|
||||
if (isNaN(cost)) {return false;}
|
||||
@ -159,31 +174,31 @@ purchaseHacknet = function() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* END INTERACTIVE TUTORIAL */
|
||||
|
||||
|
||||
var cost = getCostOfNextHacknetNode();
|
||||
if (isNaN(cost)) {throw new Error("Cost is NaN"); return;}
|
||||
if (cost > Player.money) {
|
||||
//dialogBoxCreate("You cannot afford to purchase a Hacknet Node!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//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();
|
||||
|
||||
|
||||
Player.loseMoney(cost);
|
||||
Player.hacknetNodes.push(node);
|
||||
|
||||
|
||||
displayHacknetNodesContent();
|
||||
updateTotalHacknetProduction();
|
||||
return numOwned;
|
||||
}
|
||||
|
||||
//Calculates the total production from all HacknetNodes
|
||||
//Calculates the total production from all HacknetNodes
|
||||
updateTotalHacknetProduction = function() {
|
||||
var total = 0;
|
||||
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
||||
@ -235,10 +250,10 @@ getMaxNumberLevelUpgrades = function(nodeObj) {
|
||||
if (nodeObj.calculateLevelUpgradeCost(levelsToMax) < Player.money) {
|
||||
return levelsToMax;
|
||||
}
|
||||
|
||||
|
||||
while (min <= max) {
|
||||
var curr = (min + max) / 2 | 0;
|
||||
if (curr != CONSTANTS.HacknetNodeMaxLevel &&
|
||||
if (curr != CONSTANTS.HacknetNodeMaxLevel &&
|
||||
nodeObj.calculateLevelUpgradeCost(curr) < Player.money &&
|
||||
nodeObj.calculateLevelUpgradeCost(curr+1) > Player.money) {
|
||||
return Math.min(levelsToMax, curr);
|
||||
@ -256,21 +271,21 @@ getMaxNumberLevelUpgrades = function(nodeObj) {
|
||||
displayHacknetNodesContent = function() {
|
||||
//Update Hacknet Nodes button
|
||||
var newPurchaseButton = clearEventListeners("hacknet-nodes-purchase-button");
|
||||
|
||||
|
||||
newPurchaseButton.addEventListener("click", function() {
|
||||
purchaseHacknet();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
//Handle Purchase multiplier buttons
|
||||
updateHacknetNodesMultiplierButtons();
|
||||
|
||||
|
||||
//Remove all old hacknet Node DOM elements
|
||||
var hacknetNodesList = document.getElementById("hacknet-nodes-list");
|
||||
while (hacknetNodesList.firstChild) {
|
||||
hacknetNodesList.removeChild(hacknetNodesList.firstChild);
|
||||
}
|
||||
|
||||
|
||||
//Then re-create them
|
||||
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
||||
createHacknetNodeDomElement(Player.hacknetNodes[i]);
|
||||
@ -289,12 +304,12 @@ updateHacknetNodesContent = function() {
|
||||
} else {
|
||||
purchaseButton.setAttribute("class", "a-link-button");
|
||||
}
|
||||
|
||||
|
||||
//Update player's money
|
||||
var moneyElem = document.getElementById("hacknet-nodes-money");
|
||||
moneyElem.innerHTML = "Money: $" + formatNumber(Player.money, 2) + "<br>" +
|
||||
moneyElem.innerHTML = "Money: $" + formatNumber(Player.money, 2) + "<br>" +
|
||||
"Total production from all Hacknet Nodes: $" + formatNumber(Player.totalHacknetNodeProduction, 2) + " / second";
|
||||
|
||||
|
||||
//Update information in each owned hacknet node
|
||||
for (var i = 0; i < Player.hacknetNodes.length; ++i) {
|
||||
updateHacknetNodeDomElement(Player.hacknetNodes[i]);
|
||||
@ -304,26 +319,26 @@ updateHacknetNodesContent = function() {
|
||||
//Creates a single Hacknet Node DOM element
|
||||
createHacknetNodeDomElement = function(nodeObj) {
|
||||
var nodeName = nodeObj.name;
|
||||
|
||||
|
||||
var listItem = document.createElement("li");
|
||||
listItem.setAttribute("class", "hacknet-node");
|
||||
|
||||
|
||||
var span = document.createElement("span");
|
||||
span.style.display = "inline";
|
||||
|
||||
|
||||
var buttonDiv = document.createElement("div");
|
||||
buttonDiv.setAttribute("class", "hacknet-node-button-div");
|
||||
|
||||
|
||||
//Text
|
||||
var txt = document.createElement("p");
|
||||
//txt.setAttribute("id", "hacknet-node-text-" + nodeName);
|
||||
txt.id = "hacknet-node-text-" + nodeName;
|
||||
|
||||
|
||||
//Upgrade buttons
|
||||
var upgradeLevelButton = document.createElement("a");
|
||||
var upgradeRamButton = document.createElement("a");
|
||||
var upgradeCoreButton = document.createElement("a");
|
||||
|
||||
|
||||
//upgradeLevelButton.setAttribute("id", "hacknet-node-upgrade-level-" + nodeName);
|
||||
upgradeLevelButton.id = "hacknet-node-upgrade-level-" + nodeName;
|
||||
upgradeLevelButton.setAttribute("class", "a-link-button-inactive");
|
||||
@ -352,7 +367,7 @@ createHacknetNodeDomElement = function(nodeObj) {
|
||||
updateHacknetNodesContent();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
//Put all the components together in the li element
|
||||
span.appendChild(txt);
|
||||
buttonDiv.appendChild(upgradeLevelButton);
|
||||
@ -360,9 +375,9 @@ createHacknetNodeDomElement = function(nodeObj) {
|
||||
buttonDiv.appendChild(upgradeCoreButton);
|
||||
span.appendChild(buttonDiv);
|
||||
listItem.appendChild(span);
|
||||
|
||||
|
||||
document.getElementById("hacknet-nodes-list").appendChild(listItem);
|
||||
|
||||
|
||||
//Set the text and stuff inside the DOM element
|
||||
updateHacknetNodeDomElement(nodeObj);
|
||||
}
|
||||
@ -373,12 +388,12 @@ updateHacknetNodeDomElement = function(nodeObj) {
|
||||
var txt = document.getElementById("hacknet-node-text-" + nodeName);
|
||||
if (txt == null) {throw new Error("Cannot find text element");}
|
||||
txt.innerHTML = "Node name: " + nodeName + "<br>" +
|
||||
"Production: $" + formatNumber(nodeObj.totalMoneyGenerated, 2) +
|
||||
" ($" + formatNumber(nodeObj.moneyGainRatePerSecond, 2) + " / second) <br>" +
|
||||
"Level: " + nodeObj.level + "<br>" +
|
||||
"RAM: " + nodeObj.ram + "GB<br>" +
|
||||
"Production: $" + formatNumber(nodeObj.totalMoneyGenerated, 2) +
|
||||
" ($" + formatNumber(nodeObj.moneyGainRatePerSecond, 2) + " / second) <br>" +
|
||||
"Level: " + nodeObj.level + "<br>" +
|
||||
"RAM: " + nodeObj.ram + "GB<br>" +
|
||||
"Cores: " + nodeObj.cores;
|
||||
|
||||
|
||||
//Upgrade level
|
||||
var upgradeLevelButton = document.getElementById("hacknet-node-upgrade-level-" + nodeName);
|
||||
if (upgradeLevelButton == null) {throw new Error("Cannot find upgrade level button element");}
|
||||
@ -394,7 +409,7 @@ updateHacknetNodeDomElement = function(nodeObj) {
|
||||
var levelsToMax = CONSTANTS.HacknetNodeMaxLevel - nodeObj.level;
|
||||
multiplier = Math.min(levelsToMax, hacknetNodePurchaseMultiplier);
|
||||
}
|
||||
|
||||
|
||||
var upgradeLevelCost = nodeObj.calculateLevelUpgradeCost(multiplier);
|
||||
upgradeLevelButton.innerHTML = "Upgrade Hacknet Node Level x" + multiplier +
|
||||
" - $" + formatNumber(upgradeLevelCost, 2);
|
||||
@ -404,7 +419,7 @@ updateHacknetNodeDomElement = function(nodeObj) {
|
||||
upgradeLevelButton.setAttribute("class", "a-link-button");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Upgrade RAM
|
||||
var upgradeRamButton = document.getElementById("hacknet-node-upgrade-ram-" + nodeName);
|
||||
if (upgradeRamButton == null) {throw new Error("Cannot find upgrade ram button element");}
|
||||
@ -420,7 +435,7 @@ updateHacknetNodeDomElement = function(nodeObj) {
|
||||
upgradeRamButton.setAttribute("class", "a-link-button");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Upgrade Cores
|
||||
var upgradeCoreButton = document.getElementById("hacknet-node-upgrade-core-" + nodeName);
|
||||
if (upgradeCoreButton == null) {throw new Error("Cannot find upgrade cores button element");}
|
||||
@ -464,4 +479,4 @@ getHacknetNode = function(name) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user