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-09-04 08:21:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
2021-09-04 08:21:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
import { Money } from "../../ui/React/Money";
|
2021-10-13 08:15:29 +02:00
|
|
|
import { MathJax, MathJaxContext } from "better-react-mathjax";
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
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
|
|
|
};
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
export function CoresButton(props: IProps): React.ReactElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
const homeComputer = props.p.getHomeComputer();
|
|
|
|
const maxCores = homeComputer.cpuCores >= 8;
|
|
|
|
if (maxCores) {
|
2021-09-25 21:34:12 +02:00
|
|
|
return <Button>Upgrade 'home' cores - MAX</Button>;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-09-04 08:21:31 +02:00
|
|
|
|
2021-10-13 21:48:34 +02:00
|
|
|
const cost = props.p.getUpgradeHomeCoresCost();
|
2021-09-04 08:21:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
function buy(): void {
|
|
|
|
if (maxCores) return;
|
|
|
|
if (!props.p.canAfford(cost)) return;
|
2021-10-27 20:18:33 +02:00
|
|
|
props.p.loseMoney(cost, "servers");
|
2021-09-05 01:09:30 +02:00
|
|
|
homeComputer.cpuCores++;
|
2021-09-07 23:26:49 +02:00
|
|
|
props.rerender();
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-09-04 20:43:22 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return (
|
2021-10-13 08:15:29 +02:00
|
|
|
<Tooltip
|
|
|
|
title={
|
|
|
|
<MathJaxContext>
|
2021-10-13 21:57:15 +02:00
|
|
|
<MathJax>{`\\(\\large{cost = 10^9 \\cdot 7.5 ^{\\text{cores}}}\\)`}</MathJax>
|
2021-10-13 08:15:29 +02:00
|
|
|
</MathJaxContext>
|
|
|
|
}
|
|
|
|
>
|
2021-10-01 02:06:40 +02:00
|
|
|
<span>
|
|
|
|
<Button disabled={!props.p.canAfford(cost)} onClick={buy}>
|
|
|
|
Upgrade 'home' cores ({homeComputer.cpuCores} -> {homeComputer.cpuCores + 1}) -
|
|
|
|
<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
|
|
|
);
|
2021-09-04 08:21:31 +02:00
|
|
|
}
|