import { Box, Container, Paper, Table, TableBody, Tooltip } from "@mui/material"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import { uniqueId } from "lodash"; import React, { useEffect, useState } from "react"; import { Companies } from "../Company/Companies"; import { Company } from "../Company/Company"; import { CONSTANTS } from "../Constants"; import { LocationName } from "../Locations/data/LocationNames"; import { Locations } from "../Locations/Locations"; import { Settings } from "../Settings/Settings"; import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions"; import { use } from "./Context"; import { numeralWrapper } from "./numeralFormat"; import { Money } from "./React/Money"; import { MoneyRate } from "./React/MoneyRate"; import { ProgressBar } from "./React/Progress"; import { Reputation } from "./React/Reputation"; import { ReputationRate } from "./React/ReputationRate"; import { StatsRow } from "./React/StatsRow"; import { WorkType } from "../utils/WorkType"; import { isCrimeWork } from "../Work/CrimeWork"; import { isClassWork } from "../Work/ClassWork"; import { WorkStats } from "../Work/WorkStats"; import { isCreateProgramWork } from "../Work/CreateProgramWork"; import { isGraftingWork } from "../Work/GraftingWork"; import { isFactionWork } from "../Work/FactionWork"; import { FactionWorkType } from "../Work/data/FactionWorkType"; import { isCompanyWork } from "../Work/CompanyWork"; const CYCLES_PER_SEC = 1000 / CONSTANTS.MilliPerCycle; interface IWorkInfo { buttons: { cancel: () => void; unfocus?: () => void; }; title: string | React.ReactElement; description?: string | React.ReactElement; gains?: (string | React.ReactElement)[]; progress?: { elapsed?: number; remaining?: number; percentage?: number; }; stopText: string; stopTooltip?: string | React.ReactElement; } export function ExpRows(rate: WorkStats): React.ReactElement[] { return [ rate.hackExp > 0 ? ( ) : ( <> ), rate.strExp > 0 ? ( ) : ( <> ), rate.defExp > 0 ? ( ) : ( <> ), rate.dexExp > 0 ? ( ) : ( <> ), rate.agiExp > 0 ? ( ) : ( <> ), rate.chaExp > 0 ? ( ) : ( <> ), ]; } export function WorkInProgressRoot(): React.ReactElement { const setRerender = useState(false)[1]; function rerender(): void { setRerender((old) => !old); } useEffect(() => { const id = setInterval(rerender, CONSTANTS.MilliPerCycle); return () => clearInterval(id); }, []); const player = use.Player(); const router = use.Router(); let workInfo: IWorkInfo = { buttons: { cancel: () => undefined, }, title: "", stopText: "", }; if (player.currentWork !== null) { if (isCrimeWork(player.currentWork)) { const crime = player.currentWork.getCrime(); const completion = ((player.currentWork.cyclesWorked * CONSTANTS._idleSpeed) / crime.time) * 100; workInfo = { buttons: { cancel: () => { router.toLocation(Locations[LocationName.Slums]); player.finishNEWWork(true); }, unfocus: () => { router.toCity(); player.stopFocusing(); }, }, title: `You are attempting to ${crime.type}`, progress: { remaining: crime.time - player.currentWork.cyclesWorked * CONSTANTS._idleSpeed, percentage: completion, }, stopText: "Cancel crime", }; } if (isClassWork(player.currentWork)) { const classWork = player.currentWork; function cancel(): void { player.finishNEWWork(true); router.toCity(); } function unfocus(): void { router.toCity(); player.stopFocusing(); } let stopText = ""; if (classWork.isGym()) { stopText = "Stop training at gym"; } else { stopText = "Stop taking course"; } const rates = classWork.calculateRates(player); workInfo = { buttons: { cancel: cancel, unfocus: unfocus, }, title: ( <> You are currently {classWork.getClass().youAreCurrently} ), gains: [ () , ...ExpRows(rates), ], progress: { elapsed: classWork.cyclesWorked * CONSTANTS._idleSpeed, }, stopText: stopText, }; } if (isCreateProgramWork(player.currentWork)) { const create = player.currentWork; function cancel(): void { player.finishNEWWork(true); router.toTerminal(); } function unfocus(): void { router.toTerminal(); player.stopFocusing(); } const completion = (create.unitCompleted / create.unitNeeded()) * 100; workInfo = { buttons: { cancel: cancel, unfocus: unfocus, }, title: ( <> You are currently working on coding {create.programName} ), progress: { elapsed: create.cyclesWorked * CONSTANTS._idleSpeed, percentage: completion, }, stopText: "Stop creating program", stopTooltip: "Your work will be saved and you can return to complete the program later.", }; } if (isGraftingWork(player.currentWork)) { const graft = player.currentWork; function cancel(): void { player.finishNEWWork(true); router.toTerminal(); } function unfocus(): void { router.toTerminal(); player.stopFocusing(); } workInfo = { buttons: { cancel: cancel, unfocus: unfocus, }, title: ( <> You are currently working on grafting {graft.augmentation} ), progress: { elapsed: graft.cyclesWorked * CONSTANTS._idleSpeed, percentage: (graft.unitCompleted / graft.unitNeeded()) * 100, }, stopText: "Stop grafting", stopTooltip: ( <> If you cancel, your work will not be saved, and the money you spent will not be returned ), }; } if (isFactionWork(player.currentWork)) { const faction = player.currentWork.getFaction(); if (!faction) { workInfo = { buttons: { cancel: () => router.toFactions(), }, title: `You have not joined ${player.currentWork.factionName || "(Faction not found)"} at this time,` + " please try again if you think this should have worked", stopText: "Back to Factions", }; } function cancel(): void { router.toFaction(faction); player.finishNEWWork(true); } function unfocus(): void { router.toFaction(faction); player.stopFocusing(); } const description = { [FactionWorkType.HACKING]: "carrying out hacking contracts", [FactionWorkType.FIELD]: "carrying out field missions", [FactionWorkType.SECURITY]: "performing security detail", }; const exp = player.currentWork.getExpRates(player); workInfo = { buttons: { cancel: cancel, unfocus: unfocus, }, title: ( <> You are currently {description[player.currentWork.factionWorkType]} for {faction.name} ), description: ( <> Current Faction Reputation: ( ) ), gains: ExpRows(exp), progress: { elapsed: player.currentWork.cyclesWorked * CONSTANTS._idleSpeed, }, stopText: "Stop Faction work", }; } if (isCompanyWork(player.currentWork)) { const comp = Companies[player.currentWork.companyName]; if (comp == null || !(comp instanceof Company)) { workInfo = { buttons: { cancel: () => router.toTerminal(), }, title: `You cannot work for ${player.currentWork.companyName || "(Company not found)"} at this time,` + " please try again if you think this should have worked", stopText: "Back to Terminal", }; } const companyRep = comp.playerReputation; function cancel(): void { player.finishNEWWork(true); router.toJob(); } function unfocus(): void { player.stopFocusing(); router.toJob(); } const position = player.jobs[player.companyName]; const gains = player.currentWork.getGainRates(player); workInfo = { buttons: { cancel: cancel, unfocus: unfocus, }, title: ( <> You are currently working as a {position} at {player.currentWork.companyName} ), description: ( <> Current Company Reputation: ), gains: [ , , ...ExpRows(gains), ], progress: { elapsed: player.currentWork.cyclesWorked * CYCLES_PER_SEC, }, stopText: "Stop working", }; } } if (workInfo.title === "") { return <>; } const tooltipInfo = typeof workInfo?.stopTooltip === "string" ? ( {workInfo.stopTooltip} ) : ( workInfo.stopTooltip || <> ); return ( {workInfo.title} {workInfo.description} {workInfo.gains && ( {workInfo.gains.map((row) => ( {row} ))}
)}
{workInfo.progress !== undefined && ( {workInfo.progress.elapsed !== undefined && ( {convertTimeMsToTimeElapsedString(workInfo.progress.elapsed)} elapsed )} {workInfo.progress.remaining !== undefined && ( {convertTimeMsToTimeElapsedString(workInfo.progress.remaining)} remaining )} {workInfo.progress.percentage !== undefined && ( {workInfo.progress.percentage.toFixed(2)}% done )} {workInfo.progress.percentage !== undefined && ( )} )} {workInfo.stopTooltip ? ( ) : ( )} {workInfo.buttons.unfocus && ( )}
); }