import React, { useState, useEffect } from "react";
import { numeralWrapper } from "../ui/numeralFormat";
import { BitNodes } from "../BitNode/BitNode";
import { IPlayer } from "../PersonObjects/IPlayer";
import { MoneySourceTracker } from "../utils/MoneySourceTracker";
import { dialogBoxCreate } from "../../utils/DialogBox";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
import { getPurchaseServerLimit } from "../Server/ServerPurchases";
import { HacknetServerConstants } from "../Hacknet/data/Constants";
import { StatsTable } from "./React/StatsTable";
import { Money } from "./React/Money";
import { use } from "./Context";
import Typography from "@mui/material/Typography";
function LastEmployer(): React.ReactElement {
const player = use.Player();
if (player.companyName) {
return (
<>
Employer at which you last worked: {player.companyName}
>
);
}
return <>>;
}
function LastJob(): React.ReactElement {
const player = use.Player();
if (player.companyName !== "") {
return (
<>
Job you last worked: {player.jobs[player.companyName]}
>
);
}
return <>>;
}
function Employers(): React.ReactElement {
const player = use.Player();
if (player.jobs && Object.keys(player.jobs).length !== 0)
return (
<>
All Employers:
{Object.keys(player.jobs).map((j) => (
* {j}
))}
>
);
return <>>;
}
function Hacknet(): React.ReactElement {
const player = use.Player();
// Can't import HacknetHelpers for some reason.
if (!(player.bitNodeN === 9 || SourceFileFlags[9] > 0)) {
return (
<>
{`Hacknet Nodes owned: ${player.hacknetNodes.length}`}
>
);
} else {
return (
<>
{`Hacknet Servers owned: ${player.hacknetNodes.length} / ${HacknetServerConstants.MaxServers}`}
>
);
}
}
function Intelligence(): React.ReactElement {
const player = use.Player();
if (player.intelligence > 0 && (player.bitNodeN === 5 || SourceFileFlags[5] > 0)) {
return (
Intelligence:
{numeralWrapper.formatSkill(player.intelligence)}
);
}
return <>>;
}
function MultiplierTable(props: any): React.ReactElement {
function bn5Stat(r: any): JSX.Element {
if (SourceFileFlags[5] > 0 && r.length > 2 && r[1] != r[2]) {
return (
{" "}
({numeralWrapper.formatPercentage(r[2])})
);
}
return <>>;
}
return (
<>
{props.rows.map((r: any) => (
{`${r[0]} multiplier:`}
{numeralWrapper.formatPercentage(r[1])}
{bn5Stat(r)}
))}
>
);
}
function BladeburnerMults(): React.ReactElement {
const player = use.Player();
if (!player.canAccessBladeburner()) return <>>;
return (
<>
>
);
}
function CurrentBitNode(): React.ReactElement {
const player = use.Player();
if (player.sourceFiles.length > 0) {
const index = "BitNode" + player.bitNodeN;
return (
<>
Current BitNode: {player.bitNodeN} ({BitNodes[index].name})
{BitNodes[index].info}
>
);
}
return <>>;
}
export function CharacterStats(): React.ReactElement {
const player = use.Player();
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
}
useEffect(() => {
const id = setInterval(rerender, 20);
return () => clearInterval(id);
}, []);
function convertMoneySourceTrackerToString(src: MoneySourceTracker): React.ReactElement {
const parts: any[][] = [[`Total:`, ]];
if (src.bladeburner) {
parts.push([`Bladeburner:`, ]);
}
if (src.codingcontract) {
parts.push([`Coding Contracts:`, ]);
}
if (src.work) {
parts.push([`Company Work:`, ]);
}
if (src.class) {
parts.push([`Class:`, ]);
}
if (src.corporation) {
parts.push([`Corporation:`, ]);
}
if (src.crime) {
parts.push([`Crimes:`, ]);
}
if (src.gang) {
parts.push([`Gang:`, ]);
}
if (src.hacking) {
parts.push([`Hacking:`, ]);
}
if (src.hacknetnode) {
parts.push([`Hacknet Nodes:`, ]);
}
if (src.hospitalization) {
parts.push([`Hospitalization:`, ]);
}
if (src.infiltration) {
parts.push([`Infiltration:`, ]);
}
if (src.stock) {
parts.push([`Stock Market:`, ]);
}
if (src.casino) {
parts.push([`Casino:`, ]);
}
if (src.sleeves) {
parts.push([`Sleeves:`, ]);
}
return StatsTable(parts);
}
function openMoneyModal(): void {
let content = (
<>
Money earned since you last installed Augmentations:
{convertMoneySourceTrackerToString(player.moneySourceA)}
>
);
if (player.sourceFiles.length !== 0) {
content = (
<>
{content}
Money earned in this BitNode:
{convertMoneySourceTrackerToString(player.moneySourceB)}
>
);
}
dialogBoxCreate(content, false);
}
const timeRows = [
["Time played since last Augmentation:", convertTimeMsToTimeElapsedString(player.playtimeSinceLastAug)],
];
if (player.sourceFiles.length > 0) {
timeRows.push([
"Time played since last Bitnode destroyed:",
convertTimeMsToTimeElapsedString(player.playtimeSinceLastBitnode),
]);
}
timeRows.push(["Total Time played:", convertTimeMsToTimeElapsedString(player.totalPlaytime)]);
return (
<>