bitburner-src/src/Locations/ui/RamButton.tsx

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-09-09 09:17:01 +02:00
import React from "react";
2021-09-25 21:34:12 +02:00
import Button from "@mui/material/Button";
import Tooltip from "@mui/material/Tooltip";
2021-12-20 20:03:25 +01:00
import Typography from "@mui/material/Typography";
2021-09-05 01:09:30 +02:00
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { purchaseRamForHomeComputer } from "../../Server/ServerPurchases";
import { Money } from "../../ui/React/Money";
2021-10-12 00:14:10 +02:00
import { numeralWrapper } from "../../ui/numeralFormat";
2022-01-08 13:48:10 +01:00
import { MathJaxWrapper } from "../../MathJaxWrapper";
2022-04-08 07:02:36 +02:00
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
type IProps = {
2021-09-05 01:09:30 +02:00
p: IPlayer;
2021-09-07 23:26:49 +02:00
rerender: () => void;
2021-09-05 01:09:30 +02:00
};
export function RamButton(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const homeComputer = props.p.getHomeComputer();
if (homeComputer.maxRam >= CONSTANTS.HomeComputerMaxRam) {
2021-09-25 21:34:12 +02:00
return <Button>Upgrade 'home' RAM - MAX</Button>;
2021-09-05 01:09:30 +02:00
}
const cost = props.p.getUpgradeHomeRamCost();
function buy(): void {
purchaseRamForHomeComputer(props.p);
2021-09-07 23:26:49 +02:00
props.rerender();
2021-09-05 01:09:30 +02:00
}
2022-04-08 07:02:36 +02:00
const bnMult = BitNodeMultipliers.HomeComputerRamCost === 1 ? "" : `\\cdot ${BitNodeMultipliers.HomeComputerRamCost}`;
2022-05-19 08:09:00 +02:00
2021-09-05 01:09:30 +02:00
return (
2021-10-13 08:15:29 +02:00
<Tooltip
2022-04-08 07:02:36 +02:00
title={
<MathJaxWrapper>{`\\(\\large{cost = ram \\cdot 3.2 \\cdot 10^4 \\cdot 1.58^{log_2{(ram)}}} ${bnMult}\\)`}</MathJaxWrapper>
}
2021-10-13 08:15:29 +02:00
>
2021-10-01 02:06:40 +02:00
<span>
2021-12-20 20:03:25 +01:00
<br />
<Typography>
<i>"More RAM means more scripts on 'home'"</i>
</Typography>
<br />
2021-10-01 02:06:40 +02:00
<Button disabled={!props.p.canAfford(cost)} onClick={buy}>
2021-10-12 00:14:10 +02:00
Upgrade 'home' RAM ({numeralWrapper.formatRAM(homeComputer.maxRam)} -&gt;&nbsp;
{numeralWrapper.formatRAM(homeComputer.maxRam * 2)}) -&nbsp;
2021-10-01 02:06:40 +02:00
<Money money={cost} player={props.p} />
</Button>
</span>
2021-09-25 21:34:12 +02:00
</Tooltip>
2021-09-05 01:09:30 +02:00
);
}