From e46c67a78ac0f6cc39a0e00753817de714d83648 Mon Sep 17 00:00:00 2001 From: parax Date: Fri, 18 Mar 2022 21:58:18 -0600 Subject: [PATCH 1/4] Added NS functions to buy WSE and TIX --- src/NetscriptFunctions/StockMarket.ts | 46 +++++++++++++++++++++- src/ScriptEditor/NetscriptDefinitions.d.ts | 14 +++++++ src/StockMarket/StockMarketCosts.ts | 8 ++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index 6f4408855..ad4677b96 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -8,7 +8,7 @@ import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/St import { OrderTypes } from "../StockMarket/data/OrderTypes"; import { PositionTypes } from "../StockMarket/data/PositionTypes"; import { StockSymbols } from "../StockMarket/data/StockSymbols"; -import { getStockMarket4SDataCost, getStockMarket4STixApiCost } from "../StockMarket/StockMarketCosts"; +import { getStockMarket4SDataCost, getStockMarket4STixApiCost, getStockMarketWseCost, getStockMarketTixApiCost } from "../StockMarket/StockMarketCosts"; import { Stock } from "../StockMarket/Stock"; import { TIX } from "../ScriptEditor/NetscriptDefinitions"; @@ -388,5 +388,49 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript workerScript.log("stock.purchase4SMarketDataTixApi", () => "Purchased 4S Market Data TIX API"); return true; }, + purchaseWseAccount: function (): boolean { + helper.updateDynamicRam("PurchaseWseAccount", getRamCost(player, "stock", "purchaseWseAccount")); + checkTixApiAccess("purchaseWseAccount"); + + if (player.hasWseAccount) { + workerScript.log("stock.purchaseWseAccount", () => "Already purchased WSE Account"); + return true; + } + + if (player.money < getStockMarketWseCost()) { + workerScript.log( + "stock.purchaseWseAccount", + () => "Not enough money to purchase WSE Account Access", + ); + return false; + } + + player.hasWseAccount = true; + player.loseMoney(getStockMarketWseCost(), "stock"); + workerScript.log("stock.purchaseWseAccount", () => "Purchased WSE Account Access"); + return true; + }, + purchaseTixApi: function (): boolean { + helper.updateDynamicRam("PurchaseTixApi", getRamCost(player, "stock", "purchaseTixApi")); + checkTixApiAccess("purchaseTixApi"); + + if (player.hasTixApiAccess) { + workerScript.log("stock.purchaseTixApi", () => "Already purchased TIX API"); + return true; + } + + if (player.money < getStockMarketTixApiCost()) { + workerScript.log( + "stock.purchaseTixApi", + () => "Not enough money to purchase TIX API Access", + ); + return false; + } + + player.hasTixApiAccess = true; + player.loseMoney(getStockMarketTixApiCost(), "stock"); + workerScript.log("stock.purchaseTixApi", () => "Purchased TIX API"); + return true; + }, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d46b1b0f6..c0c75fb8e 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1506,6 +1506,20 @@ export interface TIX { * @returns True if you successfully purchased it or if you already have access, false otherwise. */ purchase4SMarketDataTixApi(): boolean; + + /** + * Purchase WSE Account. + * @remarks RAM cost: 2.5 GB + * @returns True if you successfully purchased it or if you already have access, false otherwise. + */ + purchaseWseAccount(): boolean; + + /** + * Purchase TIX API Access + * @remarks RAM cost: 2.5 GB + * @returns True if you successfully purchased it or if you already have access, false otherwise. + */ + purchaseTixApi(): boolean; } /** diff --git a/src/StockMarket/StockMarketCosts.ts b/src/StockMarket/StockMarketCosts.ts index 623f382a2..7021fc6fa 100644 --- a/src/StockMarket/StockMarketCosts.ts +++ b/src/StockMarket/StockMarketCosts.ts @@ -8,3 +8,11 @@ export function getStockMarket4SDataCost(): number { export function getStockMarket4STixApiCost(): number { return CONSTANTS.MarketDataTixApi4SCost * BitNodeMultipliers.FourSigmaMarketDataApiCost; } + +export function getStockMarketWseCost(): number { + return CONSTANTS.WSEAccountCost; +} + +export function getStockMarketTixApiCost(): number { + return CONSTANTS.TIXAPICost; +} \ No newline at end of file From daadecb4e66b2348cff98cbb5855810af8f449f4 Mon Sep 17 00:00:00 2001 From: parax Date: Fri, 18 Mar 2022 22:33:22 -0600 Subject: [PATCH 2/4] Removed requirement to already have WSE access --- src/NetscriptFunctions/StockMarket.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index ad4677b96..ee48f9ee6 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -390,7 +390,6 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript }, purchaseWseAccount: function (): boolean { helper.updateDynamicRam("PurchaseWseAccount", getRamCost(player, "stock", "purchaseWseAccount")); - checkTixApiAccess("purchaseWseAccount"); if (player.hasWseAccount) { workerScript.log("stock.purchaseWseAccount", () => "Already purchased WSE Account"); @@ -412,7 +411,6 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript }, purchaseTixApi: function (): boolean { helper.updateDynamicRam("PurchaseTixApi", getRamCost(player, "stock", "purchaseTixApi")); - checkTixApiAccess("purchaseTixApi"); if (player.hasTixApiAccess) { workerScript.log("stock.purchaseTixApi", () => "Already purchased TIX API"); From ac38e715aa8662426ea9b1cb9a07436a96cd5710 Mon Sep 17 00:00:00 2001 From: parax Date: Fri, 18 Mar 2022 22:52:09 -0600 Subject: [PATCH 3/4] Fixed Lint Errors --- src/NetscriptFunctions/StockMarket.ts | 2 +- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 +- src/StockMarket/StockMarketCosts.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index ee48f9ee6..eafeb76c9 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -411,7 +411,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript }, purchaseTixApi: function (): boolean { helper.updateDynamicRam("PurchaseTixApi", getRamCost(player, "stock", "purchaseTixApi")); - + if (player.hasTixApiAccess) { workerScript.log("stock.purchaseTixApi", () => "Already purchased TIX API"); return true; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index c0c75fb8e..ca5a20644 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1517,7 +1517,7 @@ export interface TIX { /** * Purchase TIX API Access * @remarks RAM cost: 2.5 GB - * @returns True if you successfully purchased it or if you already have access, false otherwise. + * @returns True if you successfully purchased it or if you already have access, false otherwise. */ purchaseTixApi(): boolean; } diff --git a/src/StockMarket/StockMarketCosts.ts b/src/StockMarket/StockMarketCosts.ts index 7021fc6fa..a8887298d 100644 --- a/src/StockMarket/StockMarketCosts.ts +++ b/src/StockMarket/StockMarketCosts.ts @@ -15,4 +15,4 @@ export function getStockMarketWseCost(): number { export function getStockMarketTixApiCost(): number { return CONSTANTS.TIXAPICost; -} \ No newline at end of file +} From 458f02051f8628ee4ecd2230db2107407d2802b9 Mon Sep 17 00:00:00 2001 From: parax Date: Fri, 18 Mar 2022 23:52:13 -0600 Subject: [PATCH 4/4] Added functions to RamCostGenerator.ts --- src/Netscript/RamCostGenerator.ts | 2 ++ src/NetscriptFunctions/StockMarket.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 338cbae7d..70a6c2b0f 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -181,6 +181,8 @@ export const RamCosts: IMap = { getForecast: RamCostConstants.ScriptBuySellStockRamCost, purchase4SMarketData: RamCostConstants.ScriptBuySellStockRamCost, purchase4SMarketDataTixApi: RamCostConstants.ScriptBuySellStockRamCost, + purchaseWseAccount: RamCostConstants.ScriptBuySellStockRamCost, + purchaseTixApi: RamCostConstants.ScriptBuySellStockRamCost, }, getPurchasedServerLimit: RamCostConstants.ScriptGetPurchasedServerLimit, getPurchasedServerMaxRam: RamCostConstants.ScriptGetPurchasedServerMaxRam, diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index eafeb76c9..7e0e64f60 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -410,7 +410,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return true; }, purchaseTixApi: function (): boolean { - helper.updateDynamicRam("PurchaseTixApi", getRamCost(player, "stock", "purchaseTixApi")); + helper.updateDynamicRam("purchaseTixApi", getRamCost(player, "stock", "purchaseTixApi")); if (player.hasTixApiAccess) { workerScript.log("stock.purchaseTixApi", () => "Already purchased TIX API");