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

230 lines
7.8 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
*/
import * as React from "react";
import { AugmentationsPage } from "./AugmentationsPage";
import { DonateOption } from "./DonateOption";
import { Info } from "./Info";
import { Option } from "./Option";
import { CONSTANTS } from "../../Constants";
import { IEngine } from "../../IEngine";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { Faction } from "../../Faction/Faction";
import { IPlayer } from "../../PersonObjects/IPlayer";
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";
import { CreateGangPopup } from "./CreateGangPopup";
2019-04-14 11:08:10 +02:00
type IProps = {
2021-09-05 01:09:30 +02:00
engine: IEngine;
initiallyOnAugmentationsPage?: boolean;
faction: Faction;
p: IPlayer;
startHackingMissionFn: (faction: Faction) => void;
};
2019-04-14 11:08:10 +02:00
type IState = {
2021-09-05 01:09:30 +02:00
rerenderFlag: boolean;
purchasingAugs: boolean;
};
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
];
export class FactionRoot extends React.Component<IProps, IState> {
2021-09-05 01:09:30 +02:00
constructor(props: IProps) {
super(props);
this.state = {
rerenderFlag: false,
2021-09-09 05:47:34 +02:00
purchasingAugs: props.initiallyOnAugmentationsPage ? props.initiallyOnAugmentationsPage : false,
2021-09-05 01:09:30 +02:00
};
this.manageGang = this.manageGang.bind(this);
this.rerender = this.rerender.bind(this);
this.routeToMain = this.routeToMain.bind(this);
this.routeToPurchaseAugs = this.routeToPurchaseAugs.bind(this);
this.sleevePurchases = this.sleevePurchases.bind(this);
this.startFieldWork = this.startFieldWork.bind(this);
this.startHackingContracts = this.startHackingContracts.bind(this);
this.startHackingMission = this.startHackingMission.bind(this);
this.startSecurityWork = this.startSecurityWork.bind(this);
}
manageGang(): void {
// If player already has a gang, just go to the gang UI
if (this.props.p.inGang()) {
return this.props.engine.loadGangContent();
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,
facName: this.props.faction.name,
p: this.props.p,
engine: this.props.engine
2021-09-05 01:09:30 +02:00
});
}
rerender(): void {
this.setState((prevState) => {
return {
rerenderFlag: !prevState.rerenderFlag,
};
});
}
// Route to the main faction page
routeToMain(): void {
this.setState({ purchasingAugs: false });
}
// Route to the purchase augmentation UI for this faction
routeToPurchaseAugs(): void {
this.setState({ purchasingAugs: true });
}
sleevePurchases(): void {
createSleevePurchasesFromCovenantPopup(this.props.p);
}
startFieldWork(): void {
this.props.p.startFactionFieldWork(this.props.faction);
}
startHackingContracts(): void {
this.props.p.startFactionHackWork(this.props.faction);
}
startHackingMission(): void {
const fac = this.props.faction;
this.props.p.singularityStopWork();
this.props.engine.loadMissionContent();
this.props.startHackingMissionFn(fac);
}
startSecurityWork(): void {
this.props.p.startFactionSecurityWork(this.props.faction);
}
render(): React.ReactNode {
2021-09-09 05:47:34 +02:00
return this.state.purchasingAugs ? this.renderAugmentationsPage() : this.renderMainPage();
2021-09-05 01:09:30 +02:00
}
renderMainPage(): React.ReactNode {
const p = this.props.p;
const faction = this.props.faction;
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 (
<div id="faction-container">
2021-09-05 01:09:30 +02:00
<h1>{faction.name}</h1>
<Info faction={faction} factionInfo={factionInfo} />
2021-09-09 05:47:34 +02:00
{canAccessGang && <Option buttonText={"Manage Gang"} infoText={gangInfo} onClick={this.manageGang} />}
2021-09-05 01:09:30 +02:00
{!isPlayersGang && factionInfo.offerHackingMission && (
2021-09-09 05:47:34 +02:00
<Option buttonText={"Hacking Mission"} infoText={hackingMissionInfo} onClick={this.startHackingMission} />
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offerHackingWork && (
<Option
buttonText={"Hacking Contracts"}
infoText={hackingContractsInfo}
onClick={this.startHackingContracts}
/>
)}
{!isPlayersGang && factionInfo.offerFieldWork && (
2021-09-09 05:47:34 +02:00
<Option buttonText={"Field Work"} infoText={fieldWorkInfo} onClick={this.startFieldWork} />
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offerSecurityWork && (
2021-09-09 05:47:34 +02:00
<Option buttonText={"Security Work"} infoText={securityWorkInfo} onClick={this.startSecurityWork} />
2021-09-05 01:09:30 +02:00
)}
{!isPlayersGang && factionInfo.offersWork() && (
<DonateOption
faction={this.props.faction}
p={this.props.p}
rerender={this.rerender}
favorToDonate={favorToDonate}
disabled={!canDonate}
/>
)}
2021-09-09 05:47:34 +02:00
<Option buttonText={"Purchase Augmentations"} infoText={augmentationsInfo} onClick={this.routeToPurchaseAugs} />
2021-09-05 01:09:30 +02:00
{canPurchaseSleeves && (
<Option
buttonText={"Purchase & Upgrade Duplicate Sleeves"}
infoText={sleevePurchasesInfo}
onClick={this.sleevePurchases}
/>
)}
</div>
);
}
renderAugmentationsPage(): React.ReactNode {
return (
2021-09-11 18:24:09 +02:00
<>
2021-09-09 05:47:34 +02:00
<AugmentationsPage faction={this.props.faction} p={this.props.p} routeToMainPage={this.routeToMain} />
2021-09-11 18:24:09 +02:00
</>
2021-09-05 01:09:30 +02:00
);
}
2019-04-14 11:08:10 +02:00
}