Skip to content

Commit

Permalink
Merge pull request #128 from danielyxie/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
danielyxie authored Sep 11, 2017
2 parents 9506f5b + 1f9d0be commit e11887c
Show file tree
Hide file tree
Showing 12 changed files with 1,912 additions and 941 deletions.
2,718 changes: 1,802 additions & 916 deletions dist/bundle.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ <h1 id="faction-name"></h1>
<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>

Expand Down
2 changes: 1 addition & 1 deletion src/ActiveScriptsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
41 changes: 32 additions & 9 deletions src/Constants.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 " +
Expand Down Expand Up @@ -861,10 +875,19 @@ 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. The color will depend on your theme. " +
"Note that right now, this only applies for normal Netscript functions, not " +
"functions in the TIX API, Hacknet Node API, or Singularity Functions.<br><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>" +
Expand Down
5 changes: 4 additions & 1 deletion src/Faction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/HacknetNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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";
Expand Down
32 changes: 32 additions & 0 deletions src/NetscriptFunctions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {updateActiveScriptsItems} from "./ActiveScriptsUI.js";
import {Augmentations, Augmentation,
augmentationExists, installAugmentations,
AugmentationNames} from "./Augmentations.js";
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var ace = require('brace');
require('brace/mode/javascript');
require('brace/mode/netscript');
require('brace/theme/chaos');
require('brace/theme/chrome');
require('brace/theme/monokai');
Expand Down Expand Up @@ -44,7 +45,7 @@ function scriptEditorInit() {

//Initialize ACE Script editor
var editor = ace.edit('javascript-editor');
editor.getSession().setMode('ace/mode/javascript');
editor.getSession().setMode('ace/mode/netscript');
editor.setTheme('ace/theme/monokai');
document.getElementById('javascript-editor').style.fontSize='16px';
editor.setOption("showPrintMargin", false);
Expand Down Expand Up @@ -201,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(");
Expand Down Expand Up @@ -233,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(");
Expand Down Expand Up @@ -303,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) +
Expand Down
Loading

0 comments on commit e11887c

Please sign in to comment.