bitburner-src/src/DevMenu/ui/General.tsx

215 lines
7.7 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useState } from "react";
2023-06-26 04:53:35 +02:00
import {
Accordion,
AccordionSummary,
AccordionDetails,
Button,
MenuItem,
Select,
SelectChangeEvent,
TextField,
Typography,
} from "@mui/material";
2021-09-17 01:23:03 +02:00
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
2023-06-26 04:53:35 +02:00
import { Player } from "@player";
2023-06-26 04:53:35 +02:00
import { FactionName } from "@enums";
import { useRerender } from "../../ui/React/hooks";
2023-06-26 04:53:35 +02:00
import { Money } from "../../ui/React/Money";
import { NumberInput } from "../../ui/React/NumberInput";
import { Hashes } from "../../ui/React/Hashes";
2022-09-06 15:07:12 +02:00
import { Router } from "../../ui/GameRoot";
import { Page } from "../../ui/Router";
import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { GangConstants } from "../../Gang/data/Constants";
import { checkForMessagesToSend } from "../../Message/MessageHelpers";
import { ThemeEvents } from "../../Themes/ui/Theme";
2023-06-26 04:53:35 +02:00
import { getEnumHelper } from "../../utils/EnumHelper";
import { formatRam } from "../../ui/formatNumber";
2021-09-14 02:37:35 +02:00
2022-09-06 15:07:12 +02:00
export function General(): React.ReactElement {
const rerender = useRerender(400);
const [error, setError] = useState(false);
const [corporationName, setCorporationName] = useState("");
2023-06-26 04:53:35 +02:00
const [gangFaction, setGangFaction] = useState(FactionName.SlumSnakes);
const [devMoney, setDevMoney] = useState(0);
2023-10-23 10:01:21 +02:00
const [hash, setHash] = useState(Player.hashManager.hashes);
2021-09-14 02:37:35 +02:00
// Money functions
const addCustomMoney = () => !Number.isNaN(devMoney) && Player.gainMoney(devMoney, "other");
const addMoney = (n: number) => () => n && Player.gainMoney(n, "other");
const setMoney = (n: number) => () => {
if (!isNaN(n)) Player.money = n;
};
const addHashes = () => hash && Player.hashManager.storeHashes(hash);
const homeComputer = Player.getHomeComputer();
2021-09-14 02:37:35 +02:00
// Ram functions
2023-10-23 10:01:21 +02:00
const doubleRam = () => {
homeComputer.maxRam *= 2;
rerender();
2023-10-23 10:01:21 +02:00
};
const ramSetter = (gb: number) => () => {
homeComputer.maxRam = gb;
rerender();
2023-10-23 10:01:21 +02:00
};
2021-09-14 02:37:35 +02:00
// Node-clearing functions
const quickB1tFlum3 = () => Router.toPage(Page.BitVerse, { flume: true, quick: true });
const b1tflum3 = () => Router.toPage(Page.BitVerse, { flume: true, quick: false });
const quickHackW0r1dD43m0n = () => Router.toPage(Page.BitVerse, { flume: false, quick: true });
const hackW0r1dD43m0n = () => Router.toPage(Page.BitVerse, { flume: false, quick: false });
2021-09-14 02:37:35 +02:00
// Corp functions
const createCorporation = () => {
Player.startCorporation(corporationName, false);
// Rerender so the corp menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
};
const destroyCorporation = () => {
Player.corporation = null;
// Rerender so the corp menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
// Blade functions
const joinBladeburner = () => {
2022-09-06 15:07:12 +02:00
Player.bladeburner = new Bladeburner();
// Rerender so the blade menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
};
const leaveBladeburner = () => {
Player.bladeburner = null;
// Rerender so the blade menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
// Gang functions
const startGang = () => {
const isHacking = gangFaction === FactionName.NiteSec || gangFaction === FactionName.TheBlackHand;
2022-09-06 15:07:12 +02:00
Player.startGang(gangFaction, isHacking);
// Rerender so the gang menu option will show up immediately on the devmenu page selection
ThemeEvents.emit();
};
const stopGang = () => {
Player.gang = null;
// Rerender so the gang menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
2023-06-26 04:53:35 +02:00
const setGangFactionDropdown = (event: SelectChangeEvent) => {
// Todo: Make this a more specific check when a GangName enumlike is added
if (!getEnumHelper("FactionName").isMember(event.target.value)) return;
setGangFaction(event.target.value);
};
// Misc functions
const checkMessages = () => checkForMessagesToSend();
useEffect(() => {
if (error) throw new ReferenceError("Manually thrown error");
}, [error]);
const moneyValues = [1e6, 1e9, 1e12, 1e15, Infinity];
const ramValues = [8, 64, 1024, 1048576, 1073741824];
2023-10-23 10:01:21 +02:00
2021-09-14 02:37:35 +02:00
return (
2021-09-18 03:30:02 +02:00
<Accordion TransitionProps={{ unmountOnExit: true }}>
2021-09-14 02:37:35 +02:00
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
2021-10-01 22:22:33 +02:00
<Typography>General</Typography>
2021-09-14 02:37:35 +02:00
</AccordionSummary>
<AccordionDetails>
<Typography>
Money (current: <Money money={Player.money} />)
</Typography>
2023-10-23 10:01:21 +02:00
{moneyValues.map((value) => (
<Button key={`add money ${value}`} onClick={addMoney(value)}>
+&nbsp;
<Money money={value} />
2023-10-23 10:01:21 +02:00
</Button>
))}
<br />
<NumberInput placeholder={"$$$"} onChange={setDevMoney} />
<Button onClick={addCustomMoney}>Give Money</Button>
<Button onClick={setMoney(0)}>Clear Money</Button>
{Player.hashManager.capacity > 0 && (
<>
<br />
<br />
<Typography>
Hashes (current: <Hashes hashes={Player.hashManager.hashes} /> /&nbsp;
<Hashes hashes={Player.hashManager.capacity} />)
</Typography>
<NumberInput disabled={!Player.hashManager} placeholder={"hashes"} onChange={setHash} />
<Button disabled={!Player.hashManager} onClick={addHashes}>
Give Hashes
</Button>
<Button disabled={!Player.hashManager} onClick={() => (Player.hashManager.hashes = 0)}>
Clear Hashes
</Button>
</>
)}
<br />
2023-10-23 10:01:21 +02:00
<br />
<Typography>Max Home RAM (current: {formatRam(homeComputer.maxRam)})</Typography>
{ramValues.map((gb) => (
<Button key={gb} onClick={ramSetter(gb)}>
{formatRam(gb)}
</Button>
))}
<Button onClick={doubleRam}>RAM *= 2</Button>
2021-10-01 19:08:37 +02:00
<br />
<br />
2023-10-23 10:01:21 +02:00
<Typography>Corporation:</Typography>
{Player.corporation ? (
<Button onClick={destroyCorporation}>Destroy Corporation</Button>
) : (
<>
2023-10-23 10:01:21 +02:00
<TextField
placeholder="Enter Corp Name"
value={corporationName}
onChange={(x) => setCorporationName(x.target.value)}
/>
<Button onClick={createCorporation}>Create Corporation</Button>
</>
)}
<br />
<br />
<Typography>Gang:</Typography>
{Player.gang ? (
<Button onClick={stopGang}>Leave Gang</Button>
) : (
<>
<Select value={gangFaction} onChange={setGangFactionDropdown}>
{GangConstants.Names.map((factionName) => (
<MenuItem key={factionName} value={factionName}>
{factionName}
</MenuItem>
))}
</Select>
<Button onClick={startGang}>Create Gang</Button>
</>
)}
<br />
<br />
2023-10-23 10:01:21 +02:00
<Typography>Bladeburner:</Typography>
{Player.bladeburner ? (
<Button onClick={leaveBladeburner}>Leave BladeBurner</Button>
) : (
<Button onClick={joinBladeburner}>Join BladeBurner</Button>
)}
<br />
2023-10-23 10:01:21 +02:00
<br />
<Typography>Misc:</Typography>
<Button onClick={quickB1tFlum3}>Quick b1t_flum3.exe</Button>
<Button onClick={b1tflum3}>Run b1t_flum3.exe</Button>
<br />
<Button onClick={quickHackW0r1dD43m0n}>Quick w0rld_d34m0n</Button>
<Button onClick={hackW0r1dD43m0n}>Hack w0rld_d34m0n</Button>
2023-10-23 10:01:21 +02:00
<br />
<Button onClick={() => setError(true)}>Throw Error</Button>
<Button onClick={checkMessages}>Check Messages</Button>
2021-09-14 02:37:35 +02:00
</AccordionDetails>
</Accordion>
);
}