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";
|
2021-09-04 02:21:31 -04:00
|
|
|
|
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";
|
2022-10-09 18:42:14 -04:00
|
|
|
import { Player } from "@player";
|
2021-09-04 02:21:31 -04:00
|
|
|
|
2021-09-04 19:09:30 -04:00
|
|
|
import { Money } from "../../ui/React/Money";
|
2021-09-04 02:21:31 -04:00
|
|
|
|
2022-10-04 06:40:10 -04:00
|
|
|
/** 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" +
|
2023-12-08 04:51:29 +03:00
|
|
|
"Use the buy command in the terminal to purchase programs.",
|
2022-09-06 09:07:12 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-05 03:55:59 -04:00
|
|
|
interface IProps {
|
2021-09-07 17:26:49 -04:00
|
|
|
rerender: () => void;
|
2023-05-05 03:55:59 -04:00
|
|
|
}
|
2021-09-04 02:21:31 -04:00
|
|
|
|
|
|
|
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 -
|
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
|
|
|
);
|
2021-09-04 02:21:31 -04:00
|
|
|
}
|