more work on HacknetNode.js and also added css content for PurchaseRamForHomeBox

This commit is contained in:
Daniel Xie 2017-04-27 00:01:21 -05:00
parent 14fb303504
commit e2947cc8c3
8 changed files with 163 additions and 11 deletions

@ -108,6 +108,20 @@
text-decoration: none; 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 */
#world-container { #world-container {
position: fixed; position: fixed;
@ -219,8 +233,6 @@
list-style-type: none; list-style-type: none;
} }
/* Augmentations */ /* Augmentations */
#augmentations-container { #augmentations-container {
position: fixed; position: fixed;

@ -100,6 +100,56 @@
cursor: pointer; 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 Invitation Box */
#purchase-augmentation-box-container { #purchase-augmentation-box-container {
display: none; /* Hidden by default */ display: none; /* Hidden by default */

@ -140,7 +140,9 @@
<!-- Hacknet Nodes --> <!-- Hacknet Nodes -->
<div id="hacknet-nodes-container"> <div id="hacknet-nodes-container">
<ul id="hacknet-nodes-list" style="list-style : none;">
</ul>
</div> </div>
<!-- World --> <!-- World -->
@ -534,9 +536,11 @@
<!-- Purchase RAM for Home Computer Pop-up Box --> <!-- Purchase RAM for Home Computer Pop-up Box -->
<div id="purchase-ram-for-home-box-container"> <div id="purchase-ram-for-home-box-container">
<p id="purchase-ram-for-home-box-text"> </p> <div id="purchase-ram-for-home-box-content">
<span id="purchase-ram-for-home-box-confirm"> Purchase </span> <p id="purchase-ram-for-home-box-text"> </p>
<span id="purchase-ram-for-home-box-cancel"> Cancel </span> <span id="purchase-ram-for-home-box-confirm"> Purchase </span>
<span id="purchase-ram-for-home-box-cancel"> Cancel </span>
</div>
</div> </div>
<!-- Travel Pop-up Box --> <!-- Travel Pop-up Box -->

@ -7,6 +7,9 @@ CONSTANTS = {
//How much reputation is needed to join a megacorporation's faction //How much reputation is needed to join a megacorporation's faction
CorpFactionRepRequirement: 250000, CorpFactionRepRequirement: 250000,
//Base cost for 1GB of RAM
BaseCostFor1GBOfRam: 50000,
/* Script related things */ /* Script related things */
//Time (ms) it takes to run one operation in Netscript. //Time (ms) it takes to run one operation in Netscript.

@ -27,6 +27,44 @@ HacknetNode.prototype.calculateLevelUpgradeCost = function() {
return baseCost * Math.pow(mult, this.level); 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 */ /* Saving and loading HackNets */
HacknetNode.prototype.toJSON = function() { HacknetNode.prototype.toJSON = function() {
return Generic_toJSON("HacknetNode", this); return Generic_toJSON("HacknetNode", this);
@ -36,9 +74,54 @@ HacknetNode.fromJSON = function(value) {
return Generic_fromJSON(HacknetNode, value.data); 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 + "<br>"
"Production: " + nodeObj.totalMoneyGenerated +
" ($" + nodeObj.moneyGainRatePerSecond + ") <br>" +
"Level: " + nodeObj.level + "<br>" +
"RAM: " + nodeObj.ram + "GB<br>" +
"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() { purchaseHacknet = function() {
} }

@ -79,6 +79,7 @@ function PlayerObject() {
this.currentServer = ""; //IP address of Server currently being accessed through terminal 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.discoveredServers = []; //IP addresses of secret servers not in the network that you have discovered
this.purchasedServers = []; this.purchasedServers = [];
this.hacknetNodes = [];
//Factions //Factions
this.factions = []; //Names of all factions player has joined this.factions = []; //Names of all factions player has joined

@ -22,8 +22,7 @@ function Server() {
this.scripts = []; this.scripts = [];
this.runningScripts = []; //Names (and only names) of scripts being run this.runningScripts = []; //Names (and only names) of scripts being run
this.programs = []; this.programs = [];
this.hacknetNodes = [];
/* Hacking information (only valid for "foreign" aka non-purchased servers) */ /* Hacking information (only valid for "foreign" aka non-purchased servers) */
//Skill required to attempt a hack. Whether a hack is successful will be determined //Skill required to attempt a hack. Whether a hack is successful will be determined

@ -36,7 +36,7 @@ purchaseRamForHomeBoxCreate = function() {
//Calculate cost //Calculate cost
//Base cost of RAM is 50k per 1GB...but lets have this increase by 10% for every time //Base cost of RAM is 50k per 1GB...but lets have this increase by 10% for every time
//the RAM has been upgraded //the RAM has been upgraded
var cost = currentRam * 50000; var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRam;
var mult = Math.pow(1.1, numUpgrades); var mult = Math.pow(1.1, numUpgrades);
cost = cost * mult; cost = cost * mult;