diff --git a/css/menupages.css b/css/menupages.css index 2ad8e9c20..802dc40da 100644 --- a/css/menupages.css +++ b/css/menupages.css @@ -108,6 +108,20 @@ text-decoration: none; } +/* Hacknet Nodes */ +#hacknet-nodes-container { + position: fixed; + padding-top: 10px; + padding-left: 10px; + height: 100%; + margin-left: 10%; + width: 99%; +} + +.hacknet-node li { + +} + /* World */ #world-container { position: fixed; @@ -219,8 +233,6 @@ list-style-type: none; } - - /* Augmentations */ #augmentations-container { position: fixed; diff --git a/css/popupboxes.css b/css/popupboxes.css index 53cdf0929..8470e9079 100644 --- a/css/popupboxes.css +++ b/css/popupboxes.css @@ -100,6 +100,56 @@ cursor: pointer; } +/* Purchase RAM for Home computer pop-up box */ +#purchase-ram-for-home-box-container { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 1; /* Sit on top */ + left: 0; + right: 0; + bottom: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: black; /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ + transition: opacity 400ms ease-in; +} + +#purchase-ram-for-home-box-content { + background-color: black; + margin: 15% auto; /* 15% from the top and centered */ + padding: 1px; + border: 5px solid #FFFFFF; + width: 80%; /* Could be more or less, depending on screen size */ + color: #66ff33; +} + +#purchase-ram-for-home-box-confirm, +#purchase-ram-for-home-box-cancel { + color: #aaa; + float: right; + font-size: 16px; + font-weight: bold; + padding: 2px; + border: 1px solid white; +} + +#purchase-ram-for-home-box-confirm:hover, +#purchase-ram-for-home-box-confirm:focus { + color: #66ff33; + text-decoration: none; + cursor: pointer; +} + +#purchase-ram-for-home-box-cancel:hover, +#purchase-ram-for-home-box-cancel:focus { + color: #66ff33; + text-decoration: none; + cursor: pointer; +} + /* Purchase Invitation Box */ #purchase-augmentation-box-container { display: none; /* Hidden by default */ diff --git a/index.html b/index.html index 0b0a33296..bc64ebd14 100644 --- a/index.html +++ b/index.html @@ -140,7 +140,9 @@
- +
@@ -534,9 +536,11 @@
-

- Purchase - Cancel +
+

+ Purchase + Cancel +
diff --git a/src/Constants.js b/src/Constants.js index 4758512fb..e8ab15b27 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -7,6 +7,9 @@ CONSTANTS = { //How much reputation is needed to join a megacorporation's faction CorpFactionRepRequirement: 250000, + + //Base cost for 1GB of RAM + BaseCostFor1GBOfRam: 50000, /* Script related things */ //Time (ms) it takes to run one operation in Netscript. diff --git a/src/HacknetNode.js b/src/HacknetNode.js index ddb332d26..37349f1d0 100644 --- a/src/HacknetNode.js +++ b/src/HacknetNode.js @@ -27,6 +27,44 @@ HacknetNode.prototype.calculateLevelUpgradeCost = function() { return baseCost * Math.pow(mult, this.level); } +HacknetNode.prototype.purchaseLevelUpgrade = function() { + var cost = this.calculateLevelUpgradeCost(); + if (cost > Player.money) {return;} + Player.loseMoney(cost); + ++this.level; +} + +HacknetNode.prototype.calculateRamUpgradeCost = function() { + var numUpgrades = Math.log2(this.ram); + + //Calculate cost + //Base cost of RAM is 50k per 1GB...but lets have this increase by 10% for every time + //the RAM has been upgraded + var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRam; + var mult = Math.pow(1.1, numUpgrades); + return cost * mult; +} + +HacknetNode.prototype.purchaseRamUpgrade = function() { + var cost = this.calculateRamUpgradeCost(); + if (cost > Player.money) {return;} + Player.loseMoney(cost); + this.ram *= 2; //Ram is always doubled +} + +HacknetNode.prototype.calculateCoreUpgradeCost = function() { + var coreBaseCost = 1000000; + var mult = 1.5; + return coreBaseCost * Math.pow(mult, this.numCores); +} + +HacknetNode.prototype.purchaseCoreUpgrade = function() { + var cost = this.calculateCoreUpgradeCost(); + if (cost > Player.money) {return;} + Player.loseMoney(cost); + ++this.numCores; +} + /* Saving and loading HackNets */ HacknetNode.prototype.toJSON = function() { return Generic_toJSON("HacknetNode", this); @@ -36,9 +74,54 @@ HacknetNode.fromJSON = function(value) { return Generic_fromJSON(HacknetNode, value.data); } -Reviver.constructors.HacknetNode = HacknetNode; +createHacknetNodeDomElement = function(nodeObj) { + var nodeName = nodeObj.name; + + var list = document.getElementById("hacknet-nodes-list"); + + var listItem = document.createElement("li"); + item.setAttribute("class", "hacknet-node"); + + var span = document.createElement("span"); + span.style.display = "inline-block"; + + //Text + var txt = document.createElement("p"); + txt.setAttribute("id", "hacknet-node-text-" + nodeName); + txt.innerHTML = "Node name: " + nodeName + "
" + "Production: " + nodeObj.totalMoneyGenerated + + " ($" + nodeObj.moneyGainRatePerSecond + ")
" + + "Level: " + nodeObj.level + "
" + + "RAM: " + nodeObj.ram + "GB
" + + "Cores: " + nodeObj.numCores; + + //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.setAttribute("class", "a-link-button-inactive"); + upgradeRamButton.setAttribute("id", "hacknet-node-upgrade-ram-" + nodeName); + upgradeRamButton.setAttribute("class", "a-link-button-inactive"); + upgradeCoreButton.setAttribute("id", "hacknet-node-upgrade-core-" + nodeName); + upgradeCoreButton.setAttribute("class", "a-link-button-inactive"); + + upgradeLevelButton.innerHTML = "Upgrade Hacknet Node Level"; + upgradeRamButton.innerHTML = "Upgrade Hacknet Node RAM"; + upgradeCoreButton.innerHTML = "Purchase additional CPU Core for Hacknet Node"; + + updateHacknetNodeDomElement(item, nodeObj); + + list.appendChild(item); +} +updateHacknetNodeDomElement = function(li, nodeObj) { + var nodeName = nodeObj.name; +} + +Reviver.constructors.HacknetNode = HacknetNode; purchaseHacknet = function() { -} \ No newline at end of file +} diff --git a/src/Player.js b/src/Player.js index 879347e0f..0e77732ce 100644 --- a/src/Player.js +++ b/src/Player.js @@ -79,6 +79,7 @@ function PlayerObject() { this.currentServer = ""; //IP address of Server currently being accessed through terminal this.discoveredServers = []; //IP addresses of secret servers not in the network that you have discovered this.purchasedServers = []; + this.hacknetNodes = []; //Factions this.factions = []; //Names of all factions player has joined diff --git a/src/Server.js b/src/Server.js index 62def2c6b..c7da7cbbd 100644 --- a/src/Server.js +++ b/src/Server.js @@ -22,8 +22,7 @@ function Server() { this.scripts = []; this.runningScripts = []; //Names (and only names) of scripts being run this.programs = []; - this.hacknetNodes = []; - + /* Hacking information (only valid for "foreign" aka non-purchased servers) */ //Skill required to attempt a hack. Whether a hack is successful will be determined diff --git a/utils/PurchaseRamForHomeBox.js b/utils/PurchaseRamForHomeBox.js index 0b549af5d..f63f42374 100644 --- a/utils/PurchaseRamForHomeBox.js +++ b/utils/PurchaseRamForHomeBox.js @@ -36,7 +36,7 @@ purchaseRamForHomeBoxCreate = function() { //Calculate cost //Base cost of RAM is 50k per 1GB...but lets have this increase by 10% for every time //the RAM has been upgraded - var cost = currentRam * 50000; + var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRam; var mult = Math.pow(1.1, numUpgrades); cost = cost * mult;