mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
Refactored NetscriptJS to take in the NS environment as a parameter to main
This commit is contained in:
parent
9a9096bc70
commit
c7e155d4bc
682
dist/engine.bundle.js
vendored
682
dist/engine.bundle.js
vendored
@ -84,7 +84,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _CreateProgram_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./CreateProgram.js */ 14);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
@ -94,7 +94,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _NetscriptFunctions_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./NetscriptFunctions.js */ 29);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _utils_decimal_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../utils/decimal.js */ 24);
|
||||
/* harmony import */ var _utils_decimal_js__WEBPACK_IMPORTED_MODULE_15___default = /*#__PURE__*/__webpack_require__.n(_utils_decimal_js__WEBPACK_IMPORTED_MODULE_15__);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
@ -4141,7 +4141,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "initLocationButtons", function() { return initLocationButtons; });
|
||||
/* harmony import */ var _Bladeburner_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Bladeburner.js */ 47);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
@ -6358,13 +6358,13 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Bladeburner_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Bladeburner.js */ 47);
|
||||
/* harmony import */ var _CinematicText_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./CinematicText.js */ 70);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _CreateProgram_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./CreateProgram.js */ 14);
|
||||
/* harmony import */ var _Faction_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./Faction.js */ 11);
|
||||
@ -6385,7 +6385,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Script_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./Script.js */ 26);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _StockMarket_js__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ./StockMarket.js */ 22);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
@ -8133,6 +8133,8 @@ window.onload = function() {
|
||||
var db = e.target.result;
|
||||
var objectStore = db.createObjectStore("savestring");
|
||||
}
|
||||
|
||||
console.log(window.location.href);
|
||||
};
|
||||
|
||||
|
||||
@ -12457,6 +12459,14 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
var txt = "You must first purchase or install " + aug.prereqs.join(",") + " before you can " +
|
||||
"purchase this one.";
|
||||
if (sing) {return txt;} else {Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);}
|
||||
} else if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].money.lt(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
let txt = "You don't have enough money to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);
|
||||
} else if (fac.playerReputation < aug.baseRepRequirement) {
|
||||
let txt = "You don't have enough faction reputation to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);
|
||||
} else if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].money.gte(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].firstAugPurchased === false) {
|
||||
_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].firstAugPurchased = true;
|
||||
@ -12503,11 +12513,9 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
|
||||
displayFactionAugmentations(fac.name);
|
||||
} else {
|
||||
if (sing) {
|
||||
return "You don't have enough money to purchase " + aug.name;
|
||||
} else {
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])("You don't have enough money to purchase this Augmentation!");
|
||||
}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])("Hmm, something went wrong when trying to purchase an Augmentation. " +
|
||||
"Please report this to the game developer with an explanation of how to " +
|
||||
"reproduce this.");
|
||||
}
|
||||
Object(_utils_YesNoBox_js__WEBPACK_IMPORTED_MODULE_15__["yesNoBoxClose"])();
|
||||
}
|
||||
@ -13444,7 +13452,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
@ -15514,7 +15522,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _SaveObject_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./SaveObject.js */ 46);
|
||||
/* harmony import */ var _Script_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Script.js */ 26);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_JSONReviver_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../utils/JSONReviver.js */ 8);
|
||||
@ -18457,7 +18465,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addWorkerScript", function() { return addWorkerScript; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateOnlineScriptTimes", function() { return updateOnlineScriptTimes; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeWorkerScripts", function() { return prestigeWorkerScripts; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptEnvironment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./NetscriptEnvironment.js */ 69);
|
||||
@ -18508,6 +18516,18 @@ WorkerScript.prototype.getServer = function() {
|
||||
return _Server_js__WEBPACK_IMPORTED_MODULE_7__["AllServers"][this.serverIp];
|
||||
}
|
||||
|
||||
//Returns the Script object for the underlying script
|
||||
WorkerScript.prototype.getScript = function() {
|
||||
let server = this.getServer();
|
||||
for (var i = 0; i < server.scripts.length; ++i) {
|
||||
if (server.scripts[i].filename === this.name) {
|
||||
return server.scripts[i];
|
||||
}
|
||||
}
|
||||
console.log("ERROR: Failed to find underlying Script object in WorkerScript.getScript(). This probably means somethings wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Array containing all scripts that are running across all servers, to easily run them all
|
||||
let workerScripts = [];
|
||||
|
||||
@ -18578,8 +18598,7 @@ function startJsScript(workerScript) {
|
||||
|
||||
// Note: the environment that we pass to the JS script only needs to contain the functions visible
|
||||
// to that script, which env.vars does at this point.
|
||||
return Object(_NetscriptJSEvaluator_js__WEBPACK_IMPORTED_MODULE_5__["executeJSScript"])(workerScript.scriptRef.scriptRef,
|
||||
workerScript.getServer().scripts,
|
||||
return Object(_NetscriptJSEvaluator_js__WEBPACK_IMPORTED_MODULE_5__["executeJSScript"])(workerScript.getServer().scripts,
|
||||
workerScript).then(function (mainReturnValue) {
|
||||
if (mainReturnValue === undefined) return workerScript;
|
||||
return [mainReturnValue, workerScript];
|
||||
@ -18624,13 +18643,14 @@ function runScriptsLoop() {
|
||||
workerScripts.splice(i, 1);
|
||||
}
|
||||
}
|
||||
Object(_ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__["updateActiveScriptsItems"])(); //Force Update
|
||||
|
||||
//Run any scripts that haven't been started
|
||||
for (var i = 0; i < workerScripts.length; i++) {
|
||||
//If it isn't running, start the script
|
||||
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) {
|
||||
let p = null; // p is the script's result promise.
|
||||
if (workerScripts[i].name.endsWith(".js")) {
|
||||
if (workerScripts[i].name.endsWith(".js") || workerScripts[i].name.endsWith(".ns")) {
|
||||
p = startJsScript(workerScripts[i]);
|
||||
} else {
|
||||
try {
|
||||
@ -25794,7 +25814,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _utils_acorn_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../utils/acorn.js */ 35);
|
||||
/* harmony import */ var _utils_acorn_js__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(_utils_acorn_js__WEBPACK_IMPORTED_MODULE_12__);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
@ -25845,7 +25865,7 @@ var keybindings = {
|
||||
};
|
||||
|
||||
function isScriptFilename(f) {
|
||||
return f.endsWith(".js") || f.endsWith(".script");
|
||||
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
|
||||
}
|
||||
|
||||
var scriptEditorRamCheck = null, scriptEditorRamText = null;
|
||||
@ -26144,6 +26164,7 @@ Script.prototype.saveScript = function() {
|
||||
|
||||
//Calculate/update ram usage, execution time, etc.
|
||||
this.updateRamUsage();
|
||||
console.log(this.module);
|
||||
|
||||
this.module = "";
|
||||
}
|
||||
@ -27147,7 +27168,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasCorporationSF", function() { return hasCorporationSF; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasAISF", function() { return hasAISF; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasBladeburnerSF", function() { return hasBladeburnerSF; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
@ -27168,7 +27189,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _StockMarket_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./StockMarket.js */ 22);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7);
|
||||
/* harmony import */ var _NetscriptEnvironment_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./NetscriptEnvironment.js */ 69);
|
||||
@ -49665,6 +49686,309 @@ function getHacknetNode(name) {
|
||||
|
||||
/***/ }),
|
||||
/* 40 */
|
||||
/*!********************************!*\
|
||||
!*** ./src/ActiveScriptsUI.js ***!
|
||||
\********************************/
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addActiveScriptsItem", function() { return addActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteActiveScriptsItem", function() { return deleteActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateActiveScriptsItems", function() { return updateActiveScriptsItems; });
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/numeral.min.js */ 13);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* {
|
||||
* serverName: {
|
||||
* header: Server Header Element
|
||||
* panel: Server Panel List (ul) element
|
||||
* scripts: {
|
||||
* script id: Ref to Script information
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
*/
|
||||
let ActiveScriptsUI = {};
|
||||
let ActiveScriptsTasks = []; //Sequentially schedule the creation/deletion of UI elements
|
||||
|
||||
function createActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
|
||||
var activeScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:hostname});
|
||||
let li = res[0];
|
||||
var hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
if (ActiveScriptsUI[hostname] != null) {
|
||||
console.log("WARNING: Tried to create already-existing Active Scripts Server panel. This is most likely fine. It probably means many scripts just got started up on a new server. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
var panelScriptList = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("ul");
|
||||
panel.appendChild(panelScriptList);
|
||||
activeScriptsList.appendChild(li);
|
||||
|
||||
ActiveScriptsUI[hostname] = {
|
||||
header: hdr,
|
||||
panel: panel,
|
||||
panelList: panelScriptList,
|
||||
scripts: {}, //Holds references to li elements for each active script
|
||||
scriptHdrs: {}, //Holds references to header elements for each active script
|
||||
scriptStats: {} //Holds references to the p elements containing text for each active script
|
||||
};
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
//Deletes the info for a particular server (Dropdown header + Panel with all info)
|
||||
//in the Active Scripts page if it exists
|
||||
function deleteActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("WARNING: Tried to delete non-existent Active Scripts Server panel. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure it's empty
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length > 0) {
|
||||
console.log("WARNING: Tried to delete Active Scripts Server panel that still has scripts. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].panel);
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].header);
|
||||
delete ActiveScriptsUI[hostname];
|
||||
}
|
||||
|
||||
function addActiveScriptsItem(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript in addActiveScriptsItem()");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
|
||||
ActiveScriptsTasks.push(function(workerscript, hostname) {
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
createActiveScriptsServerPanel(server);
|
||||
}
|
||||
|
||||
//Create the unique identifier (key) for this script
|
||||
var itemNameArray = ["active", "scripts", hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:workerscript.name});
|
||||
let li = res[0];
|
||||
let hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
hdr.classList.remove("accordion-header");
|
||||
hdr.classList.add("active-scripts-script-header");
|
||||
panel.classList.remove("accordion-panel");
|
||||
panel.classList.add("active-scripts-script-panel");
|
||||
|
||||
//Handle the constant elements on the panel that don't change after creation
|
||||
//Threads, args, kill/log button
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerHTML: "Threads: " + workerscript.scriptRef.threads + "<br>" +
|
||||
"Args: " + Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["printArray"])(workerscript.args)
|
||||
}));
|
||||
var panelText = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerText:"Loading...", fontSize:"14px",
|
||||
});
|
||||
panel.appendChild(panelText);
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("br"));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Log", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__["logBoxCreate"])(workerscript.scriptRef);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Kill Script", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["killWorkerScript"])(workerscript.scriptRef, workerscript.scriptRef.scriptRef.server);
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__["dialogBoxCreate"])("Killing script, may take a few minutes to complete...");
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//Append element to list
|
||||
ActiveScriptsUI[hostname]["panelList"].appendChild(li);
|
||||
ActiveScriptsUI[hostname].scripts[itemName] = li;
|
||||
ActiveScriptsUI[hostname].scriptHdrs[itemName] = hdr;
|
||||
ActiveScriptsUI[hostname].scriptStats[itemName] = panelText;
|
||||
}.bind(null, workerscript, hostname));
|
||||
}
|
||||
|
||||
function deleteActiveScriptsItem(workerscript) {
|
||||
ActiveScriptsTasks.push(function(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
throw new Error("ERROR: Invalid server IP for workerscript. This most likely occurred because " +
|
||||
"you tried to delete a large number of scripts and also deleted servers at the " +
|
||||
"same time. It's not a big deal, just save and refresh the game.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("ERROR: Trying to delete Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let li = ActiveScriptsUI[hostname].scripts[itemName];
|
||||
if (li == null) {
|
||||
console.log("ERROR: Cannot find Active Script UI element for workerscript: ");
|
||||
console.log(workerscript);
|
||||
return;
|
||||
}
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(li);
|
||||
delete ActiveScriptsUI[hostname].scripts[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptHdrs[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length === 0) {
|
||||
deleteActiveScriptsServerPanel(server);
|
||||
}
|
||||
}.bind(null, workerscript));
|
||||
}
|
||||
|
||||
//Update the ActiveScriptsItems array
|
||||
function updateActiveScriptsItems(maxTasks=100) {
|
||||
//Run tasks that need to be done sequentially (adding items, creating/deleting server panels)
|
||||
//We'll limit this to 50 at a time in case someone decides to start a bunch of scripts all at once...
|
||||
let numTasks = Math.min(maxTasks, ActiveScriptsTasks.length);
|
||||
for (let i = 0; i < numTasks; ++i) {
|
||||
let task = ActiveScriptsTasks.shift();
|
||||
try {
|
||||
task();
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
console.log(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (_engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].currentPage !== _engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].Page.ActiveScripts) {return;}
|
||||
var total = 0;
|
||||
for (var i = 0; i < _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"].length; ++i) {
|
||||
try {
|
||||
total += updateActiveScriptsItemContent(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"][i]);
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
}
|
||||
}
|
||||
document.getElementById("active-scripts-total-prod").innerHTML =
|
||||
"Total online production of Active Scripts: " + _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(total).format('$0.000a') + " / sec<br>" +
|
||||
"Total online production since last Aug installation: " +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug).format('$0.000a') + " (" +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug / (_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].playtimeSinceLastAug/1000)).format('$0.000a') + " / sec)";
|
||||
return total;
|
||||
}
|
||||
|
||||
//Updates the content of the given item in the Active Scripts list
|
||||
function updateActiveScriptsItemContent(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
return; //Hasn't been created yet. We'll skip it
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
if (ActiveScriptsUI[hostname].scriptStats[itemName] == null) {
|
||||
return; //Hasn't been fully added yet. We'll skip it
|
||||
}
|
||||
var item = ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
|
||||
//Update the text if necessary. This fn returns the online $/s production
|
||||
return updateActiveScriptsText(workerscript, item, itemName);
|
||||
}
|
||||
|
||||
function updateActiveScriptsText(workerscript, item, itemName) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null || ActiveScriptsUI[hostname].scriptHdrs[itemName] == null) {
|
||||
console.log("ERROR: Trying to update Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
|
||||
//Only update if the item is visible
|
||||
if (ActiveScriptsUI[hostname].header.classList.contains("active") === false) {return onlineMps;}
|
||||
if (ActiveScriptsUI[hostname].scriptHdrs[itemName].classList.contains("active") === false) {return onlineMps;}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeChildrenFromElement"])(item);
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var onlineMpsText = "Online production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
item.innerHTML = onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 41 */
|
||||
/*!**********************************!*\
|
||||
!*** ./src/CompanyManagement.js ***!
|
||||
\**********************************/
|
||||
@ -54603,7 +54927,7 @@ _utils_JSONReviver_js__WEBPACK_IMPORTED_MODULE_9__["Reviver"].constructors.Corpo
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 41 */
|
||||
/* 42 */
|
||||
/*!*************************!*\
|
||||
!*** ./src/TextFile.js ***!
|
||||
\*************************/
|
||||
@ -54709,7 +55033,7 @@ function deleteTextFile(fn, server) {
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 42 */
|
||||
/* 43 */
|
||||
/*!***************************!*\
|
||||
!*** ./src/SourceFile.js ***!
|
||||
\***************************/
|
||||
@ -54917,309 +55241,6 @@ function applySourceFile(srcFile) {
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 43 */
|
||||
/*!********************************!*\
|
||||
!*** ./src/ActiveScriptsUI.js ***!
|
||||
\********************************/
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addActiveScriptsItem", function() { return addActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteActiveScriptsItem", function() { return deleteActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateActiveScriptsItems", function() { return updateActiveScriptsItems; });
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/numeral.min.js */ 13);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* {
|
||||
* serverName: {
|
||||
* header: Server Header Element
|
||||
* panel: Server Panel List (ul) element
|
||||
* scripts: {
|
||||
* script id: Ref to Script information
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
*/
|
||||
let ActiveScriptsUI = {};
|
||||
let ActiveScriptsTasks = []; //Sequentially schedule the creation/deletion of UI elements
|
||||
|
||||
function createActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
|
||||
var activeScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:hostname});
|
||||
let li = res[0];
|
||||
var hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
if (ActiveScriptsUI[hostname] != null) {
|
||||
console.log("WARNING: Tried to create already-existing Active Scripts Server panel. This is most likely fine. It probably means many scripts just got started up on a new server. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
var panelScriptList = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("ul");
|
||||
panel.appendChild(panelScriptList);
|
||||
activeScriptsList.appendChild(li);
|
||||
|
||||
ActiveScriptsUI[hostname] = {
|
||||
header: hdr,
|
||||
panel: panel,
|
||||
panelList: panelScriptList,
|
||||
scripts: {}, //Holds references to li elements for each active script
|
||||
scriptHdrs: {}, //Holds references to header elements for each active script
|
||||
scriptStats: {} //Holds references to the p elements containing text for each active script
|
||||
};
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
//Deletes the info for a particular server (Dropdown header + Panel with all info)
|
||||
//in the Active Scripts page if it exists
|
||||
function deleteActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("WARNING: Tried to delete non-existent Active Scripts Server panel. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure it's empty
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length > 0) {
|
||||
console.log("WARNING: Tried to delete Active Scripts Server panel that still has scripts. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].panel);
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].header);
|
||||
delete ActiveScriptsUI[hostname];
|
||||
}
|
||||
|
||||
function addActiveScriptsItem(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript in addActiveScriptsItem()");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
|
||||
ActiveScriptsTasks.push(function(workerscript, hostname) {
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
createActiveScriptsServerPanel(server);
|
||||
}
|
||||
|
||||
//Create the unique identifier (key) for this script
|
||||
var itemNameArray = ["active", "scripts", hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:workerscript.name});
|
||||
let li = res[0];
|
||||
let hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
hdr.classList.remove("accordion-header");
|
||||
hdr.classList.add("active-scripts-script-header");
|
||||
panel.classList.remove("accordion-panel");
|
||||
panel.classList.add("active-scripts-script-panel");
|
||||
|
||||
//Handle the constant elements on the panel that don't change after creation
|
||||
//Threads, args, kill/log button
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerHTML: "Threads: " + workerscript.scriptRef.threads + "<br>" +
|
||||
"Args: " + Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["printArray"])(workerscript.args)
|
||||
}));
|
||||
var panelText = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerText:"Loading...", fontSize:"14px",
|
||||
});
|
||||
panel.appendChild(panelText);
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("br"));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Log", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__["logBoxCreate"])(workerscript.scriptRef);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Kill Script", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["killWorkerScript"])(workerscript.scriptRef, workerscript.scriptRef.scriptRef.server);
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__["dialogBoxCreate"])("Killing script, may take a few minutes to complete...");
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//Append element to list
|
||||
ActiveScriptsUI[hostname]["panelList"].appendChild(li);
|
||||
ActiveScriptsUI[hostname].scripts[itemName] = li;
|
||||
ActiveScriptsUI[hostname].scriptHdrs[itemName] = hdr;
|
||||
ActiveScriptsUI[hostname].scriptStats[itemName] = panelText;
|
||||
}.bind(null, workerscript, hostname));
|
||||
}
|
||||
|
||||
function deleteActiveScriptsItem(workerscript) {
|
||||
ActiveScriptsTasks.push(function(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
throw new Error("ERROR: Invalid server IP for workerscript. This most likely occurred because " +
|
||||
"you tried to delete a large number of scripts and also purchased servers at the " +
|
||||
"same time. It's not a big deal, just save and refresh the game.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("ERROR: Trying to delete Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let li = ActiveScriptsUI[hostname].scripts[itemName];
|
||||
if (li == null) {
|
||||
console.log("ERROR: Cannot find Active Script UI element for workerscript: ");
|
||||
console.log(workerscript);
|
||||
return;
|
||||
}
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(li);
|
||||
delete ActiveScriptsUI[hostname].scripts[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptHdrs[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length === 0) {
|
||||
deleteActiveScriptsServerPanel(server);
|
||||
}
|
||||
}.bind(null, workerscript));
|
||||
}
|
||||
|
||||
//Update the ActiveScriptsItems array
|
||||
function updateActiveScriptsItems(maxTasks=100) {
|
||||
//Run tasks that need to be done sequentially (adding items, creating/deleting server panels)
|
||||
//We'll limit this to 50 at a time in case someone decides to start a bunch of scripts all at once...
|
||||
let numTasks = Math.min(maxTasks, ActiveScriptsTasks.length);
|
||||
for (let i = 0; i < numTasks; ++i) {
|
||||
let task = ActiveScriptsTasks.shift();
|
||||
try {
|
||||
task();
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
console.log(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (_engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].currentPage !== _engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].Page.ActiveScripts) {return;}
|
||||
var total = 0;
|
||||
for (var i = 0; i < _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"].length; ++i) {
|
||||
try {
|
||||
total += updateActiveScriptsItemContent(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"][i]);
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
}
|
||||
}
|
||||
document.getElementById("active-scripts-total-prod").innerHTML =
|
||||
"Total online production of Active Scripts: " + _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(total).format('$0.000a') + " / sec<br>" +
|
||||
"Total online production since last Aug installation: " +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug).format('$0.000a') + " (" +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug / (_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].playtimeSinceLastAug/1000)).format('$0.000a') + " / sec)";
|
||||
return total;
|
||||
}
|
||||
|
||||
//Updates the content of the given item in the Active Scripts list
|
||||
function updateActiveScriptsItemContent(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
return; //Hasn't been created yet. We'll skip it
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
if (ActiveScriptsUI[hostname].scriptStats[itemName] == null) {
|
||||
return; //Hasn't been fully added yet. We'll skip it
|
||||
}
|
||||
var item = ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
|
||||
//Update the text if necessary. This fn returns the online $/s production
|
||||
return updateActiveScriptsText(workerscript, item, itemName);
|
||||
}
|
||||
|
||||
function updateActiveScriptsText(workerscript, item, itemName) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null || ActiveScriptsUI[hostname].scriptHdrs[itemName] == null) {
|
||||
console.log("ERROR: Trying to update Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
|
||||
//Only update if the item is visible
|
||||
if (ActiveScriptsUI[hostname].header.classList.contains("active") === false) {return onlineMps;}
|
||||
if (ActiveScriptsUI[hostname].scriptHdrs[itemName].classList.contains("active") === false) {return onlineMps;}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeChildrenFromElement"])(item);
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var onlineMpsText = "Online production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
item.innerHTML = onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 44 */
|
||||
/*!************************!*\
|
||||
@ -55235,7 +55256,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Prestige_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Prestige.js */ 57);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
@ -56804,8 +56825,6 @@ Action.prototype.getSuccessChance = function(inst, params={}) {
|
||||
//Tests for success. Should be called when an action has completed
|
||||
// @inst - Bladeburner Object
|
||||
Action.prototype.attempt = function(inst) {
|
||||
console.log("Current City Pop: " + inst.getCurrentCity().pop);
|
||||
console.log("Action.attempt success chance: " + this.getSuccessChance(inst));
|
||||
return (Math.random() < this.getSuccessChance(inst));
|
||||
}
|
||||
|
||||
@ -61137,7 +61156,7 @@ exports.Utf8EncodeWorker = Utf8EncodeWorker;
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* WEBPACK VAR INJECTION */(function($) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeAugmentation", function() { return prestigeAugmentation; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeSourceFile", function() { return prestigeSourceFile; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _CinematicText_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./CinematicText.js */ 70);
|
||||
@ -63632,9 +63651,10 @@ function makeScriptBlob(code) {
|
||||
// (i.e. hack, grow, etc.).
|
||||
// When the promise returned by this resolves, we'll have finished
|
||||
// running the main function of the script.
|
||||
async function executeJSScript(script, scripts = [], workerScript) {
|
||||
async function executeJSScript(scripts = [], workerScript) {
|
||||
let loadedModule;
|
||||
let urlStack = null;
|
||||
let script = workerScript.getScript();
|
||||
if (script.module === "") {
|
||||
// The URL at the top is the one we want to import. It will
|
||||
// recursively import all the other modules in the urlStack.
|
||||
|
682
dist/tests.bundle.js
vendored
682
dist/tests.bundle.js
vendored
@ -84,7 +84,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _CreateProgram_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./CreateProgram.js */ 14);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
@ -94,7 +94,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _NetscriptFunctions_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./NetscriptFunctions.js */ 29);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _utils_decimal_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../utils/decimal.js */ 24);
|
||||
/* harmony import */ var _utils_decimal_js__WEBPACK_IMPORTED_MODULE_15___default = /*#__PURE__*/__webpack_require__.n(_utils_decimal_js__WEBPACK_IMPORTED_MODULE_15__);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
@ -4141,7 +4141,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "initLocationButtons", function() { return initLocationButtons; });
|
||||
/* harmony import */ var _Bladeburner_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Bladeburner.js */ 47);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
@ -6358,13 +6358,13 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_3__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Bladeburner_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Bladeburner.js */ 47);
|
||||
/* harmony import */ var _CinematicText_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./CinematicText.js */ 70);
|
||||
/* harmony import */ var _Company_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./Company.js */ 9);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./CompanyManagement.js */ 40);
|
||||
/* harmony import */ var _CompanyManagement_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./CompanyManagement.js */ 41);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _CreateProgram_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./CreateProgram.js */ 14);
|
||||
/* harmony import */ var _Faction_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./Faction.js */ 11);
|
||||
@ -6385,7 +6385,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Script_js__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./Script.js */ 26);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _StockMarket_js__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ./StockMarket.js */ 22);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
@ -8133,6 +8133,8 @@ window.onload = function() {
|
||||
var db = e.target.result;
|
||||
var objectStore = db.createObjectStore("savestring");
|
||||
}
|
||||
|
||||
console.log(window.location.href);
|
||||
};
|
||||
|
||||
|
||||
@ -12457,6 +12459,14 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
var txt = "You must first purchase or install " + aug.prereqs.join(",") + " before you can " +
|
||||
"purchase this one.";
|
||||
if (sing) {return txt;} else {Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);}
|
||||
} else if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].money.lt(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
let txt = "You don't have enough money to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);
|
||||
} else if (fac.playerReputation < aug.baseRepRequirement) {
|
||||
let txt = "You don't have enough faction reputation to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])(txt);
|
||||
} else if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].money.gte(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
if (_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].firstAugPurchased === false) {
|
||||
_Player_js__WEBPACK_IMPORTED_MODULE_7__["Player"].firstAugPurchased = true;
|
||||
@ -12503,11 +12513,9 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
|
||||
displayFactionAugmentations(fac.name);
|
||||
} else {
|
||||
if (sing) {
|
||||
return "You don't have enough money to purchase " + aug.name;
|
||||
} else {
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])("You don't have enough money to purchase this Augmentation!");
|
||||
}
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_9__["dialogBoxCreate"])("Hmm, something went wrong when trying to purchase an Augmentation. " +
|
||||
"Please report this to the game developer with an explanation of how to " +
|
||||
"reproduce this.");
|
||||
}
|
||||
Object(_utils_YesNoBox_js__WEBPACK_IMPORTED_MODULE_15__["yesNoBoxClose"])();
|
||||
}
|
||||
@ -13444,7 +13452,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
@ -15514,7 +15522,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _SaveObject_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./SaveObject.js */ 46);
|
||||
/* harmony import */ var _Script_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Script.js */ 26);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_JSONReviver_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../utils/JSONReviver.js */ 8);
|
||||
@ -18457,7 +18465,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addWorkerScript", function() { return addWorkerScript; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateOnlineScriptTimes", function() { return updateOnlineScriptTimes; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeWorkerScripts", function() { return prestigeWorkerScripts; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Constants.js */ 3);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptEnvironment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./NetscriptEnvironment.js */ 69);
|
||||
@ -18508,6 +18516,18 @@ WorkerScript.prototype.getServer = function() {
|
||||
return _Server_js__WEBPACK_IMPORTED_MODULE_7__["AllServers"][this.serverIp];
|
||||
}
|
||||
|
||||
//Returns the Script object for the underlying script
|
||||
WorkerScript.prototype.getScript = function() {
|
||||
let server = this.getServer();
|
||||
for (var i = 0; i < server.scripts.length; ++i) {
|
||||
if (server.scripts[i].filename === this.name) {
|
||||
return server.scripts[i];
|
||||
}
|
||||
}
|
||||
console.log("ERROR: Failed to find underlying Script object in WorkerScript.getScript(). This probably means somethings wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Array containing all scripts that are running across all servers, to easily run them all
|
||||
let workerScripts = [];
|
||||
|
||||
@ -18578,8 +18598,7 @@ function startJsScript(workerScript) {
|
||||
|
||||
// Note: the environment that we pass to the JS script only needs to contain the functions visible
|
||||
// to that script, which env.vars does at this point.
|
||||
return Object(_NetscriptJSEvaluator_js__WEBPACK_IMPORTED_MODULE_5__["executeJSScript"])(workerScript.scriptRef.scriptRef,
|
||||
workerScript.getServer().scripts,
|
||||
return Object(_NetscriptJSEvaluator_js__WEBPACK_IMPORTED_MODULE_5__["executeJSScript"])(workerScript.getServer().scripts,
|
||||
workerScript).then(function (mainReturnValue) {
|
||||
if (mainReturnValue === undefined) return workerScript;
|
||||
return [mainReturnValue, workerScript];
|
||||
@ -18624,13 +18643,14 @@ function runScriptsLoop() {
|
||||
workerScripts.splice(i, 1);
|
||||
}
|
||||
}
|
||||
Object(_ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__["updateActiveScriptsItems"])(); //Force Update
|
||||
|
||||
//Run any scripts that haven't been started
|
||||
for (var i = 0; i < workerScripts.length; i++) {
|
||||
//If it isn't running, start the script
|
||||
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) {
|
||||
let p = null; // p is the script's result promise.
|
||||
if (workerScripts[i].name.endsWith(".js")) {
|
||||
if (workerScripts[i].name.endsWith(".js") || workerScripts[i].name.endsWith(".ns")) {
|
||||
p = startJsScript(workerScripts[i]);
|
||||
} else {
|
||||
try {
|
||||
@ -25794,7 +25814,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _Settings_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Settings.js */ 23);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _utils_acorn_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../utils/acorn.js */ 35);
|
||||
/* harmony import */ var _utils_acorn_js__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(_utils_acorn_js__WEBPACK_IMPORTED_MODULE_12__);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
@ -25845,7 +25865,7 @@ var keybindings = {
|
||||
};
|
||||
|
||||
function isScriptFilename(f) {
|
||||
return f.endsWith(".js") || f.endsWith(".script");
|
||||
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
|
||||
}
|
||||
|
||||
var scriptEditorRamCheck = null, scriptEditorRamText = null;
|
||||
@ -26144,6 +26164,7 @@ Script.prototype.saveScript = function() {
|
||||
|
||||
//Calculate/update ram usage, execution time, etc.
|
||||
this.updateRamUsage();
|
||||
console.log(this.module);
|
||||
|
||||
this.module = "";
|
||||
}
|
||||
@ -27147,7 +27168,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasCorporationSF", function() { return hasCorporationSF; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasAISF", function() { return hasAISF; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasBladeburnerSF", function() { return hasBladeburnerSF; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _Crimes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Crimes.js */ 20);
|
||||
@ -27168,7 +27189,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _SpecialServerIps_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./SpecialServerIps.js */ 17);
|
||||
/* harmony import */ var _StockMarket_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./StockMarket.js */ 22);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./TextFile.js */ 41);
|
||||
/* harmony import */ var _TextFile_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./TextFile.js */ 42);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _NetscriptEvaluator_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./NetscriptEvaluator.js */ 7);
|
||||
/* harmony import */ var _NetscriptEnvironment_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./NetscriptEnvironment.js */ 69);
|
||||
@ -49665,6 +49686,309 @@ function getHacknetNode(name) {
|
||||
|
||||
/***/ }),
|
||||
/* 40 */
|
||||
/*!********************************!*\
|
||||
!*** ./src/ActiveScriptsUI.js ***!
|
||||
\********************************/
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addActiveScriptsItem", function() { return addActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteActiveScriptsItem", function() { return deleteActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateActiveScriptsItems", function() { return updateActiveScriptsItems; });
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/numeral.min.js */ 13);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* {
|
||||
* serverName: {
|
||||
* header: Server Header Element
|
||||
* panel: Server Panel List (ul) element
|
||||
* scripts: {
|
||||
* script id: Ref to Script information
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
*/
|
||||
let ActiveScriptsUI = {};
|
||||
let ActiveScriptsTasks = []; //Sequentially schedule the creation/deletion of UI elements
|
||||
|
||||
function createActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
|
||||
var activeScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:hostname});
|
||||
let li = res[0];
|
||||
var hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
if (ActiveScriptsUI[hostname] != null) {
|
||||
console.log("WARNING: Tried to create already-existing Active Scripts Server panel. This is most likely fine. It probably means many scripts just got started up on a new server. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
var panelScriptList = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("ul");
|
||||
panel.appendChild(panelScriptList);
|
||||
activeScriptsList.appendChild(li);
|
||||
|
||||
ActiveScriptsUI[hostname] = {
|
||||
header: hdr,
|
||||
panel: panel,
|
||||
panelList: panelScriptList,
|
||||
scripts: {}, //Holds references to li elements for each active script
|
||||
scriptHdrs: {}, //Holds references to header elements for each active script
|
||||
scriptStats: {} //Holds references to the p elements containing text for each active script
|
||||
};
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
//Deletes the info for a particular server (Dropdown header + Panel with all info)
|
||||
//in the Active Scripts page if it exists
|
||||
function deleteActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("WARNING: Tried to delete non-existent Active Scripts Server panel. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure it's empty
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length > 0) {
|
||||
console.log("WARNING: Tried to delete Active Scripts Server panel that still has scripts. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].panel);
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].header);
|
||||
delete ActiveScriptsUI[hostname];
|
||||
}
|
||||
|
||||
function addActiveScriptsItem(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript in addActiveScriptsItem()");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
|
||||
ActiveScriptsTasks.push(function(workerscript, hostname) {
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
createActiveScriptsServerPanel(server);
|
||||
}
|
||||
|
||||
//Create the unique identifier (key) for this script
|
||||
var itemNameArray = ["active", "scripts", hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:workerscript.name});
|
||||
let li = res[0];
|
||||
let hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
hdr.classList.remove("accordion-header");
|
||||
hdr.classList.add("active-scripts-script-header");
|
||||
panel.classList.remove("accordion-panel");
|
||||
panel.classList.add("active-scripts-script-panel");
|
||||
|
||||
//Handle the constant elements on the panel that don't change after creation
|
||||
//Threads, args, kill/log button
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerHTML: "Threads: " + workerscript.scriptRef.threads + "<br>" +
|
||||
"Args: " + Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["printArray"])(workerscript.args)
|
||||
}));
|
||||
var panelText = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerText:"Loading...", fontSize:"14px",
|
||||
});
|
||||
panel.appendChild(panelText);
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("br"));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Log", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__["logBoxCreate"])(workerscript.scriptRef);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Kill Script", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["killWorkerScript"])(workerscript.scriptRef, workerscript.scriptRef.scriptRef.server);
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__["dialogBoxCreate"])("Killing script, may take a few minutes to complete...");
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//Append element to list
|
||||
ActiveScriptsUI[hostname]["panelList"].appendChild(li);
|
||||
ActiveScriptsUI[hostname].scripts[itemName] = li;
|
||||
ActiveScriptsUI[hostname].scriptHdrs[itemName] = hdr;
|
||||
ActiveScriptsUI[hostname].scriptStats[itemName] = panelText;
|
||||
}.bind(null, workerscript, hostname));
|
||||
}
|
||||
|
||||
function deleteActiveScriptsItem(workerscript) {
|
||||
ActiveScriptsTasks.push(function(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
throw new Error("ERROR: Invalid server IP for workerscript. This most likely occurred because " +
|
||||
"you tried to delete a large number of scripts and also deleted servers at the " +
|
||||
"same time. It's not a big deal, just save and refresh the game.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("ERROR: Trying to delete Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let li = ActiveScriptsUI[hostname].scripts[itemName];
|
||||
if (li == null) {
|
||||
console.log("ERROR: Cannot find Active Script UI element for workerscript: ");
|
||||
console.log(workerscript);
|
||||
return;
|
||||
}
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(li);
|
||||
delete ActiveScriptsUI[hostname].scripts[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptHdrs[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length === 0) {
|
||||
deleteActiveScriptsServerPanel(server);
|
||||
}
|
||||
}.bind(null, workerscript));
|
||||
}
|
||||
|
||||
//Update the ActiveScriptsItems array
|
||||
function updateActiveScriptsItems(maxTasks=100) {
|
||||
//Run tasks that need to be done sequentially (adding items, creating/deleting server panels)
|
||||
//We'll limit this to 50 at a time in case someone decides to start a bunch of scripts all at once...
|
||||
let numTasks = Math.min(maxTasks, ActiveScriptsTasks.length);
|
||||
for (let i = 0; i < numTasks; ++i) {
|
||||
let task = ActiveScriptsTasks.shift();
|
||||
try {
|
||||
task();
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
console.log(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (_engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].currentPage !== _engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].Page.ActiveScripts) {return;}
|
||||
var total = 0;
|
||||
for (var i = 0; i < _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"].length; ++i) {
|
||||
try {
|
||||
total += updateActiveScriptsItemContent(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"][i]);
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
}
|
||||
}
|
||||
document.getElementById("active-scripts-total-prod").innerHTML =
|
||||
"Total online production of Active Scripts: " + _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(total).format('$0.000a') + " / sec<br>" +
|
||||
"Total online production since last Aug installation: " +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug).format('$0.000a') + " (" +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug / (_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].playtimeSinceLastAug/1000)).format('$0.000a') + " / sec)";
|
||||
return total;
|
||||
}
|
||||
|
||||
//Updates the content of the given item in the Active Scripts list
|
||||
function updateActiveScriptsItemContent(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
return; //Hasn't been created yet. We'll skip it
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
if (ActiveScriptsUI[hostname].scriptStats[itemName] == null) {
|
||||
return; //Hasn't been fully added yet. We'll skip it
|
||||
}
|
||||
var item = ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
|
||||
//Update the text if necessary. This fn returns the online $/s production
|
||||
return updateActiveScriptsText(workerscript, item, itemName);
|
||||
}
|
||||
|
||||
function updateActiveScriptsText(workerscript, item, itemName) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null || ActiveScriptsUI[hostname].scriptHdrs[itemName] == null) {
|
||||
console.log("ERROR: Trying to update Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
|
||||
//Only update if the item is visible
|
||||
if (ActiveScriptsUI[hostname].header.classList.contains("active") === false) {return onlineMps;}
|
||||
if (ActiveScriptsUI[hostname].scriptHdrs[itemName].classList.contains("active") === false) {return onlineMps;}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeChildrenFromElement"])(item);
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var onlineMpsText = "Online production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
item.innerHTML = onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 41 */
|
||||
/*!**********************************!*\
|
||||
!*** ./src/CompanyManagement.js ***!
|
||||
\**********************************/
|
||||
@ -54603,7 +54927,7 @@ _utils_JSONReviver_js__WEBPACK_IMPORTED_MODULE_9__["Reviver"].constructors.Corpo
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 41 */
|
||||
/* 42 */
|
||||
/*!*************************!*\
|
||||
!*** ./src/TextFile.js ***!
|
||||
\*************************/
|
||||
@ -54709,7 +55033,7 @@ function deleteTextFile(fn, server) {
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 42 */
|
||||
/* 43 */
|
||||
/*!***************************!*\
|
||||
!*** ./src/SourceFile.js ***!
|
||||
\***************************/
|
||||
@ -54917,309 +55241,6 @@ function applySourceFile(srcFile) {
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 43 */
|
||||
/*!********************************!*\
|
||||
!*** ./src/ActiveScriptsUI.js ***!
|
||||
\********************************/
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "addActiveScriptsItem", function() { return addActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deleteActiveScriptsItem", function() { return deleteActiveScriptsItem; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "updateActiveScriptsItems", function() { return updateActiveScriptsItems; });
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./NetscriptWorker.js */ 21);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Server_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Server.js */ 10);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
/* harmony import */ var _utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/LogBox.js */ 51);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/numeral.min.js */ 13);
|
||||
/* harmony import */ var _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7__);
|
||||
/* harmony import */ var _utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/StringHelperFunctions.js */ 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* {
|
||||
* serverName: {
|
||||
* header: Server Header Element
|
||||
* panel: Server Panel List (ul) element
|
||||
* scripts: {
|
||||
* script id: Ref to Script information
|
||||
* }
|
||||
* }
|
||||
* ...
|
||||
*/
|
||||
let ActiveScriptsUI = {};
|
||||
let ActiveScriptsTasks = []; //Sequentially schedule the creation/deletion of UI elements
|
||||
|
||||
function createActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
|
||||
var activeScriptsList = document.getElementById("active-scripts-list");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:hostname});
|
||||
let li = res[0];
|
||||
var hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
if (ActiveScriptsUI[hostname] != null) {
|
||||
console.log("WARNING: Tried to create already-existing Active Scripts Server panel. This is most likely fine. It probably means many scripts just got started up on a new server. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
var panelScriptList = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("ul");
|
||||
panel.appendChild(panelScriptList);
|
||||
activeScriptsList.appendChild(li);
|
||||
|
||||
ActiveScriptsUI[hostname] = {
|
||||
header: hdr,
|
||||
panel: panel,
|
||||
panelList: panelScriptList,
|
||||
scripts: {}, //Holds references to li elements for each active script
|
||||
scriptHdrs: {}, //Holds references to header elements for each active script
|
||||
scriptStats: {} //Holds references to the p elements containing text for each active script
|
||||
};
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
//Deletes the info for a particular server (Dropdown header + Panel with all info)
|
||||
//in the Active Scripts page if it exists
|
||||
function deleteActiveScriptsServerPanel(server) {
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("WARNING: Tried to delete non-existent Active Scripts Server panel. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure it's empty
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length > 0) {
|
||||
console.log("WARNING: Tried to delete Active Scripts Server panel that still has scripts. Aborting");
|
||||
return;
|
||||
}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].panel);
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(ActiveScriptsUI[hostname].header);
|
||||
delete ActiveScriptsUI[hostname];
|
||||
}
|
||||
|
||||
function addActiveScriptsItem(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript in addActiveScriptsItem()");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
|
||||
ActiveScriptsTasks.push(function(workerscript, hostname) {
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
createActiveScriptsServerPanel(server);
|
||||
}
|
||||
|
||||
//Create the unique identifier (key) for this script
|
||||
var itemNameArray = ["active", "scripts", hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let res = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createAccordionElement"])({hdrText:workerscript.name});
|
||||
let li = res[0];
|
||||
let hdr = res[1];
|
||||
let panel = res[2];
|
||||
|
||||
hdr.classList.remove("accordion-header");
|
||||
hdr.classList.add("active-scripts-script-header");
|
||||
panel.classList.remove("accordion-panel");
|
||||
panel.classList.add("active-scripts-script-panel");
|
||||
|
||||
//Handle the constant elements on the panel that don't change after creation
|
||||
//Threads, args, kill/log button
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerHTML: "Threads: " + workerscript.scriptRef.threads + "<br>" +
|
||||
"Args: " + Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["printArray"])(workerscript.args)
|
||||
}));
|
||||
var panelText = Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("p", {
|
||||
innerText:"Loading...", fontSize:"14px",
|
||||
});
|
||||
panel.appendChild(panelText);
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("br"));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Log", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_utils_LogBox_js__WEBPACK_IMPORTED_MODULE_6__["logBoxCreate"])(workerscript.scriptRef);
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
panel.appendChild(Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["createElement"])("span", {
|
||||
innerText:"Kill Script", class:"active-scripts-button", margin:"4px", padding:"4px",
|
||||
clickListener:()=>{
|
||||
Object(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["killWorkerScript"])(workerscript.scriptRef, workerscript.scriptRef.scriptRef.server);
|
||||
Object(_utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_4__["dialogBoxCreate"])("Killing script, may take a few minutes to complete...");
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
|
||||
//Append element to list
|
||||
ActiveScriptsUI[hostname]["panelList"].appendChild(li);
|
||||
ActiveScriptsUI[hostname].scripts[itemName] = li;
|
||||
ActiveScriptsUI[hostname].scriptHdrs[itemName] = hdr;
|
||||
ActiveScriptsUI[hostname].scriptStats[itemName] = panelText;
|
||||
}.bind(null, workerscript, hostname));
|
||||
}
|
||||
|
||||
function deleteActiveScriptsItem(workerscript) {
|
||||
ActiveScriptsTasks.push(function(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
throw new Error("ERROR: Invalid server IP for workerscript. This most likely occurred because " +
|
||||
"you tried to delete a large number of scripts and also purchased servers at the " +
|
||||
"same time. It's not a big deal, just save and refresh the game.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
console.log("ERROR: Trying to delete Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
let li = ActiveScriptsUI[hostname].scripts[itemName];
|
||||
if (li == null) {
|
||||
console.log("ERROR: Cannot find Active Script UI element for workerscript: ");
|
||||
console.log(workerscript);
|
||||
return;
|
||||
}
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeElement"])(li);
|
||||
delete ActiveScriptsUI[hostname].scripts[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptHdrs[itemName];
|
||||
delete ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
if (Object.keys(ActiveScriptsUI[hostname].scripts).length === 0) {
|
||||
deleteActiveScriptsServerPanel(server);
|
||||
}
|
||||
}.bind(null, workerscript));
|
||||
}
|
||||
|
||||
//Update the ActiveScriptsItems array
|
||||
function updateActiveScriptsItems(maxTasks=100) {
|
||||
//Run tasks that need to be done sequentially (adding items, creating/deleting server panels)
|
||||
//We'll limit this to 50 at a time in case someone decides to start a bunch of scripts all at once...
|
||||
let numTasks = Math.min(maxTasks, ActiveScriptsTasks.length);
|
||||
for (let i = 0; i < numTasks; ++i) {
|
||||
let task = ActiveScriptsTasks.shift();
|
||||
try {
|
||||
task();
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
console.log(task);
|
||||
}
|
||||
}
|
||||
|
||||
if (_engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].currentPage !== _engine_js__WEBPACK_IMPORTED_MODULE_0__["Engine"].Page.ActiveScripts) {return;}
|
||||
var total = 0;
|
||||
for (var i = 0; i < _NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"].length; ++i) {
|
||||
try {
|
||||
total += updateActiveScriptsItemContent(_NetscriptWorker_js__WEBPACK_IMPORTED_MODULE_1__["workerScripts"][i]);
|
||||
} catch(e) {
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["exceptionAlert"])(e);
|
||||
}
|
||||
}
|
||||
document.getElementById("active-scripts-total-prod").innerHTML =
|
||||
"Total online production of Active Scripts: " + _utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(total).format('$0.000a') + " / sec<br>" +
|
||||
"Total online production since last Aug installation: " +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug).format('$0.000a') + " (" +
|
||||
_utils_numeral_min_js__WEBPACK_IMPORTED_MODULE_7___default()(_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].scriptProdSinceLastAug / (_Player_js__WEBPACK_IMPORTED_MODULE_2__["Player"].playtimeSinceLastAug/1000)).format('$0.000a') + " / sec)";
|
||||
return total;
|
||||
}
|
||||
|
||||
//Updates the content of the given item in the Active Scripts list
|
||||
function updateActiveScriptsItemContent(workerscript) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null) {
|
||||
return; //Hasn't been created yet. We'll skip it
|
||||
}
|
||||
|
||||
var itemNameArray = ["active", "scripts", server.hostname, workerscript.name];
|
||||
for (var i = 0; i < workerscript.args.length; ++i) {
|
||||
itemNameArray.push(String(workerscript.args[i]));
|
||||
}
|
||||
var itemName = itemNameArray.join("-");
|
||||
|
||||
if (ActiveScriptsUI[hostname].scriptStats[itemName] == null) {
|
||||
return; //Hasn't been fully added yet. We'll skip it
|
||||
}
|
||||
var item = ActiveScriptsUI[hostname].scriptStats[itemName];
|
||||
|
||||
//Update the text if necessary. This fn returns the online $/s production
|
||||
return updateActiveScriptsText(workerscript, item, itemName);
|
||||
}
|
||||
|
||||
function updateActiveScriptsText(workerscript, item, itemName) {
|
||||
var server = Object(_Server_js__WEBPACK_IMPORTED_MODULE_3__["getServer"])(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
console.log("ERROR: Invalid server IP for workerscript.");
|
||||
return;
|
||||
}
|
||||
let hostname = server.hostname;
|
||||
if (ActiveScriptsUI[hostname] == null || ActiveScriptsUI[hostname].scriptHdrs[itemName] == null) {
|
||||
console.log("ERROR: Trying to update Active Script UI Element with a hostname that cant be found in ActiveScriptsUI: " + hostname);
|
||||
return;
|
||||
}
|
||||
|
||||
var onlineMps = workerscript.scriptRef.onlineMoneyMade / workerscript.scriptRef.onlineRunningTime;
|
||||
|
||||
//Only update if the item is visible
|
||||
if (ActiveScriptsUI[hostname].header.classList.contains("active") === false) {return onlineMps;}
|
||||
if (ActiveScriptsUI[hostname].scriptHdrs[itemName].classList.contains("active") === false) {return onlineMps;}
|
||||
|
||||
Object(_utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_5__["removeChildrenFromElement"])(item);
|
||||
|
||||
//Online
|
||||
var onlineTotalMoneyMade = "Total online production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineMoneyMade, 2);
|
||||
var onlineTotalExpEarned = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.onlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var onlineMpsText = "Online production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineMps, 2) + "/second";
|
||||
var onlineEps = workerscript.scriptRef.onlineExpGained / workerscript.scriptRef.onlineRunningTime;
|
||||
var onlineEpsText = (Array(25).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(onlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
//Offline
|
||||
var offlineTotalMoneyMade = "Total offline production: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineMoneyMade, 2);
|
||||
var offlineTotalExpEarned = (Array(27).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(workerscript.scriptRef.offlineExpGained, 2) + " hacking exp").replace( / /g, " ");
|
||||
|
||||
var offlineMps = workerscript.scriptRef.offlineMoneyMade / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineMpsText = "Offline production rate: $" + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineMps, 2) + "/second";
|
||||
var offlineEps = workerscript.scriptRef.offlineExpGained / workerscript.scriptRef.offlineRunningTime;
|
||||
var offlineEpsText = (Array(26).join(" ") + Object(_utils_StringHelperFunctions_js__WEBPACK_IMPORTED_MODULE_8__["formatNumber"])(offlineEps, 4) + " hacking exp/second").replace( / /g, " ");
|
||||
|
||||
item.innerHTML = onlineTotalMoneyMade + "<br>" + onlineTotalExpEarned + "<br>" +
|
||||
onlineMpsText + "<br>" + onlineEpsText + "<br>" + offlineTotalMoneyMade + "<br>" + offlineTotalExpEarned + "<br>" +
|
||||
offlineMpsText + "<br>" + offlineEpsText + "<br>";
|
||||
return onlineMps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 44 */
|
||||
/*!************************!*\
|
||||
@ -55235,7 +55256,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony import */ var _engine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./engine.js */ 5);
|
||||
/* harmony import */ var _Player_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Player.js */ 0);
|
||||
/* harmony import */ var _Prestige_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Prestige.js */ 57);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SourceFile.js */ 42);
|
||||
/* harmony import */ var _SourceFile_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SourceFile.js */ 43);
|
||||
/* harmony import */ var _Terminal_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Terminal.js */ 18);
|
||||
/* harmony import */ var _utils_DialogBox_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/DialogBox.js */ 6);
|
||||
/* harmony import */ var _utils_HelperFunctions_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/HelperFunctions.js */ 1);
|
||||
@ -56804,8 +56825,6 @@ Action.prototype.getSuccessChance = function(inst, params={}) {
|
||||
//Tests for success. Should be called when an action has completed
|
||||
// @inst - Bladeburner Object
|
||||
Action.prototype.attempt = function(inst) {
|
||||
console.log("Current City Pop: " + inst.getCurrentCity().pop);
|
||||
console.log("Action.attempt success chance: " + this.getSuccessChance(inst));
|
||||
return (Math.random() < this.getSuccessChance(inst));
|
||||
}
|
||||
|
||||
@ -61137,7 +61156,7 @@ exports.Utf8EncodeWorker = Utf8EncodeWorker;
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* WEBPACK VAR INJECTION */(function($) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeAugmentation", function() { return prestigeAugmentation; });
|
||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "prestigeSourceFile", function() { return prestigeSourceFile; });
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 43);
|
||||
/* harmony import */ var _ActiveScriptsUI_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ActiveScriptsUI.js */ 40);
|
||||
/* harmony import */ var _Augmentations_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Augmentations.js */ 19);
|
||||
/* harmony import */ var _BitNode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./BitNode.js */ 15);
|
||||
/* harmony import */ var _CinematicText_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./CinematicText.js */ 70);
|
||||
@ -63673,9 +63692,10 @@ function makeScriptBlob(code) {
|
||||
// (i.e. hack, grow, etc.).
|
||||
// When the promise returned by this resolves, we'll have finished
|
||||
// running the main function of the script.
|
||||
async function executeJSScript(script, scripts = [], workerScript) {
|
||||
async function executeJSScript(scripts = [], workerScript) {
|
||||
let loadedModule;
|
||||
let urlStack = null;
|
||||
let script = workerScript.getScript();
|
||||
if (script.module === "") {
|
||||
// The URL at the top is the one we want to import. It will
|
||||
// recursively import all the other modules in the urlStack.
|
||||
|
BIN
doc/build/doctrees/environment.pickle
vendored
BIN
doc/build/doctrees/environment.pickle
vendored
Binary file not shown.
BIN
doc/build/doctrees/netscript.doctree
vendored
BIN
doc/build/doctrees/netscript.doctree
vendored
Binary file not shown.
BIN
doc/build/doctrees/netscriptjs.doctree
vendored
Normal file
BIN
doc/build/doctrees/netscriptjs.doctree
vendored
Normal file
Binary file not shown.
BIN
doc/build/doctrees/terminal.doctree
vendored
BIN
doc/build/doctrees/terminal.doctree
vendored
Binary file not shown.
1
doc/build/html/_sources/netscript.rst.txt
vendored
1
doc/build/html/_sources/netscript.rst.txt
vendored
@ -14,6 +14,7 @@ to reach out to the developer!
|
||||
:maxdepth: 5
|
||||
:caption: Sections:
|
||||
|
||||
NetscriptJS (Netscript 2.0) <netscriptjs>
|
||||
Data Types and Variables <netscriptdatatypes>
|
||||
Operators <netscriptoperators>
|
||||
Loops and Conditionals <netscriptloopsandconditionals>
|
||||
|
202
doc/build/html/_sources/netscriptjs.rst.txt
vendored
Normal file
202
doc/build/html/_sources/netscriptjs.rst.txt
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
NetscriptJS (Netscript 2.0)
|
||||
===========================
|
||||
Netscript 2.0, or Netscript JS, is the new and improved version of Netscript that
|
||||
allows users to write (almost) full-fledged Javascript code in their scripts, while
|
||||
still being able to access the Netscript functions.
|
||||
|
||||
NetscriptJS was developed primarily by `Github user jaguilar <https://github.com/jaguilar>`_
|
||||
|
||||
On top of having almost all of the features and capabilities of Javascript, NetscriptJS is also
|
||||
significantly faster than Netscript 1.0.
|
||||
|
||||
This documentation will not go over any of the additional features of NetscriptJS, since
|
||||
there is plenty of documentation on Javascript available on the web.
|
||||
|
||||
NetscriptJS in Mozilla Firefox
|
||||
------------------------------
|
||||
As of the time of writing this, the Mozilla Firefox browser does not support
|
||||
dynamic import functionality and therefore cannot run NetscriptJS scripts.
|
||||
|
||||
(This may be some option/method for enabling this in Firefox, but I don't know
|
||||
what is it)
|
||||
|
||||
How to use NetscriptJS
|
||||
----------------------
|
||||
Working with NetscriptJS scripts is the same as Netscript 1.0 scripts. The only difference
|
||||
is that NetscriptJS scripts use the ".ns" or ".js" extension rather than ".script". E.g.::
|
||||
|
||||
$ nano foo.ns
|
||||
$ run foo.ns -t 100 arg1 arg2 arg3
|
||||
exec("foo.ns", "purchasedServer1", "100", "randomArg");
|
||||
|
||||
The caveat when using NetscriptJS to write scripts is that your code must be
|
||||
asynchronous. Furthermore, instead of using the global scope and executing your code
|
||||
sequentially, NetscriptJS uses a :code:`main()` function as an entry point.
|
||||
|
||||
Furthermore, the "Netscript environment" must be passed into a NetscriptJS script through
|
||||
the main function. This environment includes all of the pre-defined Netscript functions
|
||||
(:code:`hack()`, :code:`exec`, etc.) as well as the arguments you pass to the script.
|
||||
|
||||
Therefore, the signature of the :code:`main()` function must be::
|
||||
|
||||
export async function main(ns) {
|
||||
ns.print("Starting script here");
|
||||
}
|
||||
|
||||
Here is a summary of all rules you need to follow when writing Netscript JS code:
|
||||
|
||||
* Write :code:`await` before any call to the following Netscript functions:
|
||||
|
||||
* hack
|
||||
* grow
|
||||
* weaken
|
||||
* sleep
|
||||
* run
|
||||
* exec
|
||||
* prompt
|
||||
|
||||
* Any function that contains :code:`await` must be declared as :code:`async`
|
||||
|
||||
* Always :code:`await` any function that is marked as :code:`async`
|
||||
|
||||
* Any functions that you want to be visible from other scripts must be marked with :code:`export`.
|
||||
|
||||
* **Do not write any infinite loops** without using a :code:`sleep` or one of the timed Netscript functions like :code:`hack`. Doing so will crash your game.
|
||||
|
||||
* Any global variable declared in a NetscriptJS script is shared between all instances of that
|
||||
script. For example, assume you write a script *foo.ns* and declared a global variable like so::
|
||||
|
||||
//foo.ns
|
||||
let globalVariable;
|
||||
|
||||
export async function main(ns) {
|
||||
globalVariable = ns.args.length;
|
||||
while(true) {
|
||||
tprint(globalVariable);
|
||||
await sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
Then, you ran multiple instances of *foo.ns*::
|
||||
|
||||
$ run foo.ns 1
|
||||
$ run foo.ns 1 2 3
|
||||
$ run foo.ns 1 2 3 4 5
|
||||
|
||||
Then all three instances of foo.ns will share the same instance of :code:`globalVariable`.
|
||||
(In this example, the value of :code:`globalVariable` will be set to 5 because the
|
||||
last instance of *foo.ns* to run has 5 arguments. This means that all three instances of
|
||||
the script will repeatedly print the value 5).
|
||||
|
||||
These global variables can be thought of as `C++ static class members <https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm>`_,
|
||||
where a NetscriptJS script is a class and a global variable is a static member within that class.
|
||||
|
||||
Warnings
|
||||
--------
|
||||
The NetscriptJS evaluation engine works by converting your code into a blob URL and then
|
||||
using a dynamic import to load your code as a module. Every unique NetscriptJS script
|
||||
is loaded as its own module. This means that
|
||||
making a small edit to a NetscriptJS script results in a new module being generated.
|
||||
|
||||
At this point, we have been unable to find a method for deleting modules from browsers so that
|
||||
they get garbage collected.
|
||||
|
||||
The result is that these modules from NetscriptJS scripts accumulate in your browser,
|
||||
using memory that never gets released. Over time, this results in a memory-leak type
|
||||
situation that can slow down your computer.
|
||||
|
||||
Therefore, there are two recommendations for those who decide to use NetscriptJS:
|
||||
|
||||
1. Every now and then, close and re-open the game. This will clear all of the modules.
|
||||
To be safe, I recommend **completely** closing the game's tab and then re-opening it.
|
||||
Depending on your browser, a refresh or page reload does not always clear the modules.
|
||||
|
||||
2. Only use NetscriptJS scripts when needed. It is very unlikely that NetscriptJS
|
||||
is needed for very simple scripts. By doing this, you will reduce the number of modules
|
||||
that are loaded.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
**DOM Manipulation (tprintColored.ns)**
|
||||
|
||||
Directly alter the game's terminal and print colored text::
|
||||
|
||||
export function tprintColored(txt, color) {
|
||||
let terminalInput = document.getElementById("terminal-input");
|
||||
let rowElement = document.createElement("tr");
|
||||
let cellElement = document.createElement("td");
|
||||
|
||||
rowElement.classList.add("posted");
|
||||
cellElement.classList.add("terminal-line");
|
||||
cellElement.style.color = color;
|
||||
cellElement.innerText = txt;
|
||||
|
||||
rowElement.appendChild(cellElement);
|
||||
terminalInput.before(rowElement);
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Red Text!", "red");
|
||||
tprintColored("Blue Text!", "blue");
|
||||
tprintColored("Use Hex Codes!", "#3087E3");
|
||||
}
|
||||
|
||||
**Script Scheduler (scriptScheduler.ns)**
|
||||
|
||||
This script shows some of the new functionality that is available in NetscriptJS,
|
||||
including objects and object constructors, changing an object's prototype, and
|
||||
importing other NetscriptJS scripts::
|
||||
|
||||
import {tprintColored} from "tprintColored.ns"; //Importing from other NetscriptJS scripts works!
|
||||
|
||||
function ScriptJob(params) {
|
||||
if (params.fn == null) {
|
||||
throw new Error("No Filename (fn) passed into ScriptJob ctor");
|
||||
}
|
||||
|
||||
this.fn = params.fn;
|
||||
this.threads = params.threads ? params.threads : 1;
|
||||
this.args = params.args ? params.args : [];
|
||||
}
|
||||
|
||||
ScriptJob.prototype.run = async function(ns) {
|
||||
let runArgs = [this.fn, this.threads].concat(this.args);
|
||||
await ns.run.apply(this, runArgs);
|
||||
tprintColored("Running " + this.fn + " on " + ns.getHostname(), "blue");
|
||||
}
|
||||
|
||||
ScriptJob.prototype.exec = async function(ns, target) {
|
||||
ns.scp(this.fn, target);
|
||||
|
||||
let execArgs = [this.fn, target, this.threads].concat(this.args);
|
||||
await ns.exec.apply(this, execArgs);
|
||||
|
||||
tprintColored("Executing " + this.fn + " on " + target, "blue");
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Starting scriptScheduler.ns", "red");
|
||||
try {
|
||||
let job = new ScriptJob({
|
||||
fn: "test.js",
|
||||
threads: 1,
|
||||
args: ["foodnstuff"]
|
||||
});
|
||||
await job.run(ns);
|
||||
await job.exec(ns, "foodnstuff");
|
||||
} catch (e) {
|
||||
ns.tprint("Exception thrown in scriptScheduler.ns: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
Final Note
|
||||
----------
|
||||
NetscriptJS opens up a lot of possibilities when scripting. I look forward to seeing
|
||||
the scripts that people come up with. Just remember that the power and capabilities of
|
||||
NetscriptJS come with risks. Please backup your save if you're going to experiment with
|
||||
NetscriptJS and report any serious exploits.
|
||||
|
||||
With great power comes great responsibility
|
||||
|
||||
Happy hacking
|
2
doc/build/html/_sources/terminal.rst.txt
vendored
2
doc/build/html/_sources/terminal.rst.txt
vendored
@ -266,7 +266,7 @@ nano
|
||||
|
||||
$ nano [filename]
|
||||
|
||||
Opens up the specified file in the Text Editor. Only scripts (.script) and
|
||||
Opens up the specified file in the Text Editor. Only scripts (.script, .ns, .js) and
|
||||
text files (.txt) can be edited. If the file does not already exist, then a new
|
||||
empty file will be created.
|
||||
|
||||
|
8
doc/build/html/index.html
vendored
8
doc/build/html/index.html
vendored
@ -62,6 +62,14 @@ secrets that you've been searching for.</p>
|
||||
<p class="caption"><span class="caption-text">Contents:</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="netscript.html"> Netscript</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html"> NetscriptJS (Netscript 2.0)</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptjs.html#netscriptjs-in-mozilla-firefox">NetscriptJS in Mozilla Firefox</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptjs.html#how-to-use-netscriptjs">How to use NetscriptJS</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptjs.html#warnings">Warnings</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptjs.html#examples">Examples</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptjs.html#final-note">Final Note</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html"> Data Types and Variables</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptdatatypes.html#data-types">Data Types</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptdatatypes.html#variables">Variables</a></li>
|
||||
|
15
doc/build/html/netscript.html
vendored
15
doc/build/html/netscript.html
vendored
@ -24,7 +24,7 @@
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="next" title="Netscript Data Types and Variables" href="netscriptdatatypes.html" />
|
||||
<link rel="next" title="NetscriptJS (Netscript 2.0)" href="netscriptjs.html" />
|
||||
<link rel="prev" title="Welcome to Bitburner's documentation!" href="index.html" />
|
||||
</head>
|
||||
<body>
|
||||
@ -35,7 +35,7 @@
|
||||
<div class="rel" role="navigation" aria-label="related navigation">
|
||||
<a href="index.html" title="Welcome to Bitburner's documentation!"
|
||||
accesskey="P">previous</a> |
|
||||
<a href="netscriptdatatypes.html" title="Netscript Data Types and Variables"
|
||||
<a href="netscriptjs.html" title="NetscriptJS (Netscript 2.0)"
|
||||
accesskey="N">next</a> |
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a>
|
||||
@ -63,6 +63,14 @@ to reach out to the developer!</p>
|
||||
<div class="toctree-wrapper compound">
|
||||
<p class="caption"><span class="caption-text">Sections:</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="netscriptjs.html"> NetscriptJS (Netscript 2.0)</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html#netscriptjs-in-mozilla-firefox">NetscriptJS in Mozilla Firefox</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html#how-to-use-netscriptjs">How to use NetscriptJS</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html#warnings">Warnings</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html#examples">Examples</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html#final-note">Final Note</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="netscriptdatatypes.html"> Data Types and Variables</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html#data-types">Data Types</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html#variables">Variables</a></li>
|
||||
@ -226,6 +234,7 @@ to reach out to the developer!</p>
|
||||
<p class="caption"><span class="caption-text">Contents:</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#"> Netscript</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html"> NetscriptJS (Netscript 2.0)</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html"> Data Types and Variables</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptoperators.html"> Operators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptloopsandconditionals.html"> Loops and Conditionals</a></li>
|
||||
@ -262,7 +271,7 @@ to reach out to the developer!</p>
|
||||
<div role="navigation" aria-label="related navigaton">
|
||||
<a href="index.html" title="Welcome to Bitburner's documentation!"
|
||||
>previous</a> |
|
||||
<a href="netscriptdatatypes.html" title="Netscript Data Types and Variables"
|
||||
<a href="netscriptjs.html" title="NetscriptJS (Netscript 2.0)"
|
||||
>next</a> |
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a>
|
||||
|
325
doc/build/html/netscriptjs.html
vendored
Normal file
325
doc/build/html/netscriptjs.html
vendored
Normal file
@ -0,0 +1,325 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="English">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>NetscriptJS (Netscript 2.0) — Bitburner 1.0 documentation</title>
|
||||
<link rel="stylesheet" href="_static/agogo.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<script type="text/javascript">
|
||||
var DOCUMENTATION_OPTIONS = {
|
||||
URL_ROOT: './',
|
||||
VERSION: '1.0',
|
||||
COLLAPSE_INDEX: false,
|
||||
FILE_SUFFIX: '.html',
|
||||
HAS_SOURCE: true,
|
||||
SOURCELINK_SUFFIX: '.txt'
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="next" title="Netscript Data Types and Variables" href="netscriptdatatypes.html" />
|
||||
<link rel="prev" title="Netscript Documentation" href="netscript.html" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="header-wrapper" role="banner">
|
||||
<div class="header">
|
||||
<div class="headertitle"><a
|
||||
href="index.html">Bitburner 1.0 documentation</a></div>
|
||||
<div class="rel" role="navigation" aria-label="related navigation">
|
||||
<a href="netscript.html" title="Netscript Documentation"
|
||||
accesskey="P">previous</a> |
|
||||
<a href="netscriptdatatypes.html" title="Netscript Data Types and Variables"
|
||||
accesskey="N">next</a> |
|
||||
<a href="genindex.html" title="General Index"
|
||||
accesskey="I">index</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-wrapper">
|
||||
<div class="content">
|
||||
<div class="document">
|
||||
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
<div class="body" role="main">
|
||||
|
||||
<div class="section" id="netscriptjs-netscript-2-0">
|
||||
<h1>NetscriptJS (Netscript 2.0)<a class="headerlink" href="#netscriptjs-netscript-2-0" title="Permalink to this headline">¶</a></h1>
|
||||
<p>Netscript 2.0, or Netscript JS, is the new and improved version of Netscript that
|
||||
allows users to write (almost) full-fledged Javascript code in their scripts, while
|
||||
still being able to access the Netscript functions.</p>
|
||||
<p>NetscriptJS was developed primarily by <a class="reference external" href="https://github.com/jaguilar">Github user jaguilar</a></p>
|
||||
<p>On top of having almost all of the features and capabilities of Javascript, NetscriptJS is also
|
||||
significantly faster than Netscript 1.0.</p>
|
||||
<p>This documentation will not go over any of the additional features of NetscriptJS, since
|
||||
there is plenty of documentation on Javascript available on the web.</p>
|
||||
<div class="section" id="netscriptjs-in-mozilla-firefox">
|
||||
<h2>NetscriptJS in Mozilla Firefox<a class="headerlink" href="#netscriptjs-in-mozilla-firefox" title="Permalink to this headline">¶</a></h2>
|
||||
<p>As of the time of writing this, the Mozilla Firefox browser does not support
|
||||
dynamic import functionality and therefore cannot run NetscriptJS scripts.</p>
|
||||
<p>(This may be some option/method for enabling this in Firefox, but I don't know
|
||||
what is it)</p>
|
||||
</div>
|
||||
<div class="section" id="how-to-use-netscriptjs">
|
||||
<h2>How to use NetscriptJS<a class="headerlink" href="#how-to-use-netscriptjs" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Working with NetscriptJS scripts is the same as Netscript 1.0 scripts. The only difference
|
||||
is that NetscriptJS scripts use the ".ns" or ".js" extension rather than ".script". E.g.:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>$ nano foo.ns
|
||||
$ run foo.ns -t 100 arg1 arg2 arg3
|
||||
exec("foo.ns", "purchasedServer1", "100", "randomArg");
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>The caveat when using NetscriptJS to write scripts is that your code must be
|
||||
asynchronous. Furthermore, instead of using the global scope and executing your code
|
||||
sequentially, NetscriptJS uses a <code class="code docutils literal"><span class="pre">main()</span></code> function as an entry point.</p>
|
||||
<p>Furthermore, the "Netscript environment" must be passed into a NetscriptJS script through
|
||||
the main function. This environment includes all of the pre-defined Netscript functions
|
||||
(<code class="code docutils literal"><span class="pre">hack()</span></code>, <code class="code docutils literal"><span class="pre">exec</span></code>, etc.) as well as the arguments you pass to the script.</p>
|
||||
<p>Therefore, the signature of the <code class="code docutils literal"><span class="pre">main()</span></code> function must be:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">export</span> <span class="k">async</span> <span class="n">function</span> <span class="n">main</span><span class="p">(</span><span class="n">ns</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">ns</span><span class="o">.</span><span class="n">print</span><span class="p">(</span><span class="s2">"Starting script here"</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Here is a summary of all rules you need to follow when writing Netscript JS code:</p>
|
||||
<ul>
|
||||
<li><p class="first">Write <code class="code docutils literal"><span class="pre">await</span></code> before any call to the following Netscript functions:</p>
|
||||
<blockquote>
|
||||
<div><ul class="simple">
|
||||
<li>hack</li>
|
||||
<li>grow</li>
|
||||
<li>weaken</li>
|
||||
<li>sleep</li>
|
||||
<li>run</li>
|
||||
<li>exec</li>
|
||||
<li>prompt</li>
|
||||
</ul>
|
||||
</div></blockquote>
|
||||
</li>
|
||||
<li><p class="first">Any function that contains <code class="code docutils literal"><span class="pre">await</span></code> must be declared as <code class="code docutils literal"><span class="pre">async</span></code></p>
|
||||
</li>
|
||||
<li><p class="first">Always <code class="code docutils literal"><span class="pre">await</span></code> any function that is marked as <code class="code docutils literal"><span class="pre">async</span></code></p>
|
||||
</li>
|
||||
<li><p class="first">Any functions that you want to be visible from other scripts must be marked with <code class="code docutils literal"><span class="pre">export</span></code>.</p>
|
||||
</li>
|
||||
<li><p class="first"><strong>Do not write any infinite loops</strong> without using a <code class="code docutils literal"><span class="pre">sleep</span></code> or one of the timed Netscript functions like <code class="code docutils literal"><span class="pre">hack</span></code>. Doing so will crash your game.</p>
|
||||
</li>
|
||||
<li><p class="first">Any global variable declared in a NetscriptJS script is shared between all instances of that
|
||||
script. For example, assume you write a script <em>foo.ns</em> and declared a global variable like so:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">//</span><span class="n">foo</span><span class="o">.</span><span class="n">ns</span>
|
||||
<span class="n">let</span> <span class="n">globalVariable</span><span class="p">;</span>
|
||||
|
||||
<span class="n">export</span> <span class="k">async</span> <span class="n">function</span> <span class="n">main</span><span class="p">(</span><span class="n">ns</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">globalVariable</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">length</span><span class="p">;</span>
|
||||
<span class="k">while</span><span class="p">(</span><span class="n">true</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">tprint</span><span class="p">(</span><span class="n">globalVariable</span><span class="p">);</span>
|
||||
<span class="k">await</span> <span class="n">sleep</span><span class="p">(</span><span class="mi">3000</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Then, you ran multiple instances of <em>foo.ns</em>:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>$ run foo.ns 1
|
||||
$ run foo.ns 1 2 3
|
||||
$ run foo.ns 1 2 3 4 5
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Then all three instances of foo.ns will share the same instance of <code class="code docutils literal"><span class="pre">globalVariable</span></code>.
|
||||
(In this example, the value of <code class="code docutils literal"><span class="pre">globalVariable</span></code> will be set to 5 because the
|
||||
last instance of <em>foo.ns</em> to run has 5 arguments. This means that all three instances of
|
||||
the script will repeatedly print the value 5).</p>
|
||||
<p>These global variables can be thought of as <a class="reference external" href="https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm">C++ static class members</a>,
|
||||
where a NetscriptJS script is a class and a global variable is a static member within that class.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="warnings">
|
||||
<h2>Warnings<a class="headerlink" href="#warnings" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The NetscriptJS evaluation engine works by converting your code into a blob URL and then
|
||||
using a dynamic import to load your code as a module. Every unique NetscriptJS script
|
||||
is loaded as its own module. This means that
|
||||
making a small edit to a NetscriptJS script results in a new module being generated.</p>
|
||||
<p>At this point, we have been unable to find a method for deleting modules from browsers so that
|
||||
they get garbage collected.</p>
|
||||
<p>The result is that these modules from NetscriptJS scripts accumulate in your browser,
|
||||
using memory that never gets released. Over time, this results in a memory-leak type
|
||||
situation that can slow down your computer.</p>
|
||||
<p>Therefore, there are two recommendations for those who decide to use NetscriptJS:</p>
|
||||
<p>1. Every now and then, close and re-open the game. This will clear all of the modules.
|
||||
To be safe, I recommend <strong>completely</strong> closing the game's tab and then re-opening it.
|
||||
Depending on your browser, a refresh or page reload does not always clear the modules.</p>
|
||||
<p>2. Only use NetscriptJS scripts when needed. It is very unlikely that NetscriptJS
|
||||
is needed for very simple scripts. By doing this, you will reduce the number of modules
|
||||
that are loaded.</p>
|
||||
</div>
|
||||
<div class="section" id="examples">
|
||||
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
|
||||
<p><strong>DOM Manipulation (tprintColored.ns)</strong></p>
|
||||
<p>Directly alter the game's terminal and print colored text:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">export</span> <span class="n">function</span> <span class="n">tprintColored</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">color</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">let</span> <span class="n">terminalInput</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">getElementById</span><span class="p">(</span><span class="s2">"terminal-input"</span><span class="p">);</span>
|
||||
<span class="n">let</span> <span class="n">rowElement</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">createElement</span><span class="p">(</span><span class="s2">"tr"</span><span class="p">);</span>
|
||||
<span class="n">let</span> <span class="n">cellElement</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">createElement</span><span class="p">(</span><span class="s2">"td"</span><span class="p">);</span>
|
||||
|
||||
<span class="n">rowElement</span><span class="o">.</span><span class="n">classList</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s2">"posted"</span><span class="p">);</span>
|
||||
<span class="n">cellElement</span><span class="o">.</span><span class="n">classList</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s2">"terminal-line"</span><span class="p">);</span>
|
||||
<span class="n">cellElement</span><span class="o">.</span><span class="n">style</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="n">color</span><span class="p">;</span>
|
||||
<span class="n">cellElement</span><span class="o">.</span><span class="n">innerText</span> <span class="o">=</span> <span class="n">txt</span><span class="p">;</span>
|
||||
|
||||
<span class="n">rowElement</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">cellElement</span><span class="p">);</span>
|
||||
<span class="n">terminalInput</span><span class="o">.</span><span class="n">before</span><span class="p">(</span><span class="n">rowElement</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="n">export</span> <span class="k">async</span> <span class="n">function</span> <span class="n">main</span><span class="p">(</span><span class="n">ns</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">tprintColored</span><span class="p">(</span><span class="s2">"Red Text!"</span><span class="p">,</span> <span class="s2">"red"</span><span class="p">);</span>
|
||||
<span class="n">tprintColored</span><span class="p">(</span><span class="s2">"Blue Text!"</span><span class="p">,</span> <span class="s2">"blue"</span><span class="p">);</span>
|
||||
<span class="n">tprintColored</span><span class="p">(</span><span class="s2">"Use Hex Codes!"</span><span class="p">,</span> <span class="s2">"#3087E3"</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p><strong>Script Scheduler (scriptScheduler.ns)</strong></p>
|
||||
<p>This script shows some of the new functionality that is available in NetscriptJS,
|
||||
including objects and object constructors, changing an object's prototype, and
|
||||
importing other NetscriptJS scripts:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>import {tprintColored} from "tprintColored.ns"; //Importing from other NetscriptJS scripts works!
|
||||
|
||||
function ScriptJob(params) {
|
||||
if (params.fn == null) {
|
||||
throw new Error("No Filename (fn) passed into ScriptJob ctor");
|
||||
}
|
||||
|
||||
this.fn = params.fn;
|
||||
this.threads = params.threads ? params.threads : 1;
|
||||
this.args = params.args ? params.args : [];
|
||||
}
|
||||
|
||||
ScriptJob.prototype.run = async function(ns) {
|
||||
let runArgs = [this.fn, this.threads].concat(this.args);
|
||||
await ns.run.apply(this, runArgs);
|
||||
tprintColored("Running " + this.fn + " on " + ns.getHostname(), "blue");
|
||||
}
|
||||
|
||||
ScriptJob.prototype.exec = async function(ns, target) {
|
||||
ns.scp(this.fn, target);
|
||||
|
||||
let execArgs = [this.fn, target, this.threads].concat(this.args);
|
||||
await ns.exec.apply(this, execArgs);
|
||||
|
||||
tprintColored("Executing " + this.fn + " on " + target, "blue");
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Starting scriptScheduler.ns", "red");
|
||||
try {
|
||||
let job = new ScriptJob({
|
||||
fn: "test.js",
|
||||
threads: 1,
|
||||
args: ["foodnstuff"]
|
||||
});
|
||||
await job.run(ns);
|
||||
await job.exec(ns, "foodnstuff");
|
||||
} catch (e) {
|
||||
ns.tprint("Exception thrown in scriptScheduler.ns: " + e);
|
||||
}
|
||||
}
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="final-note">
|
||||
<h2>Final Note<a class="headerlink" href="#final-note" title="Permalink to this headline">¶</a></h2>
|
||||
<p>NetscriptJS opens up a lot of possibilities when scripting. I look forward to seeing
|
||||
the scripts that people come up with. Just remember that the power and capabilities of
|
||||
NetscriptJS come with risks. Please backup your save if you're going to experiment with
|
||||
NetscriptJS and report any serious exploits.</p>
|
||||
<p>With great power comes great responsibility</p>
|
||||
<p>Happy hacking</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
<h3>Table Of Contents</h3>
|
||||
<p class="caption"><span class="caption-text">Contents:</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1 current"><a class="reference internal" href="netscript.html"> Netscript</a><ul class="current">
|
||||
<li class="toctree-l2 current"><a class="current reference internal" href="#"> NetscriptJS (Netscript 2.0)</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#netscriptjs-in-mozilla-firefox">NetscriptJS in Mozilla Firefox</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#how-to-use-netscriptjs">How to use NetscriptJS</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#warnings">Warnings</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#examples">Examples</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#final-note">Final Note</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html"> Data Types and Variables</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptoperators.html"> Operators</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptloopsandconditionals.html"> Loops and Conditionals</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptscriptarguments.html"> Script Arguments</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptfunctions.html"> Basic Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptadvancedfunctions.html"> Advanced Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscripthacknetnodeapi.html"> Hacknet Node API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="terminal.html"> Terminal</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="shortcuts.html"> Keyboard Shortcuts</a></li>
|
||||
</ul>
|
||||
|
||||
<div role="search">
|
||||
<h3 style="margin-top: 1.5em;">Search</h3>
|
||||
<form class="search" action="search.html" method="get">
|
||||
<input type="text" name="q" />
|
||||
<input type="submit" value="Go" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-wrapper">
|
||||
<div class="footer">
|
||||
<div class="left">
|
||||
<div role="navigation" aria-label="related navigaton">
|
||||
<a href="netscript.html" title="Netscript Documentation"
|
||||
>previous</a> |
|
||||
<a href="netscriptdatatypes.html" title="Netscript Data Types and Variables"
|
||||
>next</a> |
|
||||
<a href="genindex.html" title="General Index"
|
||||
>index</a>
|
||||
</div>
|
||||
<div role="note" aria-label="source link">
|
||||
<br/>
|
||||
<a href="_sources/netscriptjs.rst.txt"
|
||||
rel="nofollow">Show Source</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
|
||||
<div class="footer" role="contentinfo">
|
||||
© Copyright 2017, Bitburner.
|
||||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.4.
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
BIN
doc/build/html/objects.inv
vendored
BIN
doc/build/html/objects.inv
vendored
Binary file not shown.
2
doc/build/html/searchindex.js
vendored
2
doc/build/html/searchindex.js
vendored
File diff suppressed because one or more lines are too long
2
doc/build/html/terminal.html
vendored
2
doc/build/html/terminal.html
vendored
@ -291,7 +291,7 @@ to run 'foo.script' with 50 threads.</p>
|
||||
<h3>nano<a class="headerlink" href="#nano" title="Permalink to this headline">¶</a></h3>
|
||||
<blockquote>
|
||||
<div>$ nano [filename]</div></blockquote>
|
||||
<p>Opens up the specified file in the Text Editor. Only scripts (.script) and
|
||||
<p>Opens up the specified file in the Text Editor. Only scripts (.script, .ns, .js) and
|
||||
text files (.txt) can be edited. If the file does not already exist, then a new
|
||||
empty file will be created.</p>
|
||||
</div>
|
||||
|
@ -14,6 +14,7 @@ to reach out to the developer!
|
||||
:maxdepth: 5
|
||||
:caption: Sections:
|
||||
|
||||
NetscriptJS (Netscript 2.0) <netscriptjs>
|
||||
Data Types and Variables <netscriptdatatypes>
|
||||
Operators <netscriptoperators>
|
||||
Loops and Conditionals <netscriptloopsandconditionals>
|
||||
|
202
doc/source/netscriptjs.rst
Normal file
202
doc/source/netscriptjs.rst
Normal file
@ -0,0 +1,202 @@
|
||||
NetscriptJS (Netscript 2.0)
|
||||
===========================
|
||||
Netscript 2.0, or Netscript JS, is the new and improved version of Netscript that
|
||||
allows users to write (almost) full-fledged Javascript code in their scripts, while
|
||||
still being able to access the Netscript functions.
|
||||
|
||||
NetscriptJS was developed primarily by `Github user jaguilar <https://github.com/jaguilar>`_
|
||||
|
||||
On top of having almost all of the features and capabilities of Javascript, NetscriptJS is also
|
||||
significantly faster than Netscript 1.0.
|
||||
|
||||
This documentation will not go over any of the additional features of NetscriptJS, since
|
||||
there is plenty of documentation on Javascript available on the web.
|
||||
|
||||
NetscriptJS in Mozilla Firefox
|
||||
------------------------------
|
||||
As of the time of writing this, the Mozilla Firefox browser does not support
|
||||
dynamic import functionality and therefore cannot run NetscriptJS scripts.
|
||||
|
||||
(This may be some option/method for enabling this in Firefox, but I don't know
|
||||
what is it)
|
||||
|
||||
How to use NetscriptJS
|
||||
----------------------
|
||||
Working with NetscriptJS scripts is the same as Netscript 1.0 scripts. The only difference
|
||||
is that NetscriptJS scripts use the ".ns" or ".js" extension rather than ".script". E.g.::
|
||||
|
||||
$ nano foo.ns
|
||||
$ run foo.ns -t 100 arg1 arg2 arg3
|
||||
exec("foo.ns", "purchasedServer1", "100", "randomArg");
|
||||
|
||||
The caveat when using NetscriptJS to write scripts is that your code must be
|
||||
asynchronous. Furthermore, instead of using the global scope and executing your code
|
||||
sequentially, NetscriptJS uses a :code:`main()` function as an entry point.
|
||||
|
||||
Furthermore, the "Netscript environment" must be passed into a NetscriptJS script through
|
||||
the main function. This environment includes all of the pre-defined Netscript functions
|
||||
(:code:`hack()`, :code:`exec`, etc.) as well as the arguments you pass to the script.
|
||||
|
||||
Therefore, the signature of the :code:`main()` function must be::
|
||||
|
||||
export async function main(ns) {
|
||||
ns.print("Starting script here");
|
||||
}
|
||||
|
||||
Here is a summary of all rules you need to follow when writing Netscript JS code:
|
||||
|
||||
* Write :code:`await` before any call to the following Netscript functions:
|
||||
|
||||
* hack
|
||||
* grow
|
||||
* weaken
|
||||
* sleep
|
||||
* run
|
||||
* exec
|
||||
* prompt
|
||||
|
||||
* Any function that contains :code:`await` must be declared as :code:`async`
|
||||
|
||||
* Always :code:`await` any function that is marked as :code:`async`
|
||||
|
||||
* Any functions that you want to be visible from other scripts must be marked with :code:`export`.
|
||||
|
||||
* **Do not write any infinite loops** without using a :code:`sleep` or one of the timed Netscript functions like :code:`hack`. Doing so will crash your game.
|
||||
|
||||
* Any global variable declared in a NetscriptJS script is shared between all instances of that
|
||||
script. For example, assume you write a script *foo.ns* and declared a global variable like so::
|
||||
|
||||
//foo.ns
|
||||
let globalVariable;
|
||||
|
||||
export async function main(ns) {
|
||||
globalVariable = ns.args.length;
|
||||
while(true) {
|
||||
tprint(globalVariable);
|
||||
await sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
Then, you ran multiple instances of *foo.ns*::
|
||||
|
||||
$ run foo.ns 1
|
||||
$ run foo.ns 1 2 3
|
||||
$ run foo.ns 1 2 3 4 5
|
||||
|
||||
Then all three instances of foo.ns will share the same instance of :code:`globalVariable`.
|
||||
(In this example, the value of :code:`globalVariable` will be set to 5 because the
|
||||
last instance of *foo.ns* to run has 5 arguments. This means that all three instances of
|
||||
the script will repeatedly print the value 5).
|
||||
|
||||
These global variables can be thought of as `C++ static class members <https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm>`_,
|
||||
where a NetscriptJS script is a class and a global variable is a static member within that class.
|
||||
|
||||
Warnings
|
||||
--------
|
||||
The NetscriptJS evaluation engine works by converting your code into a blob URL and then
|
||||
using a dynamic import to load your code as a module. Every unique NetscriptJS script
|
||||
is loaded as its own module. This means that
|
||||
making a small edit to a NetscriptJS script results in a new module being generated.
|
||||
|
||||
At this point, we have been unable to find a method for deleting modules from browsers so that
|
||||
they get garbage collected.
|
||||
|
||||
The result is that these modules from NetscriptJS scripts accumulate in your browser,
|
||||
using memory that never gets released. Over time, this results in a memory-leak type
|
||||
situation that can slow down your computer.
|
||||
|
||||
Therefore, there are two recommendations for those who decide to use NetscriptJS:
|
||||
|
||||
1. Every now and then, close and re-open the game. This will clear all of the modules.
|
||||
To be safe, I recommend **completely** closing the game's tab and then re-opening it.
|
||||
Depending on your browser, a refresh or page reload does not always clear the modules.
|
||||
|
||||
2. Only use NetscriptJS scripts when needed. It is very unlikely that NetscriptJS
|
||||
is needed for very simple scripts. By doing this, you will reduce the number of modules
|
||||
that are loaded.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
**DOM Manipulation (tprintColored.ns)**
|
||||
|
||||
Directly alter the game's terminal and print colored text::
|
||||
|
||||
export function tprintColored(txt, color) {
|
||||
let terminalInput = document.getElementById("terminal-input");
|
||||
let rowElement = document.createElement("tr");
|
||||
let cellElement = document.createElement("td");
|
||||
|
||||
rowElement.classList.add("posted");
|
||||
cellElement.classList.add("terminal-line");
|
||||
cellElement.style.color = color;
|
||||
cellElement.innerText = txt;
|
||||
|
||||
rowElement.appendChild(cellElement);
|
||||
terminalInput.before(rowElement);
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Red Text!", "red");
|
||||
tprintColored("Blue Text!", "blue");
|
||||
tprintColored("Use Hex Codes!", "#3087E3");
|
||||
}
|
||||
|
||||
**Script Scheduler (scriptScheduler.ns)**
|
||||
|
||||
This script shows some of the new functionality that is available in NetscriptJS,
|
||||
including objects and object constructors, changing an object's prototype, and
|
||||
importing other NetscriptJS scripts::
|
||||
|
||||
import {tprintColored} from "tprintColored.ns"; //Importing from other NetscriptJS scripts works!
|
||||
|
||||
function ScriptJob(params) {
|
||||
if (params.fn == null) {
|
||||
throw new Error("No Filename (fn) passed into ScriptJob ctor");
|
||||
}
|
||||
|
||||
this.fn = params.fn;
|
||||
this.threads = params.threads ? params.threads : 1;
|
||||
this.args = params.args ? params.args : [];
|
||||
}
|
||||
|
||||
ScriptJob.prototype.run = async function(ns) {
|
||||
let runArgs = [this.fn, this.threads].concat(this.args);
|
||||
await ns.run.apply(this, runArgs);
|
||||
tprintColored("Running " + this.fn + " on " + ns.getHostname(), "blue");
|
||||
}
|
||||
|
||||
ScriptJob.prototype.exec = async function(ns, target) {
|
||||
ns.scp(this.fn, target);
|
||||
|
||||
let execArgs = [this.fn, target, this.threads].concat(this.args);
|
||||
await ns.exec.apply(this, execArgs);
|
||||
|
||||
tprintColored("Executing " + this.fn + " on " + target, "blue");
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Starting scriptScheduler.ns", "red");
|
||||
try {
|
||||
let job = new ScriptJob({
|
||||
fn: "test.js",
|
||||
threads: 1,
|
||||
args: ["foodnstuff"]
|
||||
});
|
||||
await job.run(ns);
|
||||
await job.exec(ns, "foodnstuff");
|
||||
} catch (e) {
|
||||
ns.tprint("Exception thrown in scriptScheduler.ns: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
Final Note
|
||||
----------
|
||||
NetscriptJS opens up a lot of possibilities when scripting. I look forward to seeing
|
||||
the scripts that people come up with. Just remember that the power and capabilities of
|
||||
NetscriptJS come with risks. Please backup your save if you're going to experiment with
|
||||
NetscriptJS and report any serious exploits.
|
||||
|
||||
With great power comes great responsibility
|
||||
|
||||
Happy hacking
|
@ -266,7 +266,7 @@ nano
|
||||
|
||||
$ nano [filename]
|
||||
|
||||
Opens up the specified file in the Text Editor. Only scripts (.script) and
|
||||
Opens up the specified file in the Text Editor. Only scripts (.script, .ns, .js) and
|
||||
text files (.txt) can be edited. If the file does not already exist, then a new
|
||||
empty file will be created.
|
||||
|
||||
|
@ -146,7 +146,7 @@ function deleteActiveScriptsItem(workerscript) {
|
||||
var server = getServer(workerscript.serverIp);
|
||||
if (server == null) {
|
||||
throw new Error("ERROR: Invalid server IP for workerscript. This most likely occurred because " +
|
||||
"you tried to delete a large number of scripts and also purchased servers at the " +
|
||||
"you tried to delete a large number of scripts and also deleted servers at the " +
|
||||
"same time. It's not a big deal, just save and refresh the game.");
|
||||
return;
|
||||
}
|
||||
|
@ -506,8 +506,6 @@ Action.prototype.getSuccessChance = function(inst, params={}) {
|
||||
//Tests for success. Should be called when an action has completed
|
||||
// @inst - Bladeburner Object
|
||||
Action.prototype.attempt = function(inst) {
|
||||
console.log("Current City Pop: " + inst.getCurrentCity().pop);
|
||||
console.log("Action.attempt success chance: " + this.getSuccessChance(inst));
|
||||
return (Math.random() < this.getSuccessChance(inst));
|
||||
}
|
||||
|
||||
|
@ -1031,6 +1031,14 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
var txt = "You must first purchase or install " + aug.prereqs.join(",") + " before you can " +
|
||||
"purchase this one.";
|
||||
if (sing) {return txt;} else {dialogBoxCreate(txt);}
|
||||
} else if (Player.money.lt(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
let txt = "You don't have enough money to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
dialogBoxCreate(txt);
|
||||
} else if (fac.playerReputation < aug.baseRepRequirement) {
|
||||
let txt = "You don't have enough faction reputation to purchase " + aug.name;
|
||||
if (sing) {return txt;}
|
||||
dialogBoxCreate(txt);
|
||||
} else if (Player.money.gte(aug.baseCost * fac.augmentationPriceMult)) {
|
||||
if (Player.firstAugPurchased === false) {
|
||||
Player.firstAugPurchased = true;
|
||||
@ -1077,11 +1085,9 @@ function purchaseAugmentation(aug, fac, sing=false) {
|
||||
|
||||
displayFactionAugmentations(fac.name);
|
||||
} else {
|
||||
if (sing) {
|
||||
return "You don't have enough money to purchase " + aug.name;
|
||||
} else {
|
||||
dialogBoxCreate("You don't have enough money to purchase this Augmentation!");
|
||||
}
|
||||
dialogBoxCreate("Hmm, something went wrong when trying to purchase an Augmentation. " +
|
||||
"Please report this to the game developer with an explanation of how to " +
|
||||
"reproduce this.");
|
||||
}
|
||||
yesNoBoxClose();
|
||||
}
|
||||
|
@ -14,9 +14,10 @@ export function makeScriptBlob(code) {
|
||||
// (i.e. hack, grow, etc.).
|
||||
// When the promise returned by this resolves, we'll have finished
|
||||
// running the main function of the script.
|
||||
export async function executeJSScript(script, scripts = [], workerScript) {
|
||||
export async function executeJSScript(scripts = [], workerScript) {
|
||||
let loadedModule;
|
||||
let urlStack = null;
|
||||
let script = workerScript.getScript();
|
||||
if (script.module === "") {
|
||||
// The URL at the top is the one we want to import. It will
|
||||
// recursively import all the other modules in the urlStack.
|
||||
|
@ -40,6 +40,18 @@ WorkerScript.prototype.getServer = function() {
|
||||
return AllServers[this.serverIp];
|
||||
}
|
||||
|
||||
//Returns the Script object for the underlying script
|
||||
WorkerScript.prototype.getScript = function() {
|
||||
let server = this.getServer();
|
||||
for (var i = 0; i < server.scripts.length; ++i) {
|
||||
if (server.scripts[i].filename === this.name) {
|
||||
return server.scripts[i];
|
||||
}
|
||||
}
|
||||
console.log("ERROR: Failed to find underlying Script object in WorkerScript.getScript(). This probably means somethings wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Array containing all scripts that are running across all servers, to easily run them all
|
||||
let workerScripts = [];
|
||||
|
||||
@ -110,8 +122,7 @@ function startJsScript(workerScript) {
|
||||
|
||||
// Note: the environment that we pass to the JS script only needs to contain the functions visible
|
||||
// to that script, which env.vars does at this point.
|
||||
return executeJSScript(workerScript.scriptRef.scriptRef,
|
||||
workerScript.getServer().scripts,
|
||||
return executeJSScript(workerScript.getServer().scripts,
|
||||
workerScript).then(function (mainReturnValue) {
|
||||
if (mainReturnValue === undefined) return workerScript;
|
||||
return [mainReturnValue, workerScript];
|
||||
@ -156,13 +167,14 @@ function runScriptsLoop() {
|
||||
workerScripts.splice(i, 1);
|
||||
}
|
||||
}
|
||||
updateActiveScriptsItems(); //Force Update
|
||||
|
||||
//Run any scripts that haven't been started
|
||||
for (var i = 0; i < workerScripts.length; i++) {
|
||||
//If it isn't running, start the script
|
||||
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) {
|
||||
let p = null; // p is the script's result promise.
|
||||
if (workerScripts[i].name.endsWith(".js")) {
|
||||
if (workerScripts[i].name.endsWith(".js") || workerScripts[i].name.endsWith(".ns")) {
|
||||
p = startJsScript(workerScripts[i]);
|
||||
} else {
|
||||
try {
|
||||
|
@ -46,7 +46,7 @@ var keybindings = {
|
||||
};
|
||||
|
||||
function isScriptFilename(f) {
|
||||
return f.endsWith(".js") || f.endsWith(".script");
|
||||
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
|
||||
}
|
||||
|
||||
var scriptEditorRamCheck = null, scriptEditorRamText = null;
|
||||
@ -345,6 +345,7 @@ Script.prototype.saveScript = function() {
|
||||
|
||||
//Calculate/update ram usage, execution time, etc.
|
||||
this.updateRamUsage();
|
||||
console.log(this.module);
|
||||
|
||||
this.module = "";
|
||||
}
|
||||
|
@ -1764,6 +1764,8 @@ window.onload = function() {
|
||||
var db = e.target.result;
|
||||
var objectStore = db.createObjectStore("savestring");
|
||||
}
|
||||
|
||||
console.log(window.location.href);
|
||||
};
|
||||
|
||||
export {Engine};
|
||||
|
Loading…
Reference in New Issue
Block a user