bitburner-src/src/StockMarket/PlayerInfluencing.ts

87 lines
3.0 KiB
TypeScript
Raw Normal View History

/**
* Implementation of the mechanisms that allow the player to affect the
* Stock Market
*/
import { Stock } from "./Stock";
import { StockMarket } from "./StockMarket";
import { Company } from "../Company/Company";
import { Server } from "../Server/Server";
// Change in second-order forecast due to hacks/grows
export const forecastForecastChangeFromHack = 0.1;
// Change in second-order forecast due to company work
export const forecastForecastChangeFromCompanyWork = 0.001;
/**
* Potentially decreases a stock's second-order forecast when its corresponding
* server is hacked. The chance of the hack decreasing the stock's second-order
* forecast is dependent on what percentage of the server's money is hacked
* @param {Server} server - Server being hack()ed
* @param {number} moneyHacked - Amount of money stolen from the server
*/
2021-09-09 05:47:34 +02:00
export function influenceStockThroughServerHack(server: Server, moneyHacked: number): void {
2021-09-05 01:09:30 +02:00
const orgName = server.organizationName;
let stock: Stock | null = null;
if (typeof orgName === "string" && orgName !== "") {
stock = StockMarket[orgName];
}
if (!(stock instanceof Stock)) {
return;
}
2021-09-05 01:09:30 +02:00
const percTotalMoneyHacked = moneyHacked / server.moneyMax;
if (Math.random() < percTotalMoneyHacked) {
2021-09-09 05:47:34 +02:00
stock.changeForecastForecast(stock.otlkMagForecast - forecastForecastChangeFromHack);
2021-09-05 01:09:30 +02:00
}
}
/**
* Potentially increases a stock's second-order forecast when its corresponding
* server is grown (grow()). The chance of the grow() to increase the stock's
* second-order forecast is dependent on how much money is added to the server
* @param {Server} server - Server being grow()n
* @param {number} moneyGrown - Amount of money added to the server
*/
2021-09-09 05:47:34 +02:00
export function influenceStockThroughServerGrow(server: Server, moneyGrown: number): void {
2021-09-05 01:09:30 +02:00
const orgName = server.organizationName;
let stock: Stock | null = null;
if (typeof orgName === "string" && orgName !== "") {
stock = StockMarket[orgName];
}
if (!(stock instanceof Stock)) {
return;
}
2021-09-05 01:09:30 +02:00
const percTotalMoneyGrown = moneyGrown / server.moneyMax;
if (Math.random() < percTotalMoneyGrown) {
2021-09-09 05:47:34 +02:00
stock.changeForecastForecast(stock.otlkMagForecast + forecastForecastChangeFromHack);
2021-09-05 01:09:30 +02:00
}
}
/**
* Potentially increases a stock's second-order forecast when the player works for
* its corresponding company.
* @param {Company} company - Company being worked for
* @param {number} performanceMult - Effectiveness of player's work. Affects influence
* @param {number} cyclesOfWork - # game cycles of work being processed
*/
2021-09-05 01:09:30 +02:00
export function influenceStockThroughCompanyWork(
company: Company,
performanceMult: number,
cyclesOfWork: number,
): void {
const compName = company.name;
let stock: Stock | null = null;
2023-07-11 15:23:17 +02:00
stock = StockMarket[compName];
2021-09-05 01:09:30 +02:00
if (!(stock instanceof Stock)) {
return;
}
2021-09-05 01:09:30 +02:00
if (Math.random() < 0.002 * cyclesOfWork) {
const change = forecastForecastChangeFromCompanyWork * performanceMult;
stock.changeForecastForecast(stock.otlkMagForecast + change);
}
}