mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
/**
|
|
* Root React component for the popup that lets player purchase Duplicate
|
|
* Sleeves and Sleeve-related upgrades from The Covenant
|
|
*/
|
|
import React, { useState } from "react";
|
|
|
|
import { CovenantSleeveMemoryUpgrade } from "./CovenantSleeveMemoryUpgrade";
|
|
|
|
import { Sleeve } from "../Sleeve";
|
|
import { BaseCostPerSleeve, MaxSleevesFromCovenant } from "../SleeveCovenantPurchases";
|
|
|
|
import { Money } from "../../../ui/React/Money";
|
|
import { Modal } from "../../../ui/React/Modal";
|
|
import { use } from "../../../ui/Context";
|
|
|
|
import { dialogBoxCreate } from "../../../ui/React/DialogBox";
|
|
import Typography from "@mui/material/Typography";
|
|
import Button from "@mui/material/Button";
|
|
import { FactionNames } from "../../../Faction/data/FactionNames";
|
|
|
|
interface IProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export function CovenantPurchasesRoot(props: IProps): React.ReactElement {
|
|
const player = use.Player();
|
|
const [update, setUpdate] = useState(0);
|
|
|
|
/**
|
|
* Get the cost to purchase a new Duplicate Sleeve
|
|
*/
|
|
function purchaseCost(): number {
|
|
return Math.pow(10, player.sleevesFromCovenant) * BaseCostPerSleeve;
|
|
}
|
|
|
|
/**
|
|
* Force a rerender by just changing an arbitrary state value
|
|
*/
|
|
function rerender(): void {
|
|
setUpdate(update + 1);
|
|
}
|
|
|
|
// Purchasing a new Duplicate Sleeve
|
|
let purchaseDisabled = false;
|
|
if (!player.canAfford(purchaseCost())) {
|
|
purchaseDisabled = true;
|
|
}
|
|
if (player.sleevesFromCovenant >= MaxSleevesFromCovenant) {
|
|
purchaseDisabled = true;
|
|
}
|
|
|
|
function purchaseOnClick(): void {
|
|
if (player.sleevesFromCovenant >= MaxSleevesFromCovenant) return;
|
|
|
|
if (player.canAfford(purchaseCost())) {
|
|
player.loseMoney(purchaseCost(), "sleeves");
|
|
player.sleevesFromCovenant += 1;
|
|
player.sleeves.push(new Sleeve(player));
|
|
rerender();
|
|
} else {
|
|
dialogBoxCreate(`You cannot afford to purchase a Duplicate Sleeve`);
|
|
}
|
|
}
|
|
|
|
// Purchasing Upgrades for Sleeves
|
|
const upgradePanels = [];
|
|
for (let i = 0; i < player.sleeves.length; ++i) {
|
|
const sleeve = player.sleeves[i];
|
|
upgradePanels.push(<CovenantSleeveMemoryUpgrade index={i} p={player} rerender={rerender} sleeve={sleeve} />);
|
|
}
|
|
|
|
return (
|
|
<Modal open={props.open} onClose={props.onClose}>
|
|
<>
|
|
{player.sleevesFromCovenant < MaxSleevesFromCovenant && (
|
|
<>
|
|
<Typography>
|
|
Purchase an additional Sleeves. These Duplicate Sleeves are permanent (they persist through BitNodes). You
|
|
can purchase a total of {MaxSleevesFromCovenant} from {FactionNames.TheCovenant}.
|
|
</Typography>
|
|
<Button disabled={purchaseDisabled} onClick={purchaseOnClick}>
|
|
Purchase -
|
|
<Money money={purchaseCost()} player={player} />
|
|
</Button>
|
|
</>
|
|
)}
|
|
<br />
|
|
<br />
|
|
<Typography>You can also purchase upgrades for your Sleeves. These upgrades are also permanent.</Typography>
|
|
{upgradePanels}
|
|
</>
|
|
</Modal>
|
|
);
|
|
}
|