v0.28.4 - Bug fixes, getScriptIncome(), syntax highlighting for regular Netscript functions,

This commit is contained in:
danielyxie 2017-09-11 18:14:51 -05:00
parent 68fcc12ac8
commit 024546b4f1
12 changed files with 1060 additions and 889 deletions

1818
dist/bundle.js vendored

File diff suppressed because it is too large Load Diff

@ -503,8 +503,9 @@
<p> --------------- </p>
<p id="faction-work-description-text">
Perform work/carry out assignments for your faction to help further its cause! By doing so
you will gain reputation for your faction. You will also gain reputation passively over time,
although at a very slow rate. Note that you cannot
you will earn reputation for your faction. You will also gain reputation passively over time,
although at a very slow rate. Earning reputation will allow you to purchase Augmentations
through this faction, which are powerful upgrades that enhance your abilities. Note that you cannot
use your terminal or create scripts when you are performing a task! <br><br><br><br>
</p>

@ -183,6 +183,7 @@ function updateActiveScriptsItems() {
}
document.getElementById("active-scripts-total-prod").innerHTML =
"Total online production rate: $" + formatNumber(total, 2) + " / second";
return total;
}
//Updates the content of the given item in the Active Scripts list
@ -197,7 +198,6 @@ function updateActiveScriptsItemContent(workerscript) {
itemNameArray.push(workerscript.args[i].toString());
}
var itemName = itemNameArray.join("-");
//var itemName = "active-scripts-" + server.hostname + "-" + workerscript.name;
var itemContent = document.getElementById(itemName + "-content")
//Clear the item

@ -1,5 +1,5 @@
let CONSTANTS = {
Version: "0.28.3",
Version: "0.28.4",
//Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience
//and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then
@ -536,21 +536,35 @@ let CONSTANTS = {
"on the server specified by the hostname/ip. The argument must be a string with the hostname/ip of the target server.<br><br>" +
"<i>getWeakenTime(hostname/ip)</i><br>Returns the amount of time in seconds it takes to execute the weaken() Netscript function " +
"on the server specified by the hostname/ip. The argument must be a string with the hostname/ip of the target server.<br><br>" +
"<i>getScriptIncome([scriptname], [hostname/ip], [args...])</i><br>" +
"Returns the amount of income the specified script generates while online (when the game is open, does not apply for " +
"offline income). This function can also return the total income of all of your active scripts by running the function " +
"with no arguments.<br><br>" +
"Remember that a script is uniquely identified by both its name and its arguments. So for example if you ran a script " +
"with the arguments 'foodnstuff' and '5' then in order to use this function to get that script's income you must " +
"specify those arguments in this function call.<br><br>" +
"The first argument, if specified, must be a string with the name of the script (including the .script extension). " +
"The second argument must be a string with the hostname/IP of the target server. If the first argument is specified " +
"then the second argument must be specified as well. Any additional arguments passed to the function will specify " +
"the arguments passed into the target script.<br><br>" +
"<u><h1>Hacknet Nodes API</h1></u><br>" +
"Netscript provides the following API for accessing and upgrading your Hacknet Nodes through scripts. This API does NOT work offline.<br><br>" +
"<i>hacknetnodes</i><br> A special variable. This is an array that maps to the Player's Hacknet Nodes. The Hacknet Nodes are accessed through " +
"indexes. These indexes correspond to the number at the end of the name of the Hacknet Node. For example, the first Hacknet Node you purchase " +
"will have the same 'hacknet-node-0' and can be accessed with hacknetnodes[0]. The fourth Hacknet Node you purchase will have the name " +
"'hacknet-node-3' and can be accessed with hacknetnodes[3]. <br><br>" +
"<i>hacknetnodes.length</i><br> Returns the number of Hacknet Nodes that the player owns<br><br>" +
"<i>hacknetnodes[i].level</i><br> Returns the level of the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].ram</i><br> Returns the amount of RAM on the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].cores</i><br> Returns the number of cores on the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].upgradeLevel(n)</i><br> Tries to upgrade the level of the corresponding Hacknet Node n times. The argument n must be a " +
"<i>hacknetnodes.length</i><br>Returns the number of Hacknet Nodes that the player owns<br><br>" +
"<i>hacknetnodes[i].level</i><br>Returns the level of the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].ram</i><br>Returns the amount of RAM on the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].cores</i><br>Returns the number of cores on the corresponding Hacknet Node<br><br>" +
"<i>hacknetnodes[i].totalMoneyGenerated</i><br>Returns the total amount of money that the corresponding Hacknet Node has earned<br><br>" +
"<i>hacknetnodes[i].onlineTimeSeconds</i><br>Returns the total amount of time that the corresponding Hacknet Node has existed<br><br>" +
"<i>hacknetnodes[i].moneyGainRatePerSecond</i><br>Returns the income ($ / sec) that the corresponding Hacknet Node earns<br><br>" +
"<i>hacknetnodes[i].upgradeLevel(n)</i><br>Tries to upgrade the level of the corresponding Hacknet Node n times. The argument n must be a " +
"positive integer. Returns true if the Hacknet Node's level is successfully upgraded n times or up to the max level (200), and false otherwise.<br><br>" +
"<i>hacknetnodes[i].upgradeRam()</i><br> Tries to upgrade the amount of RAM on the corresponding Hacknet Node. Returns true if the " +
"<i>hacknetnodes[i].upgradeRam()</i><br>Tries to upgrade the amount of RAM on the corresponding Hacknet Node. Returns true if the " +
"RAM is successfully upgraded, and false otherwise. <br><br>" +
"<i>hacknetnodes[i].upgradeCore()</i><br> Attempts to purchase an additional core for the corresponding Hacknet Node. Returns true if the " +
"<i>hacknetnodes[i].upgradeCore()</i><br>Attempts to purchase an additional core for the corresponding Hacknet Node. Returns true if the " +
"additional core is successfully purchase, and false otherwise. <br><br>" +
"Example: The following is an example of one way a script can be used to automate the purchasing and upgrading of Hacknet Nodes. " +
"This script purchases new Hacknet Nodes until the player has four. Then, it iteratively upgrades each of those four Hacknet Nodes " +
@ -861,10 +875,18 @@ let CONSTANTS = {
"World Stock Exchange account and TIX API Access<br>",
LatestUpdate:
"v0.28.4<br>" +
"-Added getScriptIncome() Netscript function<br>" +
"-Added several member variables for the Hacknet Node API that allow you to access info about their income<br>" +
"-All valid Netscript functions are now syntax highlighted as keywords in the editor. This means they will a different " +
"color than invalid netscript functions (so you can see if you have a typo/if your function is valid, etc.). The color " +
"depends on your theme.<br>" +
"-Comments and operators no longer count towards RAM usage in scripts.<br>" +
"-Variety of bug fixes and updates to informational text in the game<br><br>" +
"v0.28.3<br>" +
"-Added ls() Netscript function<br>" +
"-Increased company wages by about ~10% across the board<br>" +
"-The scp() Netsction function and Terminal command now works for .lit files<br>" +
"-The scp() Netsction function and Terminal command now works for .lit files<br>" +
"-Increased the amount of RAM on many lower level servers (up to level 200 hacking level required).<br><br>" +
"v0.28.2<br>" +
"-Added a few script editor configuration options. Includes key bindings, themes, etc.<br>" +

@ -766,7 +766,10 @@ function displayFactionContent(factionName) {
}
function displayFactionAugmentations(factionName) {
document.getElementById("faction-augmentations-page-desc").innerHTML = "Lists all augmentations that are available to purchase from " + factionName;
document.getElementById("faction-augmentations-page-desc").innerHTML =
"Lists all Augmentations that are available to purchase from " + factionName + "<br><br>" +
"Augmentations are powerful upgrades that will enhance your abilities.";
var faction = Factions[factionName];
var augmentationsList = document.getElementById("faction-augmentations-list");

@ -92,7 +92,7 @@ HacknetNode.prototype.getLevelUpgradeCost = function(levels=1) {
HacknetNode.prototype.purchaseLevelUpgrade = function(levels=1) {
var cost = this.calculateLevelUpgradeCost(levels);
if (isNaN(cost)) {return false;}
if (isNaN(cost) || levels < 0) {return false;}
if (this.level + levels > CONSTANTS.HacknetNodeMaxLevel) {
var diff = Math.max(0, CONSTANTS.HacknetNodeMaxLevel - this.level);
return this.purchaseLevelUpgrade(diff);

@ -120,7 +120,7 @@ function displayLocationContent() {
console.log("displayLocationContent() called with location " + Player.location)
}
var returnToWorld = document.getElementById("location-return-to-world-button");
var returnToWorld = document.getElementById("location-return-to-world-button");
var locationName = document.getElementById("location-name");
@ -304,7 +304,7 @@ function displayLocationContent() {
//Check if the player is employed at this Location. If he is, display the "Work" button,
//update the job title, etc.
if (loc == Player.companyName) {
if (loc != "" && loc === Player.companyName) {
var company = Companies[loc];
jobTitle.style.display = "block";

@ -1,3 +1,4 @@
import {updateActiveScriptsItems} from "./ActiveScriptsUI.js";
import {Augmentations, Augmentation,
augmentationExists, installAugmentations,
AugmentationNames} from "./Augmentations.js";
@ -1013,6 +1014,29 @@ function NetscriptFunctions(workerScript) {
}
return scriptCalculateWeakenTime(server) / 1000; //Returns seconds
},
getScriptIncome : function(scriptname, ip) {
if (arguments.length === 0) {
//Get total script income
return updateActiveScriptsItems();
} else {
//Get income for a particular script
var server = getServer(ip);
if (server === null) {
workerScript.scriptRef.log("getScriptIncome() failed. Invalid IP or hostnamed passed in: " + ip);
throw makeRuntimeRejectMsg(workerScript, "getScriptIncome() failed. Invalid IP or hostnamed passed in: " + ip);
}
var argsForScript = [];
for (var i = 2; i < arguments.length; ++i) {
argsForScript.push(arguments[i]);
}
var runningScriptObj = findRunningScript(scriptname, argsForScript, server);
if (runningScriptObj == null) {
workerScript.scriptRef.log("getScriptIncome() failed. No such script "+ scriptname + " on " + server.hostname + " with args: " + printArray(argsForScript));
return -1;
}
return runningScriptObj.onlineMoneyMade / runningScriptObj.onlineRunningTime;
}
},
/* Singularity Functions */
universityCourse(universityName, className) {
@ -1034,6 +1058,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot study at Summit University because you are not in Aevum. universityCourse() failed");
return false;
}
Player.location = Locations.AevumSummitUniversity;
costMult = 4;
expMult = 3;
break;
@ -1042,6 +1067,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot study at Rothman University because you are not in Sector-12. universityCourse() failed");
return false;
}
Player.location = Locations.Sector12RothmanUniversity;
costMult = 3;
expMult = 2;
break;
@ -1050,6 +1076,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot study at ZB Institute of Technology because you are not in Volhaven. universityCourse() failed");
return false;
}
Player.location = Locations.VolhavenZBInstituteOfTechnology;
costMult = 5;
expMult = 4;
break;
@ -1105,6 +1132,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot workout at Crush Fitness because you are not in Aevum. gymWorkout() failed");
return false;
}
Player.location = Locations.AevumCrushFitnessGym;
costMult = 2;
expMult = 1.5;
break;
@ -1113,6 +1141,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot workout at Snap Fitness because you are not in Aevum. gymWorkout() failed");
return false;
}
Player.location = Locations.AevumSnapFitnessGym;
costMult = 6;
expMult = 4;
break;
@ -1121,6 +1150,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot workout at Iron Gym because you are not in Sector-12. gymWorkout() failed");
return false;
}
Player.location = Locations.Sector12IronGym;
costMult = 1;
expMult = 1;
break;
@ -1129,6 +1159,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot workout at Powerhouse Gym because you are not in Sector-12. gymWorkout() failed");
return false;
}
Player.location = Locations.Sector12PowerhouseGym;
costMult = 10;
expMult = 7.5;
break;
@ -1137,6 +1168,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.log("ERROR: You cannot workout at Millenium Fitness Gym because you are not in Volhaven. gymWorkout() failed");
return false;
}
Player.location = Locations.VolhavenMilleniumFitnessGym;
costMult = 3;
expMult = 2.5;
break;

@ -1008,6 +1008,7 @@ PlayerObject.prototype.workForFaction = function(numCycles) {
//If timeWorked == 20 hours, then finish. You can only work for the faction for 20 hours
if (this.timeWorked >= CONSTANTS.MillisecondsPer20Hours) {
var maxCycles = CONSTANTS.GameCyclesPer20Hours;
this.timeWorked = CONSTANTS.MillisecondsPer20Hours;
this.workHackExpGained = this.workHackExpGainRate * maxCycles;
this.workStrExpGained = this.workStrExpGainRate * maxCycles;
this.workDefExpGained = this.workDefExpGainRate * maxCycles;
@ -1255,7 +1256,7 @@ PlayerObject.prototype.startClass = function(costMult, expMult, className) {
agiExp = baseGymExp * expMult / gameCPS;
break;
default:
throw new Error("ERR: Invalid/unregocnized class name");
throw new Error("ERR: Invalid/recognized class name");
return;
}

@ -202,6 +202,7 @@ Script.prototype.updateRamUsage = function() {
}
function calculateRamUsage(codeCopy) {
codeCopy = codeCopy.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1'); //Delete comments
codeCopy = codeCopy.replace(/\s/g,''); //Remove all whitespace
var baseRam = 1.4;
var whileCount = numOccurrences(codeCopy, "while(");
@ -234,7 +235,6 @@ function calculateRamUsage(codeCopy) {
numOccurrences(codeCopy, "getServerRam(");
var fileExistsCount = numOccurrences(codeCopy, "fileExists(");
var isRunningCount = numOccurrences(codeCopy, "isRunning(");
var numOperators = numNetscriptOperators(codeCopy);
var purchaseHacknetCount = numOccurrences(codeCopy, "purchaseHacknetNode(");
var hacknetnodesArrayCount = numOccurrences(codeCopy, "hacknetnodes[");
var hnUpgLevelCount = numOccurrences(codeCopy, ".upgradeLevel(");
@ -304,7 +304,6 @@ function calculateRamUsage(codeCopy) {
(getServerCount * CONSTANTS.ScriptGetServerCost) +
(fileExistsCount * CONSTANTS.ScriptFileExistsRamCost) +
(isRunningCount * CONSTANTS.ScriptIsRunningRamCost) +
(numOperators * CONSTANTS.ScriptOperatorRamCost) +
(purchaseHacknetCount * CONSTANTS.ScriptPurchaseHacknetRamCost) +
(hacknetnodesArrayCount * CONSTANTS.ScriptHacknetNodesRamCost) +
(hnUpgLevelCount * CONSTANTS.ScriptHNUpgLevelRamCost) +

@ -24,7 +24,7 @@ import {SpecialServerIps,
SpecialServerNames} from "./SpecialServerIps.js";
import {containsAllStrings, longestCommonStart,
formatNumber} from "../utils/StringHelperFunctions.js";
formatNumber, isString} from "../utils/StringHelperFunctions.js";
import {addOffset, printArray} from "../utils/HelperFunctions.js";
import {logBoxCreate} from "../utils/LogBox.js";
@ -211,13 +211,13 @@ function tabCompletion(command, arg, allPossibilities, index=0) {
//that we are attempting to autocomplete
if (arg == "") {
for (var i = allPossibilities.length-1; i >= 0; --i) {
if (!allPossibilities[i].startsWith(command)) {
if (!allPossibilities[i].toLowerCase().startsWith(command.toLowerCase())) {
allPossibilities.splice(i, 1);
}
}
} else {
for (var i = allPossibilities.length-1; i >= 0; --i) {
if (!allPossibilities[i].startsWith(arg)) {
if (!allPossibilities[i].toLowerCase().startsWith(arg.toLowerCase())) {
allPossibilities.splice(i, 1);
}
}
@ -337,7 +337,7 @@ function determineAllPossibilitiesForTabCompletion(input, index=0) {
}
if (input.startsWith("kill ") || input.startsWith("nano ") ||
input.startsWith("tail ") || input.startsWith("rm ") ||
input.startsWith("tail ") ||
input.startsWith("mem ") || input.startsWith("check ")) {
//All Scripts
for (var i = 0; i < currServ.scripts.length; ++i) {
@ -346,6 +346,22 @@ function determineAllPossibilitiesForTabCompletion(input, index=0) {
return allPos;
}
if (input.startsWith("rm ")) {
for (var i = 0; i < currServ.scripts.length; ++i) {
allPos.push(currServ.scripts[i].filename);
}
for (var i = 0; i < currServ.programs.length; ++i) {
allPos.push(currServ.programs[i]);
}
for (var i = 0; i < currServ.messages.length; ++i) {
if (!(currServ.messages[i] instanceof Message) && isString(currServ.messages[i]) &&
currServ.messages[i].endsWith(".lit")) {
allPos.push(currServ.messages[i]);
}
}
return allPos;
}
if (input.startsWith("run ")) {
//All programs and scripts
for (var i = 0; i < currServ.scripts.length; ++i) {
@ -961,6 +977,15 @@ let Terminal = {
}
}
//Check literature files
for (var i = 0; i < s.messages.length; ++i) {
var f = s.messages[i];
if (!(f instanceof Message) && isString(f) && f === delTarget) {
s.messages.splice(i, 1);
return;
}
}
post("No such file exists");
break;
case "run":

@ -60,7 +60,7 @@ function longestCommonStart(strings) {
var A = strings.concat().sort(),
a1= A[0], a2= A[A.length-1], L= a1.length, i= 0;
while(i<L && a1.charAt(i)=== a2.charAt(i)) i++;
while(i<L && a1.charAt(i).toLowerCase() === a2.charAt(i).toLowerCase()) i++;
return a1.substring(0, i);
}