mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
Slight rebalancing. Added kill() and killall() commands
This commit is contained in:
parent
f7018f082c
commit
d3fa9f8c6e
@ -40,7 +40,7 @@ CONSTANTS = {
|
||||
ScriptWhileRamCost: 0.2,
|
||||
ScriptForRamCost: 0.2,
|
||||
ScriptIfRamCost: 0.1,
|
||||
ScriptHackRamCost: 0.15,
|
||||
ScriptHackRamCost: 0.1,
|
||||
ScriptGrowRamCost: 0.15,
|
||||
ScriptWeakenRamCost: 0.15,
|
||||
ScriptNukeRamCost: 0.05,
|
||||
@ -53,7 +53,7 @@ CONSTANTS = {
|
||||
ScriptExecRamCost: 1.1,
|
||||
ScriptScpRamCost: 0.5,
|
||||
ScriptHasRootAccessRamCost: 0.05,
|
||||
ScriptGetHostnameRamCost: 0.1,
|
||||
ScriptGetHostnameRamCost: 0.05,
|
||||
ScriptGetHackingLevelRamCost: 0.05,
|
||||
ScriptGetServerMoneyRamCost: 0.1,
|
||||
ScriptGetServerSecurityRamCost: 0.1,
|
||||
@ -335,6 +335,18 @@ CONSTANTS = {
|
||||
"second argument is a string with the hostname or IP of the 'target server' on which to run the script. The specified script must exist on the target server. Returns " +
|
||||
"true if the script is successfully started, and false otherwise. Does NOT work while offline<br> " +
|
||||
"Example: exec('generic-hack.script', 'foodnstuff'); <br> The example above will try to launch the script 'generic-hack.script' on the 'foodnstuff' server.<br><br>" +
|
||||
"<i>kill(script, [hostname/ip])</i><br> Kills a script on a server. The first argument must be a string with the name of the script. The name is case-sensitive. " +
|
||||
"The second argument must be a string with the hostname or IP of the target server. The function will try to kill the specified script on the target server. " +
|
||||
"The second argument is optional. If it is omitted, then the function will try to kill the specified script on the current server (the server running " +
|
||||
"the script that calls this function). If the script is found on the specified server and is running, then it will be killed and this function " +
|
||||
"will return true. Otherwise, this function will return false. <br> " +
|
||||
"Example: kill('foo.script', 'foodnstuff');<br>" +
|
||||
"Example: kill('foo.script');<br>" +
|
||||
"The first example above will look for a script called 'foo.script' on the 'foodnstuff' server. If the script exists and is running, then it will " +
|
||||
"be killed and the function will return true. Otherwise false will be returned. The second example above will do the same thing, except on the " +
|
||||
"current server (the server running the script that calls the kill() function).<br><br>" +
|
||||
"<i>killall(hostname/ip)</i><br> Kills all running scripts on the specified server. This function takes a single argument which " +
|
||||
"must be a string containing the hostname or IP of the target server. This function will always return true. <br><br>" +
|
||||
"<i>scp(script, hostname/ip)</i><br>Copies a script to another server. The first argument is a string with the filename of the script " +
|
||||
"to be copied. The second argument is a string with the hostname or IP of the destination server. Returns true if the script is successfully " +
|
||||
"copied over and false otherwise. <br> Example: scp('hack-template.script', 'foodnstuff');<br><br>" +
|
||||
@ -520,6 +532,7 @@ CONSTANTS = {
|
||||
"such as a variable assignment, a function call, a binary operator, getting a variable's value, etc. used to take up to several seconds, " +
|
||||
"now each one should only take 750 milliseconds). <br> " +
|
||||
"-Percentage money stolen when hacking lowered to compensate for faster script speeds<br>" +
|
||||
"-Slightly lowered the runtime of weaken()<br>" +
|
||||
"-Lowered base growth rate by 25%(which affects amount of money gained from grow())<br>" +
|
||||
"-Hacking experience granted by grow() halved<b>" +
|
||||
"-Weaken() is now 10% faster, but only grants 3 base hacking exp upon completion instead of 5 <br>" +
|
||||
@ -528,6 +541,8 @@ CONSTANTS = {
|
||||
"-Added getServerRequiredHackingLevel(server) Netscript command. <br>" +
|
||||
"-Added fileExists(file, [server]) Netscript command, which is used to check if a script/program exists on a " +
|
||||
"specified server<br>" +
|
||||
"-Added killall Terminal command. Kills all running scripts on the current machine<br> " +
|
||||
"-Added kill() and killall() Netscript commands. Used to kill scripts on specified machines. See Netscript documentation<br>" +
|
||||
"v0.19.7<br>" +
|
||||
"-Added changelog to Options menu<br>" +
|
||||
"-Bug fix with autocompletion (wasn't working properly for capitalized filenames/programs<br><br>" +
|
||||
|
@ -257,9 +257,61 @@ function evaluate(exp, workerScript) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "kill") {
|
||||
if (exp.args.length != 1 && exp.args.length != 2) {
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "kill() call has incorrect number of arguments. Takes 1 or 2 arguments"));
|
||||
}
|
||||
var argPromises = exp.args.map(function(arg) {
|
||||
return evaluate(arg, workerScript);
|
||||
});
|
||||
|
||||
var filename = "";
|
||||
Promise.all(argPromises).then(function(args) {
|
||||
if (env.stopFlag) {return reject(workerScript);}
|
||||
filename = args[0];
|
||||
if (exp.args.length == 2) {
|
||||
return Promise.resolve(workerScript.serverIp);
|
||||
} else {
|
||||
return evaluate(exp.args[1], workerScript);
|
||||
}
|
||||
}).then(function(ip) {
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
workerScript.scriptRef.log("kill() failed. Invalid IP or hostname passed in: " + ip);
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into kill() command"));
|
||||
}
|
||||
|
||||
for (var i = 0; i < server.runningScripts.length; ++i) {
|
||||
if (filename == server.runningScripts[i].filename) {
|
||||
killWorkerScript(filename, server.ip);
|
||||
workerScript.scriptRef.log("Killing " + scriptName + ". May take up to a few minutes for the scripts to die...");
|
||||
return resolve(true);
|
||||
}
|
||||
}
|
||||
workerScript.scriptRef.log("kill() failed. No such script "+ scriptName + " on " + server.hostname);
|
||||
return resolve(false);
|
||||
}).catch(function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "killall") {
|
||||
|
||||
if (exp.args.length != 1) {
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "killall() call has incorrect number of arguments. Takes 1 argument"));
|
||||
}
|
||||
var ipPromise = evaluate(exp.args[0], workerScript);
|
||||
ipPromise.then(function(ip) {
|
||||
if (env.stopFlag) {return reject(workerScript);}
|
||||
var server = getServer(ip);
|
||||
if (server == null) {
|
||||
workerScript.scriptRef.log("killall() failed. Invalid IP or hostname passed in: " + ip);
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into killall() command"));
|
||||
}
|
||||
workerScript.scriptRef.log("killall(): Killing all scrips on " + server.hostname);
|
||||
for (var i = server.runningScripts.length; i >= 0; --i) {
|
||||
killWorkerScript(server.runningScripts[i], server.ip);
|
||||
}
|
||||
resolve(true);
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
} else if (exp.func.value == "scp") {
|
||||
if (exp.args.length != 2) {
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "scp() call has incorrect number of arguments. Takes 2 arguments"));
|
||||
@ -921,7 +973,7 @@ function scriptCalculatePercentMoneyHacked(server) {
|
||||
function scriptCalculateGrowTime(server) {
|
||||
var difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
|
||||
var skillFactor = (2.5 * difficultyMult + 500) / (Player.hacking_skill + 50);
|
||||
var growTime = skillFactor * Player.hacking_speed_mult * 17; //This is in seconds
|
||||
var growTime = skillFactor * Player.hacking_speed_mult * 16; //This is in seconds
|
||||
return growTime * 1000;
|
||||
}
|
||||
|
||||
@ -929,6 +981,6 @@ function scriptCalculateGrowTime(server) {
|
||||
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 * 45; //This is in seconds
|
||||
var weakenTime = skillFactor * Player.hacking_speed_mult * 40; //This is in seconds
|
||||
return weakenTime * 1000;
|
||||
}
|
@ -204,7 +204,7 @@ Script.prototype.reset = function() {
|
||||
|
||||
//Updates how much RAM the script uses when it is running.
|
||||
Script.prototype.updateRamUsage = function() {
|
||||
var baseRam = 1.5;
|
||||
var baseRam = 1.4;
|
||||
var codeCopy = this.code.repeat(1);
|
||||
codeCopy = codeCopy.replace(/\s/g,''); //Remove all whitespace
|
||||
|
||||
|
@ -412,11 +412,14 @@ var Terminal = {
|
||||
//Replace all extra whitespace in command with a single space
|
||||
command = command.replace(/\s\s+/g, ' ');
|
||||
|
||||
|
||||
if (Terminal.commandHistory[Terminal.commandHistory.length-1] != command) {
|
||||
Terminal.commandHistory.push(command);
|
||||
if (Terminal.commandHistory.length > 50) {
|
||||
Terminal.commandHistory.splice(0, 1);
|
||||
}
|
||||
Terminal.commandHistoryIndex = Terminal.commandHistory.length;
|
||||
}
|
||||
|
||||
//Process any aliases
|
||||
command = substituteAliases(command);
|
||||
|
@ -1042,7 +1042,7 @@ var Engine = {
|
||||
return false;
|
||||
});
|
||||
relaySmtpALink.addEventListener("click", function() {
|
||||
Player.startCreateProgramWork(Programs.RelaySMTPProgram. CONSTANTS.MillisecondsPer2Hours, 250);
|
||||
Player.startCreateProgramWork(Programs.RelaySMTPProgram, CONSTANTS.MillisecondsPer2Hours, 250);
|
||||
return false;
|
||||
});
|
||||
httpWormALink.addEventListener("click", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user