From 585e1ac7aa294270cbe6eac286bc628d5a363e12 Mon Sep 17 00:00:00 2001 From: danielyxie Date: Wed, 1 May 2019 15:20:14 -0700 Subject: [PATCH] Stock transactions can now influence forecast in addition to price. Several more minor bug/UI fixes --- doc/source/basicgameplay/stockmarket.rst | 8 +++ doc/source/index.rst | 1 + doc/source/toolsandresources.rst | 23 +++++++ src/Augmentation/AugmentationHelpers.js | 11 --- src/CodingContracts.ts | 1 + src/Constants.ts | 8 ++- src/Faction/ui/Info.tsx | 22 ++++-- src/NetscriptEvaluator.js | 10 +-- src/NetscriptFunctions.js | 67 ++++++++++++------- src/PersonObjects/IPlayer.ts | 1 + .../Player/PlayerObjectGangMethods.js | 6 +- src/Script/ScriptHelpers.js | 2 +- src/StockMarket/StockMarket.jsx | 1 + src/StockMarket/StockMarketHelpers.ts | 13 +++- .../ui/StockTickerPositionText.tsx | 4 +- src/ui/React/AutoupdatingParagraph.tsx | 17 +++-- utils/helpers/arrayToString.ts | 6 +- utils/helpers/compareArrays.ts | 15 ++++- 18 files changed, 155 insertions(+), 61 deletions(-) create mode 100644 doc/source/toolsandresources.rst diff --git a/doc/source/basicgameplay/stockmarket.rst b/doc/source/basicgameplay/stockmarket.rst index 42545b084..fb47bf251 100644 --- a/doc/source/basicgameplay/stockmarket.rst +++ b/doc/source/basicgameplay/stockmarket.rst @@ -73,6 +73,14 @@ be sold at $98.01, and so on. This is an important concept to keep in mind if you are trying to purchase/sell a large number of shares, as **it can negatively affect your profits**. +Transactions Influencing Stock Forecast +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +In addition to influencing stock price, buying or selling a large number of shares +of a stock will also influence that stock's "forecast". The forecast is the likelihood +that the stock will increase or decrease in price. The magnitude of this effect depends +on the number of shares being transacted. More shares will have a bigger effect on the +stock forecast. + .. _gameplay_stock_market_order_types: Order Types diff --git a/doc/source/index.rst b/doc/source/index.rst index 6a449c319..631708028 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -27,6 +27,7 @@ secrets that you've been searching for. Script Editors Game Frozen or Stuck? Guides & Tips + Tools & Resources Changelog Donate diff --git a/doc/source/toolsandresources.rst b/doc/source/toolsandresources.rst new file mode 100644 index 000000000..7adb890a0 --- /dev/null +++ b/doc/source/toolsandresources.rst @@ -0,0 +1,23 @@ +Tools & Resources +================= + +Official Script Repository +-------------------------- +There are plans to create an official repository of Bitburner scripts. As of right now, +this is not a priority and has not been started. However, if you'd like +to contribute scripts now, you can find the repository +`here `_ and submit pull requests. + +Visual Studio Code Extension +---------------------------- +One user created a Bitburner extension for the Visual Studio Code (VSCode) editor. + +This extension includes several features such as: + +* Dynamic RAM calculation +* RAM Usage breakdown +* Typescript definition files with jsdoc comments +* Netscript syntax highlighting + +You can find more information and download links +`on this reddit post `_. diff --git a/src/Augmentation/AugmentationHelpers.js b/src/Augmentation/AugmentationHelpers.js index 99b2f5cee..37836a77a 100644 --- a/src/Augmentation/AugmentationHelpers.js +++ b/src/Augmentation/AugmentationHelpers.js @@ -2105,17 +2105,6 @@ function augmentationExists(name) { return Augmentations.hasOwnProperty(name); } -//Used for testing balance -function giveAllAugmentations() { - for (var name in Augmentations) { - var aug = Augmentations[name]; - if (aug == null) {continue;} - var ownedAug = new PlayerOwnedAugmentation(name); - Player.augmentations.push(ownedAug); - } - Player.reapplyAllAugmentations(); -} - function displayAugmentationsContent(contentEl) { removeChildrenFromElement(contentEl); contentEl.appendChild(createElement("h1", { diff --git a/src/CodingContracts.ts b/src/CodingContracts.ts index 222c8ef69..73c5f1423 100644 --- a/src/CodingContracts.ts +++ b/src/CodingContracts.ts @@ -205,6 +205,7 @@ export class CodingContract { } }, placeholder: "Enter Solution here", + width: "50%", }) as HTMLInputElement; solveBtn = createElement("a", { class: "a-link-button", diff --git a/src/Constants.ts b/src/Constants.ts index e6b60358e..3f836d321 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -278,7 +278,7 @@ export let CONSTANTS: IMap = { v0.47.0 * Stock Market changes: ** Implemented spread. Stock's now have bid and ask prices at which transactions occur - ** Large transactions will now influence a stock's price. + ** Large transactions will now influence a stock's price and forecast ** This "influencing" can take effect in the middle of a transaction ** See documentation for more details on these changes ** Added getStockAskPrice(), getStockBidPrice() Netscript functions to the TIX API @@ -286,12 +286,16 @@ export let CONSTANTS: IMap = { * Re-sleeves can no longer have the NeuroFlux Governor augmentation ** This is just a temporary patch until the mechanic gets re-worked - + + * Corporation employees no longer have an "age" stat + * Bug Fix: Corporation employees stats should no longer become negative * Bug Fix: Fixed sleeve.getInformation() throwing error in certain scenarios * Bug Fix: Coding contracts should no longer generate on the w0r1d_d43m0n server * Bug Fix: Duplicate Sleeves now properly have access to all Augmentations if you have a gang + * Bug Fix: getAugmentationsFromFaction() & purchaseAugmentation() functions should now work properly if you have a gang * Bug Fix: Fixed issue that caused messages (.msg) to be sent when refreshing/reloading the game * Bug Fix: Purchasing hash upgrades for Bladeburner/Corporation when you don't actually have access to those mechanics no longer gives hashes * Bug Fix: run(), exec(), and spawn() Netscript functions now throw if called with 0 threads + * Bug Fix: Faction UI should now automatically update reputation ` } diff --git a/src/Faction/ui/Info.tsx b/src/Faction/ui/Info.tsx index eac2e0e5c..126eb7ef9 100644 --- a/src/Faction/ui/Info.tsx +++ b/src/Faction/ui/Info.tsx @@ -30,10 +30,24 @@ const infoStyleMarkup = { } export class Info extends React.Component { - render() { + constructor(props: IProps) { + super(props); - const formattedRep = numeralWrapper.format(this.props.faction.playerReputation, "0.000a"); + this.getFavorGainText = this.getFavorGainText.bind(this); + this.getReputationText = this.getReputationText.bind(this); + } + + getFavorGainText(): string { const favorGain = this.props.faction.getFavorGain()[0]; + return `You will earn ${numeralWrapper.format(favorGain, "0,0")} faction favor upon resetting after installing an Augmentation` + } + + getReputationText(): string { + const formattedRep = numeralWrapper.format(this.props.faction.playerReputation, "0.000a"); + return `Reputation: ${formattedRep}` + } + + render() { const favorTooltip = "Faction favor increases the rate at which you earn reputation for " + "this faction by 1% per favor. Faction favor is gained whenever you " + "reset after installing an Augmentation. The amount of " + @@ -51,8 +65,8 @@ export class Info extends React.Component {

-------------------------

-------------------------

{ // Caculate total returns const totalCost = stock.playerShares * stock.playerAvgPx; - const gains = (stock.price - stock.playerAvgPx) * stock.playerShares; + const gains = (stock.getBidPrice() - stock.playerAvgPx) * stock.playerShares; let percentageGains = gains / totalCost; if (isNaN(percentageGains)) { percentageGains = 0; } @@ -56,7 +56,7 @@ export class StockTickerPositionText extends React.Component { // Caculate total returns const totalCost = stock.playerShortShares * stock.playerAvgShortPx; - const gains = (stock.playerAvgShortPx - stock.price) * stock.playerShortShares; + const gains = (stock.playerAvgShortPx - stock.getAskPrice()) * stock.playerShortShares; let percentageGains = gains / totalCost; if (isNaN(percentageGains)) { percentageGains = 0; } diff --git a/src/ui/React/AutoupdatingParagraph.tsx b/src/ui/React/AutoupdatingParagraph.tsx index 919d9cd4f..d50caf495 100644 --- a/src/ui/React/AutoupdatingParagraph.tsx +++ b/src/ui/React/AutoupdatingParagraph.tsx @@ -8,8 +8,8 @@ import * as React from "react"; interface IProps { intervalTime?: number; style?: object; - text: string; - tooltip?: string; + getText: () => string; + getTooltip?: () => string; } interface IState { @@ -49,7 +49,14 @@ export class AutoupdatingParagraph extends React.Component { } render() { - const hasTooltip = this.props.tooltip != null && this.props.tooltip !== ""; + let hasTooltip = this.props.getTooltip != null; + let tooltip: string | null; + if (hasTooltip) { + tooltip = this.props.getTooltip!(); + if (tooltip === "") { + hasTooltip = false; + } + } const className = "tooltip"; @@ -57,13 +64,13 @@ export class AutoupdatingParagraph extends React.Component { let tooltipMarkup: IInnerHTMLMarkup | null; if (hasTooltip) { tooltipMarkup = { - __html: this.props.tooltip! + __html: tooltip! } } return (

- {this.props.text} + {this.props.getText()} { hasTooltip && diff --git a/utils/helpers/arrayToString.ts b/utils/helpers/arrayToString.ts index f6645bf74..815dd4495 100644 --- a/utils/helpers/arrayToString.ts +++ b/utils/helpers/arrayToString.ts @@ -9,11 +9,13 @@ export function arrayToString(a: T[]) { const vals: any[] = []; for (let i = 0; i < a.length; ++i) { let elem: any = a[i]; - if (typeof elem === "string") { + if (Array.isArray(elem)) { + elem = arrayToString(elem); + } else if (typeof elem === "string") { elem = `"${elem}"`; } vals.push(elem); } - + return `[${vals.join(", ")}]`; } diff --git a/utils/helpers/compareArrays.ts b/utils/helpers/compareArrays.ts index 95d0f29b2..257b2912a 100644 --- a/utils/helpers/compareArrays.ts +++ b/utils/helpers/compareArrays.ts @@ -9,8 +9,19 @@ export function compareArrays(a1: T[], a2: T[]) { return false; } - for (let i: number = 0; i < a1.length; ++i) { - if (a1[i] !== a2[i]) { + for (let i = 0; i < a1.length; ++i) { + if (Array.isArray(a1[i])) { + // If the other element is not an array, then these cannot be equal + if (!Array.isArray(a2[i])) { + return false; + } + + const elem1 = a1[i]; + const elem2 = a2[i]; + if (!compareArrays(elem1, elem2)) { + return false; + } + } else if (a1[i] !== a2[i]) { return false; } }