import React, { useEffect, useState } from "react"; import { Box, Button, Container, Paper, TableBody, TableRow, Typography } from "@mui/material"; import { Augmentations } from "../../Augmentation/Augmentations"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { IPlayer } from "../../PersonObjects/IPlayer"; import { Table, TableCell } from "../../ui/React/Table"; import { IRouter } from "../../ui/Router"; import { Faction } from "../Faction"; import { joinFaction } from "../FactionHelpers"; import { Factions } from "../Factions"; export const InvitationsSeen: string[] = []; interface IProps { player: IPlayer; router: IRouter; } export function FactionsRoot(props: IProps): React.ReactElement { const setRerender = useState(false)[1]; function rerender(): void { setRerender((old) => !old); } useEffect(() => { const id = setInterval(rerender, 200); return () => clearInterval(id); }, []); useEffect(() => { props.player.factionInvitations.forEach((faction) => { if (InvitationsSeen.includes(faction)) return; InvitationsSeen.push(faction); }); }, []); function openFaction(faction: Faction): void { props.router.toFaction(faction); } function openFactionAugPage(faction: Faction): void { props.router.toFaction(faction, true); } function acceptInvitation(event: React.MouseEvent, faction: string): void { if (!event.isTrusted) return; joinFaction(Factions[faction]); setRerender((x) => !x); } const getAugsLeft = (faction: Faction, player: IPlayer): number => { const isPlayersGang = player.inGang() && player.getGangName() === faction.name; let augs: string[] = []; if (isPlayersGang) { for (const augName of Object.keys(Augmentations)) { if ( augName === AugmentationNames.NeuroFluxGovernor || augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2 ) continue; if (!Augmentations[augName].isSpecial) { augs.push(augName) } } } else { augs = faction.augmentations.slice(); } return augs.filter( (augmentation: string) => !player.hasAugmentation(augmentation) ).length; } return ( Factions Throughout the game you may receive invitations from factions. There are many different factions, and each faction has different criteria for determining its potential members. Joining a faction and furthering its cause is crucial to progressing in the game and unlocking endgame content. Factions you have joined: {(props.player.factions.length > 0 && ( {props.player.factions.map((faction: string) => ( {faction} ))}
)) || You haven't joined any factions.} Outstanding Faction Invitations Factions you have been invited to. You can accept these faction invitations at any time: {(props.player.factionInvitations.length > 0 && ( {props.player.factionInvitations.map((faction: string) => ( {faction} ))}
)) || You have no outstanding faction invites.}
); }