From 6979082be7596a57b06b6469a7a0ad5a3965cd33 Mon Sep 17 00:00:00 2001 From: vmesecher Date: Tue, 7 Sep 2021 20:33:34 -0700 Subject: [PATCH] Adds getAugmentationPrice() and getAugmentationReqRep() Netscript Singularity functions. Deprecates getAugmentationCost() Netscript singularity function. --- .../netscriptsingularityfunctions.rst | 4 ++- .../getAugmentationCost.rst | 7 +++-- .../getAugmentationPrereq.rst | 2 +- .../getAugmentationPrice.rst | 14 +++++++++ .../getAugmentationReqRep.rst | 14 +++++++++ src/Netscript/RamCostGenerator.ts | 4 ++- src/NetscriptFunctions.js | 30 +++++++++++++++---- src/ScriptEditor/NetscriptDefinitions.ts | 4 ++- test/Netscript/DynamicRamCalculation.test.js | 14 +++++++-- test/Netscript/StaticRamCalculation.test.js | 14 +++++++-- 10 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 doc/source/netscript/singularityfunctions/getAugmentationPrice.rst create mode 100644 doc/source/netscript/singularityfunctions/getAugmentationReqRep.rst diff --git a/doc/source/netscript/netscriptsingularityfunctions.rst b/doc/source/netscript/netscriptsingularityfunctions.rst index a6924920d..146fac645 100644 --- a/doc/source/netscript/netscriptsingularityfunctions.rst +++ b/doc/source/netscript/netscriptsingularityfunctions.rst @@ -55,8 +55,10 @@ The player has access to all of these functions while in BitNode-4. Completing B getOwnedAugmentations() getOwnedSourceFiles() getAugmentationsFromFaction() - getAugmentationPrereq() getAugmentationCost() + getAugmentationPrereq() + getAugmentationPrice() + getAugmentationRepReq() getAugmentationStats() purchaseAugmentation() installAugmentations() diff --git a/doc/source/netscript/singularityfunctions/getAugmentationCost.rst b/doc/source/netscript/singularityfunctions/getAugmentationCost.rst index 01a5735a2..9e3a40d89 100644 --- a/doc/source/netscript/singularityfunctions/getAugmentationCost.rst +++ b/doc/source/netscript/singularityfunctions/getAugmentationCost.rst @@ -3,12 +3,15 @@ getAugmentationCost() Netscript Function .. js:function:: getAugmentationCost(augName) + .. warning:: This function is deprecated. + :RAM cost: 5 GB - :param string augName: Name of Augmentation. case-sensitive. + + :param string augName: Name of Augmentation. CASE-SENSITIVE If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function. This function returns an array with two elements that gives the cost for the specified Augmentation. The first element in the returned array is the reputation requirement of the Augmentation, and the second element is the money cost. - If an invalid Augmentation name is passed in for the ``augName`` argument, this function will return the array [-1, -1]. + If an invalid Augmentation name is passed in for the ``augName`` argument, this function will throw a runtime error. diff --git a/doc/source/netscript/singularityfunctions/getAugmentationPrereq.rst b/doc/source/netscript/singularityfunctions/getAugmentationPrereq.rst index f9549cc8d..266544473 100644 --- a/doc/source/netscript/singularityfunctions/getAugmentationPrereq.rst +++ b/doc/source/netscript/singularityfunctions/getAugmentationPrereq.rst @@ -12,4 +12,4 @@ getAugmentationPrereq() Netscript Function This function returns an array with the names of the prerequisite Augmentation(s) for the specified Augmentation. If there are no prerequisites, a blank array is returned. - If an invalid Augmentation name is passed in for the *augName* argument, this function will return a blank array. + If an invalid Augmentation name is passed in for the *augName* argument, this function will throw a runtime error. diff --git a/doc/source/netscript/singularityfunctions/getAugmentationPrice.rst b/doc/source/netscript/singularityfunctions/getAugmentationPrice.rst new file mode 100644 index 000000000..87a9ad27d --- /dev/null +++ b/doc/source/netscript/singularityfunctions/getAugmentationPrice.rst @@ -0,0 +1,14 @@ +getAugmentationPrice() Netscript Function +========================================== + +.. js:function:: getAugmentationPrice(augName) + + :RAM cost: 2.5 GB + + :param string augName: Name of Augmentation. CASE-SENSITIVE + + If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function. + + This function returns the money cost for the specified Augmentation. + + If an invalid Augmentation name is passed in for the *augName* argument, this function will throw a runtime error. diff --git a/doc/source/netscript/singularityfunctions/getAugmentationReqRep.rst b/doc/source/netscript/singularityfunctions/getAugmentationReqRep.rst new file mode 100644 index 000000000..3f9a3c069 --- /dev/null +++ b/doc/source/netscript/singularityfunctions/getAugmentationReqRep.rst @@ -0,0 +1,14 @@ +getAugmentationRepReq() Netscript Function +========================================== + +.. js:function:: getAugmentationRepReq(augName) + + :RAM cost: 2.5 GB + + :param string augName: Name of Augmentation. CASE-SENSITIVE + + If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function. + + This function returns the reputation requirement for the specified Augmentation. + + If an invalid Augmentation name is passed in for the *augName* argument, this function will throw a runtime error. diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 9b7ee964c..4d5674d74 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -214,8 +214,10 @@ export const RamCosts: IMap = { getOwnedAugmentations: () => RamCostConstants.ScriptSingularityFn3RamCost, getOwnedSourceFiles: () => RamCostConstants.ScriptSingularityFn3RamCost, getAugmentationsFromFaction: () => RamCostConstants.ScriptSingularityFn3RamCost, - getAugmentationPrereq: () => RamCostConstants.ScriptSingularityFn3RamCost, getAugmentationCost: () => RamCostConstants.ScriptSingularityFn3RamCost, + getAugmentationPrereq: () => RamCostConstants.ScriptSingularityFn3RamCost, + getAugmentationPrice: () => RamCostConstants.ScriptSingularityFn3RamCost / 2, + getAugmentationRepReq: () => RamCostConstants.ScriptSingularityFn3RamCost / 2, getAugmentationStats: () => RamCostConstants.ScriptSingularityFn3RamCost, purchaseAugmentation: () => RamCostConstants.ScriptSingularityFn3RamCost, softReset: () => RamCostConstants.ScriptSingularityFn3RamCost, diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index cad5fe393..ef34ae184 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -4598,6 +4598,15 @@ function NetscriptFunctions(workerScript) { return faction.augmentations.slice(); }, + getAugmentationCost: function (name) { + updateDynamicRam( + "getAugmentationCost", + getRamCost("getAugmentationCost"), + ); + checkSingularityAccess("getAugmentationCost", 3); + const aug = getAugmentation("getAugmentationCost", name); + return [aug.baseRepRequirement, aug.baseCost]; + }, getAugmentationPrereq: function (name) { updateDynamicRam( "getAugmentationPrereq", @@ -4607,14 +4616,23 @@ function NetscriptFunctions(workerScript) { const aug = getAugmentation("getAugmentationPrereq", name); return aug.prereqs.slice(); }, - getAugmentationCost: function (name) { + getAugmentationPrice: function (name) { updateDynamicRam( - "getAugmentationCost", - getRamCost("getAugmentationCost"), + "getAugmentationPrice", + getRamCost("getAugmentationPrice"), ); - checkSingularityAccess("getAugmentationCost", 3); - const aug = getAugmentation("getAugmentationCost", name); - return [aug.baseRepRequirement, aug.baseCost]; + checkSingularityAccess("getAugmentationPrice", 3); + const aug = getAugmentation("getAugmentationPrice", name); + return aug.baseCost; + }, + getAugmentationRepReq: function (name) { + updateDynamicRam( + "getAugmentationRepReq", + getRamCost("getAugmentationRepReq"), + ); + checkSingularityAccess("getAugmentationRepReq", 3); + const aug = getAugmentation("getAugmentationRepReq", name); + return aug.baseRepRequirement; }, getAugmentationStats: function (name) { updateDynamicRam( diff --git a/src/ScriptEditor/NetscriptDefinitions.ts b/src/ScriptEditor/NetscriptDefinitions.ts index 9ee0da624..d77dececc 100644 --- a/src/ScriptEditor/NetscriptDefinitions.ts +++ b/src/ScriptEditor/NetscriptDefinitions.ts @@ -146,8 +146,10 @@ export const libSource = `interface NS { getOwnedAugmentations(purchased: boolean): string[]; getOwnedSourceFiles(): any; // complex type getAugmentationsFromFaction(facname: string): string[]; - getAugmentationPrereq(name: string): string[]; getAugmentationCost(name: string): number; + getAugmentationPrereq(name: string): string[]; + getAugmentationPrice(name: string): number; + getAugmentationRepReq(name: string): number; getAugmentationStats(name: string): any; // complex type purchaseAugmentation(faction: string, name: string): boolean; softReset(cbScript: string): void; diff --git a/test/Netscript/DynamicRamCalculation.test.js b/test/Netscript/DynamicRamCalculation.test.js index ea437bc96..1e91d3368 100644 --- a/test/Netscript/DynamicRamCalculation.test.js +++ b/test/Netscript/DynamicRamCalculation.test.js @@ -812,13 +812,23 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { await testNonzeroDynamicRamCost(f); }); + it("getAugmentationCost()", async function () { + const f = ["getAugmentationCost"]; + await testNonzeroDynamicRamCost(f); + }); + it("getAugmentationPrereq()", async function () { const f = ["getAugmentationPrereq"]; await testNonzeroDynamicRamCost(f); }); - it("getAugmentationCost()", async function () { - const f = ["getAugmentationCost"]; + it("getAugmentationPrice()", async function () { + const f = ["getAugmentationPrice"]; + await testNonzeroDynamicRamCost(f); + }); + + it("getAugmentationRepReq()", async function () { + const f = ["getAugmentationRepReq"]; await testNonzeroDynamicRamCost(f); }); diff --git a/test/Netscript/StaticRamCalculation.test.js b/test/Netscript/StaticRamCalculation.test.js index 917936dd7..8065959bb 100644 --- a/test/Netscript/StaticRamCalculation.test.js +++ b/test/Netscript/StaticRamCalculation.test.js @@ -756,13 +756,23 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () { await expectNonZeroRamCost(f); }); + it("getAugmentationCost()", async function () { + const f = ["getAugmentationCost"]; + await expectNonZeroRamCost(f); + }); + it("getAugmentationPrereq()", async function () { const f = ["getAugmentationPrereq"]; await expectNonZeroRamCost(f); }); - it("getAugmentationCost()", async function () { - const f = ["getAugmentationCost"]; + it("getAugmentationPrice()", async function () { + const f = ["getAugmentationPrice"]; + await expectNonZeroRamCost(f); + }); + + it("getAugmentationRepReq()", async function () { + const f = ["getAugmentationRepReq"]; await expectNonZeroRamCost(f); });