mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 06:02:26 +01:00
updated README with TODOS. FIxed kill command and sleep() command in script
This commit is contained in:
parent
2e6206ac16
commit
c485f28e20
16
README.md
16
README.md
@ -1,13 +1,21 @@
|
||||
# netburner
|
||||
Netburner Idle Game
|
||||
|
||||
|
||||
|
||||
TESTING TODO:
|
||||
Kill command
|
||||
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:
|
||||
If a server has no more money available it cannot be hacked anymore
|
||||
Script RAM Usage and corresponding terminal commands
|
||||
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() {
|
||||
if (exp.func.value == "hack") {
|
||||
console.log("Execute hack()");
|
||||
if (exp.args.length != 0) {
|
||||
throw new Error("Hack() call has incorrect number of arguments. Takes no arguments");
|
||||
if (exp.args.length != 1) {
|
||||
throw new Error("Hack() call has incorrect number of arguments. Takes 1 argument");
|
||||
}
|
||||
|
||||
//Calculate the hacking time
|
||||
var currentServer = AllServers[workerScript.serverIp];
|
||||
var difficultyMult = currentServer.requiredHackingSkill * currentServer.hackDifficulty;
|
||||
var skillFactor = difficultMult / Player.hacking_skill;
|
||||
var hackingTime = skillFactor * Player.hacking_speed_multiplier; //This is in seconds
|
||||
//IP of server to hack
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
|
||||
//TODO Add a safeguard to prevent a script from hacking a Server that the player
|
||||
//cannot hack
|
||||
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
var hackChance = Player.calculateHackingChance();
|
||||
var rand = Math.random();
|
||||
var expGainedOnSuccess = Player.calculateExpGain();
|
||||
var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
|
||||
if (rand < hackChance) { //Success!
|
||||
var moneyGained = Player.calculatePercentMoneyHacked();
|
||||
moneyGained = Math.floor(Player.getCurrentServer().moneyAvailable * moneyGained);
|
||||
|
||||
Player.getCurrentServer().moneyAvailable -= moneyGained;
|
||||
Player.money += moneyGained;
|
||||
|
||||
Player.hacking_exp += expGainedOnSuccess;
|
||||
} else {
|
||||
//Player only gains 25% exp for failure? TODO Can change this later to balance
|
||||
Player.hacking_exp += expGainedOnFailure;
|
||||
}
|
||||
}, hackingTime * 1000);
|
||||
});
|
||||
|
||||
p.then(function(res) {
|
||||
resolve("hackExecuted");
|
||||
ipPromise.then(function(ip) {
|
||||
//Calculate the hacking time
|
||||
var server = AllServers[ip];
|
||||
var hackingTime = scriptCalculateHackingTime(server); //This is in seconds
|
||||
|
||||
//TODO Add a safeguard to prevent a script from hacking a Server that the player
|
||||
//cannot hack
|
||||
if (server.hasAdminRights == false) {
|
||||
console.log("Cannot hack server " + server.hostname);
|
||||
resolve("Cannot hack");
|
||||
//TODO LOG That it can't be hacked
|
||||
}
|
||||
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
console.log("Hacking " + server.hostname + " after " + hackingTime.toString() + " seconds.");
|
||||
setTimeout(function() {
|
||||
var hackChance = scriptCalculateHackingChance(server);
|
||||
var rand = Math.random();
|
||||
var expGainedOnSuccess = scriptCalculateExpGain(server);
|
||||
var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
|
||||
if (rand < hackChance) { //Success!
|
||||
var moneyGained = scriptCalculatePercentMoneyHacked(server);
|
||||
moneyGained = Math.floor(server.moneyAvailable * moneyGained);
|
||||
|
||||
server.moneyAvailable -= moneyGained;
|
||||
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") {
|
||||
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.");
|
||||
}
|
||||
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
resolve("foo");
|
||||
}, exp.args[0]);
|
||||
});
|
||||
var sleepTimePromise = evaluate(exp.args[0], workerScript);
|
||||
sleepTimePromise.then(function(sleepTime) {
|
||||
console.log("Sleep time: " + sleepTime);
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
resolve("foo");
|
||||
}, sleepTime);
|
||||
});
|
||||
|
||||
p.then(function(res) {
|
||||
resolve("sleepExecuted");
|
||||
p.then(function(res) {
|
||||
resolve("sleepExecuted");
|
||||
}, function() {
|
||||
reject(workerScript);
|
||||
});
|
||||
}, function() {
|
||||
reject(workerScript)
|
||||
});
|
||||
|
||||
|
||||
} else if (exp.func.value == "print") {
|
||||
if (exp.args.length != 1) {
|
||||
@ -450,3 +477,32 @@ function apply_op(op, a, b) {
|
||||
}
|
||||
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
|
||||
for (var i = workerScripts.length - 1; i >= 0; i--) {
|
||||
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
|
||||
var ip = workerScripts[i].serverIp;
|
||||
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.
|
||||
//The runScriptsLoop() will then delete the script from worker scripts
|
||||
function killWorkerScript(scriptName, serverIp) {
|
||||
console.log("killWorkerScript called for script " + scriptName + " on server " + serverIp);
|
||||
for (var i = 0; i < workerScripts.length; i++) {
|
||||
if (workerScripts[i].name == scriptName && workerScripts[i].serverIp == serverIp) {
|
||||
workerScripts[i].env.stopFlag = true;
|
||||
|
@ -507,86 +507,86 @@ initForeignServers = function() {
|
||||
|
||||
for (var i = 0; i < NetworkGroup2.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup1[Math.floor(Math.random() * NetworkGroup1.length)];
|
||||
NetworkGroup2[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup2[i].hostname);
|
||||
NetworkGroup2[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup2[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup3.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup2[Math.floor(Math.random() * NetworkGroup2.length)];
|
||||
NetworkGroup3[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup3[i].hostname);
|
||||
NetworkGroup3[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup3[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup4.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup3[Math.floor(Math.random() * NetworkGroup3.length)];
|
||||
NetworkGroup4[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup4[i].hostname);
|
||||
NetworkGroup4[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup4[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup5.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup4[Math.floor(Math.random() * NetworkGroup4.length)];
|
||||
NetworkGroup5[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup5[i].hostname);
|
||||
NetworkGroup5[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup5[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup6.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup5[Math.floor(Math.random() * NetworkGroup5.length)];
|
||||
NetworkGroup6[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup6[i].hostname);
|
||||
NetworkGroup6[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup6[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup7.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup6[Math.floor(Math.random() * NetworkGroup6.length)];
|
||||
NetworkGroup7[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup7[i].hostname);
|
||||
NetworkGroup7[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup7[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup8.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup7[Math.floor(Math.random() * NetworkGroup7.length)];
|
||||
NetworkGroup8[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup8[i].hostname);
|
||||
NetworkGroup8[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup8[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup9.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup8[Math.floor(Math.random() * NetworkGroup8.length)];
|
||||
NetworkGroup9[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup9[i].hostname);
|
||||
NetworkGroup9[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup9[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup10.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup9[Math.floor(Math.random() * NetworkGroup9.length)];
|
||||
NetworkGroup10[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup10[i].hostname);
|
||||
NetworkGroup10[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup10[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup11.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup10[Math.floor(Math.random() * NetworkGroup10.length)];
|
||||
NetworkGroup11[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup11[i].hostname);
|
||||
NetworkGroup11[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup11[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup12.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup11[Math.floor(Math.random() * NetworkGroup11.length)];
|
||||
NetworkGroup12[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup12[i].hostname);
|
||||
NetworkGroup12[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup12[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup13.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup12[Math.floor(Math.random() * NetworkGroup12.length)];
|
||||
NetworkGroup13[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup13[i].hostname);
|
||||
NetworkGroup13[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup13[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup14.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup13[Math.floor(Math.random() * NetworkGroup13.length)];
|
||||
NetworkGroup14[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup14[i].hostname);
|
||||
NetworkGroup14[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup14[i].ip);
|
||||
}
|
||||
|
||||
for (var i = 0; i < NetworkGroup15.length; i++) {
|
||||
var randomServerFromPrevGroup = NetworkGroup14[Math.floor(Math.random() * NetworkGroup14.length)];
|
||||
NetworkGroup15[i].serversOnNetwork.push(randomServerFromPrevGroup.hostname);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup15[i].hostname);
|
||||
NetworkGroup15[i].serversOnNetwork.push(randomServerFromPrevGroup.ip);
|
||||
randomServerFromPrevGroup.serversOnNetwork.push(NetworkGroup15[i].ip);
|
||||
}
|
||||
|
||||
//Connect the first tier of servers to the player's home computer
|
||||
|
@ -255,6 +255,9 @@ var Terminal = {
|
||||
case "help":
|
||||
//TODO
|
||||
break;
|
||||
case "home":
|
||||
//TODO return to home computer
|
||||
break;
|
||||
case "hostname":
|
||||
if (commandArray.length != 1) {
|
||||
post("Incorrect usage of hostname command. Usage: hostname"); return;
|
||||
@ -276,10 +279,10 @@ var Terminal = {
|
||||
|
||||
var scriptName = commandArray[1];
|
||||
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
||||
if (Player.getCurrentServer().runningScripts[i] == scriptName) {
|
||||
Player.getCurrentServer().runningScripts.splice(i, 1);
|
||||
|
||||
if (Player.getCurrentServer().runningScripts[i] == scriptName) {
|
||||
killWorkerScript(scriptName, Player.getCurrentServer().ip);
|
||||
post("Killing " + scriptName + ". May take a few seconds");
|
||||
return;
|
||||
}
|
||||
}
|
||||
post("No such script is running. Nothing to kill");
|
||||
@ -403,6 +406,7 @@ var Terminal = {
|
||||
//TODO
|
||||
break;
|
||||
case "tail":
|
||||
//TODO
|
||||
break;
|
||||
case "top":
|
||||
//TODO List each's script RAM usage
|
||||
@ -490,6 +494,7 @@ var Terminal = {
|
||||
if (Player.getCurrentServer().scripts[i].filename == scriptName) {
|
||||
if (Player.getCurrentServer().hasAdminRights == false) {
|
||||
post("Need root access to run script");
|
||||
return;
|
||||
} else {
|
||||
var filename = Player.getCurrentServer().scripts[i].filename;
|
||||
|
||||
|
@ -255,9 +255,7 @@ var Engine = {
|
||||
Companies.init();
|
||||
CompanyPositions.init();
|
||||
}
|
||||
|
||||
PrintAllServers();
|
||||
|
||||
|
||||
//Main menu buttons and content
|
||||
Engine.Clickables.terminalMainMenuButton = document.getElementById("terminal-menu-link");
|
||||
Engine.Clickables.terminalMainMenuButton.addEventListener("click", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user