remove unused eventEmitterForUiReset

This commit is contained in:
Snarling 2022-08-20 19:08:05 -04:00
parent 97961d6896
commit 0f15431b5f
4 changed files with 13 additions and 40 deletions

@ -34,7 +34,7 @@ export function placeOrder(
price: number, price: number,
type: OrderTypes, type: OrderTypes,
position: PositionTypes, position: PositionTypes,
ctx: NetscriptContext | null = null, ctx?: NetscriptContext,
): boolean { ): boolean {
if (!(stock instanceof Stock)) { if (!(stock instanceof Stock)) {
if (ctx) { if (ctx) {
@ -87,9 +87,7 @@ export interface ICancelOrderParams {
type?: OrderTypes; type?: OrderTypes;
} }
export function cancelOrder(params: ICancelOrderParams, ctx?: NetscriptContext): boolean { export function cancelOrder(params: ICancelOrderParams, ctx?: NetscriptContext): boolean {
if (StockMarket["Orders"] == null) { if (StockMarket["Orders"] == null) return false;
return false;
}
if (params.order && params.order instanceof Order) { if (params.order && params.order instanceof Order) {
const order = params.order; const order = params.order;
// An 'Order' object is passed in // An 'Order' object is passed in
@ -121,15 +119,11 @@ export function cancelOrder(params: ICancelOrderParams, ctx?: NetscriptContext):
params.pos === order.pos params.pos === order.pos
) { ) {
stockOrders.splice(i, 1); stockOrders.splice(i, 1);
if (ctx) { if (ctx) helpers.log(ctx, () => "Successfully cancelled order: " + orderTxt);
helpers.log(ctx, () => "Successfully cancelled order: " + orderTxt);
}
return true; return true;
} }
} }
if (ctx) { if (ctx) helpers.log(ctx, () => "Failed to cancel order: " + orderTxt);
helpers.log(ctx, () => "Failed to cancel order: " + orderTxt);
}
return false; return false;
} }
return false; return false;
@ -143,9 +137,7 @@ export function loadStockMarket(saveString: string): void {
storedCycles: 0, storedCycles: 0,
ticksUntilCycle: 0, ticksUntilCycle: 0,
} as IStockMarket; } as IStockMarket;
} else { } else StockMarket = JSON.parse(saveString, Reviver);
StockMarket = JSON.parse(saveString, Reviver);
}
} }
export function deleteStockMarket(): void { export function deleteStockMarket(): void {
@ -159,9 +151,7 @@ export function deleteStockMarket(): void {
export function initStockMarket(): void { export function initStockMarket(): void {
for (const stk of Object.keys(StockMarket)) { for (const stk of Object.keys(StockMarket)) {
if (StockMarket.hasOwnProperty(stk)) { if (StockMarket.hasOwnProperty(stk)) delete StockMarket[stk];
delete StockMarket[stk];
}
} }
for (const metadata of InitStockMetadata) { for (const metadata of InitStockMetadata) {
@ -172,9 +162,7 @@ export function initStockMarket(): void {
const orders: IOrderBook = {}; const orders: IOrderBook = {};
for (const name of Object.keys(StockMarket)) { for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name]; const stock = StockMarket[name];
if (!(stock instanceof Stock)) { if (!(stock instanceof Stock)) continue;
continue;
}
orders[stock.symbol] = []; orders[stock.symbol] = [];
} }
StockMarket["Orders"] = orders; StockMarket["Orders"] = orders;
@ -201,9 +189,7 @@ export function initSymbolToStockMap(): void {
function stockMarketCycle(): void { function stockMarketCycle(): void {
for (const name of Object.keys(StockMarket)) { for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name]; const stock = StockMarket[name];
if (!(stock instanceof Stock)) { if (!(stock instanceof Stock)) continue;
continue;
}
const roll = Math.random(); const roll = Math.random();
if (roll < 0.45) { if (roll < 0.45) {
@ -231,9 +217,7 @@ export function processStockPrices(numCycles = 1): void {
// We can process the update every 4 seconds as long as there are enough // We can process the update every 4 seconds as long as there are enough
// stored cycles. This lets us account for offline time // stored cycles. This lets us account for offline time
const timeNow = new Date().getTime(); const timeNow = new Date().getTime();
if (timeNow - StockMarket.lastUpdate < 4e3) { if (timeNow - StockMarket.lastUpdate < 4e3) return;
return;
}
StockMarket.lastUpdate = timeNow; StockMarket.lastUpdate = timeNow;
StockMarket.storedCycles -= cyclesPerStockUpdate; StockMarket.storedCycles -= cyclesPerStockUpdate;
@ -243,16 +227,12 @@ export function processStockPrices(numCycles = 1): void {
StockMarket.ticksUntilCycle = TicksPerCycle; StockMarket.ticksUntilCycle = TicksPerCycle;
} }
--StockMarket.ticksUntilCycle; --StockMarket.ticksUntilCycle;
if (StockMarket.ticksUntilCycle <= 0) { if (StockMarket.ticksUntilCycle <= 0) stockMarketCycle();
stockMarketCycle();
}
const v = Math.random(); const v = Math.random();
for (const name of Object.keys(StockMarket)) { for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name]; const stock = StockMarket[name];
if (!(stock instanceof Stock)) { if (!(stock instanceof Stock)) continue;
continue;
}
let av = (v * stock.mv) / 100; let av = (v * stock.mv) / 100;
if (isNaN(av)) { if (isNaN(av)) {
av = 0.02; av = 0.02;
@ -311,5 +291,3 @@ export function initStockMarketFn(): void {
initStockMarket(); initStockMarket();
initSymbolToStockMap(); initSymbolToStockMap();
} }
export const eventEmitterForUiReset = new EventEmitter<[]>();

@ -9,10 +9,8 @@ import { StockTickers } from "./StockTickers";
import { IStockMarket } from "../IStockMarket"; import { IStockMarket } from "../IStockMarket";
import { IPlayer } from "../../PersonObjects/IPlayer"; import { IPlayer } from "../../PersonObjects/IPlayer";
import { EventEmitter } from "../../utils/EventEmitter";
type IProps = { type IProps = {
eventEmitterForReset?: EventEmitter<[]>;
initStockMarket: () => void; initStockMarket: () => void;
p: IPlayer; p: IPlayer;
stockMarket: IStockMarket; stockMarket: IStockMarket;
@ -32,7 +30,7 @@ export function StockMarketRoot(props: IProps): React.ReactElement {
<> <>
<InfoAndPurchases initStockMarket={props.initStockMarket} p={props.p} rerender={rerender} /> <InfoAndPurchases initStockMarket={props.initStockMarket} p={props.p} rerender={rerender} />
{props.p.hasWseAccount && ( {props.p.hasWseAccount && (
<StockTickers eventEmitterForReset={props.eventEmitterForReset} p={props.p} stockMarket={props.stockMarket} /> <StockTickers p={props.p} stockMarket={props.stockMarket} />
)} )}
</> </>
); );

@ -12,10 +12,8 @@ import { IStockMarket } from "../IStockMarket";
import { Stock } from "../Stock"; import { Stock } from "../Stock";
import { IPlayer } from "../../PersonObjects/IPlayer"; import { IPlayer } from "../../PersonObjects/IPlayer";
import { EventEmitter } from "../../utils/EventEmitter";
type IProps = { type IProps = {
eventEmitterForReset?: EventEmitter<[]>;
p: IPlayer; p: IPlayer;
stockMarket: IStockMarket; stockMarket: IStockMarket;
}; };

@ -17,7 +17,7 @@ import { prestigeAugmentation } from "../Prestige";
import { dialogBoxCreate } from "./React/DialogBox"; import { dialogBoxCreate } from "./React/DialogBox";
import { GetAllServers } from "../Server/AllServers"; import { GetAllServers } from "../Server/AllServers";
import { Factions } from "../Faction/Factions"; import { Factions } from "../Faction/Factions";
import { eventEmitterForUiReset, initStockMarketFn, StockMarket } from "../StockMarket/StockMarket"; import { initStockMarketFn, StockMarket } from "../StockMarket/StockMarket";
import { Theme } from "@mui/material/styles"; import { Theme } from "@mui/material/styles";
import makeStyles from "@mui/styles/makeStyles"; import makeStyles from "@mui/styles/makeStyles";
@ -437,7 +437,6 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
case Page.StockMarket: { case Page.StockMarket: {
mainPage = ( mainPage = (
<StockMarketRoot <StockMarketRoot
eventEmitterForReset={eventEmitterForUiReset}
initStockMarket={initStockMarketFn} initStockMarket={initStockMarketFn}
p={player} p={player}
stockMarket={StockMarket} stockMarket={StockMarket}