diff --git a/src/Achievements/Achievements.ts b/src/Achievements/Achievements.ts index 2085a031e..acbf35dd8 100644 --- a/src/Achievements/Achievements.ts +++ b/src/Achievements/Achievements.ts @@ -347,18 +347,18 @@ export const achievements: IMap = { FIRST_HACKNET_NODE: { ...achievementData["FIRST_HACKNET_NODE"], Icon: "node", - Condition: () => !hasHacknetServers(Player) && Player.hacknetNodes.length > 0, + Condition: () => !hasHacknetServers() && Player.hacknetNodes.length > 0, }, "30_HACKNET_NODE": { ...achievementData["30_HACKNET_NODE"], Icon: "hacknet-all", - Condition: () => !hasHacknetServers(Player) && Player.hacknetNodes.length >= 30, + Condition: () => !hasHacknetServers() && Player.hacknetNodes.length >= 30, }, MAX_HACKNET_NODE: { ...achievementData["MAX_HACKNET_NODE"], Icon: "hacknet-max", Condition: (): boolean => { - if (hasHacknetServers(Player)) return false; + if (hasHacknetServers()) return false; for (const h of Player.hacknetNodes) { if (!(h instanceof HacknetNode)) return false; if ( @@ -374,7 +374,7 @@ export const achievements: IMap = { HACKNET_NODE_10M: { ...achievementData["HACKNET_NODE_10M"], Icon: "hacknet-10m", - Condition: () => !hasHacknetServers(Player) && Player.moneySourceB.hacknet >= 10e6, + Condition: () => !hasHacknetServers() && Player.moneySourceB.hacknet >= 10e6, }, REPUTATION_10M: { ...achievementData["REPUTATION_10M"], @@ -515,14 +515,14 @@ export const achievements: IMap = { ...achievementData["FIRST_HACKNET_SERVER"], Icon: "HASHNET", Visible: () => hasAccessToSF(Player, 9), - Condition: () => hasHacknetServers(Player) && Player.hacknetNodes.length > 0, + Condition: () => hasHacknetServers() && Player.hacknetNodes.length > 0, AdditionalUnlock: [achievementData.FIRST_HACKNET_NODE.ID], }, ALL_HACKNET_SERVER: { ...achievementData["ALL_HACKNET_SERVER"], Icon: "HASHNETALL", Visible: () => hasAccessToSF(Player, 9), - Condition: () => hasHacknetServers(Player) && Player.hacknetNodes.length === HacknetServerConstants.MaxServers, + Condition: () => hasHacknetServers() && Player.hacknetNodes.length === HacknetServerConstants.MaxServers, AdditionalUnlock: [achievementData["30_HACKNET_NODE"].ID], }, MAX_HACKNET_SERVER: { @@ -530,7 +530,7 @@ export const achievements: IMap = { Icon: "HASHNETALL", Visible: () => hasAccessToSF(Player, 9), Condition: (): boolean => { - if (!hasHacknetServers(Player)) return false; + if (!hasHacknetServers()) return false; for (const h of Player.hacknetNodes) { if (typeof h !== "string") return false; const hs = GetServer(h); @@ -551,7 +551,7 @@ export const achievements: IMap = { ...achievementData["HACKNET_SERVER_1B"], Icon: "HASHNETMONEY", Visible: () => hasAccessToSF(Player, 9), - Condition: () => hasHacknetServers(Player) && Player.moneySourceB.hacknet >= 1e9, + Condition: () => hasHacknetServers() && Player.moneySourceB.hacknet >= 1e9, AdditionalUnlock: [achievementData.HACKNET_NODE_10M.ID], }, MAX_CACHE: { @@ -559,7 +559,7 @@ export const achievements: IMap = { Icon: "HASHNETCAP", Visible: () => hasAccessToSF(Player, 9), Condition: () => - hasHacknetServers(Player) && + hasHacknetServers() && Player.hashManager.hashes === Player.hashManager.capacity && Player.hashManager.capacity > 0, }, diff --git a/src/Arcade/ui/ArcadeRoot.tsx b/src/Arcade/ui/ArcadeRoot.tsx index efb1f92d9..ff353313e 100644 --- a/src/Arcade/ui/ArcadeRoot.tsx +++ b/src/Arcade/ui/ArcadeRoot.tsx @@ -2,7 +2,7 @@ import React, { useState } from "react"; import { BBCabinetRoot } from "./BBCabinet"; import Button from "@mui/material/Button"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { AlertEvents } from "../../ui/React/AlertManager"; enum Page { @@ -11,11 +11,10 @@ enum Page { } export function ArcadeRoot(): React.ReactElement { - const player = use.Player(); const [page, setPage] = useState(Page.None); function mbBurner2000(): void { - if (player.sourceFileLvl(1) === 0) { + if (Player.sourceFileLvl(1) === 0) { AlertEvents.emit("This machine is broken."); } else { setPage(Page.Megabyteburner2000); diff --git a/src/Arcade/ui/BBCabinet.tsx b/src/Arcade/ui/BBCabinet.tsx index b0627b2f0..1b3c95a85 100644 --- a/src/Arcade/ui/BBCabinet.tsx +++ b/src/Arcade/ui/BBCabinet.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from "react"; import Typography from "@mui/material/Typography"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Exploit } from "../../Exploits/Exploit"; const metaBB = "https://bitburner-official.github.io/bitburner-legacy/"; @@ -12,11 +12,10 @@ const style = { }; export function BBCabinetRoot(): React.ReactElement { - const player = use.Player(); useEffect(() => { window.addEventListener("message", function (this: Window, ev: MessageEvent) { if (ev.isTrusted && ev.origin == "https://bitburner-official.github.io" && ev.data) { - player.giveExploit(Exploit.TrueRecursion); + Player.giveExploit(Exploit.TrueRecursion); } }); }); diff --git a/src/Augmentation/Augmentation.tsx b/src/Augmentation/Augmentation.tsx index e1154bb5c..9dafe06e0 100644 --- a/src/Augmentation/Augmentation.tsx +++ b/src/Augmentation/Augmentation.tsx @@ -8,7 +8,7 @@ import { Money } from "../ui/React/Money"; import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver"; import { FactionNames } from "../Faction/data/FactionNames"; -import { IPlayer } from "../PersonObjects/IPlayer"; +import { Player } from "../Player"; import { AugmentationNames } from "./data/AugmentationNames"; import { CONSTANTS } from "../Constants"; import { StaticAugmentations } from "./StaticAugmentations"; @@ -531,26 +531,26 @@ export class Augmentation { } } - getCost(player: IPlayer): AugmentationCosts { + getCost(): AugmentationCosts { const augmentationReference = StaticAugmentations[this.name]; let moneyCost = augmentationReference.baseCost; let repCost = augmentationReference.baseRepRequirement; if (augmentationReference.name === AugmentationNames.NeuroFluxGovernor) { - let nextLevel = this.getLevel(player); + let nextLevel = this.getLevel(); --nextLevel; const multiplier = Math.pow(CONSTANTS.NeuroFluxGovernorLevelMult, nextLevel); repCost = augmentationReference.baseRepRequirement * multiplier * BitNodeMultipliers.AugmentationRepCost; moneyCost = augmentationReference.baseCost * multiplier * BitNodeMultipliers.AugmentationMoneyCost; - for (let i = 0; i < player.queuedAugmentations.length; ++i) { + for (let i = 0; i < Player.queuedAugmentations.length; ++i) { moneyCost *= getBaseAugmentationPriceMultiplier(); } } else if (augmentationReference.factions.includes(FactionNames.ShadowsOfAnarchy)) { const soaAugmentationNames = initSoAAugmentations().map((augmentation) => augmentation.name); const soaMultiplier = Math.pow( CONSTANTS.SoACostMult, - soaAugmentationNames.filter((augmentationName) => player.hasAugmentation(augmentationName)).length, + soaAugmentationNames.filter((augmentationName) => Player.hasAugmentation(augmentationName)).length, ); moneyCost = augmentationReference.baseCost * soaMultiplier; if (soaAugmentationNames.find((augmentationName) => augmentationName === augmentationReference.name)) { @@ -566,19 +566,19 @@ export class Augmentation { return { moneyCost, repCost }; } - getLevel(player: IPlayer): number { + getLevel(): number { // Get current Neuroflux level based on Player's augmentations if (this.name === AugmentationNames.NeuroFluxGovernor) { let currLevel = 0; - for (let i = 0; i < player.augmentations.length; ++i) { - if (player.augmentations[i].name === AugmentationNames.NeuroFluxGovernor) { - currLevel = player.augmentations[i].level; + for (let i = 0; i < Player.augmentations.length; ++i) { + if (Player.augmentations[i].name === AugmentationNames.NeuroFluxGovernor) { + currLevel = Player.augmentations[i].level; } } // Account for purchased but uninstalled Augmentations - for (let i = 0; i < player.queuedAugmentations.length; ++i) { - if (player.queuedAugmentations[i].name == AugmentationNames.NeuroFluxGovernor) { + for (let i = 0; i < Player.queuedAugmentations.length; ++i) { + if (Player.queuedAugmentations[i].name == AugmentationNames.NeuroFluxGovernor) { ++currLevel; } } diff --git a/src/Augmentation/AugmentationHelpers.tsx b/src/Augmentation/AugmentationHelpers.tsx index a8ffa8e83..90610c71e 100644 --- a/src/Augmentation/AugmentationHelpers.tsx +++ b/src/Augmentation/AugmentationHelpers.tsx @@ -1,6 +1,6 @@ import { Augmentation } from "./Augmentation"; import { StaticAugmentations } from "./StaticAugmentations"; -import { PlayerOwnedAugmentation, IPlayerOwnedAugmentation } from "./PlayerOwnedAugmentation"; +import { PlayerOwnedAugmentation } from "./PlayerOwnedAugmentation"; import { AugmentationNames } from "./data/AugmentationNames"; import { CONSTANTS } from "../Constants"; @@ -21,7 +21,7 @@ import { initUnstableCircadianModulator, } from "./data/AugmentationCreator"; import { Router } from "../ui/GameRoot"; -import { mergeAugmentation } from "../PersonObjects/Multipliers"; +import { mergeMultipliers } from "../PersonObjects/Multipliers"; export function AddToStaticAugmentations(aug: Augmentation): void { const name = aug.name; @@ -71,11 +71,11 @@ function resetAugmentation(aug: Augmentation): void { AddToStaticAugmentations(aug); } -function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void { +function applyAugmentation(aug: PlayerOwnedAugmentation, reapply = false): void { const staticAugmentation = StaticAugmentations[aug.name]; // Apply multipliers - Player.mults = mergeAugmentation(Player.mults, staticAugmentation.mults); + Player.mults = mergeMultipliers(Player.mults, staticAugmentation.mults); // Special logic for Congruity Implant if (aug.name === AugmentationNames.CongruityImplant && !reapply) { @@ -126,15 +126,15 @@ function installAugmentations(force?: boolean): boolean { if (ownedAug.name === AugmentationNames.NeuroFluxGovernor) { level = ` - ${ownedAug.level}`; } - augmentationList += aug.name + level + "
"; + augmentationList += aug.name + level + "\n"; } Player.queuedAugmentations = []; if (!force) { dialogBoxCreate( "You slowly drift to sleep as scientists put you under in order " + - "to install the following Augmentations:
" + + "to install the following Augmentations:\n" + augmentationList + - "
You wake up in your home...you feel different...", + "\nYou wake up in your home...you feel different...", ); } prestigeAugmentation(); @@ -146,8 +146,8 @@ function augmentationExists(name: string): boolean { return StaticAugmentations.hasOwnProperty(name); } -export function isRepeatableAug(aug: Augmentation): boolean { - const augName = aug instanceof Augmentation ? aug.name : aug; +export function isRepeatableAug(aug: Augmentation | string): boolean { + const augName = typeof aug === "string" ? aug : aug.name; return augName === AugmentationNames.NeuroFluxGovernor; } diff --git a/src/Augmentation/PlayerOwnedAugmentation.ts b/src/Augmentation/PlayerOwnedAugmentation.ts index e8807b894..b762b2e41 100644 --- a/src/Augmentation/PlayerOwnedAugmentation.ts +++ b/src/Augmentation/PlayerOwnedAugmentation.ts @@ -6,8 +6,3 @@ export class PlayerOwnedAugmentation { this.name = name; } } - -export interface IPlayerOwnedAugmentation { - level: number; - name: string; -} diff --git a/src/Augmentation/data/AugmentationCreator.tsx b/src/Augmentation/data/AugmentationCreator.tsx index b34f48eb5..04f3085cb 100644 --- a/src/Augmentation/data/AugmentationCreator.tsx +++ b/src/Augmentation/data/AugmentationCreator.tsx @@ -6,7 +6,6 @@ import { WHRNG } from "../../Casino/RNG"; import React from "react"; import { FactionNames } from "../../Faction/data/FactionNames"; import { CONSTANTS } from "../../Constants"; -import { Faction } from "src/Faction/Faction"; interface CircadianBonus { bonuses: { diff --git a/src/Augmentation/ui/AugmentationsRoot.tsx b/src/Augmentation/ui/AugmentationsRoot.tsx index 033ac95d6..912ebf540 100644 --- a/src/Augmentation/ui/AugmentationsRoot.tsx +++ b/src/Augmentation/ui/AugmentationsRoot.tsx @@ -10,8 +10,6 @@ import { PurchasedAugmentations } from "./PurchasedAugmentations"; import { SourceFilesElement } from "./SourceFiles"; import { canGetBonus } from "../../ExportBonus"; -import { use } from "../../ui/Context"; - import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import Tooltip from "@mui/material/Tooltip"; @@ -20,7 +18,7 @@ import Paper from "@mui/material/Paper"; import Container from "@mui/material/Container"; import { Settings } from "../../Settings/Settings"; import { ConfirmationModal } from "../../ui/React/ConfirmationModal"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Player } from "../../Player"; import { AugmentationNames } from "../data/AugmentationNames"; import { StaticAugmentations } from "../StaticAugmentations"; import { CONSTANTS } from "../../Constants"; @@ -29,12 +27,8 @@ import { Info } from "@mui/icons-material"; import { Link } from "@mui/material"; import { AlertEvents } from "../../ui/React/AlertManager"; -interface NFGDisplayProps { - player: IPlayer; -} - -const NeuroFluxDisplay = ({ player }: NFGDisplayProps): React.ReactElement => { - const level = player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0; +const NeuroFluxDisplay = (): React.ReactElement => { + const level = Player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0; const openBloodDonation = () => { AlertEvents.emit( @@ -67,18 +61,14 @@ const NeuroFluxDisplay = ({ player }: NFGDisplayProps): React.ReactElement => { ); }; -interface EntropyDisplayProps { - player: IPlayer; -} - -const EntropyDisplay = ({ player }: EntropyDisplayProps): React.ReactElement => { - return player.entropy > 0 ? ( +const EntropyDisplay = (): React.ReactElement => { + return Player.entropy > 0 ? ( - Entropy Virus - Level {player.entropy} + Entropy Virus - Level {Player.entropy} - All multipliers decreased by: {formatNumber((1 - CONSTANTS.EntropyEffect ** player.entropy) * 100, 3)}% + All multipliers decreased by: {formatNumber((1 - CONSTANTS.EntropyEffect ** Player.entropy) * 100, 3)}% (multiplicative) @@ -94,7 +84,6 @@ interface IProps { export function AugmentationsRoot(props: IProps): React.ReactElement { const [installOpen, setInstallOpen] = useState(false); - const player = use.Player(); const setRerender = useState(false)[1]; function rerender(): void { setRerender((o) => !o); @@ -187,7 +176,7 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { 'I never asked for this'}> - @@ -199,7 +188,7 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { - {player.queuedAugmentations.length > 0 ? ( + {Player.queuedAugmentations.length > 0 ? ( @@ -216,14 +205,14 @@ export function AugmentationsRoot(props: IProps): React.ReactElement { my: 1, display: "grid", gridTemplateColumns: `repeat(${ - +!!((player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0) > 0) + - +!!(player.entropy > 0) + +!!((Player.augmentations.find((e) => e.name === AugmentationNames.NeuroFluxGovernor)?.level ?? 0) > 0) + + +!!(Player.entropy > 0) }, 1fr)`, gap: 1, }} > - - + + diff --git a/src/Augmentation/ui/InstalledAugmentations.tsx b/src/Augmentation/ui/InstalledAugmentations.tsx index 1ec34391f..3c06a68a4 100644 --- a/src/Augmentation/ui/InstalledAugmentations.tsx +++ b/src/Augmentation/ui/InstalledAugmentations.tsx @@ -12,14 +12,13 @@ import Tooltip from "@mui/material/Tooltip"; import React, { useState } from "react"; import { OwnedAugmentationsOrderSetting } from "../../Settings/SettingEnums"; import { Settings } from "../../Settings/Settings"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { StaticAugmentations } from "../StaticAugmentations"; import { AugmentationNames } from "../data/AugmentationNames"; export function InstalledAugmentations(): React.ReactElement { const setRerender = useState(true)[1]; - const player = use.Player(); - const sourceAugs = player.augmentations.slice().filter((aug) => aug.name !== AugmentationNames.NeuroFluxGovernor); + const sourceAugs = Player.augmentations.slice().filter((aug) => aug.name !== AugmentationNames.NeuroFluxGovernor); const [selectedAug, setSelectedAug] = useState(sourceAugs[0]); diff --git a/src/Augmentation/ui/PlayerMultipliers.tsx b/src/Augmentation/ui/PlayerMultipliers.tsx index 5ddb8b07f..ca7b4c58a 100644 --- a/src/Augmentation/ui/PlayerMultipliers.tsx +++ b/src/Augmentation/ui/PlayerMultipliers.tsx @@ -4,7 +4,7 @@ import { DoubleArrow } from "@mui/icons-material"; import { List, ListItem, ListItemText, Paper, Typography } from "@mui/material"; import * as React from "react"; -import { Multipliers, defaultMultipliers, mergeAugmentation } from "../../PersonObjects/Multipliers"; +import { Multipliers, defaultMultipliers, mergeMultipliers } from "../../PersonObjects/Multipliers"; import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers"; import { Player } from "../../Player"; import { Settings } from "../../Settings/Settings"; @@ -15,7 +15,7 @@ function calculateAugmentedStats(): Multipliers { let augP: Multipliers = defaultMultipliers(); for (const aug of Player.queuedAugmentations) { const augObj = StaticAugmentations[aug.name]; - augP = mergeAugmentation(augP, augObj.mults); + augP = mergeMultipliers(augP, augObj.mults); } return augP; } diff --git a/src/Augmentation/ui/PurchasableAugmentations.tsx b/src/Augmentation/ui/PurchasableAugmentations.tsx index 27a8f927b..6c6e93da9 100644 --- a/src/Augmentation/ui/PurchasableAugmentations.tsx +++ b/src/Augmentation/ui/PurchasableAugmentations.tsx @@ -6,7 +6,7 @@ import { CheckBox, CheckBoxOutlineBlank, CheckCircle, NewReleases, Report } from import { Box, Button, Container, Paper, Tooltip, Typography } from "@mui/material"; import React, { useState } from "react"; import { Faction } from "../../Faction/Faction"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Player } from "../../Player"; import { Settings } from "../../Settings/Settings"; import { numeralWrapper } from "../../ui/numeralFormat"; import { Augmentation } from "../Augmentation"; @@ -15,12 +15,11 @@ import { StaticAugmentations } from "../StaticAugmentations"; import { PurchaseAugmentationModal } from "./PurchaseAugmentationModal"; interface IPreReqsProps { - player: IPlayer; aug: Augmentation; } const PreReqs = (props: IPreReqsProps): React.ReactElement => { - const ownedPreReqs = props.aug.prereqs.filter((aug) => props.player.hasAugmentation(aug)); + const ownedPreReqs = props.aug.prereqs.filter((aug) => Player.hasAugmentation(aug)); const hasPreReqs = props.aug.prereqs.length > 0 && ownedPreReqs.length === props.aug.prereqs.length; return ( @@ -32,7 +31,7 @@ const PreReqs = (props: IPreReqsProps): React.ReactElement => { {props.aug.prereqs.map((preAug) => ( { }; interface IExclusiveProps { - player: IPlayer; aug: Augmentation; } @@ -85,18 +83,16 @@ const Exclusive = (props: IExclusiveProps): React.ReactElement => {
  • {props.aug.factions[0]} faction
  • - {props.player.isAwareOfGang() && !props.aug.isSpecial && ( + {Player.isAwareOfGang() && !props.aug.isSpecial && (
  • Certain gangs
  • )} - {props.player.canAccessGrafting() && - !props.aug.isSpecial && - props.aug.name !== AugmentationNames.TheRedPill && ( -
  • - Grafting -
  • - )} + {Player.canAccessGrafting() && !props.aug.isSpecial && props.aug.name !== AugmentationNames.TheRedPill && ( +
  • + Grafting +
  • + )} @@ -130,10 +126,9 @@ const Requirement = (props: IReqProps): React.ReactElement => { interface IPurchasableAugsProps { augNames: string[]; ownedAugNames: string[]; - player: IPlayer; - canPurchase: (player: IPlayer, aug: Augmentation) => boolean; - purchaseAugmentation: (player: IPlayer, aug: Augmentation, showModal: (open: boolean) => void) => void; + canPurchase: (aug: Augmentation) => boolean; + purchaseAugmentation: (aug: Augmentation, showModal: (open: boolean) => void) => void; rep?: number; sleeveAugs?: boolean; @@ -167,7 +162,7 @@ export function PurchasableAugmentation(props: IPurchasableAugProps): React.Reac const [open, setOpen] = useState(false); const aug = StaticAugmentations[props.augName]; - const augCosts = aug.getCost(props.parent.player); + const augCosts = aug.getCost(); const cost = props.parent.sleeveAugs ? aug.baseCost : augCosts.moneyCost; const repCost = augCosts.repCost; const info = typeof aug.info === "string" ? {aug.info} : aug.info; @@ -195,11 +190,11 @@ export function PurchasableAugmentation(props: IPurchasableAugProps): React.Reac ) : ( - + )} ); diff --git a/src/Bladeburner/ui/BladeburnerCinematic.tsx b/src/Bladeburner/ui/BladeburnerCinematic.tsx index 5be3e1030..8ce17ea5c 100644 --- a/src/Bladeburner/ui/BladeburnerCinematic.tsx +++ b/src/Bladeburner/ui/BladeburnerCinematic.tsx @@ -1,11 +1,10 @@ import React from "react"; import { FactionNames } from "../../Faction/data/FactionNames"; -import { use } from "../../ui/Context"; +import { Router } from "../../ui/GameRoot"; import { CinematicText } from "../../ui/React/CinematicText"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; export function BladeburnerCinematic(): React.ReactElement { - const router = use.Router(); return ( { - router.toTerminal(); + Router.toTerminal(); dialogBoxCreate( `Visit the National Security Agency (NSA) to apply for their ${FactionNames.Bladeburners} ` + "division! You will need 100 of each combat stat before doing this.", diff --git a/src/Bladeburner/ui/BladeburnerRoot.tsx b/src/Bladeburner/ui/BladeburnerRoot.tsx index 593874a62..4d9103939 100644 --- a/src/Bladeburner/ui/BladeburnerRoot.tsx +++ b/src/Bladeburner/ui/BladeburnerRoot.tsx @@ -3,12 +3,10 @@ import { Stats } from "./Stats"; import { Console } from "./Console"; import { AllPages } from "./AllPages"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import Box from "@mui/material/Box"; export function BladeburnerRoot(): React.ReactElement { - const player = use.Player(); - const router = use.Router(); const setRerender = useState(false)[1]; function rerender(): void { setRerender((old) => !old); @@ -19,16 +17,16 @@ export function BladeburnerRoot(): React.ReactElement { return () => clearInterval(id); }, []); - const bladeburner = player.bladeburner; - if (bladeburner === null) return <>; + const bladeburner = Player.bladeburner; + if (!bladeburner) return <>; return ( - - + + - + ); } diff --git a/src/Bladeburner/ui/Console.tsx b/src/Bladeburner/ui/Console.tsx index 8a6a82935..5c5565e08 100644 --- a/src/Bladeburner/ui/Console.tsx +++ b/src/Bladeburner/ui/Console.tsx @@ -1,8 +1,7 @@ import React, { useState, useRef, useEffect } from "react"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { KEY } from "../../utils/helpers/keyCodes"; -import { IPlayer } from "../../PersonObjects/IPlayer"; import Paper from "@mui/material/Paper"; import List from "@mui/material/List"; import ListItem from "@mui/material/ListItem"; @@ -49,8 +48,7 @@ function Line(props: ILineProps): React.ReactElement { } interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function Console(props: IProps): React.ReactElement { @@ -81,7 +79,7 @@ export function Console(props: IProps): React.ReactElement { event.preventDefault(); if (command.length > 0) { props.bladeburner.postToConsole("> " + command); - props.bladeburner.executeConsoleCommands(props.player, command); + props.bladeburner.executeConsoleCommands(command); setConsoleHistoryIndex(props.bladeburner.consoleHistory.length); setCommand(""); } diff --git a/src/Bladeburner/ui/ContractElem.tsx b/src/Bladeburner/ui/ContractElem.tsx index 5edf04842..49dfc5add 100644 --- a/src/Bladeburner/ui/ContractElem.tsx +++ b/src/Bladeburner/ui/ContractElem.tsx @@ -3,9 +3,9 @@ import { ActionTypes } from "../data/ActionTypes"; import { createProgressBarText } from "../../utils/helpers/createProgressBarText"; import { formatNumber, convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions"; import { Contracts } from "../data/Contracts"; -import { IBladeburner } from "../IBladeburner"; -import { IAction } from "../IAction"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; +import { Action } from "../Action"; +import { Player } from "../../Player"; import { SuccessChance } from "./SuccessChance"; import { CopyableText } from "../../ui/React/CopyableText"; import { ActionLevel } from "./ActionLevel"; @@ -16,9 +16,8 @@ import Typography from "@mui/material/Typography"; import Paper from "@mui/material/Paper"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; - action: IAction; + bladeburner: Bladeburner; + action: Action; } export function ContractElem(props: IProps): React.ReactElement { @@ -32,7 +31,7 @@ export function ContractElem(props: IProps): React.ReactElement { props.bladeburner.actionTimeCurrent + props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete, ); - const actionTime = props.action.getActionTime(props.bladeburner, props.player); + const actionTime = props.action.getActionTime(props.bladeburner, Player); const actionData = Contracts[props.action.name]; if (actionData === undefined) { diff --git a/src/Bladeburner/ui/ContractList.tsx b/src/Bladeburner/ui/ContractList.tsx index 7bd24c53b..689238495 100644 --- a/src/Bladeburner/ui/ContractList.tsx +++ b/src/Bladeburner/ui/ContractList.tsx @@ -1,11 +1,9 @@ import React from "react"; import { ContractElem } from "./ContractElem"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function ContractList(props: IProps): React.ReactElement { @@ -14,7 +12,7 @@ export function ContractList(props: IProps): React.ReactElement { return ( <> {names.map((name: string) => ( - + ))} ); diff --git a/src/Bladeburner/ui/ContractPage.tsx b/src/Bladeburner/ui/ContractPage.tsx index 9a3e96a6d..d8a54bc2f 100644 --- a/src/Bladeburner/ui/ContractPage.tsx +++ b/src/Bladeburner/ui/ContractPage.tsx @@ -1,12 +1,10 @@ import * as React from "react"; import { ContractList } from "./ContractList"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function ContractPage(props: IProps): React.ReactElement { @@ -20,7 +18,7 @@ export function ContractPage(props: IProps): React.ReactElement { You can unlock higher-level contracts by successfully completing them. Higher-level contracts are more difficult, but grant more rank, experience, and money. - + ); } diff --git a/src/Bladeburner/ui/GeneralActionElem.tsx b/src/Bladeburner/ui/GeneralActionElem.tsx index b064b298d..b88b98dd9 100644 --- a/src/Bladeburner/ui/GeneralActionElem.tsx +++ b/src/Bladeburner/ui/GeneralActionElem.tsx @@ -2,10 +2,10 @@ import React, { useState } from "react"; import { ActionTypes } from "../data/ActionTypes"; import { createProgressBarText } from "../../utils/helpers/createProgressBarText"; import { formatNumber, convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions"; -import { IBladeburner } from "../IBladeburner"; -import { IAction } from "../IAction"; +import { Bladeburner } from "../Bladeburner"; +import { Action } from "../Action"; import { GeneralActions } from "../data/GeneralActions"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Player } from "../../Player"; import { CopyableText } from "../../ui/React/CopyableText"; import { StartButton } from "./StartButton"; @@ -15,9 +15,8 @@ import Box from "@mui/material/Box"; import Paper from "@mui/material/Paper"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; - action: IAction; + bladeburner: Bladeburner; + action: Action; } export function GeneralActionElem(props: IProps): React.ReactElement { @@ -40,13 +39,13 @@ export function GeneralActionElem(props: IProps): React.ReactElement { case "Incite Violence": return 60; case "Recruitment": - return props.bladeburner.getRecruitmentTime(props.player); + return props.bladeburner.getRecruitmentTime(Player); } return -1; // dead code })(); const successChance = props.action.name === "Recruitment" - ? Math.max(0, Math.min(props.bladeburner.getRecruitmentSuccessChance(props.player), 1)) + ? Math.max(0, Math.min(props.bladeburner.getRecruitmentSuccessChance(Player), 1)) : -1; const actionData = GeneralActions[props.action.name]; diff --git a/src/Bladeburner/ui/GeneralActionList.tsx b/src/Bladeburner/ui/GeneralActionList.tsx index 5693d4925..58a64d944 100644 --- a/src/Bladeburner/ui/GeneralActionList.tsx +++ b/src/Bladeburner/ui/GeneralActionList.tsx @@ -2,12 +2,10 @@ import React from "react"; import { GeneralActionElem } from "./GeneralActionElem"; import { Action } from "../Action"; import { GeneralActions } from "../GeneralActions"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function GeneralActionList(props: IProps): React.ReactElement { @@ -20,7 +18,7 @@ export function GeneralActionList(props: IProps): React.ReactElement { return ( <> {actions.map((action: Action) => ( - + ))} ); diff --git a/src/Bladeburner/ui/GeneralActionPage.tsx b/src/Bladeburner/ui/GeneralActionPage.tsx index 9893f210c..3dcf808c2 100644 --- a/src/Bladeburner/ui/GeneralActionPage.tsx +++ b/src/Bladeburner/ui/GeneralActionPage.tsx @@ -1,19 +1,17 @@ import * as React from "react"; import { GeneralActionList } from "./GeneralActionList"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function GeneralActionPage(props: IProps): React.ReactElement { return ( <> These are generic actions that will assist you in your Bladeburner duties. - + ); } diff --git a/src/Bladeburner/ui/OperationElem.tsx b/src/Bladeburner/ui/OperationElem.tsx index e217e4225..161003d60 100644 --- a/src/Bladeburner/ui/OperationElem.tsx +++ b/src/Bladeburner/ui/OperationElem.tsx @@ -7,18 +7,17 @@ import { ActionLevel } from "./ActionLevel"; import { Autolevel } from "./Autolevel"; import { StartButton } from "./StartButton"; import { TeamSizeButton } from "./TeamSizeButton"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { Operation } from "../Operation"; import { Operations } from "../data/Operations"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Player } from "../../Player"; import { CopyableText } from "../../ui/React/CopyableText"; import Typography from "@mui/material/Typography"; import Paper from "@mui/material/Paper"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; action: Operation; } @@ -33,7 +32,7 @@ export function OperationElem(props: IProps): React.ReactElement { props.bladeburner.actionTimeCurrent + props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete, ); - const actionTime = props.action.getActionTime(props.bladeburner, props.player); + const actionTime = props.action.getActionTime(props.bladeburner, Player); const actionData = Operations[props.action.name]; if (actionData === undefined) { diff --git a/src/Bladeburner/ui/OperationList.tsx b/src/Bladeburner/ui/OperationList.tsx index e18b8cdc4..610896b6c 100644 --- a/src/Bladeburner/ui/OperationList.tsx +++ b/src/Bladeburner/ui/OperationList.tsx @@ -1,11 +1,9 @@ import React from "react"; import { OperationElem } from "./OperationElem"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function OperationList(props: IProps): React.ReactElement { @@ -14,7 +12,7 @@ export function OperationList(props: IProps): React.ReactElement { return ( <> {names.map((name: string) => ( - + ))} ); diff --git a/src/Bladeburner/ui/OperationPage.tsx b/src/Bladeburner/ui/OperationPage.tsx index 4b5b0a261..c2b212da7 100644 --- a/src/Bladeburner/ui/OperationPage.tsx +++ b/src/Bladeburner/ui/OperationPage.tsx @@ -1,12 +1,10 @@ import * as React from "react"; import { OperationList } from "./OperationList"; -import { IBladeburner } from "../IBladeburner"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; interface IProps { - bladeburner: IBladeburner; - player: IPlayer; + bladeburner: Bladeburner; } export function OperationPage(props: IProps): React.ReactElement { @@ -29,7 +27,7 @@ export function OperationPage(props: IProps): React.ReactElement { You can unlock higher-level operations by successfully completing them. Higher-level operations are more difficult, but grant more rank and experience. - + ); } diff --git a/src/Bladeburner/ui/SkillElem.tsx b/src/Bladeburner/ui/SkillElem.tsx index c51217bd0..e878f4339 100644 --- a/src/Bladeburner/ui/SkillElem.tsx +++ b/src/Bladeburner/ui/SkillElem.tsx @@ -1,7 +1,7 @@ import React from "react"; import { CopyableText } from "../../ui/React/CopyableText"; import { formatNumber } from "../../utils/StringHelperFunctions"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; import IconButton from "@mui/material/IconButton"; @@ -13,7 +13,7 @@ import { Skill } from "../Skill"; interface IProps { skill: Skill; - bladeburner: IBladeburner; + bladeburner: Bladeburner; onUpgrade: () => void; } diff --git a/src/Bladeburner/ui/SkillList.tsx b/src/Bladeburner/ui/SkillList.tsx index c6e801c58..f28b56fc2 100644 --- a/src/Bladeburner/ui/SkillList.tsx +++ b/src/Bladeburner/ui/SkillList.tsx @@ -1,10 +1,10 @@ import * as React from "react"; import { SkillElem } from "./SkillElem"; import { Skills } from "../Skills"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; interface IProps { - bladeburner: IBladeburner; + bladeburner: Bladeburner; onUpgrade: () => void; } diff --git a/src/Bladeburner/ui/SkillPage.tsx b/src/Bladeburner/ui/SkillPage.tsx index 376efc748..44795d62c 100644 --- a/src/Bladeburner/ui/SkillPage.tsx +++ b/src/Bladeburner/ui/SkillPage.tsx @@ -2,10 +2,10 @@ import React, { useState } from "react"; import { SkillList } from "./SkillList"; import { BladeburnerConstants } from "../data/Constants"; import { formatNumber } from "../../utils/StringHelperFunctions"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; interface IProps { - bladeburner: IBladeburner; + bladeburner: Bladeburner; } export function SkillPage(props: IProps): React.ReactElement { diff --git a/src/Bladeburner/ui/StartButton.tsx b/src/Bladeburner/ui/StartButton.tsx index 18f30b869..b7ff5489c 100644 --- a/src/Bladeburner/ui/StartButton.tsx +++ b/src/Bladeburner/ui/StartButton.tsx @@ -1,20 +1,20 @@ import React from "react"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { BlackOperation } from "../BlackOperation"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import Button from "@mui/material/Button"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; +import { ActionIdentifier } from "../ActionIdentifier"; interface IProps { - bladeburner: IBladeburner; + bladeburner: Bladeburner; type: number; name: string; rerender: () => void; } export function StartButton(props: IProps): React.ReactElement { - const player = use.Player(); - const action = props.bladeburner.getActionObject({ name: props.name, type: props.type }); + const action = props.bladeburner.getActionObject(new ActionIdentifier({ name: props.name, type: props.type })); if (action == null) { throw new Error("Failed to get Operation Object for: " + props.name); } @@ -33,8 +33,8 @@ export function StartButton(props: IProps): React.ReactElement { if (disabled) return; props.bladeburner.action.type = props.type; props.bladeburner.action.name = props.name; - if (!player.hasAugmentation(AugmentationNames.BladesSimulacrum, true)) player.finishWork(true); - props.bladeburner.startAction(player, props.bladeburner.action); + if (!Player.hasAugmentation(AugmentationNames.BladesSimulacrum, true)) Player.finishWork(true); + props.bladeburner.startAction(props.bladeburner.action); props.rerender(); } diff --git a/src/Bladeburner/ui/Stats.tsx b/src/Bladeburner/ui/Stats.tsx index 477852b61..a0e6c2417 100644 --- a/src/Bladeburner/ui/Stats.tsx +++ b/src/Bladeburner/ui/Stats.tsx @@ -1,13 +1,13 @@ import React, { useState, useEffect } from "react"; import { formatNumber, convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions"; import { BladeburnerConstants } from "../data/Constants"; -import { IPlayer } from "../../PersonObjects/IPlayer"; +import { Player } from "../../Player"; import { Money } from "../../ui/React/Money"; import { numeralWrapper } from "../../ui/numeralFormat"; import { Factions } from "../../Faction/Factions"; -import { IRouter } from "../../ui/Router"; +import { Router } from "../../ui/GameRoot"; import { joinFaction } from "../../Faction/FactionHelpers"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { TravelModal } from "./TravelModal"; import Typography from "@mui/material/Typography"; @@ -18,9 +18,7 @@ import Paper from "@mui/material/Paper"; import { FactionNames } from "../../Faction/data/FactionNames"; interface IProps { - bladeburner: IBladeburner; - router: IRouter; - player: IPlayer; + bladeburner: Bladeburner; } export function Stats(props: IProps): React.ReactElement { @@ -40,7 +38,7 @@ export function Stats(props: IProps): React.ReactElement { joinFaction(faction); } - props.router.toFaction(faction); + Router.toFaction(faction); } return ( @@ -170,13 +168,13 @@ export function Stats(props: IProps): React.ReactElement { Skill Points: {formatNumber(props.bladeburner.skillPoints, 0)}
    - Aug. Success Chance mult: {formatNumber(props.player.mults.bladeburner_success_chance * 100, 1)}% + Aug. Success Chance mult: {formatNumber(Player.mults.bladeburner_success_chance * 100, 1)}%
    - Aug. Max Stamina mult: {formatNumber(props.player.mults.bladeburner_max_stamina * 100, 1)}% + Aug. Max Stamina mult: {formatNumber(Player.mults.bladeburner_max_stamina * 100, 1)}%
    - Aug. Stamina Gain mult: {formatNumber(props.player.mults.bladeburner_stamina_gain * 100, 1)}% + Aug. Stamina Gain mult: {formatNumber(Player.mults.bladeburner_stamina_gain * 100, 1)}%
    - Aug. Field Analysis mult: {formatNumber(props.player.mults.bladeburner_analysis * 100, 1)}% + Aug. Field Analysis mult: {formatNumber(Player.mults.bladeburner_analysis * 100, 1)}%
    diff --git a/src/Bladeburner/ui/SuccessChance.tsx b/src/Bladeburner/ui/SuccessChance.tsx index 285a730d6..fe39358a5 100644 --- a/src/Bladeburner/ui/SuccessChance.tsx +++ b/src/Bladeburner/ui/SuccessChance.tsx @@ -2,13 +2,13 @@ import React from "react"; import { formatNumber } from "../../utils/StringHelperFunctions"; import { StealthIcon } from "./StealthIcon"; import { KillIcon } from "./KillIcon"; -import { IAction } from "../IAction"; -import { IBladeburner } from "../IBladeburner"; +import { Action } from "../Action"; +import { Bladeburner } from "../Bladeburner"; import { Player } from "../../Player"; interface IProps { - bladeburner: IBladeburner; - action: IAction; + bladeburner: Bladeburner; + action: Action; } export function SuccessChance(props: IProps): React.ReactElement { diff --git a/src/Bladeburner/ui/TeamSizeButton.tsx b/src/Bladeburner/ui/TeamSizeButton.tsx index 81093a23a..9972afb35 100644 --- a/src/Bladeburner/ui/TeamSizeButton.tsx +++ b/src/Bladeburner/ui/TeamSizeButton.tsx @@ -1,12 +1,12 @@ import React, { useState } from "react"; import { Operation } from "../Operation"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { TeamSizeModal } from "./TeamSizeModal"; import { formatNumber } from "../../utils/StringHelperFunctions"; import Button from "@mui/material/Button"; interface IProps { action: Operation; - bladeburner: IBladeburner; + bladeburner: Bladeburner; } export function TeamSizeButton(props: IProps): React.ReactElement { const [open, setOpen] = useState(false); diff --git a/src/Bladeburner/ui/TeamSizeModal.tsx b/src/Bladeburner/ui/TeamSizeModal.tsx index 743f864aa..52a74f621 100644 --- a/src/Bladeburner/ui/TeamSizeModal.tsx +++ b/src/Bladeburner/ui/TeamSizeModal.tsx @@ -2,13 +2,13 @@ import React, { useState } from "react"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { Modal } from "../../ui/React/Modal"; import { Action } from "../Action"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; interface IProps { - bladeburner: IBladeburner; + bladeburner: Bladeburner; action: Action; open: boolean; onClose: () => void; diff --git a/src/Bladeburner/ui/TravelModal.tsx b/src/Bladeburner/ui/TravelModal.tsx index c4e5351db..fb7bcaef5 100644 --- a/src/Bladeburner/ui/TravelModal.tsx +++ b/src/Bladeburner/ui/TravelModal.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { IBladeburner } from "../IBladeburner"; +import { Bladeburner } from "../Bladeburner"; import { WorldMap } from "../../ui/React/WorldMap"; import { Modal } from "../../ui/React/Modal"; import { CityName } from "../../Locations/data/CityNames"; @@ -8,7 +8,7 @@ import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; interface IProps { - bladeburner: IBladeburner; + bladeburner: Bladeburner; open: boolean; onClose: () => void; } diff --git a/src/Casino/Blackjack.tsx b/src/Casino/Blackjack.tsx index 542989e0d..445d59a7b 100644 --- a/src/Casino/Blackjack.tsx +++ b/src/Casino/Blackjack.tsx @@ -1,8 +1,8 @@ import * as React from "react"; -import { IPlayer } from "../PersonObjects/IPlayer"; +import { Player } from "../Player"; import { Money } from "../ui/React/Money"; -import { Game, reachedLimit } from "./Game"; +import { win, reachedLimit } from "./Game"; import { Deck } from "./CardDeck/Deck"; import { Hand } from "./CardDeck/Hand"; import { InputAdornment } from "@mui/material"; @@ -24,10 +24,6 @@ enum Result { Tie = "Push! (Tie)", } -type Props = { - p: IPlayer; -}; - type State = { playerHand: Hand; dealerHand: Hand; @@ -40,11 +36,11 @@ type State = { wagerInvalidHelperText: string; }; -export class Blackjack extends Game { +export class Blackjack extends React.Component, State> { deck: Deck; - constructor(props: Props) { - super(props); + constructor() { + super({}); this.deck = new Deck(DECK_COUNT); @@ -64,20 +60,19 @@ export class Blackjack extends Game { } canStartGame = (): boolean => { - const { p } = this.props; const { bet } = this.state; - return p.canAfford(bet); + return Player.canAfford(bet); }; startGame = (): void => { - if (!this.canStartGame() || reachedLimit(this.props.p)) { + if (!this.canStartGame() || reachedLimit()) { return; } // Take money from player right away so that player's dont just "leave" to avoid the loss (I mean they could // always reload without saving but w.e) TODO: Save/Restore the RNG state to limit the value of save-scumming. - this.props.p.loseMoney(this.state.bet, "casino"); + win(-this.state.bet); const playerHand = new Hand([this.deck.safeDrawCard(), this.deck.safeDrawCard()]); const dealerHand = new Hand([this.deck.safeDrawCard(), this.deck.safeDrawCard()]); @@ -230,7 +225,7 @@ export class Blackjack extends Game { : (() => { throw new Error(`Unexpected result: ${result}`); })(); // This can't happen, right? - this.win(this.props.p, gains); + win(gains); this.setState({ gameInProgress: false, result, @@ -239,7 +234,6 @@ export class Blackjack extends Game { }; wagerOnChange = (event: React.ChangeEvent): void => { - const { p } = this.props; const betInput = event.target.value; const wager = Math.round(parseFloat(betInput)); if (isNaN(wager)) { @@ -263,7 +257,7 @@ export class Blackjack extends Game { wagerInvalid: true, wagerInvalidHelperText: "Exceeds max bet", }); - } else if (!p.canAfford(wager)) { + } else if (!Player.canAfford(wager)) { this.setState({ bet: 0, betInput, diff --git a/src/Casino/CoinFlip.tsx b/src/Casino/CoinFlip.tsx index 17b09488c..32fdae274 100644 --- a/src/Casino/CoinFlip.tsx +++ b/src/Casino/CoinFlip.tsx @@ -5,7 +5,6 @@ */ import React, { useState } from "react"; -import { IPlayer } from "../PersonObjects/IPlayer"; import { BadRNG } from "./RNG"; import { win, reachedLimit } from "./Game"; import { trusted } from "./utils"; @@ -15,14 +14,10 @@ import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import Box from "@mui/material/Box"; -type IProps = { - p: IPlayer; -}; - const minPlay = 0; const maxPlay = 10e3; -export function CoinFlip(props: IProps): React.ReactElement { +export function CoinFlip(): React.ReactElement { const [investment, setInvestment] = useState(1000); const [result, setResult] = useState( ); const [status, setStatus] = useState(""); @@ -43,7 +38,7 @@ export function CoinFlip(props: IProps): React.ReactElement { } function play(guess: string): void { - if (reachedLimit(props.p)) return; + if (reachedLimit()) return; const v = BadRNG.random(); let letter: string; if (v < 0.5) { @@ -65,11 +60,11 @@ export function CoinFlip(props: IProps): React.ReactElement { setTimeout(() => setPlayLock(false), 250); if (correct) { - win(props.p, investment); + win(investment); } else { - win(props.p, -investment); + win(-investment); } - if (reachedLimit(props.p)) return; + if (reachedLimit()) return; } return ( diff --git a/src/Casino/Game.ts b/src/Casino/Game.ts new file mode 100644 index 000000000..1a0d90032 --- /dev/null +++ b/src/Casino/Game.ts @@ -0,0 +1,16 @@ +import { Player } from "../Player"; +import { dialogBoxCreate } from "../ui/React/DialogBox"; + +const gainLimit = 10e9; + +export function win(n: number): void { + Player.gainMoney(n, "casino"); +} + +export function reachedLimit(): boolean { + const reached = Player.getCasinoWinnings() > gainLimit; + if (reached) { + dialogBoxCreate("Alright cheater get out of here. You're not allowed here anymore."); + } + return reached; +} diff --git a/src/Casino/Game.tsx b/src/Casino/Game.tsx deleted file mode 100644 index 1da783d28..000000000 --- a/src/Casino/Game.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import * as React from "react"; -import { IPlayer } from "../PersonObjects/IPlayer"; -import { dialogBoxCreate } from "../ui/React/DialogBox"; - -const gainLimit = 10e9; - -export function win(p: IPlayer, n: number): void { - p.gainMoney(n, "casino"); -} - -export function reachedLimit(p: IPlayer): boolean { - const reached = p.getCasinoWinnings() > gainLimit; - if (reached) { - dialogBoxCreate(<>Alright cheater get out of here. You're not allowed here anymore.); - } - return reached; -} - -export class Game extends React.Component { - win(p: IPlayer, n: number): void { - p.gainMoney(n, "casino"); - } - - reachedLimit(p: IPlayer): boolean { - const reached = p.getCasinoWinnings() > gainLimit; - if (reached) { - dialogBoxCreate(<>Alright cheater get out of here. You're not allowed here anymore.); - } - return reached; - } -} diff --git a/src/Casino/Roulette.tsx b/src/Casino/Roulette.tsx index da1dd59d2..f45af1cb3 100644 --- a/src/Casino/Roulette.tsx +++ b/src/Casino/Roulette.tsx @@ -1,6 +1,5 @@ import React, { useState, useEffect } from "react"; -import { IPlayer } from "../PersonObjects/IPlayer"; import { Money } from "../ui/React/Money"; import { win, reachedLimit } from "./Game"; import { WHRNG } from "./RNG"; @@ -9,10 +8,6 @@ import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; -type IProps = { - p: IPlayer; -}; - const minPlay = 0; const maxPlay = 1e7; @@ -111,7 +106,7 @@ function Single(s: number): Strategy { }; } -export function Roulette(props: IProps): React.ReactElement { +export function Roulette(): React.ReactElement { const [rng] = useState(new WHRNG(new Date().getTime())); const [investment, setInvestment] = useState(1000); const [canPlay, setCanPlay] = useState(true); @@ -151,7 +146,7 @@ export function Roulette(props: IProps): React.ReactElement { } function play(strategy: Strategy): void { - if (reachedLimit(props.p)) return; + if (reachedLimit()) return; setCanPlay(false); setLock(false); @@ -184,14 +179,14 @@ export function Roulette(props: IProps): React.ReactElement { ); } - win(props.p, gain); + win(gain); setCanPlay(true); setLock(true); setStatus(status); setN(n); - reachedLimit(props.p); + reachedLimit(); }, 1600); } diff --git a/src/Casino/SlotMachine.tsx b/src/Casino/SlotMachine.tsx index a7fdbd083..6655f041b 100644 --- a/src/Casino/SlotMachine.tsx +++ b/src/Casino/SlotMachine.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react"; -import { IPlayer } from "../PersonObjects/IPlayer"; +import { Player } from "../Player"; import { Money } from "../ui/React/Money"; import { WHRNG } from "./RNG"; import { win, reachedLimit } from "./Game"; @@ -9,10 +9,6 @@ import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; -type IProps = { - p: IPlayer; -}; - // statically shuffled array of symbols. const symbols = [ "D", @@ -141,8 +137,8 @@ const payLines = [ const minPlay = 0; const maxPlay = 1e6; -export function SlotMachine(props: IProps): React.ReactElement { - const [rng] = useState(new WHRNG(props.p.totalPlaytime)); +export function SlotMachine(): React.ReactElement { + const [rng] = useState(new WHRNG(Player.totalPlaytime)); const [index, setIndex] = useState([0, 0, 0, 0, 0]); const [locks, setLocks] = useState([0, 0, 0, 0, 0]); const [investment, setInvestment] = useState(1000); @@ -191,9 +187,9 @@ export function SlotMachine(props: IProps): React.ReactElement { } function play(): void { - if (reachedLimit(props.p)) return; + if (reachedLimit()) return; setStatus("playing"); - win(props.p, -investment); + win(-investment); if (!canPlay) return; unlock(); setTimeout(lock, rng.random() * 2000 + 1000); @@ -235,7 +231,7 @@ export function SlotMachine(props: IProps): React.ReactElement { if (count < 3) continue; const payout = getPayout(data[0], count - 3); gains += investment * payout; - win(props.p, investment * payout); + win(investment * payout); } setStatus( @@ -244,7 +240,7 @@ export function SlotMachine(props: IProps): React.ReactElement { , ); setCanPlay(true); - if (reachedLimit(props.p)) return; + if (reachedLimit()) return; } function unlock(): void { diff --git a/src/Company/Companies.ts b/src/Company/Companies.ts index 0847795eb..7ad6d9d39 100644 --- a/src/Company/Companies.ts +++ b/src/Company/Companies.ts @@ -29,7 +29,7 @@ export function initCompanies(): void { for (const companyName of Object.keys(Companies)) { const company = Companies[companyName]; const oldCompany = oldCompanies[companyName]; - if (!(oldCompany instanceof Company)) { + if (!oldCompany) { // New game, so no OldCompanies data company.favor = 0; } else { diff --git a/src/Company/Company.ts b/src/Company/Company.ts index 49473c6d4..492ed4ad3 100644 --- a/src/Company/Company.ts +++ b/src/Company/Company.ts @@ -88,11 +88,7 @@ export class Company { } hasPosition(pos: CompanyPosition | string): boolean { - if (pos instanceof CompanyPosition) { - return this.companyPositions[pos.name] != null; - } else { - return this.companyPositions[pos] != null; - } + return this.companyPositions[typeof pos === "string" ? pos : pos.name] != null; } hasAgentPositions(): boolean { diff --git a/src/Company/ui/QuitJobModal.tsx b/src/Company/ui/QuitJobModal.tsx index 7ee05b506..0b766c28a 100644 --- a/src/Company/ui/QuitJobModal.tsx +++ b/src/Company/ui/QuitJobModal.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Company } from "../Company"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Modal } from "../../ui/React/Modal"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -14,9 +14,8 @@ interface IProps { } export function QuitJobModal(props: IProps): React.ReactElement { - const player = use.Player(); function quit(): void { - player.quitJob(props.locName); + Player.quitJob(props.locName); props.onQuit(); props.onClose(); } diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index bf53d1e2f..3b65654a7 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -1,9 +1,6 @@ import { Player } from "../Player"; -import { IPlayer } from "src/PersonObjects/IPlayer"; import { MaterialSizes } from "./MaterialSizes"; -import { ICorporation } from "./ICorporation"; import { Corporation } from "./Corporation"; -import { IIndustry } from "./IIndustry"; import { IndustryStartingCosts, IndustryResearchTrees } from "./IndustryData"; import { Industry } from "./Industry"; import { CorporationConstants } from "./data/Constants"; @@ -18,7 +15,7 @@ import { EmployeePositions } from "./EmployeePositions"; import { ResearchMap } from "./ResearchMap"; import { isRelevantMaterial } from "./ui/Helpers"; -export function NewIndustry(corporation: ICorporation, industry: string, name: string): void { +export function NewIndustry(corporation: Corporation, industry: string, name: string): void { if (corporation.divisions.find(({ type }) => industry == type)) throw new Error(`You have already expanded into the ${industry} industry!`); @@ -48,7 +45,7 @@ export function NewIndustry(corporation: ICorporation, industry: string, name: s } } -export function NewCity(corporation: ICorporation, division: IIndustry, city: string): void { +export function NewCity(corporation: Corporation, division: Industry, city: string): void { if (corporation.funds < CorporationConstants.OfficeInitialCost) { throw new Error("You don't have enough company funds to open a new office!"); } @@ -62,7 +59,7 @@ export function NewCity(corporation: ICorporation, division: IIndustry, city: st }); } -export function UnlockUpgrade(corporation: ICorporation, upgrade: CorporationUnlockUpgrade): void { +export function UnlockUpgrade(corporation: Corporation, upgrade: CorporationUnlockUpgrade): void { if (corporation.funds < upgrade.price) { throw new Error("Insufficient funds"); } @@ -72,7 +69,7 @@ export function UnlockUpgrade(corporation: ICorporation, upgrade: CorporationUnl corporation.unlock(upgrade); } -export function LevelUpgrade(corporation: ICorporation, upgrade: CorporationUpgrade): void { +export function LevelUpgrade(corporation: Corporation, upgrade: CorporationUpgrade): void { const baseCost = upgrade.basePrice; const priceMult = upgrade.priceMult; const level = corporation.upgrades[upgrade.index]; @@ -84,7 +81,7 @@ export function LevelUpgrade(corporation: ICorporation, upgrade: CorporationUpgr } } -export function IssueDividends(corporation: ICorporation, rate: number): void { +export function IssueDividends(corporation: Corporation, rate: number): void { if (isNaN(rate) || rate < 0 || rate > CorporationConstants.DividendMaxRate) { throw new Error(`Invalid value. Must be an number between 0 and ${CorporationConstants.DividendMaxRate}`); } @@ -253,7 +250,7 @@ export function BuyMaterial(material: Material, amt: number): void { material.buy = amt; } -export function BulkPurchase(corp: ICorporation, warehouse: Warehouse, material: Material, amt: number): void { +export function BulkPurchase(corp: Corporation, warehouse: Warehouse, material: Material, amt: number): void { const matSize = MaterialSizes[material.name]; const maxAmount = (warehouse.size - warehouse.sizeUsed) / matSize; if (isNaN(amt) || amt < 0) { @@ -271,7 +268,7 @@ export function BulkPurchase(corp: ICorporation, warehouse: Warehouse, material: } } -export function SellShares(corporation: ICorporation, player: IPlayer, numShares: number): number { +export function SellShares(corporation: Corporation, numShares: number): number { if (isNaN(numShares)) throw new Error("Invalid value for number of shares"); if (numShares < 0) throw new Error("Invalid value for number of shares"); if (numShares > corporation.numShares) throw new Error("You don't have that many shares to sell!"); @@ -287,20 +284,20 @@ export function SellShares(corporation: ICorporation, player: IPlayer, numShares corporation.sharePrice = newSharePrice; corporation.shareSalesUntilPriceUpdate = newSharesUntilUpdate; corporation.shareSaleCooldown = CorporationConstants.SellSharesCooldown; - player.gainMoney(profit, "corporation"); + Player.gainMoney(profit, "corporation"); return profit; } -export function BuyBackShares(corporation: ICorporation, player: IPlayer, numShares: number): boolean { +export function BuyBackShares(corporation: Corporation, numShares: number): boolean { if (isNaN(numShares)) throw new Error("Invalid value for number of shares"); if (numShares < 0) throw new Error("Invalid value for number of shares"); if (numShares > corporation.issuedShares) throw new Error("You don't have that many shares to buy!"); if (!corporation.public) throw new Error("You haven't gone public!"); const buybackPrice = corporation.sharePrice * 1.1; - if (player.money < numShares * buybackPrice) throw new Error("You cant afford that many shares!"); + if (Player.money < numShares * buybackPrice) throw new Error("You cant afford that many shares!"); corporation.numShares += numShares; corporation.issuedShares -= numShares; - player.loseMoney(numShares * buybackPrice, "corporation"); + Player.loseMoney(numShares * buybackPrice, "corporation"); return true; } @@ -319,7 +316,7 @@ export function AutoAssignJob(office: OfficeSpace, job: string, count: number): return office.autoAssignJob(job, count); } -export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size: number): void { +export function UpgradeOfficeSize(corp: Corporation, office: OfficeSpace, size: number): void { const initialPriceMult = Math.round(office.size / CorporationConstants.OfficeInitialSize); const costMultiplier = 1.09; // Calculate cost to upgrade size by 15 employees @@ -333,7 +330,7 @@ export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size: corp.funds = corp.funds - cost; } -export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean { +export function BuyCoffee(corp: Corporation, office: OfficeSpace): boolean { const cost = office.getCoffeeCost(); if (corp.funds < cost) { return false; @@ -347,7 +344,7 @@ export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean { return true; } -export function ThrowParty(corp: ICorporation, office: OfficeSpace, costPerEmployee: number): number { +export function ThrowParty(corp: Corporation, office: OfficeSpace, costPerEmployee: number): number { const mult = 1 + costPerEmployee / 10e6; const cost = costPerEmployee * office.employees.length; if (corp.funds < cost) { @@ -362,9 +359,9 @@ export function ThrowParty(corp: ICorporation, office: OfficeSpace, costPerEmplo return mult; } -export function PurchaseWarehouse(corp: ICorporation, division: IIndustry, city: string): void { +export function PurchaseWarehouse(corp: Corporation, division: Industry, city: string): void { if (corp.funds < CorporationConstants.WarehouseInitialCost) return; - if (division.warehouses[city] instanceof Warehouse) return; + if (division.warehouses[city]) return; division.warehouses[city] = new Warehouse({ corp: corp, industry: division, @@ -381,7 +378,7 @@ export function UpgradeWarehouseCost(warehouse: Warehouse, amt: number): number ); } -export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, warehouse: Warehouse, amt = 1): void { +export function UpgradeWarehouse(corp: Corporation, division: Industry, warehouse: Warehouse, amt = 1): void { const sizeUpgradeCost = UpgradeWarehouseCost(warehouse, amt); if (corp.funds < sizeUpgradeCost) return; warehouse.level += amt; @@ -389,7 +386,7 @@ export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, wareho corp.funds = corp.funds - sizeUpgradeCost; } -export function HireAdVert(corp: ICorporation, division: IIndustry): void { +export function HireAdVert(corp: Corporation, division: Industry): void { const cost = division.getAdVertCost(); if (corp.funds < cost) return; corp.funds = corp.funds - cost; @@ -397,8 +394,8 @@ export function HireAdVert(corp: ICorporation, division: IIndustry): void { } export function MakeProduct( - corp: ICorporation, - division: IIndustry, + corp: Corporation, + division: Industry, city: string, productName: string, designInvest: number, @@ -442,7 +439,7 @@ export function MakeProduct( designCost: designInvest, advCost: marketingInvest, }); - if (products[product.name] instanceof Product) { + if (products[product.name]) { throw new Error(`You already have a product with this name!`); } @@ -450,7 +447,7 @@ export function MakeProduct( products[product.name] = product; } -export function Research(division: IIndustry, researchName: string): void { +export function Research(division: Industry, researchName: string): void { const researchTree = IndustryResearchTrees[division.type]; if (researchTree === undefined) throw new Error(`No research tree for industry '${division.type}'`); const allResearch = researchTree.getAllNodes(); @@ -473,10 +470,10 @@ export function Research(division: IIndustry, researchName: string): void { for (let i = 0; i < CorporationConstants.Cities.length; ++i) { const city = CorporationConstants.Cities[i]; const warehouse = division.warehouses[city]; - if (!(warehouse instanceof Warehouse)) { + if (!warehouse) { continue; } - if (Player.corporation instanceof Corporation) { + if (Player.corporation) { // Stores cycles in a "buffer". Processed separately using Engine Counters warehouse.updateSize(Player.corporation, division); } diff --git a/src/Corporation/Corporation.tsx b/src/Corporation/Corporation.tsx index cf6ac9125..dacb5ea24 100644 --- a/src/Corporation/Corporation.tsx +++ b/src/Corporation/Corporation.tsx @@ -1,14 +1,13 @@ import { CorporationState } from "./CorporationState"; import { CorporationUnlockUpgrade, CorporationUnlockUpgrades } from "./data/CorporationUnlockUpgrades"; import { CorporationUpgrade, CorporationUpgrades } from "./data/CorporationUpgrades"; -import { Warehouse } from "./Warehouse"; import { CorporationConstants } from "./data/Constants"; import { Industry } from "./Industry"; import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers"; import { showLiterature } from "../Literature/LiteratureHelpers"; import { LiteratureNames } from "../Literature/data/LiteratureNames"; -import { IPlayer } from "../PersonObjects/IPlayer"; +import { Player } from "../Player"; import { dialogBoxCreate } from "../ui/React/DialogBox"; import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver"; @@ -76,7 +75,7 @@ export class Corporation { this.storedCycles += numCycles; } - process(player: IPlayer): void { + process(): void { if (this.storedCycles >= CorporationConstants.CyclesPerIndustryStateCycle) { const state = this.getState(); const marketCycles = 1; @@ -120,7 +119,7 @@ export class Corporation { if (isNaN(this.funds) || this.funds === Infinity || this.funds === -Infinity) { dialogBoxCreate( "There was an error calculating your Corporations funds and they got reset to 0. " + - "This is a bug. Please report to game developer.

    " + + "This is a bug. Please report to game developer.\n\n" + "(Your funds have been set to $150b for the inconvenience)", ); this.funds = 150e9; @@ -139,7 +138,7 @@ export class Corporation { } else { const totalDividends = this.dividendRate * cycleProfit; const retainedEarnings = cycleProfit - totalDividends; - player.gainMoney(this.getCycleDividends(), "corporation"); + Player.gainMoney(this.getCycleDividends(), "corporation"); this.addFunds(retainedEarnings); } } else { @@ -331,7 +330,7 @@ export class Corporation { for (const city of Object.keys(industry.warehouses)) { const warehouse = industry.warehouses[city]; if (warehouse === 0) continue; - if (industry.warehouses.hasOwnProperty(city) && warehouse instanceof Warehouse) { + if (industry.warehouses.hasOwnProperty(city) && warehouse) { warehouse.updateSize(this, industry); } } @@ -428,9 +427,9 @@ export class Corporation { // Adds the Corporation Handbook (Starter Guide) to the player's home computer. // This is a lit file that gives introductory info to the player // This occurs when the player clicks the "Getting Started Guide" button on the overview panel - getStarterGuide(player: IPlayer): void { + getStarterGuide(): void { // Check if player already has Corporation Handbook - const homeComp = player.getHomeComputer(); + const homeComp = Player.getHomeComputer(); let hasHandbook = false; const handbookFn = LiteratureNames.CorporationManagementHandbook; for (let i = 0; i < homeComp.messages.length; ++i) { diff --git a/src/Corporation/Employee.ts b/src/Corporation/Employee.ts index a8c71e636..8cbd5e9cb 100644 --- a/src/Corporation/Employee.ts +++ b/src/Corporation/Employee.ts @@ -2,8 +2,8 @@ import { CorporationConstants } from "./data/Constants"; import { getRandomInt } from "../utils/helpers/getRandomInt"; import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver"; import { EmployeePositions } from "./EmployeePositions"; -import { ICorporation } from "./ICorporation"; -import { IIndustry } from "./IIndustry"; +import { Corporation } from "./Corporation"; +import { Industry } from "./Industry"; interface IParams { name?: string; @@ -77,7 +77,7 @@ export class Employee { return salary; } - calculateProductivity(corporation: ICorporation, industry: IIndustry): number { + calculateProductivity(corporation: Corporation, industry: Industry): number { const effCre = this.cre * corporation.getEmployeeCreMultiplier() * industry.getEmployeeCreMultiplier(), effCha = this.cha * corporation.getEmployeeChaMultiplier() * industry.getEmployeeChaMultiplier(), effInt = this.int * corporation.getEmployeeIntMultiplier() * industry.getEmployeeIntMultiplier(), diff --git a/src/Corporation/ICorporation.ts b/src/Corporation/ICorporation.ts deleted file mode 100644 index 4165d48a8..000000000 --- a/src/Corporation/ICorporation.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Industry } from "./Industry"; -import { IPlayer } from "../PersonObjects/IPlayer"; -import { CorporationUnlockUpgrade } from "./data/CorporationUnlockUpgrades"; -import { CorporationUpgrade } from "./data/CorporationUpgrades"; -import { CorporationState } from "./CorporationState"; -import { IReviverValue } from "../utils/JSONReviver"; - -export interface ICorporation { - name: string; - - divisions: Industry[]; - - funds: number; - revenue: number; - expenses: number; - fundingRound: number; - public: boolean; - totalShares: number; - numShares: number; - shareSalesUntilPriceUpdate: number; - shareSaleCooldown: number; - issueNewSharesCooldown: number; - dividendRate: number; - dividendTax: number; - issuedShares: number; - sharePrice: number; - storedCycles: number; - valuation: number; - - unlockUpgrades: number[]; - upgrades: number[]; - upgradeMultipliers: number[]; - - state: CorporationState; - - addFunds(amt: number): void; - getState(): string; - storeCycles(numCycles: number): void; - process(player: IPlayer): void; - determineValuation(): void; - determineCycleValuation(): number; - getTargetSharePrice(): number; - updateSharePrice(): void; - immediatelyUpdateSharePrice(): void; - calculateShareSale(numShares: number): [number, number, number]; - convertCooldownToString(cd: number): string; - unlock(upgrade: CorporationUnlockUpgrade): void; - upgrade(upgrade: CorporationUpgrade): void; - getProductionMultiplier(): number; - getStorageMultiplier(): number; - getDreamSenseGain(): number; - getAdvertisingMultiplier(): number; - getEmployeeCreMultiplier(): number; - getEmployeeChaMultiplier(): number; - getEmployeeIntMultiplier(): number; - getEmployeeEffMultiplier(): number; - getSalesMultiplier(): number; - getScientificResearchMultiplier(): number; - getStarterGuide(player: IPlayer): void; - updateDividendTax(): void; - getCycleDividends(): number; - toJSON(): IReviverValue; -} diff --git a/src/Corporation/IIndustry.ts b/src/Corporation/IIndustry.ts deleted file mode 100644 index 0ea8646a1..000000000 --- a/src/Corporation/IIndustry.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Material } from "./Material"; -import { Warehouse } from "./Warehouse"; -import { ICorporation } from "./ICorporation"; -import { OfficeSpace } from "./OfficeSpace"; -import { Product } from "./Product"; -import { IReviverValue } from "../utils/JSONReviver"; - -export interface IIndustry { - name: string; - type: string; - sciResearch: Material; - researched: { [key: string]: boolean | undefined }; - reqMats: { [key: string]: number | undefined }; - - prodMats: string[]; - - products: { [key: string]: Product | undefined }; - makesProducts: boolean; - - awareness: number; - popularity: number; - startingCost: number; - - reFac: number; - sciFac: number; - hwFac: number; - robFac: number; - aiFac: number; - advFac: number; - - prodMult: number; - - // Decimal - lastCycleRevenue: number; - lastCycleExpenses: number; - thisCycleRevenue: number; - thisCycleExpenses: number; - - state: string; - newInd: boolean; - warehouses: { [key: string]: Warehouse | 0 }; - offices: { [key: string]: OfficeSpace | 0 }; - numAdVerts: number; - - init(): void; - getProductDescriptionText(): string; - getMaximumNumberProducts(): number; - hasMaximumNumberProducts(): boolean; - calculateProductionFactors(): void; - updateWarehouseSizeUsed(warehouse: Warehouse): void; - process(marketCycles: number, state: string, corporation: ICorporation): void; - processMaterialMarket(): void; - processProductMarket(marketCycles: number): void; - processMaterials(marketCycles: number, corporation: ICorporation): [number, number]; - processProducts(marketCycles: number, corporation: ICorporation): [number, number]; - processProduct(marketCycles: number, product: Product, corporation: ICorporation): number; - resetImports(state: string): void; - discontinueProduct(product: Product): void; - getAdVertCost(): number; - applyAdVert(corporation: ICorporation): void; - getOfficeProductivity(office: OfficeSpace, params?: { forProduct?: boolean }): number; - getBusinessFactor(office: OfficeSpace): number; - getAdvertisingFactors(): [number, number, number, number]; - getMarketFactor(mat: { dmd: number; cmp: number }): number; - hasResearch(name: string): boolean; - updateResearchTree(): void; - getAdvertisingMultiplier(): number; - getEmployeeChaMultiplier(): number; - getEmployeeCreMultiplier(): number; - getEmployeeEffMultiplier(): number; - getEmployeeIntMultiplier(): number; - getProductionMultiplier(): number; - getProductProductionMultiplier(): number; - getSalesMultiplier(): number; - getScientificResearchMultiplier(): number; - getStorageMultiplier(): number; - toJSON(): IReviverValue; -} diff --git a/src/Corporation/Industry.ts b/src/Corporation/Industry.ts index 8ec68f26f..fe1a6d8a8 100644 --- a/src/Corporation/Industry.ts +++ b/src/Corporation/Industry.ts @@ -12,16 +12,15 @@ import { dialogBoxCreate } from "../ui/React/DialogBox"; import { isString } from "../utils/helpers/isString"; import { MaterialSizes } from "./MaterialSizes"; import { Warehouse } from "./Warehouse"; -import { ICorporation } from "./ICorporation"; -import { IIndustry } from "./IIndustry"; +import { Corporation } from "./Corporation"; interface IParams { name?: string; - corp?: ICorporation; + corp?: Corporation; type?: string; } -export class Industry implements IIndustry { +export class Industry { name = ""; type = Industries.Agriculture; sciResearch = new Material({ name: "Scientific Research" }); @@ -356,9 +355,7 @@ export class Industry implements IIndustry { for (let i = 0; i < CorporationConstants.Cities.length; ++i) { const city = CorporationConstants.Cities[i]; const warehouse = this.warehouses[city]; - if (!(warehouse instanceof Warehouse)) { - continue; - } + if (!warehouse) continue; const materials = warehouse.materials; @@ -385,7 +382,7 @@ export class Industry implements IIndustry { } } - process(marketCycles = 1, state: string, corporation: ICorporation): void { + process(marketCycles = 1, state: string, corporation: Corporation): void { this.state = state; //At the start of a cycle, store and reset revenue/expenses @@ -414,10 +411,7 @@ export class Industry implements IIndustry { let employeeSalary = 0; for (const officeLoc of Object.keys(this.offices)) { const office = this.offices[officeLoc]; - if (office === 0) continue; - if (office instanceof OfficeSpace) { - employeeSalary += office.process(marketCycles, corporation, this); - } + if (office) employeeSalary += office.process(marketCycles, corporation, this); } this.thisCycleExpenses = this.thisCycleExpenses + employeeSalary; @@ -468,7 +462,7 @@ export class Industry implements IIndustry { for (let i = 0; i < CorporationConstants.Cities.length; ++i) { //If this industry has a warehouse in this city, process the market //for every material this industry requires or produces - if (this.warehouses[CorporationConstants.Cities[i]] instanceof Warehouse) { + if (this.warehouses[CorporationConstants.Cities[i]]) { const wh = this.warehouses[CorporationConstants.Cities[i]]; if (wh === 0) continue; for (const name of Object.keys(reqMats)) { @@ -518,7 +512,7 @@ export class Industry implements IIndustry { } //Process production, purchase, and import/export of materials - processMaterials(marketCycles = 1, corporation: ICorporation): [number, number] { + processMaterials(marketCycles = 1, corporation: Corporation): [number, number] { let revenue = 0, expenses = 0; this.calculateProductionFactors(); @@ -528,7 +522,7 @@ export class Industry implements IIndustry { const office = this.offices[city]; if (office === 0) continue; - if (this.warehouses[city] instanceof Warehouse) { + if (this.warehouses[city]) { const warehouse = this.warehouses[city]; if (warehouse === 0) continue; @@ -825,14 +819,7 @@ export class Industry implements IIndustry { sellAmt = eval(tmp); } catch (e) { dialogBoxCreate( - "Error evaluating your sell amount for material " + - mat.name + - " in " + - this.name + - "'s " + - city + - " office. The sell amount " + - "is being set to zero", + `Error evaluating your sell amount for material ${mat.name} in ${this.name}'s ${city} office. The sell amount is being set to zero`, ); sellAmt = 0; } @@ -879,27 +866,13 @@ export class Industry implements IIndustry { amt = eval(amtStr); } catch (e) { dialogBoxCreate( - "Calculating export for " + - mat.name + - " in " + - this.name + - "'s " + - city + - " division failed with " + - "error: " + - e, + `Calculating export for ${mat.name} in ${this.name}'s ${city} division failed with error: ${e}`, ); continue; } if (isNaN(amt)) { dialogBoxCreate( - "Error calculating export amount for " + - mat.name + - " in " + - this.name + - "'s " + - city + - " division.", + `Error calculating export amount for ${mat.name} in ${this.name}'s ${city} division.`, ); continue; } @@ -915,7 +888,7 @@ export class Industry implements IIndustry { if (corporation.divisions[foo].name === exp.ind) { const expIndustry = corporation.divisions[foo]; const expWarehouse = expIndustry.warehouses[exp.city]; - if (!(expWarehouse instanceof Warehouse)) { + if (!expWarehouse) { console.error(`Invalid export! ${expIndustry.name} ${exp.city}`); break; } @@ -958,7 +931,7 @@ export class Industry implements IIndustry { //Produce Scientific Research based on R&D employees //Scientific Research can be produced without a warehouse - if (office instanceof OfficeSpace) { + if (office) { this.sciResearch.qty += 0.004 * Math.pow(office.employeeProd[EmployeePositions.RandD], 0.5) * @@ -970,7 +943,7 @@ export class Industry implements IIndustry { } //Process production & sale of this industry's FINISHED products (including all of their stats) - processProducts(marketCycles = 1, corporation: ICorporation): [number, number] { + processProducts(marketCycles = 1, corporation: Corporation): [number, number] { let revenue = 0; const expenses = 0; @@ -997,7 +970,7 @@ export class Industry implements IIndustry { for (const prodName of Object.keys(this.products)) { if (this.products.hasOwnProperty(prodName)) { const prod = this.products[prodName]; - if (prod instanceof Product && prod.fin) { + if (prod && prod.fin) { revenue += this.processProduct(marketCycles, prod, corporation); } } @@ -1006,14 +979,14 @@ export class Industry implements IIndustry { } //Processes FINISHED products - processProduct(marketCycles = 1, product: Product, corporation: ICorporation): number { + processProduct(marketCycles = 1, product: Product, corporation: Corporation): number { let totalProfit = 0; for (let i = 0; i < CorporationConstants.Cities.length; ++i) { const city = CorporationConstants.Cities[i]; const office = this.offices[city]; if (office === 0) continue; const warehouse = this.warehouses[city]; - if (warehouse instanceof Warehouse) { + if (warehouse) { switch (this.state) { case "PRODUCTION": { //Calculate the maximum production of this material based @@ -1172,13 +1145,7 @@ export class Industry implements IIndustry { tmp = eval(tmp); } catch (e) { dialogBoxCreate( - "Error evaluating your sell price expression for " + - product.name + - " in " + - this.name + - "'s " + - city + - " office. Sell price is being set to MAX", + `Error evaluating your sell price expression for ${product.name} in ${this.name}'s ${city} office. Sell price is being set to MAX`, ); tmp = product.maxsll; } @@ -1223,7 +1190,7 @@ export class Industry implements IIndustry { if (state === "EXPORT") { for (let i = 0; i < CorporationConstants.Cities.length; ++i) { const city = CorporationConstants.Cities[i]; - if (!(this.warehouses[city] instanceof Warehouse)) { + if (!this.warehouses[city]) { continue; } const warehouse = this.warehouses[city]; @@ -1252,7 +1219,7 @@ export class Industry implements IIndustry { return 1e9 * Math.pow(1.06, this.numAdVerts); } - applyAdVert(corporation: ICorporation): void { + applyAdVert(corporation: Corporation): void { const advMult = corporation.getAdvertisingMultiplier() * this.getAdvertisingMultiplier(); const awareness = (this.awareness + 3 * advMult) * (1.01 * advMult); this.awareness = Math.min(awareness, Number.MAX_VALUE); diff --git a/src/Corporation/IndustryData.tsx b/src/Corporation/IndustryData.tsx index d2ae99dd3..0608129ef 100644 --- a/src/Corporation/IndustryData.tsx +++ b/src/Corporation/IndustryData.tsx @@ -1,6 +1,6 @@ import React from "react"; import { ResearchTree } from "./ResearchTree"; -import { ICorporation } from "./ICorporation"; +import { Corporation } from "./Corporation"; import { getBaseResearchTreeCopy, getProductIndustryResearchTreeCopy } from "./data/BaseResearchTree"; import { MoneyCost } from "./ui/MoneyCost"; @@ -59,8 +59,8 @@ export const IndustryStartingCosts: IIndustryMap = { }; // Map of description for each industry -export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.ReactElement> = { - Energy: (corp: ICorporation) => ( +export const IndustryDescriptions: IIndustryMap<(corp: Corporation) => React.ReactElement> = { + Energy: (corp: Corporation) => ( <> Engage in the production and distribution of energy.
    @@ -70,7 +70,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Utilities: (corp: ICorporation) => ( + Utilities: (corp: Corporation) => ( <> Distribute water and provide wastewater services.
    @@ -80,7 +80,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Agriculture: (corp: ICorporation) => ( + Agriculture: (corp: Corporation) => ( <> Cultivate crops and breed livestock to produce food.
    @@ -90,7 +90,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: YES ), - Fishing: (corp: ICorporation) => ( + Fishing: (corp: Corporation) => ( <> Produce food through the breeding and processing of fish and fish products.
    @@ -100,7 +100,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Mining: (corp: ICorporation) => ( + Mining: (corp: Corporation) => ( <> Extract and process metals from the earth.
    @@ -110,7 +110,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Food: (corp: ICorporation) => ( + Food: (corp: Corporation) => ( <> Create your own restaurants all around the world.
    @@ -120,7 +120,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: YES ), - Tobacco: (corp: ICorporation) => ( + Tobacco: (corp: Corporation) => ( <> Create and distribute tobacco and tobacco-related products.
    @@ -130,7 +130,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: YES ), - Chemical: (corp: ICorporation) => ( + Chemical: (corp: Corporation) => ( <> Produce industrial chemicals.
    @@ -140,7 +140,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Pharmaceutical: (corp: ICorporation) => ( + Pharmaceutical: (corp: Corporation) => ( <> Discover, develop, and create new pharmaceutical drugs.
    @@ -150,7 +150,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Computer: (corp: ICorporation) => ( + Computer: (corp: Corporation) => ( <> Develop and manufacture new computer hardware and networking infrastructures.
    @@ -160,7 +160,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Robotics: (corp: ICorporation) => ( + Robotics: (corp: Corporation) => ( <> Develop and create robots.
    @@ -170,7 +170,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - Software: (corp: ICorporation) => ( + Software: (corp: Corporation) => ( <> Develop computer software and create AI Cores.
    @@ -180,7 +180,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: YES ), - Healthcare: (corp: ICorporation) => ( + Healthcare: (corp: Corporation) => ( <> Create and manage hospitals.
    @@ -190,7 +190,7 @@ export const IndustryDescriptions: IIndustryMap<(corp: ICorporation) => React.Re Recommended starting Industry: NO ), - RealEstate: (corp: ICorporation) => ( + RealEstate: (corp: Corporation) => ( <> Develop and manage real estate properties.
    diff --git a/src/Corporation/OfficeSpace.ts b/src/Corporation/OfficeSpace.ts index 766e1b670..eba259395 100644 --- a/src/Corporation/OfficeSpace.ts +++ b/src/Corporation/OfficeSpace.ts @@ -4,8 +4,8 @@ import { getRandomInt } from "../utils/helpers/getRandomInt"; import { generateRandomString } from "../utils/StringHelperFunctions"; import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver"; import { Employee } from "./Employee"; -import { IIndustry } from "./IIndustry"; -import { ICorporation } from "./ICorporation"; +import { Industry } from "./Industry"; +import { Corporation } from "./Corporation"; interface IParams { loc?: string; @@ -68,7 +68,7 @@ export class OfficeSpace { return this.employees.length >= this.size; } - process(marketCycles = 1, corporation: ICorporation, industry: IIndustry): number { + process(marketCycles = 1, corporation: Corporation, industry: Industry): number { // HRBuddy AutoRecruitment and training if (industry.hasResearch("HRBuddy-Recruitment") && !this.atCapacity()) { const emp = this.hireRandomEmployee(); @@ -177,7 +177,7 @@ export class OfficeSpace { } } - calculateEmployeeProductivity(corporation: ICorporation, industry: IIndustry): void { + calculateEmployeeProductivity(corporation: Corporation, industry: Industry): void { //Reset for (const name of Object.keys(this.employeeProd)) { this.employeeProd[name] = 0; diff --git a/src/Corporation/Product.ts b/src/Corporation/Product.ts index 815c284c3..e85380372 100644 --- a/src/Corporation/Product.ts +++ b/src/Corporation/Product.ts @@ -1,6 +1,6 @@ import { EmployeePositions } from "./EmployeePositions"; import { MaterialSizes } from "./MaterialSizes"; -import { IIndustry } from "./IIndustry"; +import { Industry } from "./Industry"; import { ProductRatingWeights, IProductRatingWeight } from "./ProductRatingWeights"; import { createCityMap } from "../Locations/createCityMap"; @@ -157,7 +157,7 @@ export class Product { } // @param industry - Industry object. Reference to industry that makes this Product - finishProduct(industry: IIndustry): void { + finishProduct(industry: Industry): void { this.fin = true; // Calculate properties @@ -248,7 +248,7 @@ export class Product { } } - calculateRating(industry: IIndustry): void { + calculateRating(industry: Industry): void { const weights: IProductRatingWeight = ProductRatingWeights[industry.type]; if (weights == null) { console.error(`Could not find product rating weights for: ${industry}`); diff --git a/src/Corporation/Warehouse.ts b/src/Corporation/Warehouse.ts index 03cf81615..874651399 100644 --- a/src/Corporation/Warehouse.ts +++ b/src/Corporation/Warehouse.ts @@ -1,14 +1,14 @@ import { Material } from "./Material"; -import { ICorporation } from "./ICorporation"; -import { IIndustry } from "./IIndustry"; +import { Corporation } from "./Corporation"; +import { Industry } from "./Industry"; import { MaterialSizes } from "./MaterialSizes"; import { IMap } from "../types"; import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver"; import { exceptionAlert } from "../utils/helpers/exceptionAlert"; interface IConstructorParams { - corp?: ICorporation; - industry?: IIndustry; + corp?: Corporation; + industry?: Industry; loc?: string; size?: number; } @@ -96,7 +96,7 @@ export class Warehouse { } } - updateSize(corporation: ICorporation, industry: IIndustry): void { + updateSize(corporation: Corporation, industry: Industry): void { try { this.size = this.level * 100 * corporation.getStorageMultiplier() * industry.getStorageMultiplier(); } catch (e: unknown) { diff --git a/src/Corporation/data/Constants.ts b/src/Corporation/data/Constants.ts index e3ef5757e..776e50f3d 100644 --- a/src/Corporation/data/Constants.ts +++ b/src/Corporation/data/Constants.ts @@ -1,39 +1,7 @@ import { CityName } from "./../../Locations/data/CityNames"; const CyclesPerMarketCycle = 50; const AllCorporationStates = ["START", "PURCHASE", "PRODUCTION", "SALE", "EXPORT"]; -export const CorporationConstants: { - INITIALSHARES: number; - SHARESPERPRICEUPDATE: number; - IssueNewSharesCooldown: number; - SellSharesCooldown: number; - CyclesPerMarketCycle: number; - CyclesPerIndustryStateCycle: number; - SecsPerMarketCycle: number; - Cities: string[]; - WarehouseInitialCost: number; - WarehouseInitialSize: number; - WarehouseUpgradeBaseCost: number; - OfficeInitialCost: number; - OfficeInitialSize: number; - OfficeUpgradeBaseCost: number; - BribeThreshold: number; - BribeToRepRatio: number; - ProductProductionCostRatio: number; - DividendMaxRate: number; - EmployeeSalaryMultiplier: number; - CyclesPerEmployeeRaise: number; - EmployeeRaiseAmount: number; - BaseMaxProducts: number; - AllCorporationStates: string[]; - AllMaterials: string[]; - AllIndustryTypes: string[]; - AllUnlocks: string[]; - AllUpgrades: string[]; - AllResearch: string[]; - FundingRoundShares: number[]; - FundingRoundMultiplier: number[]; - ValuationLength: number; -} = { +export const CorporationConstants = { INITIALSHARES: 1e9, //Total number of shares you have at your company SHARESPERPRICEUPDATE: 1e6, //When selling large number of shares, price is dynamically updated for every batch of this amount IssueNewSharesCooldown: 216e3, // 12 Hour in terms of game cycles diff --git a/src/Corporation/ui/Context.ts b/src/Corporation/ui/Context.ts index 62e7f50a0..5563110d5 100644 --- a/src/Corporation/ui/Context.ts +++ b/src/Corporation/ui/Context.ts @@ -1,14 +1,11 @@ import React, { useContext } from "react"; -import { ICorporation } from "../ICorporation"; -import { IIndustry } from "../IIndustry"; +import { Corporation } from "../Corporation"; +import { Industry } from "../Industry"; -export const Context: { - Corporation: React.Context; - Division: React.Context; -} = { - Corporation: React.createContext({} as ICorporation), - Division: React.createContext({} as IIndustry), +export const Context = { + Corporation: React.createContext({} as Corporation), + Division: React.createContext({} as Industry), }; -export const useCorporation = (): ICorporation => useContext(Context.Corporation); -export const useDivision = (): IIndustry => useContext(Context.Division); +export const useCorporation = (): Corporation => useContext(Context.Corporation); +export const useDivision = (): Industry => useContext(Context.Division); diff --git a/src/Corporation/ui/CorporationRoot.tsx b/src/Corporation/ui/CorporationRoot.tsx index bf4766cf0..3ca775af3 100644 --- a/src/Corporation/ui/CorporationRoot.tsx +++ b/src/Corporation/ui/CorporationRoot.tsx @@ -2,11 +2,11 @@ // These are the tabs at the top of the UI that let you switch to different // divisions, see an overview of your corporation, or create a new industry import React, { useState, useEffect } from "react"; -import { IIndustry } from "../IIndustry"; +import { Industry } from "../Industry"; import { MainPanel } from "./MainPanel"; import { Industries } from "../IndustryData"; import { ExpandIndustryTab } from "./ExpandIndustryTab"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { Context } from "./Context"; import { Overview } from "./Overview"; @@ -14,8 +14,7 @@ import Tabs from "@mui/material/Tabs"; import Tab from "@mui/material/Tab"; export function CorporationRoot(): React.ReactElement { - const player = use.Player(); - const corporation = player.corporation; + const corporation = Player.corporation; if (corporation === null) return <>; const setRerender = useState(false)[1]; function rerender(): void { @@ -33,7 +32,7 @@ export function CorporationRoot(): React.ReactElement { const canExpand = Object.keys(Industries).filter( (industryType: string) => - corporation.divisions.find((division: IIndustry) => division.type === industryType) === undefined, + corporation.divisions.find((division: Industry) => division.type === industryType) === undefined, ).length > 0; return ( diff --git a/src/Corporation/ui/ExpandIndustryTab.tsx b/src/Corporation/ui/ExpandIndustryTab.tsx index 74faabadf..8c4a36df5 100644 --- a/src/Corporation/ui/ExpandIndustryTab.tsx +++ b/src/Corporation/ui/ExpandIndustryTab.tsx @@ -2,7 +2,7 @@ import React, { useState } from "react"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { IndustryStartingCosts, Industries, IndustryDescriptions } from "../IndustryData"; import { useCorporation } from "./Context"; -import { IIndustry } from "../IIndustry"; +import { Industry } from "../Industry"; import { NewIndustry } from "../Actions"; import Typography from "@mui/material/Typography"; @@ -23,7 +23,7 @@ export function ExpandIndustryTab(props: IProps): React.ReactElement { const possibleIndustries = allIndustries .filter( (industryType: string) => - corp.divisions.find((division: IIndustry) => division.type === industryType) === undefined, + corp.divisions.find((division: Industry) => division.type === industryType) === undefined, ) .sort(); const [industry, setIndustry] = useState(possibleIndustries.length > 0 ? possibleIndustries[0] : ""); diff --git a/src/Corporation/ui/Helpers.tsx b/src/Corporation/ui/Helpers.tsx index 30d116105..9f7b505d5 100644 --- a/src/Corporation/ui/Helpers.tsx +++ b/src/Corporation/ui/Helpers.tsx @@ -1,8 +1,8 @@ -import { IIndustry } from "../IIndustry"; +import { Industry } from "../Industry"; // Returns a boolean indicating whether the given material is relevant for the // current industry. -export function isRelevantMaterial(matName: string, division: IIndustry): boolean { +export function isRelevantMaterial(matName: string, division: Industry): boolean { // Materials that affect Production multiplier const prodMultiplierMats = ["Hardware", "Robots", "AICores", "RealEstate", "AI Cores", "Real Estate"]; diff --git a/src/Corporation/ui/Industry.tsx b/src/Corporation/ui/Industry.tsx index 9c1fafadf..447e3ccbe 100644 --- a/src/Corporation/ui/Industry.tsx +++ b/src/Corporation/ui/Industry.tsx @@ -7,7 +7,6 @@ import { IndustryOverview } from "./IndustryOverview"; import { IndustryWarehouse } from "./IndustryWarehouse"; import { Warehouse } from "../Warehouse"; import { OfficeSpace } from "../OfficeSpace"; -import { use } from "../../ui/Context"; import { useCorporation, useDivision } from "./Context"; import Box from "@mui/material/Box"; @@ -19,7 +18,6 @@ interface IProps { } export function Industry(props: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const division = useDivision(); return ( @@ -31,7 +29,6 @@ export function Industry(props: IProps): React.ReactElement { void; } @@ -94,7 +90,7 @@ function WarehouseRoot(props: IProps): React.ReactElement { // Create React components for materials const mats = []; for (const matName of Object.keys(props.warehouse.materials)) { - if (!(props.warehouse.materials[matName] instanceof Material)) continue; + if (!props.warehouse.materials[matName]) continue; // Only create UI for materials that are relevant for the industry or in stock const isInStock = props.warehouse.materials[matName].qty > 0; const isRelevant = isRelevantMaterial(matName, division); @@ -115,7 +111,7 @@ function WarehouseRoot(props: IProps): React.ReactElement { if (division.makesProducts && Object.keys(division.products).length > 0) { for (const productName of Object.keys(division.products)) { const product = division.products[productName]; - if (!(product instanceof Product)) continue; + if (!product) continue; products.push( , ); @@ -219,7 +215,7 @@ function WarehouseRoot(props: IProps): React.ReactElement { } export function IndustryWarehouse(props: IProps): React.ReactElement { - if (props.warehouse instanceof Warehouse) { + if (props.warehouse) { return ; } else { return ; diff --git a/src/Corporation/ui/MainPanel.tsx b/src/Corporation/ui/MainPanel.tsx index 35a2833fd..ac865870d 100644 --- a/src/Corporation/ui/MainPanel.tsx +++ b/src/Corporation/ui/MainPanel.tsx @@ -4,7 +4,7 @@ import React from "react"; import { CityTabs } from "./CityTabs"; -import { IIndustry } from "../IIndustry"; +import { Industry } from "../Industry"; import { Context, useCorporation } from "./Context"; import { CityName } from "../../Locations/data/CityNames"; @@ -18,7 +18,7 @@ export function MainPanel(props: IProps): React.ReactElement { const corp = useCorporation(); const division = props.divisionName !== "Overview" - ? corp.divisions.find((division: IIndustry) => division.name === props.divisionName) + ? corp.divisions.find((division: Industry) => division.name === props.divisionName) : undefined; // use undefined because find returns undefined if (division === undefined) throw new Error("Cannot find division"); diff --git a/src/Corporation/ui/MaterialElem.tsx b/src/Corporation/ui/MaterialElem.tsx index 4f37eba1f..1e16af134 100644 --- a/src/Corporation/ui/MaterialElem.tsx +++ b/src/Corporation/ui/MaterialElem.tsx @@ -2,7 +2,6 @@ // (right-side panel in the Industry UI) import React, { useState } from "react"; -import { OfficeSpace } from "../OfficeSpace"; import { Material } from "../Material"; import { Warehouse } from "../Warehouse"; import { ExportModal } from "./modals/ExportModal"; @@ -45,7 +44,7 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement { const mat = props.mat; const markupLimit = mat.getMarkupLimit(); const office = division.offices[city]; - if (!(office instanceof OfficeSpace)) { + if (!office) { throw new Error(`Could not get OfficeSpace object for this city (${city})`); } diff --git a/src/Corporation/ui/MoneyCost.tsx b/src/Corporation/ui/MoneyCost.tsx index 536ee2b95..8a2f17b6a 100644 --- a/src/Corporation/ui/MoneyCost.tsx +++ b/src/Corporation/ui/MoneyCost.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { numeralWrapper } from "../../ui/numeralFormat"; -import { ICorporation } from "../ICorporation"; +import { Corporation } from "../Corporation"; import { Theme } from "@mui/material/styles"; import makeStyles from "@mui/styles/makeStyles"; import createStyles from "@mui/styles/createStyles"; @@ -18,7 +18,7 @@ const useStyles = makeStyles((theme: Theme) => interface IProps { money: number; - corp: ICorporation; + corp: Corporation; } export function MoneyCost(props: IProps): React.ReactElement { diff --git a/src/Corporation/ui/Overview.tsx b/src/Corporation/ui/Overview.tsx index 1dc811f0c..10fb2f7b3 100644 --- a/src/Corporation/ui/Overview.tsx +++ b/src/Corporation/ui/Overview.tsx @@ -21,7 +21,7 @@ import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFuncti import { Money } from "../../ui/React/Money"; import { MoneyRate } from "../../ui/React/MoneyRate"; import { StatsTable } from "../../ui/React/StatsTable"; -import { use } from "../../ui/Context"; +import { Player } from "../../Player"; import { useCorporation } from "./Context"; import Typography from "@mui/material/Typography"; import Tooltip from "@mui/material/Tooltip"; @@ -34,7 +34,6 @@ interface IProps { rerender: () => void; } export function Overview({ rerender }: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const profit: number = corp.revenue - corp.expenses; @@ -100,7 +99,7 @@ export function Overview({ rerender }: IProps): React.ReactElement { } > - + {corp.public ? : } @@ -240,12 +239,11 @@ function PublicButtons({ rerender }: IPublicButtonsProps): React.ReactElement { } function BribeButton(): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const [open, setOpen] = useState(false); const canBribe = corp.valuation >= CorporationConstants.BribeThreshold && - player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0; + Player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0; function openBribe(): void { if (!canBribe) return; diff --git a/src/Corporation/ui/modals/BribeFactionModal.tsx b/src/Corporation/ui/modals/BribeFactionModal.tsx index 87d20105d..7c5668934 100644 --- a/src/Corporation/ui/modals/BribeFactionModal.tsx +++ b/src/Corporation/ui/modals/BribeFactionModal.tsx @@ -4,7 +4,7 @@ import { CorporationConstants } from "../../data/Constants"; import { numeralWrapper } from "../../../ui/numeralFormat"; import { dialogBoxCreate } from "../../../ui/React/DialogBox"; import { Modal } from "../../../ui/React/Modal"; -import { use } from "../../../ui/Context"; +import { Player } from "../../../Player"; import { useCorporation } from "../Context"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -19,11 +19,10 @@ interface IProps { } export function BribeFactionModal(props: IProps): React.ReactElement { - const player = use.Player(); - const factions = player.factions.filter((name: string) => { + const factions = Player.factions.filter((name: string) => { const info = Factions[name].getInfo(); if (!info.offersWork()) return false; - if (player.hasGangWith(name)) return false; + if (Player.hasGangWith(name)) return false; return true; }); const corp = useCorporation(); @@ -60,9 +59,7 @@ export function BribeFactionModal(props: IProps): React.ReactElement { const fac = Factions[selectedFaction]; if (disabled) return; const rep = repGain(money); - dialogBoxCreate( - "You gained " + numeralWrapper.formatReputation(rep) + " reputation with " + fac.name + " by bribing them.", - ); + dialogBoxCreate(`You gained ${numeralWrapper.formatReputation(rep)} reputation with ${fac.name} by bribing them.`); fac.playerReputation += rep; corp.funds = corp.funds - money; props.onClose(); @@ -79,7 +76,7 @@ export function BribeFactionModal(props: IProps): React.ReactElement { {factions.map((name: string) => { const info = Factions[name].getInfo(); if (!info.offersWork()) return; - if (player.hasGangWith(name)) return; + if (Player.hasGangWith(name)) return; return ( {name} diff --git a/src/Corporation/ui/modals/BuybackSharesModal.tsx b/src/Corporation/ui/modals/BuybackSharesModal.tsx index 5d6b33e49..6083015e7 100644 --- a/src/Corporation/ui/modals/BuybackSharesModal.tsx +++ b/src/Corporation/ui/modals/BuybackSharesModal.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { Modal } from "../../../ui/React/Modal"; import { numeralWrapper } from "../../../ui/numeralFormat"; -import { use } from "../../../ui/Context"; +import { Player } from "../../../Player"; import { useCorporation } from "../Context"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; @@ -19,7 +19,6 @@ interface IProps { // Create a popup that lets the player buyback shares // This is created when the player clicks the "Buyback Shares" button in the overview panel export function BuybackSharesModal(props: IProps): React.ReactElement { - const player = use.Player(); const corp = useCorporation(); const [shares, setShares] = useState(NaN); @@ -30,12 +29,12 @@ export function BuybackSharesModal(props: IProps): React.ReactElement { isNaN(shares) || shares <= 0 || shares > corp.issuedShares || - shares * buybackPrice > player.money; + shares * buybackPrice > Player.money; function buy(): void { if (disabled) return; try { - BuyBackShares(corp, player, shares); + BuyBackShares(corp, shares); } catch (err) { dialogBoxCreate(err + ""); } diff --git a/src/Corporation/ui/modals/CreateCorporationModal.tsx b/src/Corporation/ui/modals/CreateCorporationModal.tsx index 2c63baf4e..1b2b1b7a6 100644 --- a/src/Corporation/ui/modals/CreateCorporationModal.tsx +++ b/src/Corporation/ui/modals/CreateCorporationModal.tsx @@ -2,7 +2,8 @@ import React, { useState } from "react"; import { Money } from "../../../ui/React/Money"; import { Modal } from "../../../ui/React/Modal"; -import { use } from "../../../ui/Context"; +import { Router } from "../../../ui/GameRoot"; +import { Player } from "../../../Player"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import TextField from "@mui/material/TextField"; @@ -13,10 +14,8 @@ interface IProps { } export function CreateCorporationModal(props: IProps): React.ReactElement { - const player = use.Player(); - const router = use.Router(); - const canSelfFund = player.canAfford(150e9); - if (!player.canAccessCorporation() || player.hasCorporation()) { + const canSelfFund = Player.canAfford(150e9); + if (!Player.canAccessCorporation() || Player.hasCorporation()) { props.onClose(); return <>; } @@ -35,11 +34,11 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { return; } - player.startCorporation(name); - player.loseMoney(150e9, "corporation"); + Player.startCorporation(name); + Player.loseMoney(150e9, "corporation"); props.onClose(); - router.toCorporation(); + Router.toCorporation(); } function seed(): void { @@ -47,17 +46,17 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { return; } - player.startCorporation(name, 500e6); + Player.startCorporation(name, 500e6); props.onClose(); - router.toCorporation(); + Router.toCorporation(); } return ( Would you like to start a corporation? This will require $150b for registration and initial funding.{" "} - {player.bitNodeN === 3 && + {Player.bitNodeN === 3 && `This $150b can either be self-funded, or you can obtain the seed money from the government in exchange for 500 million shares`} @@ -66,13 +65,13 @@ export function CreateCorporationModal(props: IProps): React.ReactElement { If you would like to start one, please enter a name for your corporation below: - {player.bitNodeN === 3 && ( + {Player.bitNodeN === 3 && ( )} ); diff --git a/src/Corporation/ui/modals/ExportModal.tsx b/src/Corporation/ui/modals/ExportModal.tsx index 947e932de..41bdd057a 100644 --- a/src/Corporation/ui/modals/ExportModal.tsx +++ b/src/Corporation/ui/modals/ExportModal.tsx @@ -2,7 +2,7 @@ import React, { useState } from "react"; import { dialogBoxCreate } from "../../../ui/React/DialogBox"; import { Material } from "../../Material"; import { Export } from "../../Export"; -import { IIndustry } from "../../IIndustry"; +import { Industry } from "../../Industry"; import { ExportMaterial } from "../../Actions"; import { Modal } from "../../../ui/React/Modal"; import { useCorporation } from "../Context"; @@ -23,9 +23,7 @@ interface IProps { // Create a popup that lets the player manage exports export function ExportModal(props: IProps): React.ReactElement { const corp = useCorporation(); - const possibleDivisions = corp.divisions.filter((division: IIndustry) => - isRelevantMaterial(props.mat.name, division), - ); + const possibleDivisions = corp.divisions.filter((division: Industry) => isRelevantMaterial(props.mat.name, division)); if (possibleDivisions.length === 0) throw new Error("Export popup created with no divisions."); const defaultDivision = possibleDivisions[0]; if (Object.keys(defaultDivision.warehouses).length === 0) @@ -72,7 +70,7 @@ export function ExportModal(props: IProps): React.ReactElement { rerender(); } - const currentDivision = corp.divisions.find((division: IIndustry) => division.name === industry); + const currentDivision = corp.divisions.find((division: Industry) => division.name === industry); if (currentDivision === undefined) throw new Error(`Export popup somehow ended up with undefined division '${currentDivision}'`); const possibleCities = Object.keys(currentDivision.warehouses).filter( @@ -90,8 +88,8 @@ export function ExportModal(props: IProps): React.ReactElement {