2022-01-21 23:29:24 +01:00
|
|
|
import React, { useEffect, useState } from "react";
|
2022-03-11 20:04:17 +01:00
|
|
|
|
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
Container,
|
|
|
|
Paper,
|
|
|
|
TableBody,
|
|
|
|
TableRow,
|
|
|
|
Typography
|
|
|
|
} from "@mui/material";
|
|
|
|
|
|
|
|
import { Augmentations } from "../../Augmentation/Augmentations";
|
|
|
|
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
|
2022-01-21 23:29:24 +01:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { Table, TableCell } from "../../ui/React/Table";
|
|
|
|
import { IRouter } from "../../ui/Router";
|
2022-03-11 20:04:17 +01:00
|
|
|
|
2022-01-21 23:29:24 +01:00
|
|
|
import { Faction } from "../Faction";
|
|
|
|
import { joinFaction } from "../FactionHelpers";
|
|
|
|
import { Factions } from "../Factions";
|
2021-09-20 07:18:20 +02:00
|
|
|
|
2021-10-23 21:22:58 +02:00
|
|
|
export const InvitationsSeen: string[] = [];
|
|
|
|
|
2021-08-15 22:20:10 +02:00
|
|
|
interface IProps {
|
2021-09-05 01:09:30 +02:00
|
|
|
player: IPlayer;
|
2021-09-17 08:04:44 +02:00
|
|
|
router: IRouter;
|
2021-08-15 22:20:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 08:04:44 +02:00
|
|
|
export function FactionsRoot(props: IProps): React.ReactElement {
|
2021-09-05 01:09:30 +02:00
|
|
|
const setRerender = useState(false)[1];
|
2021-09-20 23:26:47 +02:00
|
|
|
function rerender(): void {
|
|
|
|
setRerender((old) => !old);
|
|
|
|
}
|
|
|
|
useEffect(() => {
|
2021-09-25 19:31:42 +02:00
|
|
|
const id = setInterval(rerender, 200);
|
2021-09-20 23:26:47 +02:00
|
|
|
return () => clearInterval(id);
|
|
|
|
}, []);
|
2021-10-23 21:22:58 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
props.player.factionInvitations.forEach((faction) => {
|
|
|
|
if (InvitationsSeen.includes(faction)) return;
|
|
|
|
InvitationsSeen.push(faction);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2021-09-17 08:04:44 +02:00
|
|
|
function openFaction(faction: Faction): void {
|
|
|
|
props.router.toFaction(faction);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-08-15 22:20:10 +02:00
|
|
|
|
2022-03-11 01:39:54 +01:00
|
|
|
function openFactionAugPage(faction: Faction): void {
|
|
|
|
props.router.toFaction(faction, true);
|
|
|
|
}
|
|
|
|
|
2021-09-20 07:18:20 +02:00
|
|
|
function acceptInvitation(event: React.MouseEvent<HTMLButtonElement, MouseEvent>, faction: string): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (!event.isTrusted) return;
|
|
|
|
joinFaction(Factions[faction]);
|
|
|
|
setRerender((x) => !x);
|
|
|
|
}
|
2021-08-15 22:20:10 +02:00
|
|
|
|
2022-03-11 20:04:17 +01:00
|
|
|
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 ||
|
2022-03-12 00:56:34 +01:00
|
|
|
augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2 ||
|
|
|
|
Augmentations[augName].isSpecial
|
2022-03-11 20:04:17 +01:00
|
|
|
) continue;
|
2022-03-12 00:56:34 +01:00
|
|
|
augs.push(augName)
|
2022-03-11 20:04:17 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
augs = faction.augmentations.slice();
|
|
|
|
}
|
|
|
|
|
|
|
|
return augs.filter(
|
|
|
|
(augmentation: string) => !player.hasAugmentation(augmentation)
|
|
|
|
).length;
|
|
|
|
}
|
2022-03-21 13:13:28 +01:00
|
|
|
let allJoinedFactions = props.player.factions
|
|
|
|
allJoinedFactions = allJoinedFactions.sort((a, b) =>
|
|
|
|
allJoinedFactions.indexOf(a) - allJoinedFactions.indexOf(b));
|
2022-03-11 20:04:17 +01:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return (
|
2022-01-21 23:29:24 +01:00
|
|
|
<Container disableGutters maxWidth="md" sx={{ mx: 0, mb: 10 }}>
|
2021-09-25 09:09:27 +02:00
|
|
|
<Typography variant="h4">Factions</Typography>
|
2022-01-21 23:29:24 +01:00
|
|
|
<Typography mb={4}>
|
|
|
|
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.
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
<Typography variant="h5" color="primary" mt={2} mb={1}>
|
|
|
|
Factions you have joined:
|
|
|
|
</Typography>
|
2022-03-21 13:13:28 +01:00
|
|
|
{(allJoinedFactions.length > 0 && (
|
2022-01-21 23:55:10 +01:00
|
|
|
<Paper sx={{ my: 1, p: 1, pb: 0, display: "inline-block" }}>
|
2022-03-11 01:39:54 +01:00
|
|
|
<Table padding="none" style={{ width: "fit-content" }}>
|
2021-09-20 07:18:20 +02:00
|
|
|
<TableBody>
|
2022-03-21 13:13:28 +01:00
|
|
|
{allJoinedFactions.map((faction: string) => (
|
2021-09-20 07:18:20 +02:00
|
|
|
<TableRow key={faction}>
|
|
|
|
<TableCell>
|
2022-01-21 23:55:10 +01:00
|
|
|
<Typography noWrap mb={1}>
|
|
|
|
{faction}
|
|
|
|
</Typography>
|
2021-09-20 07:18:20 +02:00
|
|
|
</TableCell>
|
|
|
|
<TableCell align="right">
|
2022-01-21 23:55:10 +01:00
|
|
|
<Box ml={1} mb={1}>
|
2022-01-21 23:29:24 +01:00
|
|
|
<Button onClick={() => openFaction(Factions[faction])}>Details</Button>
|
|
|
|
</Box>
|
|
|
|
</TableCell>
|
2022-02-28 13:04:47 +01:00
|
|
|
<TableCell align="right">
|
2022-03-11 01:39:54 +01:00
|
|
|
<Box ml={1} mb={1}>
|
|
|
|
<Button sx={{ width: '100%' }} onClick={() => openFactionAugPage(Factions[faction])}>
|
2022-03-11 20:04:17 +01:00
|
|
|
Augmentations Left: {getAugsLeft(Factions[faction], props.player)}
|
2022-03-11 01:39:54 +01:00
|
|
|
</Button>
|
|
|
|
</Box>
|
2022-02-28 13:04:47 +01:00
|
|
|
</TableCell>
|
2022-01-21 23:29:24 +01:00
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
</Paper>
|
|
|
|
)) || <Typography>You haven't joined any factions.</Typography>}
|
|
|
|
<Typography variant="h5" color="primary" mt={4} mb={1}>
|
|
|
|
Outstanding Faction Invitations
|
|
|
|
</Typography>
|
|
|
|
<Typography mb={1}>
|
|
|
|
Factions you have been invited to. You can accept these faction invitations at any time:
|
|
|
|
</Typography>
|
|
|
|
{(props.player.factionInvitations.length > 0 && (
|
2022-01-21 23:55:10 +01:00
|
|
|
<Paper sx={{ my: 1, mb: 4, p: 1, pb: 0, display: "inline-block" }}>
|
2022-01-21 23:29:24 +01:00
|
|
|
<Table padding="none">
|
|
|
|
<TableBody>
|
|
|
|
{props.player.factionInvitations.map((faction: string) => (
|
|
|
|
<TableRow key={faction}>
|
|
|
|
<TableCell>
|
|
|
|
<Typography noWrap mb={1}>
|
|
|
|
{faction}
|
|
|
|
</Typography>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell align="right">
|
|
|
|
<Box ml={1} mb={1}>
|
|
|
|
<Button onClick={(e) => acceptInvitation(e, faction)}>Join!</Button>
|
|
|
|
</Box>
|
2021-09-20 07:18:20 +02:00
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
2022-01-21 23:29:24 +01:00
|
|
|
</Paper>
|
|
|
|
)) || <Typography>You have no outstanding faction invites.</Typography>}
|
|
|
|
</Container>
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
}
|