Added functions for weakening server security and updated docuemtnation

This commit is contained in:
Daniel Xie 2017-05-31 12:37:32 -05:00
parent 07d9dc6db8
commit d825b25c73
6 changed files with 105 additions and 14 deletions

@ -1693,7 +1693,7 @@ applyAugmentation = function(aug, reapply=false) {
Player.hacking_chance_mult *= 1.01; Player.hacking_chance_mult *= 1.01;
Player.hacking_speed_mult *= 0.99; Player.hacking_speed_mult *= 0.99;
Player.hacking_money_mult *= 1.01; Player.hacking_money_mult *= 1.01;
//Player.hacking_grow_mult *= 1.01; Player.hacking_grow_mult *= 1.01;
Player.hacking_mult *= 1.01; Player.hacking_mult *= 1.01;
Player.strength_mult *= 1.01; Player.strength_mult *= 1.01;

@ -42,6 +42,7 @@ CONSTANTS = {
ScriptIfRamCost: 0.1, ScriptIfRamCost: 0.1,
ScriptHackRamCost: 0.25, ScriptHackRamCost: 0.25,
ScriptGrowRamCost: 0.25, ScriptGrowRamCost: 0.25,
ScriptWeakenRamCost: 0.5,
ScriptNukeRamCost: 0.05, ScriptNukeRamCost: 0.05,
ScriptBrutesshRamCost: 0.05, ScriptBrutesshRamCost: 0.05,
ScriptFtpcrackRamCost: 0.05, ScriptFtpcrackRamCost: 0.05,
@ -49,12 +50,13 @@ CONSTANTS = {
ScriptHttpwormRamCost: 0.05, ScriptHttpwormRamCost: 0.05,
ScriptSqlinjectRamCost: 0.05, ScriptSqlinjectRamCost: 0.05,
ScriptRunRamCost: 0.8, ScriptRunRamCost: 0.8,
ScriptExecRamCost: 1.0, ScriptExecRamCost: 1.1,
ScriptScpRamCost: 0.5, ScriptScpRamCost: 0.5,
ScriptHasRootAccessRamCost: 0.05, ScriptHasRootAccessRamCost: 0.05,
ScriptGetHostnameRamCost: 0.1, ScriptGetHostnameRamCost: 0.1,
ScriptGetHackingLevelRamCost: 0.1, ScriptGetHackingLevelRamCost: 0.1,
ScriptGetServerMoneyRamCost: 0.1, ScriptGetServerMoneyRamCost: 0.1,
ScriptGetServerSecurityRamCost: 0.2,
ScriptOperatorRamCost: 0.01, ScriptOperatorRamCost: 0.01,
ScriptPurchaseHacknetRamCost: 1.5, ScriptPurchaseHacknetRamCost: 1.5,
ScriptHacknetNodesRamCost: 1.0, //Base cost for accessing hacknet nodes array ScriptHacknetNodesRamCost: 1.0, //Base cost for accessing hacknet nodes array
@ -63,8 +65,8 @@ CONSTANTS = {
ScriptHNUpgCoreRamCost: 0.8, ScriptHNUpgCoreRamCost: 0.8,
//Server constants //Server constants
ServerGrowthRate: 1.0018, //Growth rate ServerGrowthRate: 1.0012, //Growth rate
ServerFortifyAmount: 0.001, //Amount by which server's security increases when its hacked ServerFortifyAmount: 0.002, //Amount by which server's security increases when its hacked
ServerWeakenAmount: 0.1, //Amount by which server's security decreases when weakened ServerWeakenAmount: 0.1, //Amount by which server's security decreases when weakened
//Maximum number of log entries for a script //Maximum number of log entries for a script
@ -181,7 +183,7 @@ CONSTANTS = {
TutorialHackingText: "In the year 2077, currency has become digital and decentralized. People and corporations " + TutorialHackingText: "In the year 2077, currency has become digital and decentralized. People and corporations " +
"store their money on servers. By hacking these servers, you can steal their money and gain " + "store their money on servers. By hacking these servers, you can steal their money and gain " +
"experience. <br><br>" + "experience. <br><br>" +
"<strong>Gaining root access</strong> <br>" + "<h1>Gaining root access</h1> <br>" +
"The key to hacking a server is to gain root access to that server. This can be done using " + "The key to hacking a server is to gain root access to that server. This can be done using " +
"the NUKE virus (NUKE.exe). You start the game with a copy of the NUKE virus on your home " + "the NUKE virus (NUKE.exe). You start the game with a copy of the NUKE virus on your home " +
"computer. The NUKE virus attacks the target server's open ports using buffer overflow " + "computer. The NUKE virus attacks the target server's open ports using buffer overflow " +
@ -194,10 +196,10 @@ CONSTANTS = {
"a seller. <br><br>" + "a seller. <br><br>" +
"In order to determine how many ports need to be opened to successfully NUKE a server, connect to " + "In order to determine how many ports need to be opened to successfully NUKE a server, connect to " +
"that server and run the 'analyze' command. This will also show you which ports have already been " + "that server and run the 'analyze' command. This will also show you which ports have already been " +
"opened. <br>" + "opened. <br><br>" +
"Once you have enough ports opened and have ran the NUKE virus to gain root access, the server " + "Once you have enough ports opened and have ran the NUKE virus to gain root access, the server " +
"can then be hacked by simply calling the 'hack' command through terminal, or by using a script.<br><br>" + "can then be hacked by simply calling the 'hack' command through terminal, or by using a script.<br><br>" +
"<strong>Hacking mechanics</strong><br>" + "<h1>Hacking mechanics</h1><br>" +
"When you execute the hack command, either manually through the terminal or automatically through " + "When you execute the hack command, either manually through the terminal or automatically through " +
"a script, you attempt to hack the server. This action takes time. The more advanced a server's " + "a script, you attempt to hack the server. This action takes time. The more advanced a server's " +
"security is, the more time it will take. Your hacking skill level also affects the hacking time, " + "security is, the more time it will take. Your hacking skill level also affects the hacking time, " +
@ -210,7 +212,18 @@ CONSTANTS = {
"percentage is determined by the server's security and your hacking skill level. The amount of money " + "percentage is determined by the server's security and your hacking skill level. The amount of money " +
"on a server is not limitless. So, if you constantly hack a server and deplete its money, then you will " + "on a server is not limitless. So, if you constantly hack a server and deplete its money, then you will " +
"encounter diminishing returns in your hacking (since you are only hacking a certain percentage). A server " + "encounter diminishing returns in your hacking (since you are only hacking a certain percentage). A server " +
"will regain money at a slow rate over time. ", "will regain money at a slow rate over time. <br><br>" +
"<h1>Server Security</h1><br>" +
"Each server has a security level, which is denoted by a number between 1 and 100. A higher number means " +
"the server has stronger security. As mentioned above, a server's security level is an important factor " +
"to consider when hacking. You can check a server's security level using the 'analyze' command, although this " +
"only gives an estimate (with 5% uncertainty). You can also check a server's security in a script, using the " +
"<i>getServerSecurityLevel(server)</i> function in Netscript. See the Netscript documentation for more details. " +
"This function will give you an exact value for a server's security. <br><br>" +
"Whenever a server is hacked manually or through a script, its security level increases by a small amount. This will " +
"make it harder for you to hack the server, and decrease the amount of money you can steal. You can lower a " +
"server's security level in a script using the <i>weaken(server)</i> function in Netscript. See the Netscript " +
"documentation for more details",
TutorialScriptsText: "Scripts can be used to automate the hacking process. Scripts must be written in the Netscript language. " + TutorialScriptsText: "Scripts can be used to automate the hacking process. Scripts must be written in the Netscript language. " +
"Documentation about the Netscript language can be found in the 'Netscript Programming Language' " + "Documentation about the Netscript language can be found in the 'Netscript Programming Language' " +

@ -404,6 +404,52 @@ function evaluate(exp, workerScript) {
}, function(e) { }, function(e) {
reject(e); reject(e);
}); });
} else if (exp.func.value == "weaken") {
if (env.stopFlag) {reject(workerScript); return;}
if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|weaken() call has incorrect number of arguments. Takes 1 argument");
return;
}
var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) {
if (env.stopFlag) {reject(workerScript); return;}
var server = getServer(ip);
if (server == null) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Invalid IP or hostname passed into weaken() command");
workerScript.scriptRef.log("Cannot weaken(). Invalid IP or hostname passed in: " + ip);
return;
}
//No root access or skill level too low
if (server.hasAdminRights == false) {
workerScript.scriptRef.log("Cannot weaken this server (" + server.hostname + ") because user does not have root access");
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Script crashed because it did not have root access to " + server.hostname);
return;
}
var weakenTime = scriptCalculateWeakenTime(server);
console.log("Executing weaken() on server " + server.hostname + " in " + formatNumber(weakenTime/1000, 3) + " seconds")
workerScript.scriptRef.log("Executing weaken() on server " + server.hostname + " in " + formatNumber(weakenTime/1000, 3) + " seconds");
var p = new Promise(function(resolve, reject) {
if (env.stopFlag) {reject(workerScript); return;}
setTimeout(function() {
server.weaken(CONSTANTS.ServerWeakenAmount);
resolve(CONSTANTS.ServerWeakenAmount);
}, weakenTime);
});
p.then(function(amt) {
workerScript.scriptRef.log("Using weaken(), " + server.hostname + "'s security level was decreased by " + amt + ". Gained 5 hacking exp");
Player.gainHackingExp(5);
workerScript.scriptRef.onlineExpGained += 5;
resolve("hackExecuted");
}, function(e) {
reject(e);
});
}, function(e) {
reject(e);
});
} else if (exp.func.value == "nuke") { } else if (exp.func.value == "nuke") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|nuke() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|nuke() call has incorrect number of arguments. Takes 1 argument");
@ -840,15 +886,35 @@ function evaluate(exp, workerScript) {
}, function(e) { }, function(e) {
reject(e); reject(e);
}); });
} else if (exp.func.value == "getServerSecurityLevel") {
if (exp.args.length != 1) {
reject(makeRuntimeRejectMsg(workerScript, "getServerSecurityLevel() call has incorrect number of arguments. Takes 1 arguments"));
return;
}
var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) {
setTimeout(function() {
var server = getServer(ip);
if (server == null) {
reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into getServerSecurityLevel() command"));
workerScript.scriptRef.log("Cannot getServerSecurityLevel(). Invalid IP or hostname passed in: " + ip);
return;
}
workerScript.scriptRef.log("getServerSecurityLevel() returned " + formatNumber(server.hackDifficulty, 3));
resolve(server.hackDifficulty);
}, CONSTANTS.CodeInstructionRunTime);
}, function(e) {
reject(e);
});
} else if (exp.func.value == "purchaseHacknetNode") { } else if (exp.func.value == "purchaseHacknetNode") {
if (exp.args.length != 0) { if (exp.args.length != 0) {
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|purchaseHacknetNode() call has incorrect number of arguments. Takes 0 arguments"); reject(makeRuntimeRejectMsg(workerScript, "purchaseHacknetNode() call has incorrect number of arguments. Takes 0 arguments"));
return; return;
} }
setTimeout(function() { setTimeout(function() {
var cost = getCostOfNextHacknetNode(); var cost = getCostOfNextHacknetNode();
if (isNaN(cost)) { if (isNaN(cost)) {
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|Could not calculate cost in purchaseHacknetNode(). This is a bug please report to game dev"); reject(makeRuntimeRejectMsg(workerScript, "Could not calculate cost in purchaseHacknetNode(). This is a bug please report to game dev"));
return; return;
} }
if (cost > Player.money) { if (cost > Player.money) {
@ -1304,10 +1370,18 @@ function scriptCalculatePercentMoneyHacked(server) {
return percentMoneyHacked; return percentMoneyHacked;
} }
//Amount of time to execute grow() //Amount of time to execute grow() in milliseconds
function scriptCalculateGrowTime(server) { function scriptCalculateGrowTime(server) {
var difficultyMult = server.requiredHackingSkill * server.hackDifficulty; var difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
var skillFactor = (2.5 * difficultyMult + 500) / (Player.hacking_skill + 50); var skillFactor = (2.5 * difficultyMult + 500) / (Player.hacking_skill + 50);
var growTime = skillFactor * Player.hacking_speed_mult * 16; //This is in seconds var growTime = skillFactor * Player.hacking_speed_mult * 16; //This is in seconds
return growTime * 1000; return growTime * 1000;
}
//Amount of time to execute weaken() in milliseconds
function scriptCalculateWeakenTime(server) {
var difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
var skillFactor = (2.5 * difficultyMult + 500) / (Player.hacking_skill + 50);
var weakenTime = skillFactor * Player.hacking_speed_mult * 100; //This is in seconds
return weakenTime * 1000;
} }

@ -175,6 +175,7 @@ Script.prototype.updateRamUsage = function() {
var ifCount = numOccurrences(codeCopy, "if("); var ifCount = numOccurrences(codeCopy, "if(");
var hackCount = numOccurrences(codeCopy, "hack("); var hackCount = numOccurrences(codeCopy, "hack(");
var growCount = numOccurrences(codeCopy, "grow("); var growCount = numOccurrences(codeCopy, "grow(");
var weakenCount = numOccurrences(codeCopy, "weaken(");
var nukeCount = numOccurrences(codeCopy, "nuke("); var nukeCount = numOccurrences(codeCopy, "nuke(");
var brutesshCount = numOccurrences(codeCopy, "brutessh("); var brutesshCount = numOccurrences(codeCopy, "brutessh(");
var ftpcrackCount = numOccurrences(codeCopy, "ftpcrack("); var ftpcrackCount = numOccurrences(codeCopy, "ftpcrack(");
@ -188,6 +189,7 @@ Script.prototype.updateRamUsage = function() {
var getHostnameCount = numOccurrences(codeCopy, "getHostname("); var getHostnameCount = numOccurrences(codeCopy, "getHostname(");
var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel("); var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel(");
var getServerMoneyAvailableCount = numOccurrences(codeCopy, "getServerMoneyAvailable("); var getServerMoneyAvailableCount = numOccurrences(codeCopy, "getServerMoneyAvailable(");
var getServerSecurityCount = numOccurrences(codeCopy, "getServerSecurityLevel(");
var numOperators = numNetscriptOperators(codeCopy); var numOperators = numNetscriptOperators(codeCopy);
var purchaseHacknetCount = numOccurrences(codeCopy, "purchaseHacknetNode("); var purchaseHacknetCount = numOccurrences(codeCopy, "purchaseHacknetNode(");
var hacknetnodesArrayCount = numOccurrences(codeCopy, "hacknetnodes["); var hacknetnodesArrayCount = numOccurrences(codeCopy, "hacknetnodes[");
@ -201,6 +203,7 @@ Script.prototype.updateRamUsage = function() {
(ifCount * CONSTANTS.ScriptIfRamCost) + (ifCount * CONSTANTS.ScriptIfRamCost) +
(hackCount * CONSTANTS.ScriptHackRamCost) + (hackCount * CONSTANTS.ScriptHackRamCost) +
(growCount * CONSTANTS.ScriptGrowRamCost) + (growCount * CONSTANTS.ScriptGrowRamCost) +
(weakenCount * CONSTANTS.ScriptWeakenRamCost) +
(nukeCount * CONSTANTS.ScriptNukeRamCost) + (nukeCount * CONSTANTS.ScriptNukeRamCost) +
(brutesshCount * CONSTANTS.ScriptBrutesshRamCost) + (brutesshCount * CONSTANTS.ScriptBrutesshRamCost) +
(ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) + (ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) +
@ -214,6 +217,7 @@ Script.prototype.updateRamUsage = function() {
(getHostnameCount * CONSTANTS.ScriptGetHostnameRamCost) + (getHostnameCount * CONSTANTS.ScriptGetHostnameRamCost) +
(getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) + (getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) +
(getServerMoneyAvailableCount * CONSTANTS.ScriptGetServerMoneyRamCost) + (getServerMoneyAvailableCount * CONSTANTS.ScriptGetServerMoneyRamCost) +
(getServerSecurityCount * CONSTANTS.ScriptGetServerSecurityRamCost) +
(numOperators * CONSTANTS.ScriptOperatorRamCost) + (numOperators * CONSTANTS.ScriptOperatorRamCost) +
(purchaseHacknetCount * CONSTANTS.ScriptPurchaseHacknetRamCost) + (purchaseHacknetCount * CONSTANTS.ScriptPurchaseHacknetRamCost) +
(hacknetnodesArrayCount * CONSTANTS.ScriptHacknetNodesRamCost) + (hacknetnodesArrayCount * CONSTANTS.ScriptHacknetNodesRamCost) +

@ -662,7 +662,7 @@ processServerGrowth = function(numCycles) {
var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage; var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage;
//Apply serverGrowth for the calculated number of growth cycles //Apply serverGrowth for the calculated number of growth cycles
var serverGrowth = Math.pow(CONSTANTS.ServerGrowthRate, numServerGrowthCyclesAdjusted) * Player.hacking_grow_mult; var serverGrowth = Math.pow(CONSTANTS.ServerGrowthRate, numServerGrowthCyclesAdjusted * Player.hacking_grow_mult) ;
if (serverGrowth < 1) { if (serverGrowth < 1) {
console.log("WARN: serverGrowth calculated to be less than 1"); console.log("WARN: serverGrowth calculated to be less than 1");
serverGrowth = 1; serverGrowth = 1;
@ -685,7 +685,7 @@ processSingleServerGrowth = function(server, numCycles) {
var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage; var numServerGrowthCyclesAdjusted = numServerGrowthCycles * serverGrowthPercentage;
//Apply serverGrowth for the calculated number of growth cycles //Apply serverGrowth for the calculated number of growth cycles
var serverGrowth = Math.pow(CONSTANTS.ServerGrowthRate, numServerGrowthCyclesAdjusted) * Player.hacking_grow_mult; var serverGrowth = Math.pow(CONSTANTS.ServerGrowthRate, numServerGrowthCyclesAdjusted * Player.hacking_grow_mult) ;
if (serverGrowth < 1) { if (serverGrowth < 1) {
console.log("WARN: serverGrowth calculated to be less than 1"); console.log("WARN: serverGrowth calculated to be less than 1");
serverGrowth = 1; serverGrowth = 1;

@ -319,7 +319,7 @@ var Terminal = {
else {rootAccess = "NO";} else {rootAccess = "NO";}
post("Root Access: " + rootAccess); post("Root Access: " + rootAccess);
post("Required hacking skill: " + Player.getCurrentServer().requiredHackingSkill); post("Required hacking skill: " + Player.getCurrentServer().requiredHackingSkill);
post("Estimated server security level(1-100): " + formatNumber(addOffset(Player.getCurrentServer().hackDifficulty, 5), 0)); post("Estimated server security level(1-100): " + formatNumber(addOffset(Player.getCurrentServer().hackDifficulty, 5), 3));
post("Estimated chance to hack: " + formatNumber(addOffset(Player.calculateHackingChance() * 100, 5), 2) + "%"); post("Estimated chance to hack: " + formatNumber(addOffset(Player.calculateHackingChance() * 100, 5), 2) + "%");
post("Estimated time to hack: " + formatNumber(addOffset(Player.calculateHackingTime(), 5), 3) + " seconds"); post("Estimated time to hack: " + formatNumber(addOffset(Player.calculateHackingTime(), 5), 3) + " seconds");
post("Estimated total money available on server: $" + formatNumber(addOffset(Player.getCurrentServer().moneyAvailable, 5), 2)); post("Estimated total money available on server: $" + formatNumber(addOffset(Player.getCurrentServer().moneyAvailable, 5), 2));