/**
* React component for displaying a single augmentation for purchase through
* the faction UI
*/
import React, { useState } from "react";
import { hasAugmentationPrereqs, purchaseAugmentation } from "../../Faction/FactionHelpers";
import { PurchaseAugmentationModal } from "./PurchaseAugmentationModal";
import { Augmentations } from "../Augmentations";
import { AugmentationNames } from "../data/AugmentationNames";
import { Faction } from "../../Faction/Faction";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { Settings } from "../../Settings/Settings";
import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
import { Reputation } from "../../ui/React/Reputation";
import { CheckBox, CheckBoxOutlineBlank, Verified, Info, Report, CheckCircle } from "@mui/icons-material";
import { Augmentation as AugFormat } from "../../ui/React/Augmentation";
import { Paper, Button, Typography, Tooltip, Box, TableRow, Container, List, ListItem } from "@mui/material";
import { TableCell } from "../../ui/React/Table";
import { getNextNeuroFluxLevel } from "../../Augmentation/AugmentationHelpers";
import { Augmentation } from "../Augmentation";
// interface IReqProps {
// augName: string;
// p: IPlayer;
// hasReq: boolean;
// rep: number;
// hasRep: boolean;
// cost: number;
// hasCost: boolean;
// }
// function Requirements(props: IReqProps): React.ReactElement {
// const aug = Augmentations[props.augName];
// if (!props.hasReq) {
// return (
//
//
// Requires{" "}
// {aug.prereqs.map((aug, i) => (
//
// ))}
//
//
// );
// }
// return (
//
//
//
//
//
//
//
//
// Requires faction reputation
//
//
//
// );
// }
interface IPreReqsProps {
player: IPlayer;
aug: Augmentation;
}
const PreReqs = (props: IPreReqsProps): React.ReactElement => {
const ownedPreReqs = props.aug.prereqs.filter((aug) => props.player.hasAugmentation(aug));
const hasPreReqs = props.aug.prereqs.length > 0 && ownedPreReqs.length === props.aug.prereqs.length;
return (
This Augmentation has the following pre-requisite(s):
{props.aug.prereqs.map((preAug) => (
))}
}
>
{hasPreReqs ? (
<>
Pre-requisites Owned
>
) : (
<>
Missing {props.aug.prereqs.length - ownedPreReqs.length} pre-requisite(s)
>
)}
);
};
interface IExclusiveProps {
player: IPlayer;
aug: Augmentation;
}
const Exclusive = (props: IExclusiveProps): React.ReactElement => {
return (
This Augmentation can only be acquired from the following source(s):
-
{props.aug.factions[0]} faction
{props.player.canAccessGang() && (
-
Certain gangs
)}
{props.player.canAccessGrafting() && (
-
Grafting
)}
}
>
);
};
interface IReqProps {
value: string;
color: string;
fulfilled: boolean;
}
const Requirement = (props: IReqProps): React.ReactElement => {
return (
{props.fulfilled ? : }
{props.value}
);
};
interface IPurchaseableAugsProps {
augNames: string[];
player: IPlayer;
canPurchase: (player: IPlayer, aug: Augmentation) => boolean;
purchaseAugmentation: (player: IPlayer, aug: Augmentation, showModal: (open: boolean) => void) => void;
rep?: number;
}
export const PurchaseableAugmentations = (props: IPurchaseableAugsProps): React.ReactElement => {
return (
{props.augNames.map((augName: string) => {
const aug = Augmentations[augName];
const info = typeof aug.info === "string" ? {aug.info} : aug.info;
const description = (
<>
{info}
{aug.stats}
>
);
return (
{augName}
{augName === AugmentationNames.NeuroFluxGovernor && ` - Level ${getNextNeuroFluxLevel()}`}
{description}
>
}
>
{aug.name}
{aug.name === AugmentationNames.NeuroFluxGovernor && ` - Level ${getNextNeuroFluxLevel()}`}
{aug.factions.length === 1 && }
{aug.prereqs.length > 0 && }
aug.baseCost}
value={numeralWrapper.formatMoney(aug.baseCost)}
color={Settings.theme.money}
/>
{props.rep !== undefined && (
= aug.baseRepRequirement}
value={`${numeralWrapper.formatReputation(aug.baseRepRequirement)} reputation`}
color={Settings.theme.rep}
/>
)}
);
})}
);
};
interface IPurchaseableAugProps {
augName: string;
faction: Faction;
p: IPlayer;
rerender: () => void;
owned?: boolean;
}
export function PurchaseableAugmentation(props: IPurchaseableAugProps): React.ReactElement {
const [open, setOpen] = useState(false);
const aug = Augmentations[props.augName];
if (aug == null) throw new Error(`aug ${props.augName} does not exists`);
if (aug == null) {
console.error(
`Invalid Augmentation when trying to create PurchaseableAugmentation display element: ${props.augName}`,
);
return <>>;
}
const moneyCost = aug.baseCost;
const repCost = aug.baseRepRequirement;
const hasReq = hasAugmentationPrereqs(aug);
const hasRep = props.faction.playerReputation >= repCost;
const hasCost = aug.baseCost === 0 || props.p.money > aug.baseCost;
// Determine UI properties
const color: "error" | "primary" = !hasReq || !hasRep || !hasCost ? "error" : "primary";
// Determine button txt
let btnTxt = aug.name;
if (aug.name === AugmentationNames.NeuroFluxGovernor) {
btnTxt += ` - Level ${getNextNeuroFluxLevel()}`;
}
let tooltip = <>>;
if (typeof aug.info === "string") {
tooltip = (
<>
{aug.info}
{aug.stats}
>
);
} else
tooltip = (
<>
{aug.info}
{aug.stats}
>
);
function handleClick(): void {
if (color === "error") return;
if (!Settings.SuppressBuyAugmentationConfirmation) {
setOpen(true);
} else {
purchaseAugmentation(aug, props.faction);
props.rerender();
}
}
return (
{!props.owned && (
setOpen(false)}
aug={aug}
faction={props.faction}
rerender={props.rerender}
/>
)}
{tooltip}} placement="top">
{btnTxt}
{!props.owned && (
)}
);
}