bitburner-src/src/Faction/ui/FactionRoot.tsx

209 lines
6.7 KiB
TypeScript
Raw Normal View History

2019-04-14 11:08:10 +02:00
/**
* Root React Component for displaying a Faction's UI.
* This is the component for displaying a single faction's UI, not the list of all
* accessible factions
*/
2021-09-27 23:09:48 +02:00
import React, { useState, useEffect } from "react";
2019-04-14 11:08:10 +02:00
import { AugmentationsPage } from "./AugmentationsPage";
import { DonateOption } from "./DonateOption";
import { Info } from "./Info";
import { Option } from "./Option";
import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
2022-03-06 05:05:55 +01:00
import { Faction } from "../Faction";
2019-04-14 11:08:10 +02:00
2021-09-18 01:43:08 +02:00
import { use } from "../../ui/Context";
2021-10-01 19:36:59 +02:00
import { CreateGangModal } from "./CreateGangModal";
2019-04-14 11:08:10 +02:00
2021-09-21 02:42:13 +02:00
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
2021-09-27 02:55:38 +02:00
import { CovenantPurchasesRoot } from "../../PersonObjects/Sleeve/ui/CovenantPurchasesRoot";
2021-09-21 02:42:13 +02:00
2019-04-14 11:08:10 +02:00
type IProps = {
2021-09-18 10:01:07 +02:00
faction: Faction;
2022-03-11 01:39:54 +01:00
augPage: boolean;
2021-09-05 01:09:30 +02:00
};
2019-04-14 11:08:10 +02:00
// Info text for all options on the UI
2021-09-09 05:47:34 +02:00
const gangInfo = "Create and manage a gang for this Faction. Gangs will earn you money and " + "faction reputation";
2021-09-05 01:09:30 +02:00
const hackingContractsInfo =
"Complete hacking contracts for your faction. " +
"Your effectiveness, which determines how much " +
"reputation you gain for this faction, is based on your hacking skill. " +
"You will gain hacking exp.";
const fieldWorkInfo =
"Carry out field missions for your faction. " +
"Your effectiveness, which determines how much " +
"reputation you gain for this faction, is based on all of your stats. " +
"You will gain exp for all stats.";
const securityWorkInfo =
"Serve in a security detail for your faction. " +
"Your effectiveness, which determines how much " +
"reputation you gain for this faction, is based on your combat stats. " +
"You will gain exp for all combat stats.";
const augmentationsInfo =
"As your reputation with this faction rises, you will " +
"unlock Augmentations, which you can purchase to enhance " +
"your abilities.";
2021-09-09 05:47:34 +02:00
const sleevePurchasesInfo = "Purchase Duplicate Sleeves and upgrades. These are permanent!";
2019-04-14 11:08:10 +02:00
const GangNames = [
2021-09-05 01:09:30 +02:00
"Slum Snakes",
"Tetrads",
"The Syndicate",
"The Dark Army",
"Speakers for the Dead",
"NiteSec",
"The Black Hand",
2019-04-14 11:08:10 +02:00
];
2021-09-30 23:02:07 +02:00
interface IMainProps {
faction: Faction;
rerender: () => void;
onAugmentations: () => void;
}
2021-09-05 01:09:30 +02:00
2021-09-30 23:02:07 +02:00
function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.ReactElement {
2021-09-18 01:43:08 +02:00
const player = use.Player();
const router = use.Router();
2021-09-30 23:02:07 +02:00
const [sleevesOpen, setSleevesOpen] = useState(false);
2021-10-01 19:36:59 +02:00
const [gangOpen, setGangOpen] = useState(false);
2021-09-30 23:02:07 +02:00
const factionInfo = faction.getInfo();
2021-09-18 01:43:08 +02:00
2021-10-01 19:36:59 +02:00
function manageGang(): void {
2021-09-05 01:09:30 +02:00
// If player already has a gang, just go to the gang UI
2021-09-18 01:43:08 +02:00
if (player.inGang()) {
return router.toGang();
2019-04-14 11:08:10 +02:00
}
2021-10-01 19:36:59 +02:00
setGangOpen(true);
2021-09-05 01:09:30 +02:00
}
function startWork(): void {
player.startFocusing();
router.toWork();
}
2021-09-18 01:43:08 +02:00
function startFieldWork(faction: Faction): void {
player.startFactionFieldWork(faction);
startWork();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startHackingContracts(faction: Faction): void {
player.startFactionHackWork(faction);
startWork();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startSecurityWork(faction: Faction): void {
player.startFactionSecurityWork(faction);
startWork();
2021-09-05 01:09:30 +02:00
}
2021-09-30 23:02:07 +02:00
// We have a special flag for whether the player this faction is the player's
// gang faction because if the player has a gang, they cannot do any other action
const isPlayersGang = player.inGang() && player.getGangName() === faction.name;
2021-09-05 01:09:30 +02:00
2021-09-30 23:02:07 +02:00
// Flags for whether special options (gang, sleeve purchases, donate, etc.)
// should be shown
const favorToDonate = Math.floor(CONSTANTS.BaseFavorToDonate * BitNodeMultipliers.RepToDonateToFaction);
const canDonate = faction.favor >= favorToDonate;
2021-09-05 01:09:30 +02:00
const canPurchaseSleeves = faction.name === "The Covenant" && player.bitNodeN === 10;
2021-09-05 01:09:30 +02:00
let canAccessGang = player.canAccessGang() && GangNames.includes(faction.name);
if (player.inGang()) {
if (player.getGangName() !== faction.name) {
2021-09-30 23:02:07 +02:00
canAccessGang = false;
} else if (player.getGangName() === faction.name) {
2021-09-30 23:02:07 +02:00
canAccessGang = true;
2019-04-14 11:08:10 +02:00
}
2021-09-30 23:02:07 +02:00
}
2019-04-14 11:08:10 +02:00
2021-09-30 23:02:07 +02:00
return (
<>
<Button onClick={() => router.toFactions()}>Back</Button>
<Typography variant="h4" color="primary">
{faction.name}
</Typography>
<Info faction={faction} factionInfo={factionInfo} />
2021-10-01 19:36:59 +02:00
{canAccessGang && (
<>
<Option buttonText={"Manage Gang"} infoText={gangInfo} onClick={manageGang} />
<CreateGangModal facName={faction.name} open={gangOpen} onClose={() => setGangOpen(false)} />
</>
)}
2021-09-30 23:02:07 +02:00
{!isPlayersGang && factionInfo.offerHackingWork && (
<Option
buttonText={"Hacking Contracts"}
infoText={hackingContractsInfo}
onClick={() => startHackingContracts(faction)}
/>
)}
{!isPlayersGang && factionInfo.offerFieldWork && (
<Option buttonText={"Field Work"} infoText={fieldWorkInfo} onClick={() => startFieldWork(faction)} />
)}
{!isPlayersGang && factionInfo.offerSecurityWork && (
<Option buttonText={"Security Work"} infoText={securityWorkInfo} onClick={() => startSecurityWork(faction)} />
)}
{!isPlayersGang && factionInfo.offersWork() && (
<DonateOption
faction={faction}
p={player}
rerender={rerender}
favorToDonate={favorToDonate}
disabled={!canDonate}
/>
)}
<Option buttonText={"Purchase Augmentations"} infoText={augmentationsInfo} onClick={onAugmentations} />
{canPurchaseSleeves && (
<>
2021-09-18 01:43:08 +02:00
<Option
2021-09-30 23:02:07 +02:00
buttonText={"Purchase & Upgrade Duplicate Sleeves"}
infoText={sleevePurchasesInfo}
onClick={() => setSleevesOpen(true)}
2021-09-05 01:09:30 +02:00
/>
2021-09-30 23:02:07 +02:00
<CovenantPurchasesRoot open={sleevesOpen} onClose={() => setSleevesOpen(false)} />
</>
)}
</>
);
}
export function FactionRoot(props: IProps): React.ReactElement {
const setRerender = useState(false)[1];
const player = use.Player();
const router = use.Router();
const [purchasingAugs, setPurchasingAugs] = useState(false);
2021-09-30 23:02:07 +02:00
function rerender(): void {
setRerender((old) => !old);
2021-09-05 01:09:30 +02:00
}
2021-09-30 23:02:07 +02:00
useEffect(() => {
const id = setInterval(rerender, 200);
return () => clearInterval(id);
}, []);
const faction = props.faction;
if (player && !player.factions.includes(faction.name)) {
2022-03-11 04:17:01 +01:00
return (
<>
<Typography variant="h4" color="primary">
You have not joined {faction.name} yet!
</Typography>
<Button onClick={() => router.toFactions()}>Back to Factions</Button>
</>
);
}
2021-09-30 23:02:07 +02:00
2021-09-18 01:43:08 +02:00
return purchasingAugs ? (
2021-09-30 23:02:07 +02:00
<AugmentationsPage faction={faction} routeToMainPage={() => setPurchasingAugs(false)} />
2021-09-18 01:43:08 +02:00
) : (
2021-09-30 23:02:07 +02:00
<MainPage rerender={rerender} faction={faction} onAugmentations={() => setPurchasingAugs(true)} />
2021-09-18 01:43:08 +02:00
);
2019-04-14 11:08:10 +02:00
}