updated README with TODOS. FIxed kill command and sleep() command in script

This commit is contained in:
Daniel Xie 2016-12-13 17:52:32 -06:00
parent 2e6206ac16
commit c485f28e20
6 changed files with 147 additions and 79 deletions

@ -1,13 +1,21 @@
# netburner # netburner
Netburner Idle Game Netburner Idle Game
TESTING TODO: TESTING TODO:
Kill command
hack() and sleep() in a script hack() and sleep() in a script
Hack() not finished, need a safeguard to allow script to only hack servers that the player
has admin access to
Sleep() seems to be working
Creating the foreign server network doesn't seem to be working
Tasks TODO: Tasks TODO:
If a server has no more money available it cannot be hacked anymore
Script RAM Usage and corresponding terminal commands Script RAM Usage and corresponding terminal commands
Script offline progress Script offline progress
When the game is loaded re-load all of the scripts in runningScripts
If a script has bad syntax...it fucks everything up when you try to run it so fix that
Scroll all the way down when something is post()ed
Scripts tab that shows script stats
Script logging functionality? Logs to internal "log file" (property of script itself)
Update skill level on cycle
Parse script firs tot see if there are any syntax errors, and tell user if there are (when user calls "run")

@ -180,43 +180,61 @@ function evaluate(exp, workerScript) {
setTimeout(function() { setTimeout(function() {
if (exp.func.value == "hack") { if (exp.func.value == "hack") {
console.log("Execute hack()"); console.log("Execute hack()");
if (exp.args.length != 0) { if (exp.args.length != 1) {
throw new Error("Hack() call has incorrect number of arguments. Takes no arguments"); throw new Error("Hack() call has incorrect number of arguments. Takes 1 argument");
} }
//Calculate the hacking time //IP of server to hack
var currentServer = AllServers[workerScript.serverIp]; var ipPromise = evaluate(exp.args[0], workerScript);
var difficultyMult = currentServer.requiredHackingSkill * currentServer.hackDifficulty;
var skillFactor = difficultMult / Player.hacking_skill;
var hackingTime = skillFactor * Player.hacking_speed_multiplier; //This is in seconds
//TODO Add a safeguard to prevent a script from hacking a Server that the player ipPromise.then(function(ip) {
//cannot hack //Calculate the hacking time
var server = AllServers[ip];
var p = new Promise(function(resolve, reject) { var hackingTime = scriptCalculateHackingTime(server); //This is in seconds
setTimeout(function() {
var hackChance = Player.calculateHackingChance(); //TODO Add a safeguard to prevent a script from hacking a Server that the player
var rand = Math.random(); //cannot hack
var expGainedOnSuccess = Player.calculateExpGain(); if (server.hasAdminRights == false) {
var expGainedOnFailure = Math.round(expGainedOnSuccess / 4); console.log("Cannot hack server " + server.hostname);
if (rand < hackChance) { //Success! resolve("Cannot hack");
var moneyGained = Player.calculatePercentMoneyHacked(); //TODO LOG That it can't be hacked
moneyGained = Math.floor(Player.getCurrentServer().moneyAvailable * moneyGained); }
Player.getCurrentServer().moneyAvailable -= moneyGained; var p = new Promise(function(resolve, reject) {
Player.money += moneyGained; console.log("Hacking " + server.hostname + " after " + hackingTime.toString() + " seconds.");
setTimeout(function() {
Player.hacking_exp += expGainedOnSuccess; var hackChance = scriptCalculateHackingChance(server);
} else { var rand = Math.random();
//Player only gains 25% exp for failure? TODO Can change this later to balance var expGainedOnSuccess = scriptCalculateExpGain(server);
Player.hacking_exp += expGainedOnFailure; var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
} if (rand < hackChance) { //Success!
}, hackingTime * 1000); var moneyGained = scriptCalculatePercentMoneyHacked(server);
}); moneyGained = Math.floor(server.moneyAvailable * moneyGained);
p.then(function(res) { server.moneyAvailable -= moneyGained;
resolve("hackExecuted"); Player.money += moneyGained;
Player.hacking_exp += expGainedOnSuccess;
console.log("Script successfully hacked " + server.hostname + " for $" + moneyGained + " and " + expGainedOnSuccess + " exp");
resolve("Hack success");
} else {
//Player only gains 25% exp for failure? TODO Can change this later to balance
Player.hacking_exp += expGainedOnFailure;
console.log("Script unsuccessful to hack " + server.hostname + ". Gained " + expGainedOnFailure + "exp");
resolve("Hack failure");
}
}, hackingTime * 1000);
});
p.then(function(res) {
resolve("hackExecuted");
}, function() {
reject(workerScript);
});
}, function() {
reject(workerScript)
}); });
} else if (exp.func.value == "sleep") { } else if (exp.func.value == "sleep") {
console.log("Execute sleep()"); console.log("Execute sleep()");
@ -224,15 +242,24 @@ function evaluate(exp, workerScript) {
throw new Error("Sleep() call has incorrect number of arguments. Takes 1 argument."); throw new Error("Sleep() call has incorrect number of arguments. Takes 1 argument.");
} }
var p = new Promise(function(resolve, reject) { var sleepTimePromise = evaluate(exp.args[0], workerScript);
setTimeout(function() { sleepTimePromise.then(function(sleepTime) {
resolve("foo"); console.log("Sleep time: " + sleepTime);
}, exp.args[0]); var p = new Promise(function(resolve, reject) {
}); setTimeout(function() {
resolve("foo");
}, sleepTime);
});
p.then(function(res) { p.then(function(res) {
resolve("sleepExecuted"); resolve("sleepExecuted");
}, function() {
reject(workerScript);
});
}, function() {
reject(workerScript)
}); });
} else if (exp.func.value == "print") { } else if (exp.func.value == "print") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
@ -450,3 +477,32 @@ function apply_op(op, a, b) {
} }
throw new Error("Can't apply operator " + op); throw new Error("Can't apply operator " + op);
} }
//The same as Player's calculateHackingChance() function but takes in the server as an argument
function scriptCalculateHackingChance(server) {
var difficultyMult = (100 - server.hackDifficulty) / 100;
var skillMult = (Player.hacking_chance_multiplier * Player.hacking_skill);
var skillChance = (skillMult - server.requiredHackingSkill) / skillMult;
return (skillChance * difficultyMult);
}
//The same as Player's calculateHackingTime() function but takes in the server as an argument
function scriptCalculateHackingTime(server) {
var difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
var skillFactor = difficultyMult / Player.hacking_skill;
var hackingTime = skillFactor * Player.hacking_speed_multiplier; //This is in seconds
}
//The same as Player's calculateExpGain() function but takes in the server as an argument
function scriptCalculateExpGain(server) {
return Math.round(server.hackDifficulty * server.requiredHackingSkill * Player.hacking_exp_mult);
}
//The same as Player's calculatePercentMoneyHacked() function but takes in the server as an argument
function scriptCalculatePercentMoneyHacked(server) {
var difficultyMult = (100 - server.hackDifficulty) / 100;
var skillMult = (Player.hacking_skill - (server.requiredHackingSkill - 1)) / Player.hacking_skill;
var percentMoneyHacked = difficultyMult * skillMult * Player.hacking_money_multiplier;
console.log("Percent money hacked calculated to be: " + percentMoneyHacked);
return percentMoneyHacked;
}

@ -49,7 +49,7 @@ function runScriptsLoop() {
//items fucks up the indexing //items fucks up the indexing
for (var i = workerScripts.length - 1; i >= 0; i--) { for (var i = workerScripts.length - 1; i >= 0; i--) {
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == true) { if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == true) {
console.log("Deleting scripts"); console.log("Deleting script: " + workerScripts[i].name);
//Delete script from the runningScripts array on its host serverIp //Delete script from the runningScripts array on its host serverIp
var ip = workerScripts[i].serverIp; var ip = workerScripts[i].serverIp;
var name = workerScripts[i].name; var name = workerScripts[i].name;
@ -72,6 +72,7 @@ function runScriptsLoop() {
//all of its promises recursively, and when it does so it will no longer be running. //all of its promises recursively, and when it does so it will no longer be running.
//The runScriptsLoop() will then delete the script from worker scripts //The runScriptsLoop() will then delete the script from worker scripts
function killWorkerScript(scriptName, serverIp) { function killWorkerScript(scriptName, serverIp) {
console.log("killWorkerScript called for script " + scriptName + " on server " + serverIp);
for (var i = 0; i < workerScripts.length; i++) { for (var i = 0; i < workerScripts.length; i++) {
if (workerScripts[i].name == scriptName && workerScripts[i].serverIp == serverIp) { if (workerScripts[i].name == scriptName && workerScripts[i].serverIp == serverIp) {
workerScripts[i].env.stopFlag = true; workerScripts[i].env.stopFlag = true;

@ -507,86 +507,86 @@ initForeignServers = function() {
for (var i = 0; i < NetworkGroup2.length; i++) { for (var i = 0; i < NetworkGroup2.length; i++) {
var randomServerFromPrevGroup = NetworkGroup1[Math.floor(Math.random() * NetworkGroup1.length)]; var randomServerFromPrevGroup = NetworkGroup1[Math.floor(Math.random() * NetworkGroup1.length)];
NetworkGroup2[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup2[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup2[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup2[i].ip);
} }
for (var i = 0; i < NetworkGroup3.length; i++) { for (var i = 0; i < NetworkGroup3.length; i++) {
var randomServerFromPrevGroup = NetworkGroup2[Math.floor(Math.random() * NetworkGroup2.length)]; var randomServerFromPrevGroup = NetworkGroup2[Math.floor(Math.random() * NetworkGroup2.length)];
NetworkGroup3[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup3[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup3[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup3[i].ip);
} }
for (var i = 0; i < NetworkGroup4.length; i++) { for (var i = 0; i < NetworkGroup4.length; i++) {
var randomServerFromPrevGroup = NetworkGroup3[Math.floor(Math.random() * NetworkGroup3.length)]; var randomServerFromPrevGroup = NetworkGroup3[Math.floor(Math.random() * NetworkGroup3.length)];
NetworkGroup4[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup4[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup4[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup4[i].ip);
} }
for (var i = 0; i < NetworkGroup5.length; i++) { for (var i = 0; i < NetworkGroup5.length; i++) {
var randomServerFromPrevGroup = NetworkGroup4[Math.floor(Math.random() * NetworkGroup4.length)]; var randomServerFromPrevGroup = NetworkGroup4[Math.floor(Math.random() * NetworkGroup4.length)];
NetworkGroup5[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup5[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup5[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup5[i].ip);
} }
for (var i = 0; i < NetworkGroup6.length; i++) { for (var i = 0; i < NetworkGroup6.length; i++) {
var randomServerFromPrevGroup = NetworkGroup5[Math.floor(Math.random() * NetworkGroup5.length)]; var randomServerFromPrevGroup = NetworkGroup5[Math.floor(Math.random() * NetworkGroup5.length)];
NetworkGroup6[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup6[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup6[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup6[i].ip);
} }
for (var i = 0; i < NetworkGroup7.length; i++) { for (var i = 0; i < NetworkGroup7.length; i++) {
var randomServerFromPrevGroup = NetworkGroup6[Math.floor(Math.random() * NetworkGroup6.length)]; var randomServerFromPrevGroup = NetworkGroup6[Math.floor(Math.random() * NetworkGroup6.length)];
NetworkGroup7[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup7[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup7[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup7[i].ip);
} }
for (var i = 0; i < NetworkGroup8.length; i++) { for (var i = 0; i < NetworkGroup8.length; i++) {
var randomServerFromPrevGroup = NetworkGroup7[Math.floor(Math.random() * NetworkGroup7.length)]; var randomServerFromPrevGroup = NetworkGroup7[Math.floor(Math.random() * NetworkGroup7.length)];
NetworkGroup8[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup8[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup8[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup8[i].ip);
} }
for (var i = 0; i < NetworkGroup9.length; i++) { for (var i = 0; i < NetworkGroup9.length; i++) {
var randomServerFromPrevGroup = NetworkGroup8[Math.floor(Math.random() * NetworkGroup8.length)]; var randomServerFromPrevGroup = NetworkGroup8[Math.floor(Math.random() * NetworkGroup8.length)];
NetworkGroup9[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup9[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup9[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup9[i].ip);
} }
for (var i = 0; i < NetworkGroup10.length; i++) { for (var i = 0; i < NetworkGroup10.length; i++) {
var randomServerFromPrevGroup = NetworkGroup9[Math.floor(Math.random() * NetworkGroup9.length)]; var randomServerFromPrevGroup = NetworkGroup9[Math.floor(Math.random() * NetworkGroup9.length)];
NetworkGroup10[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup10[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup10[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup10[i].ip);
} }
for (var i = 0; i < NetworkGroup11.length; i++) { for (var i = 0; i < NetworkGroup11.length; i++) {
var randomServerFromPrevGroup = NetworkGroup10[Math.floor(Math.random() * NetworkGroup10.length)]; var randomServerFromPrevGroup = NetworkGroup10[Math.floor(Math.random() * NetworkGroup10.length)];
NetworkGroup11[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup11[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup11[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup11[i].ip);
} }
for (var i = 0; i < NetworkGroup12.length; i++) { for (var i = 0; i < NetworkGroup12.length; i++) {
var randomServerFromPrevGroup = NetworkGroup11[Math.floor(Math.random() * NetworkGroup11.length)]; var randomServerFromPrevGroup = NetworkGroup11[Math.floor(Math.random() * NetworkGroup11.length)];
NetworkGroup12[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup12[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup12[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup12[i].ip);
} }
for (var i = 0; i < NetworkGroup13.length; i++) { for (var i = 0; i < NetworkGroup13.length; i++) {
var randomServerFromPrevGroup = NetworkGroup12[Math.floor(Math.random() * NetworkGroup12.length)]; var randomServerFromPrevGroup = NetworkGroup12[Math.floor(Math.random() * NetworkGroup12.length)];
NetworkGroup13[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup13[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup13[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup13[i].ip);
} }
for (var i = 0; i < NetworkGroup14.length; i++) { for (var i = 0; i < NetworkGroup14.length; i++) {
var randomServerFromPrevGroup = NetworkGroup13[Math.floor(Math.random() * NetworkGroup13.length)]; var randomServerFromPrevGroup = NetworkGroup13[Math.floor(Math.random() * NetworkGroup13.length)];
NetworkGroup14[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup14[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup14[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup14[i].ip);
} }
for (var i = 0; i < NetworkGroup15.length; i++) { for (var i = 0; i < NetworkGroup15.length; i++) {
var randomServerFromPrevGroup = NetworkGroup14[Math.floor(Math.random() * NetworkGroup14.length)]; var randomServerFromPrevGroup = NetworkGroup14[Math.floor(Math.random() * NetworkGroup14.length)];
NetworkGroup15[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname); NetworkGroup15[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup15[i].hostname); randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup15[i].ip);
} }
//Connect the first tier of servers to the player's home computer //Connect the first tier of servers to the player's home computer

@ -255,6 +255,9 @@ var Terminal = {
case "help": case "help":
//TODO //TODO
break; break;
case "home":
//TODO return to home computer
break;
case "hostname": case "hostname":
if (commandArray.length != 1) { if (commandArray.length != 1) {
post("Incorrect usage of hostname command. Usage: hostname"); return; post("Incorrect usage of hostname command. Usage: hostname"); return;
@ -276,10 +279,10 @@ var Terminal = {
var scriptName = commandArray[1]; var scriptName = commandArray[1];
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) { for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
if (Player.getCurrentServer().runningScripts[i] == scriptName) { if (Player.getCurrentServer().runningScripts[i] == scriptName) {
Player.getCurrentServer().runningScripts.splice(i, 1);
killWorkerScript(scriptName, Player.getCurrentServer().ip); killWorkerScript(scriptName, Player.getCurrentServer().ip);
post("Killing " + scriptName + ". May take a few seconds");
return;
} }
} }
post("No such script is running. Nothing to kill"); post("No such script is running. Nothing to kill");
@ -403,6 +406,7 @@ var Terminal = {
//TODO //TODO
break; break;
case "tail": case "tail":
//TODO
break; break;
case "top": case "top":
//TODO List each's script RAM usage //TODO List each's script RAM usage
@ -490,6 +494,7 @@ var Terminal = {
if (Player.getCurrentServer().scripts[i].filename == scriptName) { if (Player.getCurrentServer().scripts[i].filename == scriptName) {
if (Player.getCurrentServer().hasAdminRights == false) { if (Player.getCurrentServer().hasAdminRights == false) {
post("Need root access to run script"); post("Need root access to run script");
return;
} else { } else {
var filename = Player.getCurrentServer().scripts[i].filename; var filename = Player.getCurrentServer().scripts[i].filename;

@ -255,9 +255,7 @@ var Engine = {
Companies.init(); Companies.init();
CompanyPositions.init(); CompanyPositions.init();
} }
PrintAllServers();
//Main menu buttons and content //Main menu buttons and content
Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link"); Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link");
Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() { Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() {