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

60 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-09-09 03:17:01 -04:00
import React from "react";
2021-09-25 15:34:12 -04:00
import Button from "@mui/material/Button";
2022-09-06 09:07:12 -04:00
import { dialogBoxCreate } from "../../ui/React/DialogBox";
import { GetServer } from "../../Server/AllServers";
import { SpecialServers } from "../../Server/data/SpecialServers";
2021-09-04 19:09:30 -04:00
import { CONSTANTS } from "../../Constants";
import { Player } from "@player";
2021-09-04 19:09:30 -04:00
import { Money } from "../../ui/React/Money";
/** Attempt to purchase a TOR router using the button. */
2022-09-13 12:37:24 -04:00
export function purchaseTorRouter(): void {
2022-09-06 09:07:12 -04:00
if (Player.hasTorRouter()) {
dialogBoxCreate(`You already have a TOR Router!`);
return;
}
if (!Player.canAfford(CONSTANTS.TorRouterCost)) {
dialogBoxCreate("You cannot afford to purchase the TOR router!");
return;
}
Player.loseMoney(CONSTANTS.TorRouterCost, "other");
const darkweb = GetServer(SpecialServers.DarkWeb);
if (!darkweb) {
throw new Error("Dark web is not a server.");
}
Player.getHomeComputer().serversOnNetwork.push(darkweb.hostname);
darkweb.serversOnNetwork.push(Player.getHomeComputer().hostname);
dialogBoxCreate(
"You have purchased a TOR router!\n" +
"You now have access to the dark web from your home computer.\n" +
"Use the buy command in the terminal to purchase programs.",
2022-09-06 09:07:12 -04:00
);
}
interface IProps {
2021-09-07 17:26:49 -04:00
rerender: () => void;
}
export function TorButton(props: IProps): React.ReactElement {
2021-09-04 19:09:30 -04:00
function buy(): void {
2022-09-06 09:07:12 -04:00
purchaseTorRouter();
2021-09-07 17:26:49 -04:00
props.rerender();
2021-09-04 19:09:30 -04:00
}
2022-09-06 09:07:12 -04:00
if (Player.hasTorRouter()) {
2021-09-25 15:34:12 -04:00
return <Button>TOR Router - Purchased</Button>;
2021-09-04 19:09:30 -04:00
}
return (
2022-09-06 09:07:12 -04:00
<Button disabled={!Player.canAfford(CONSTANTS.TorRouterCost)} onClick={buy}>
2021-09-30 20:06:40 -04:00
Purchase TOR router -&nbsp;
2022-09-06 09:07:12 -04:00
<Money money={CONSTANTS.TorRouterCost} forPurchase={true} />
2021-09-25 15:34:12 -04:00
</Button>
2021-09-04 19:09:30 -04:00
);
}