bitburner-src/src/Bladeburner/ui/BlackOpElem.tsx

97 lines
3.3 KiB
TypeScript
Raw Normal View History

import React from "react";
import { formatNumberNoSuffix } from "../../ui/formatNumber";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
2021-06-18 09:38:17 +02:00
import { ActionTypes } from "../data/ActionTypes";
2021-09-25 20:42:57 +02:00
import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
2021-09-27 23:09:48 +02:00
import { TeamSizeButton } from "./TeamSizeButton";
import { Bladeburner } from "../Bladeburner";
2021-09-27 23:09:48 +02:00
import { BlackOperation } from "../BlackOperation";
import { BlackOperations } from "../data/BlackOperations";
import { Player } from "@player";
2021-08-23 17:42:14 +02:00
import { CopyableText } from "../../ui/React/CopyableText";
2021-09-27 23:09:48 +02:00
import { SuccessChance } from "./SuccessChance";
import { StartButton } from "./StartButton";
import Typography from "@mui/material/Typography";
import Paper from "@mui/material/Paper";
import { useRerender } from "../../ui/React/hooks";
2021-06-18 09:38:17 +02:00
interface IProps {
bladeburner: Bladeburner;
2021-09-27 23:09:48 +02:00
action: BlackOperation;
2021-06-18 09:38:17 +02:00
}
export function BlackOpElem(props: IProps): React.ReactElement {
const rerender = useRerender();
2021-09-05 01:09:30 +02:00
const isCompleted = props.bladeburner.blackops[props.action.name] != null;
if (isCompleted) {
return (
<Paper sx={{ my: 1, p: 1 }}>
<Typography>{props.action.name} (COMPLETED)</Typography>
</Paper>
);
2021-09-05 01:09:30 +02:00
}
2021-06-18 09:38:17 +02:00
2021-09-05 01:09:30 +02:00
const isActive =
props.bladeburner.action.type === ActionTypes.BlackOperation && props.action.name === props.bladeburner.action.name;
2022-09-06 15:07:12 +02:00
const actionTime = props.action.getActionTime(props.bladeburner, Player);
2021-09-05 01:09:30 +02:00
const hasReqdRank = props.bladeburner.rank >= props.action.reqdRank;
const computedActionTimeCurrent = Math.min(
props.bladeburner.actionTimeCurrent + props.bladeburner.actionTimeOverflow,
props.bladeburner.actionTimeToComplete,
);
2021-06-18 09:38:17 +02:00
2021-09-27 23:09:48 +02:00
const actionData = BlackOperations[props.action.name];
if (actionData === undefined) {
throw new Error(`Cannot find data for ${props.action.name}`);
2021-09-05 01:09:30 +02:00
}
2021-06-18 09:38:17 +02:00
2021-09-05 01:09:30 +02:00
return (
2021-09-27 23:09:48 +02:00
<Paper sx={{ my: 1, p: 1 }}>
2021-10-14 23:35:22 +02:00
{isActive ? (
<>
2021-09-05 01:09:30 +02:00
<>
2021-10-14 23:35:22 +02:00
<CopyableText value={props.action.name} />
<Typography>
(IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)} /{" "}
{formatNumberNoSuffix(props.bladeburner.actionTimeToComplete, 0)})
2021-10-14 23:35:22 +02:00
</Typography>
<Typography>
{createProgressBarText({
progress: computedActionTimeCurrent / props.bladeburner.actionTimeToComplete,
})}
</Typography>
2021-09-05 01:09:30 +02:00
</>
2021-10-14 23:35:22 +02:00
</>
) : (
<>
<CopyableText value={props.action.name} />
<StartButton
bladeburner={props.bladeburner}
type={ActionTypes.BlackOperation}
name={props.action.name}
rerender={rerender}
/>
<TeamSizeButton action={props.action} bladeburner={props.bladeburner} />
</>
)}
2021-09-27 23:09:48 +02:00
2021-09-05 01:09:30 +02:00
<br />
<br />
2021-09-27 23:09:48 +02:00
<Typography>{actionData.desc}</Typography>
2021-09-05 01:09:30 +02:00
<br />
<br />
2021-09-27 23:09:48 +02:00
<Typography color={hasReqdRank ? "primary" : "error"}>
Required Rank: {formatNumberNoSuffix(props.action.reqdRank, 0)}
2021-09-27 23:09:48 +02:00
</Typography>
2021-09-05 01:09:30 +02:00
<br />
2021-09-27 23:09:48 +02:00
<Typography>
<SuccessChance action={props.action} bladeburner={props.bladeburner} />
2021-06-18 09:38:17 +02:00
<br />
2021-09-05 01:09:30 +02:00
Time Required: {convertTimeMsToTimeElapsedString(actionTime * 1000)}
2021-09-27 23:09:48 +02:00
</Typography>
</Paper>
2021-09-05 01:09:30 +02:00
);
}