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

204 lines
6.9 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-22 17:32:04 +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";
import { Faction } from "../../Faction/Faction";
import { createSleevePurchasesFromCovenantPopup } from "../../PersonObjects/Sleeve/SleeveCovenantPurchases";
import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
2021-09-11 17:42:27 +02:00
import { createPopup } from "../../ui/React/createPopup";
2021-09-18 01:43:08 +02:00
import { use } from "../../ui/Context";
2021-09-11 17:42:27 +02:00
import { CreateGangPopup } from "./CreateGangPopup";
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-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;
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 hackingMissionInfo =
"Attempt a hacking mission for your faction. " +
"A mission is a mini game that, if won, earns you " +
"significant reputation with this faction. (Recommended hacking level: 200+)";
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-18 01:43:08 +02:00
export function FactionRoot(props: IProps): React.ReactElement {
2021-09-22 18:56:55 +02:00
const setRerender = useState(false)[1];
2021-09-22 17:32:04 +02:00
function rerender(): void {
2021-09-22 18:56:55 +02:00
setRerender((old) => !old);
2021-09-22 17:32:04 +02:00
}
2021-09-18 01:43:08 +02:00
const faction = props.faction;
2021-09-05 01:09:30 +02:00
2021-09-18 01:43:08 +02:00
const player = use.Player();
const router = use.Router();
const [purchasingAugs, setPurchasingAugs] = useState(false);
function manageGang(faction: Faction): 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-09-11 17:42:27 +02:00
const popupId = "create-gang-popup";
createPopup(popupId, CreateGangPopup, {
popupId: popupId,
2021-09-18 01:43:08 +02:00
facName: faction.name,
2021-09-20 07:24:39 +02:00
player: player,
router: router,
2021-09-05 01:09:30 +02:00
});
}
// Route to the main faction page
2021-09-18 01:43:08 +02:00
function routeToMain(): void {
setPurchasingAugs(false);
2021-09-05 01:09:30 +02:00
}
// Route to the purchase augmentation UI for this faction
2021-09-18 01:43:08 +02:00
function routeToPurchaseAugs(): void {
setPurchasingAugs(true);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function sleevePurchases(): void {
createSleevePurchasesFromCovenantPopup(player);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startFieldWork(faction: Faction): void {
2021-09-20 07:45:32 +02:00
player.startFactionFieldWork(router, faction);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startHackingContracts(faction: Faction): void {
2021-09-20 07:45:32 +02:00
player.startFactionHackWork(router, faction);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startHackingMission(faction: Faction): void {
player.singularityStopWork();
2021-09-19 23:05:27 +02:00
router.toHackingMission(faction);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startSecurityWork(faction: Faction): void {
2021-09-20 07:45:32 +02:00
player.startFactionSecurityWork(router, faction);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function MainPage({ faction }: { faction: Faction }): React.ReactElement {
const p = player;
2021-09-05 01:09:30 +02:00
const factionInfo = faction.getInfo();
// 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 = p.inGang() && p.getGangName() === faction.name;
// Flags for whether special options (gang, sleeve purchases, donate, etc.)
// should be shown
2021-09-09 05:47:34 +02:00
const favorToDonate = Math.floor(CONSTANTS.BaseFavorToDonate * BitNodeMultipliers.RepToDonateToFaction);
2021-09-05 01:09:30 +02:00
const canDonate = faction.favor >= favorToDonate;
2021-09-09 05:47:34 +02:00
const canPurchaseSleeves = faction.name === "The Covenant" && p.bitNodeN >= 10 && SourceFileFlags[10];
2021-09-05 01:09:30 +02:00
let canAccessGang = p.canAccessGang() && GangNames.includes(faction.name);
if (p.inGang()) {
if (p.getGangName() !== faction.name) {
canAccessGang = false;
} else if (p.getGangName() === faction.name) {
canAccessGang = true;
}
2019-04-14 11:08:10 +02:00
}
2021-09-05 01:09:30 +02:00
return (
2021-09-21 02:42:13 +02:00
<>
<Button onClick={() => router.toFactions()}>Back</Button>
2021-09-21 02:42:13 +02:00
<Typography variant="h4" color="primary">
{faction.name}
</Typography>
2021-09-05 01:09:30 +02:00
<Info faction={faction} factionInfo={factionInfo} />
2021-09-18 01:43:08 +02:00
{canAccessGang && <Option buttonText={"Manage Gang"} infoText={gangInfo} onClick={() => manageGang(faction)} />}
2021-09-05 01:09:30 +02:00
{!isPlayersGang && factionInfo.offerHackingMission && (
2021-09-18 01:43:08 +02:00
<Option
buttonText={"Hacking Mission"}
infoText={hackingMissionInfo}
onClick={() => startHackingMission(faction)}
/>
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offerHackingWork && (
<Option
buttonText={"Hacking Contracts"}
infoText={hackingContractsInfo}
2021-09-18 01:43:08 +02:00
onClick={() => startHackingContracts(faction)}
2021-09-05 01:09:30 +02:00
/>
)}
{!isPlayersGang && factionInfo.offerFieldWork && (
2021-09-18 01:43:08 +02:00
<Option buttonText={"Field Work"} infoText={fieldWorkInfo} onClick={() => startFieldWork(faction)} />
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offerSecurityWork && (
2021-09-18 01:43:08 +02:00
<Option buttonText={"Security Work"} infoText={securityWorkInfo} onClick={() => startSecurityWork(faction)} />
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offersWork() && (
<DonateOption
2021-09-18 01:43:08 +02:00
faction={faction}
p={player}
rerender={rerender}
2021-09-05 01:09:30 +02:00
favorToDonate={favorToDonate}
disabled={!canDonate}
/>
)}
2021-09-18 01:43:08 +02:00
<Option buttonText={"Purchase Augmentations"} infoText={augmentationsInfo} onClick={routeToPurchaseAugs} />
2021-09-05 01:09:30 +02:00
{canPurchaseSleeves && (
<Option
buttonText={"Purchase & Upgrade Duplicate Sleeves"}
infoText={sleevePurchasesInfo}
2021-09-18 01:43:08 +02:00
onClick={sleevePurchases}
2021-09-05 01:09:30 +02:00
/>
)}
2021-09-21 02:42:13 +02:00
</>
2021-09-05 01:09:30 +02:00
);
}
2021-09-18 01:43:08 +02:00
return purchasingAugs ? (
<AugmentationsPage faction={faction} routeToMainPage={routeToMain} />
) : (
<MainPage faction={faction} />
);
2019-04-14 11:08:10 +02:00
}