mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 19:14:32 +02:00
Updated Stock market UI for new stock Max Shares restriction. Added Netscript function for getting a stock's max shares
This commit is contained in:
@@ -1537,6 +1537,22 @@ function NetscriptFunctions(workerScript) {
|
||||
}
|
||||
return [stock.playerShares, stock.playerAvgPx, stock.playerShortShares, stock.playerAvgShortPx];
|
||||
},
|
||||
getStockMaxShares : function(symbol) {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getStockMaxShares", CONSTANTS.ScriptGetStockRamCost);
|
||||
}
|
||||
updateDynamicRam("getStockMaxShares", CONSTANTS.ScriptGetStockRamCost);
|
||||
|
||||
if (!Player.hasTixApiAccess) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "You don't have TIX API Access! Cannot use getStockMaxShares()");
|
||||
}
|
||||
const stock = SymbolToStockMap[symbol];
|
||||
if (stock == null) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "Invalid stock symbol passed into getStockMaxShares()");
|
||||
}
|
||||
|
||||
return stock.maxShares;
|
||||
},
|
||||
buyStock : function(symbol, shares) {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("buyStock", CONSTANTS.ScriptBuySellStockRamCost);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
import { getRandomInt } from "../../utils/helpers/getRandomInt";
|
||||
|
||||
/**
|
||||
* Represents the valuation of a company in the World Stock Exchange.
|
||||
*/
|
||||
export class Stock {
|
||||
/**
|
||||
* Initializes a Stock from a JSON save state
|
||||
*/
|
||||
static fromJSON(value: any): Stock {
|
||||
return Generic_fromJSON(Stock, value.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bear or bull (more likely to go up or down, based on otlkMag)
|
||||
*/
|
||||
b: boolean;
|
||||
|
||||
/**
|
||||
* Maximum price of a stock (per share)
|
||||
*/
|
||||
readonly cap: number;
|
||||
|
||||
/**
|
||||
* Maximum number of shares that player can own (both long and short combined)
|
||||
*/
|
||||
readonly maxShares: number;
|
||||
|
||||
/**
|
||||
* Maximum volatility
|
||||
*/
|
||||
readonly mv: number;
|
||||
|
||||
/**
|
||||
* Name of the company that the stock is for
|
||||
*/
|
||||
readonly name: string;
|
||||
|
||||
/**
|
||||
* Outlook magnitude. Represents the stock's forecast and likelihood
|
||||
* of increasing/decreasing (based on whether its in bear or bull mode)
|
||||
*/
|
||||
otlkMag: number;
|
||||
|
||||
/**
|
||||
* Average price of stocks that the player owns in the LONG position
|
||||
*/
|
||||
playerAvgPx: number;
|
||||
|
||||
/**
|
||||
* Average price of stocks that the player owns in the SHORT position
|
||||
*/
|
||||
playerAvgShortPx: number;
|
||||
|
||||
/**
|
||||
* Number of shares the player owns in the LONG position
|
||||
*/
|
||||
playerShares: number;
|
||||
|
||||
/**
|
||||
* Number of shares the player owns in the SHORT position
|
||||
*/
|
||||
playerShortShares: number;
|
||||
|
||||
/**
|
||||
* The HTML element that displays the stock's info in the UI
|
||||
*/
|
||||
posTxtEl: HTMLElement | null;
|
||||
|
||||
/**
|
||||
* Stock's share price
|
||||
*/
|
||||
price: number;
|
||||
|
||||
/**
|
||||
* The stock's ticker symbol
|
||||
*/
|
||||
readonly symbol: string;
|
||||
|
||||
constructor(name: string = "",
|
||||
symbol: string = "",
|
||||
mv: number = 1,
|
||||
b: boolean = true,
|
||||
otlkMag: number = 0,
|
||||
initPrice: number = 10e3,
|
||||
marketCap: number = 1e12) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
this.price = initPrice;
|
||||
this.playerShares = 0;
|
||||
this.playerAvgPx = 0;
|
||||
this.playerShortShares = 0;
|
||||
this.playerAvgShortPx = 0;
|
||||
this.mv = mv;
|
||||
this.b = b;
|
||||
this.otlkMag = otlkMag;
|
||||
this.cap = getRandomInt(initPrice * 1e3, initPrice * 25e3);
|
||||
|
||||
// Maximum shares is determined by market cap, and is rounded to nearest millions
|
||||
let maxSharesUnrounded: number = (marketCap / initPrice);
|
||||
this.maxShares = Math.round(maxSharesUnrounded / 1e6) * 1e6;
|
||||
|
||||
this.posTxtEl = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the Stock to a JSON save state.
|
||||
*/
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("Stock", this);
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.Stock = Stock;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -88,6 +88,7 @@ import "../css/mainmenu.scss";
|
||||
import "../css/characteroverview.scss";
|
||||
import "../css/terminal.scss";
|
||||
import "../css/menupages.scss";
|
||||
import "../css/stockmarket.scss";
|
||||
import "../css/workinprogress.scss";
|
||||
import "../css/popupboxes.scss";
|
||||
import "../css/gameoptions.scss";
|
||||
|
||||
@@ -43,6 +43,10 @@ class NumeralFormatter {
|
||||
formatMoney(n: number): string {
|
||||
return this.format(n, "$0.000a");
|
||||
}
|
||||
|
||||
formatBigNumber(n: number): string {
|
||||
return this.format(n, "0.000a");
|
||||
}
|
||||
}
|
||||
|
||||
export const numeralWrapper = new NumeralFormatter();
|
||||
|
||||
Reference in New Issue
Block a user