mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
Added maximum number of shares per stock
This commit is contained in:
@@ -6,8 +6,8 @@ import { Player } from "./Player";
|
||||
import { AllServers } from "./Server";
|
||||
import { hackWorldDaemon } from "./RedPill";
|
||||
import { StockMarket,
|
||||
SymbolToStockMap } from "./StockMarket";
|
||||
import { Stock } from "./Stock";
|
||||
SymbolToStockMap } from "./StockMarket/StockMarket";
|
||||
import { Stock } from "./StockMarket/Stock";
|
||||
import { Terminal } from "./Terminal";
|
||||
import { numeralWrapper } from "./ui/numeralFormat";
|
||||
import { dialogBoxCreate } from "../utils/DialogBox";
|
||||
|
||||
@@ -40,12 +40,12 @@ import {Server, getServer, AddToAllServers,
|
||||
GetServerByHostname, numCycleForGrowth} from "./Server";
|
||||
import {Settings} from "./Settings";
|
||||
import {SpecialServerIps} from "./SpecialServerIps";
|
||||
import {Stock} from "./Stock";
|
||||
import {Stock} from "./StockMarket/Stock";
|
||||
import {StockMarket, StockSymbols, SymbolToStockMap,
|
||||
initStockMarket, initSymbolToStockMap, buyStock,
|
||||
sellStock, updateStockPlayerPosition,
|
||||
shortStock, sellShort, OrderTypes,
|
||||
PositionTypes, placeOrder, cancelOrder} from "./StockMarket";
|
||||
PositionTypes, placeOrder, cancelOrder} from "./StockMarket/StockMarket";
|
||||
import {post} from "./ui/postToTerminal";
|
||||
import {TextFile, getTextFile, createTextFile} from "./TextFile";
|
||||
|
||||
@@ -1556,6 +1556,7 @@ function NetscriptFunctions(workerScript) {
|
||||
shares = Math.round(shares);
|
||||
if (shares === 0) {return 0;}
|
||||
|
||||
// Does player have enough money?
|
||||
var totalPrice = stock.price * shares;
|
||||
if (Player.money.lt(totalPrice + CONSTANTS.StockMarketCommission)) {
|
||||
workerScript.scriptRef.log("Not enough money to purchase " + formatNumber(shares, 0) + " shares of " +
|
||||
@@ -1564,6 +1565,13 @@ function NetscriptFunctions(workerScript) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Would this purchase exceed the maximum number of shares?
|
||||
if (shares + stock.playerShares + stock.playerShortShares > stock.maxShares) {
|
||||
workerScript.scriptRef.log(`You cannot purchase this many shares. ${stock.symbol} has a maximum of ` +
|
||||
`${stock.maxShares} shares.`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
var origTotal = stock.playerShares * stock.playerAvgPx;
|
||||
Player.loseMoney(totalPrice + CONSTANTS.StockMarketCommission);
|
||||
var newTotal = origTotal + totalPrice;
|
||||
|
||||
@@ -29,7 +29,7 @@ import {SpecialServerIps, SpecialServerIpsMap,
|
||||
SpecialServerNames} from "./SpecialServerIps";
|
||||
import {initStockMarket, initSymbolToStockMap,
|
||||
stockMarketContentCreated,
|
||||
setStockMarketContentCreated} from "./StockMarket";
|
||||
setStockMarketContentCreated} from "./StockMarket/StockMarket";
|
||||
import {Terminal, postNetburnerText} from "./Terminal";
|
||||
import Decimal from "decimal.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
|
||||
@@ -16,7 +16,7 @@ import {loadAllRunningScripts} from "./Script";
|
||||
import {AllServers, loadAllServers} from "./Server";
|
||||
import {Settings} from "./Settings";
|
||||
import {loadSpecialServerIps, SpecialServerIps} from "./SpecialServerIps";
|
||||
import {loadStockMarket, StockMarket} from "./StockMarket";
|
||||
import {loadStockMarket, StockMarket} from "./StockMarket/StockMarket";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {gameOptionsBoxClose} from "../utils/GameOptions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
|
||||
105
src/Stock.ts
105
src/Stock.ts
@@ -1,105 +0,0 @@
|
||||
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 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) {
|
||||
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);
|
||||
|
||||
this.posTxtEl = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the Stock to a JSON save state.
|
||||
*/
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("Stock", this);
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.Stock = Stock;
|
||||
1488
src/StockMarket.js
1488
src/StockMarket.js
File diff suppressed because it is too large
Load Diff
@@ -73,7 +73,7 @@ import {StockMarket, StockSymbols,
|
||||
SymbolToStockMap, initStockSymbols,
|
||||
initSymbolToStockMap, stockMarketCycle,
|
||||
processStockPrices,
|
||||
displayStockMarketContent} from "./StockMarket";
|
||||
displayStockMarketContent} from "./StockMarket/StockMarket";
|
||||
import {Terminal, postNetburnerText} from "./Terminal";
|
||||
import {KEY} from "../utils/helpers/keyCodes";
|
||||
import {Page, routing} from "./ui/navigationTracking";
|
||||
|
||||
Reference in New Issue
Block a user