From e97861f42b32e5664b6f55246aeb6aa44bbc724e Mon Sep 17 00:00:00 2001 From: danielyxie Date: Thu, 12 Jul 2018 00:01:52 -0500 Subject: [PATCH] Bladeburner API Improvements: Added getCurrentAction(). getSkillLevel() now fails if no argument is passed --- dist/engine.bundle.js | 4 ++++ src/Bladeburner.js | 19 ++++++++++++++++--- src/Constants.js | 4 +++- src/NetscriptFunctions.js | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dist/engine.bundle.js b/dist/engine.bundle.js index 1b6606231..30fcd6503 100644 --- a/dist/engine.bundle.js +++ b/dist/engine.bundle.js @@ -23599,6 +23599,10 @@ Bladeburner.prototype.getActionIdFromTypeAndName = function(type="", name="") { } } +Bladeburner.prototype.getTypeAndNameFromActionId = function(actionId) { + +} + Bladeburner.prototype.getContractNamesNetscriptFn = function() { return Object.keys(this.contracts); } diff --git a/src/Bladeburner.js b/src/Bladeburner.js index 9b3f14f34..ec50bafe9 100644 --- a/src/Bladeburner.js +++ b/src/Bladeburner.js @@ -3275,6 +3275,21 @@ Bladeburner.prototype.getActionIdFromTypeAndName = function(type="", name="") { } } +Bladeburner.prototype.getTypeAndNameFromActionId = function(actionId) { + var res = {}; + let types = Object.keys(ActionTypes); + for (let i = 0; i < types.length; ++i) { + if (actionId.type === ActionTypes[types[i]]) { + res.type = types[i]; + break; + } + } + if (res.type == null) {res.type = "Idle";} + + res.name = actionId.name != null ? actionId.name : "Idle"; + return res; +} + Bladeburner.prototype.getContractNamesNetscriptFn = function() { return Object.keys(this.contracts); } @@ -3424,9 +3439,7 @@ Bladeburner.prototype.getSkillLevelNetscriptFn = function(skillName, workerScrip skillName + ". Note that the name of the skill is case-sensitive"; if (skillName === "") { - //If skill name isn't specified, return an object with all of the player's skill levels - let copy = Object.assign({}, this.Skills); - return copy; + return -1; } if (!Skills.hasOwnProperty(skillName)) { diff --git a/src/Constants.js b/src/Constants.js index 7201c07c4..f58096455 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -488,8 +488,10 @@ let CONSTANTS = { LatestUpdate: "v0.40.0
" + + "* Added getCurrentAction() to Bladeburner API
" + + "* getSkillLevel() in Bladeburner API now returns an error if no argument is passed in (as opposed to an object with all skill levels). This may break scripts
" + "* Minimum Netscript execution time reduced from 15ms to 10ms (configurable in Options)
" + - "* HP is now reset (restored) when Augmenting
" + + "* HP is now reset (restored) when Augmenting
" + "* Bug Fix: Infiltration buttons can no longer be clicked through NetscriptJS
" } diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 39de69c76..58a47371a 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -3258,9 +3258,9 @@ function NetscriptFunctions(workerScript) { if (workerScript.checkingRam) { return updateStaticRam("getCurrentAction", CONSTANTS.ScriptBladeburnerApiBaseRamCost / 4); } - updateDynamicRam("getCurrentAction", CONSTANTS.ScriptBladeburnerApiBaseRamCost / 2); + updateDynamicRam("getCurrentAction", CONSTANTS.ScriptBladeburnerApiBaseRamCost / 4); if (Player.bladeburner instanceof Bladeburner && (Player.bitNodeN === 7 || hasBladeburner2079SF)) { - return Player.bladeburner.resetAction(); + return Player.bladeburner.getTypeAndNameFromActionId(Player.bladeburner.action); } throw makeRuntimeRejectMsg(workerScript, "getCurrentAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " + "at the Bladeburner division or because you do not have Source-File 7");