diff --git a/markdown/bitburner.jobname.md b/markdown/bitburner.jobname.md index 14cdc4cef..0bb063a89 100644 --- a/markdown/bitburner.jobname.md +++ b/markdown/bitburner.jobname.md @@ -34,12 +34,10 @@ declare enum JobName | IT3 | "Systems Administrator" | | | networkEng0 | "Network Engineer" | | | networkEng1 | "Network Administrator" | | -| security0 | "Police Officer" | | -| security1 | "Police Chief" | | -| security2 | "Security Guard" | | -| security3 | "Security Officer" | | -| security4 | "Security Supervisor" | | -| security5 | "Head of Security" | | +| security0 | "Security Guard" | | +| security1 | "Security Officer" | | +| security2 | "Security Supervisor" | | +| security3 | "Head of Security" | | | securityEng | "Security Engineer" | | | software0 | "Software Engineering Intern" | | | software1 | "Junior Software Engineer" | | diff --git a/markdown/bitburner.md b/markdown/bitburner.md index c655ca2a3..7f39c39df 100644 --- a/markdown/bitburner.md +++ b/markdown/bitburner.md @@ -98,6 +98,7 @@ | [SleevePerson](./bitburner.sleeveperson.md) | | | [SourceFileLvl](./bitburner.sourcefilelvl.md) | | | [Stanek](./bitburner.stanek.md) | Stanek's Gift API. | +| [StockMarketConstants](./bitburner.stockmarketconstants.md) | Constants used for the stockmarket game mechanic. | | [StockOrder](./bitburner.stockorder.md) |

Return value of [getOrders](./bitburner.tix.getorders.md)

Keys are stock symbols, properties are arrays of [StockOrderObject](./bitburner.stockorderobject.md)

| | [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) | | [TailProperties](./bitburner.tailproperties.md) | | diff --git a/markdown/bitburner.stockmarketconstants.marketdata4scost.md b/markdown/bitburner.stockmarketconstants.marketdata4scost.md new file mode 100644 index 000000000..d483fc9bb --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.marketdata4scost.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [MarketData4SCost](./bitburner.stockmarketconstants.marketdata4scost.md) + +## StockMarketConstants.MarketData4SCost property + +Cost of the 4S Market Data + +**Signature:** + +```typescript +MarketData4SCost: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.marketdatatixapi4scost.md b/markdown/bitburner.stockmarketconstants.marketdatatixapi4scost.md new file mode 100644 index 000000000..78867d7cc --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.marketdatatixapi4scost.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [MarketDataTixApi4SCost](./bitburner.stockmarketconstants.marketdatatixapi4scost.md) + +## StockMarketConstants.MarketDataTixApi4SCost property + +Cost of the 4S Market Data TIX API integration + +**Signature:** + +```typescript +MarketDataTixApi4SCost: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.md b/markdown/bitburner.stockmarketconstants.md new file mode 100644 index 000000000..19a1c03c4 --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.md @@ -0,0 +1,27 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) + +## StockMarketConstants interface + +Constants used for the stockmarket game mechanic. + +**Signature:** + +```typescript +interface StockMarketConstants +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [MarketData4SCost](./bitburner.stockmarketconstants.marketdata4scost.md) | | number | Cost of the 4S Market Data | +| [MarketDataTixApi4SCost](./bitburner.stockmarketconstants.marketdatatixapi4scost.md) | | number | Cost of the 4S Market Data TIX API integration | +| [msPerStockUpdate](./bitburner.stockmarketconstants.msperstockupdate.md) | | number | Normal time in ms between stock market updates | +| [msPerStockUpdateMin](./bitburner.stockmarketconstants.msperstockupdatemin.md) | | number | Minimum time in ms between stock market updates if there is stored offline/bonus time | +| [StockMarketCommission](./bitburner.stockmarketconstants.stockmarketcommission.md) | | number | Commission fee for transactions | +| [TicksPerCycle](./bitburner.stockmarketconstants.tickspercycle.md) | | number | An internal constant used while determining when to flip a stock's forecast | +| [TIXAPICost](./bitburner.stockmarketconstants.tixapicost.md) | | number | Cost of the TIX API | +| [WSEAccountCost](./bitburner.stockmarketconstants.wseaccountcost.md) | | number | Cost of the WSE account | + diff --git a/markdown/bitburner.stockmarketconstants.msperstockupdate.md b/markdown/bitburner.stockmarketconstants.msperstockupdate.md new file mode 100644 index 000000000..b617902f2 --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.msperstockupdate.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [msPerStockUpdate](./bitburner.stockmarketconstants.msperstockupdate.md) + +## StockMarketConstants.msPerStockUpdate property + +Normal time in ms between stock market updates + +**Signature:** + +```typescript +msPerStockUpdate: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.msperstockupdatemin.md b/markdown/bitburner.stockmarketconstants.msperstockupdatemin.md new file mode 100644 index 000000000..4e928161f --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.msperstockupdatemin.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [msPerStockUpdateMin](./bitburner.stockmarketconstants.msperstockupdatemin.md) + +## StockMarketConstants.msPerStockUpdateMin property + +Minimum time in ms between stock market updates if there is stored offline/bonus time + +**Signature:** + +```typescript +msPerStockUpdateMin: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.stockmarketcommission.md b/markdown/bitburner.stockmarketconstants.stockmarketcommission.md new file mode 100644 index 000000000..c01434225 --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.stockmarketcommission.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [StockMarketCommission](./bitburner.stockmarketconstants.stockmarketcommission.md) + +## StockMarketConstants.StockMarketCommission property + +Commission fee for transactions + +**Signature:** + +```typescript +StockMarketCommission: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.tickspercycle.md b/markdown/bitburner.stockmarketconstants.tickspercycle.md new file mode 100644 index 000000000..6a51a3aeb --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.tickspercycle.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [TicksPerCycle](./bitburner.stockmarketconstants.tickspercycle.md) + +## StockMarketConstants.TicksPerCycle property + +An internal constant used while determining when to flip a stock's forecast + +**Signature:** + +```typescript +TicksPerCycle: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.tixapicost.md b/markdown/bitburner.stockmarketconstants.tixapicost.md new file mode 100644 index 000000000..7723581d5 --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.tixapicost.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [TIXAPICost](./bitburner.stockmarketconstants.tixapicost.md) + +## StockMarketConstants.TIXAPICost property + +Cost of the TIX API + +**Signature:** + +```typescript +TIXAPICost: number; +``` diff --git a/markdown/bitburner.stockmarketconstants.wseaccountcost.md b/markdown/bitburner.stockmarketconstants.wseaccountcost.md new file mode 100644 index 000000000..c0318da9f --- /dev/null +++ b/markdown/bitburner.stockmarketconstants.wseaccountcost.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [StockMarketConstants](./bitburner.stockmarketconstants.md) > [WSEAccountCost](./bitburner.stockmarketconstants.wseaccountcost.md) + +## StockMarketConstants.WSEAccountCost property + +Cost of the WSE account + +**Signature:** + +```typescript +WSEAccountCost: number; +``` diff --git a/markdown/bitburner.tix.getconstants.md b/markdown/bitburner.tix.getconstants.md new file mode 100644 index 000000000..49c6bc211 --- /dev/null +++ b/markdown/bitburner.tix.getconstants.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [TIX](./bitburner.tix.md) > [getConstants](./bitburner.tix.getconstants.md) + +## TIX.getConstants() method + +Get game constants for the stock market mechanic. + +**Signature:** + +```typescript +getConstants(): StockMarketConstants; +``` +**Returns:** + +[StockMarketConstants](./bitburner.stockmarketconstants.md) + +## Remarks + +RAM cost: 0 GB + diff --git a/markdown/bitburner.tix.md b/markdown/bitburner.tix.md index 8c418eed2..d63d7d7d8 100644 --- a/markdown/bitburner.tix.md +++ b/markdown/bitburner.tix.md @@ -21,6 +21,7 @@ export interface TIX | [cancelOrder(sym, shares, price, type, pos)](./bitburner.tix.cancelorder.md) | Cancel order for stocks. | | [getAskPrice(sym)](./bitburner.tix.getaskprice.md) | Returns the ask price of that stock. | | [getBidPrice(sym)](./bitburner.tix.getbidprice.md) | Returns the bid price of that stock. | +| [getConstants()](./bitburner.tix.getconstants.md) | Get game constants for the stock market mechanic. | | [getForecast(sym)](./bitburner.tix.getforecast.md) | Returns the probability that the specified stock’s price will increase (as opposed to decrease) during the next tick. | | [getMaxShares(sym)](./bitburner.tix.getmaxshares.md) | Returns the maximum number of shares of a stock. | | [getOrders()](./bitburner.tix.getorders.md) | Returns your order book for the stock market. | diff --git a/src/Constants.ts b/src/Constants.ts index 90ebde8fc..9b480317c 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -228,6 +228,11 @@ Changes below include spoilers. ### NETSCRIPT: +* Added ns.stock.getConstants (@Snarling) * ns.sleeve.setToFactionWork no longer allows working for factions the player has not joined. (@Snarling) + +### Internal Code Refactors + +* Reorganize game constants (@zerbosh) `, }; diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 65a0d6cc1..365faab99 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -118,6 +118,7 @@ const hacknet = { // Stock API const stock = { + getConstants: 0, hasWSEAccount: 0.05, hasTIXAPIAccess: 0.05, has4SData: 0.05, @@ -348,7 +349,7 @@ const grafting = { const corporation = { hasCorporation: 0, // This one is free - getConstants: RamCostConstants.Corporation, + getConstants: 0, getIndustryData: RamCostConstants.Corporation, getMaterialData: RamCostConstants.Corporation, issueNewShares: RamCostConstants.Corporation, diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index 33cbef034..9d4bda3f5 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -1,4 +1,4 @@ -import { Player as player } from "../Player"; +import { Player } from "../Player"; import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling"; import { StockMarket, SymbolToStockMap, placeOrder, cancelOrder, initStockMarket } from "../StockMarket/StockMarket"; import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers"; @@ -13,14 +13,16 @@ import { Stock } from "../StockMarket/Stock"; import { StockOrder, TIX } from "@nsdefs"; import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper"; import { helpers } from "../Netscript/NetscriptHelpers"; +import { cloneDeep } from "lodash"; +import { StockMarketConstants } from "../StockMarket/data/Constants"; export function NetscriptStockMarket(): InternalAPI { /** Checks if the player has TIX API access. Throws an error if the player does not */ const checkTixApiAccess = function (ctx: NetscriptContext): void { - if (!player.hasWseAccount) { + if (!Player.hasWseAccount) { throw helpers.makeRuntimeErrorMsg(ctx, `You don't have WSE Access! Cannot use ${ctx.function}()`); } - if (!player.hasTixApiAccess) { + if (!Player.hasTixApiAccess) { throw helpers.makeRuntimeErrorMsg(ctx, `You don't have TIX API Access! Cannot use ${ctx.function}()`); } }; @@ -35,18 +37,11 @@ export function NetscriptStockMarket(): InternalAPI { }; return { - hasWSEAccount: () => () => { - return player.hasWseAccount; - }, - hasTIXAPIAccess: () => () => { - return player.hasTixApiAccess; - }, - has4SData: () => () => { - return player.has4SData; - }, - has4SDataTIXAPI: () => () => { - return player.has4SDataTixApi; - }, + getConstants: () => () => cloneDeep(StockMarketConstants), + hasWSEAccount: () => () => Player.hasWseAccount, + hasTIXAPIAccess: () => () => Player.hasTixApiAccess, + has4SData: () => () => Player.has4SData, + has4SDataTIXAPI: () => () => Player.has4SDataTixApi, getSymbols: (ctx) => () => { checkTixApiAccess(ctx); return Object.values(StockSymbol); @@ -166,8 +161,8 @@ export function NetscriptStockMarket(): InternalAPI { const symbol = helpers.string(ctx, "symbol", _symbol); const shares = helpers.number(ctx, "shares", _shares); checkTixApiAccess(ctx); - if (player.bitNodeN !== 8) { - if (player.sourceFileLvl(8) <= 1) { + if (Player.bitNodeN !== 8) { + if (Player.sourceFileLvl(8) <= 1) { throw helpers.makeRuntimeErrorMsg( ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.", @@ -183,8 +178,8 @@ export function NetscriptStockMarket(): InternalAPI { const symbol = helpers.string(ctx, "symbol", _symbol); const shares = helpers.number(ctx, "shares", _shares); checkTixApiAccess(ctx); - if (player.bitNodeN !== 8) { - if (player.sourceFileLvl(8) <= 1) { + if (Player.bitNodeN !== 8) { + if (Player.sourceFileLvl(8) <= 1) { throw helpers.makeRuntimeErrorMsg( ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.", @@ -203,8 +198,8 @@ export function NetscriptStockMarket(): InternalAPI { const type = helpers.string(ctx, "type", _type); const pos = helpers.string(ctx, "pos", _pos); checkTixApiAccess(ctx); - if (player.bitNodeN !== 8) { - if (player.sourceFileLvl(8) <= 2) { + if (Player.bitNodeN !== 8) { + if (Player.sourceFileLvl(8) <= 2) { throw helpers.makeRuntimeErrorMsg( ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.", @@ -246,8 +241,8 @@ export function NetscriptStockMarket(): InternalAPI { const type = helpers.string(ctx, "type", _type); const pos = helpers.string(ctx, "pos", _pos); checkTixApiAccess(ctx); - if (player.bitNodeN !== 8) { - if (player.sourceFileLvl(8) <= 2) { + if (Player.bitNodeN !== 8) { + if (Player.sourceFileLvl(8) <= 2) { throw helpers.makeRuntimeErrorMsg( ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.", @@ -295,8 +290,8 @@ export function NetscriptStockMarket(): InternalAPI { }, getOrders: (ctx) => () => { checkTixApiAccess(ctx); - if (player.bitNodeN !== 8) { - if (player.sourceFileLvl(8) <= 2) { + if (Player.bitNodeN !== 8) { + if (Player.sourceFileLvl(8) <= 2) { throw helpers.makeRuntimeErrorMsg(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3."); } } @@ -323,7 +318,7 @@ export function NetscriptStockMarket(): InternalAPI { }, getVolatility: (ctx) => (_symbol) => { const symbol = helpers.string(ctx, "symbol", _symbol); - if (!player.has4SDataTixApi) { + if (!Player.has4SDataTixApi) { throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!"); } const stock = getStockFromSymbol(ctx, symbol); @@ -332,7 +327,7 @@ export function NetscriptStockMarket(): InternalAPI { }, getForecast: (ctx) => (_symbol) => { const symbol = helpers.string(ctx, "symbol", _symbol); - if (!player.has4SDataTixApi) { + if (!Player.has4SDataTixApi) { throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!"); } const stock = getStockFromSymbol(ctx, symbol); @@ -342,69 +337,69 @@ export function NetscriptStockMarket(): InternalAPI { return forecast / 100; // Convert from percentage to decimal }, purchase4SMarketData: (ctx) => () => { - if (player.has4SData) { + if (Player.has4SData) { helpers.log(ctx, () => "Already purchased 4S Market Data."); return true; } - if (player.money < getStockMarket4SDataCost()) { + if (Player.money < getStockMarket4SDataCost()) { helpers.log(ctx, () => "Not enough money to purchase 4S Market Data."); return false; } - player.has4SData = true; - player.loseMoney(getStockMarket4SDataCost(), "stock"); + Player.has4SData = true; + Player.loseMoney(getStockMarket4SDataCost(), "stock"); helpers.log(ctx, () => "Purchased 4S Market Data"); return true; }, purchase4SMarketDataTixApi: (ctx) => () => { checkTixApiAccess(ctx); - if (player.has4SDataTixApi) { + if (Player.has4SDataTixApi) { helpers.log(ctx, () => "Already purchased 4S Market Data TIX API"); return true; } - if (player.money < getStockMarket4STixApiCost()) { + if (Player.money < getStockMarket4STixApiCost()) { helpers.log(ctx, () => "Not enough money to purchase 4S Market Data TIX API"); return false; } - player.has4SDataTixApi = true; - player.loseMoney(getStockMarket4STixApiCost(), "stock"); + Player.has4SDataTixApi = true; + Player.loseMoney(getStockMarket4STixApiCost(), "stock"); helpers.log(ctx, () => "Purchased 4S Market Data TIX API"); return true; }, purchaseWseAccount: (ctx) => () => { - if (player.hasWseAccount) { + if (Player.hasWseAccount) { helpers.log(ctx, () => "Already purchased WSE Account"); return true; } - if (player.money < getStockMarketWseCost()) { + if (Player.money < getStockMarketWseCost()) { helpers.log(ctx, () => "Not enough money to purchase WSE Account Access"); return false; } - player.hasWseAccount = true; + Player.hasWseAccount = true; initStockMarket(); - player.loseMoney(getStockMarketWseCost(), "stock"); + Player.loseMoney(getStockMarketWseCost(), "stock"); helpers.log(ctx, () => "Purchased WSE Account Access"); return true; }, purchaseTixApi: (ctx) => () => { - if (player.hasTixApiAccess) { + if (Player.hasTixApiAccess) { helpers.log(ctx, () => "Already purchased TIX API"); return true; } - if (player.money < getStockMarketTixApiCost()) { + if (Player.money < getStockMarketTixApiCost()) { helpers.log(ctx, () => "Not enough money to purchase TIX API Access"); return false; } - player.hasTixApiAccess = true; - player.loseMoney(getStockMarketTixApiCost(), "stock"); + Player.hasTixApiAccess = true; + Player.loseMoney(getStockMarketTixApiCost(), "stock"); helpers.log(ctx, () => "Purchased TIX API"); return true; }, diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 27afac6c1..b33e7fe65 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -393,6 +393,27 @@ interface StockOrder { [key: string]: StockOrderObject[]; } +/** Constants used for the stockmarket game mechanic. + * @public */ +interface StockMarketConstants { + /** Normal time in ms between stock market updates */ + msPerStockUpdate: number; + /** Minimum time in ms between stock market updates if there is stored offline/bonus time */ + msPerStockUpdateMin: number; + /** An internal constant used while determining when to flip a stock's forecast */ + TicksPerCycle: number; + /** Cost of the WSE account */ + WSEAccountCost: number; + /** Cost of the TIX API */ + TIXAPICost: number; + /** Cost of the 4S Market Data */ + MarketData4SCost: number; + /** Cost of the 4S Market Data TIX API integration */ + MarketDataTixApi4SCost: number; + /** Commission fee for transactions */ + StockMarketCommission: number; +} + /** * A single process on a server. * @public @@ -1077,6 +1098,9 @@ export interface NetscriptPort { * @public */ export interface TIX { + /** Get game constants for the stock market mechanic. + * @remarks RAM cost: 0 GB */ + getConstants(): StockMarketConstants; /** * Returns true if the player has access to a WSE Account * @remarks RAM cost: 0.05 GB diff --git a/src/StockMarket/data/Constants.ts b/src/StockMarket/data/Constants.ts index 3e058359e..bb7155474 100644 --- a/src/StockMarket/data/Constants.ts +++ b/src/StockMarket/data/Constants.ts @@ -1,12 +1,9 @@ -export const StockMarketConstants = { - //stock tick times in milliseconds +import { StockMarketConstants as ConstantsType } from "@nsdefs"; + +export const StockMarketConstants: ConstantsType = { msPerStockUpdate: 6e3, msPerStockUpdateMin: 4e3, - - //defines the length of the flip timer in stock cycles TicksPerCycle: 75, - - // Stockmarket costs Constants WSEAccountCost: 200e6, TIXAPICost: 5e9, MarketData4SCost: 1e9,