From 23792333516bdf1c3af6cdad77c56707cf057dcd Mon Sep 17 00:00:00 2001 From: nickofolas Date: Wed, 4 May 2022 11:59:51 -0500 Subject: [PATCH] Fix faction augs cost check --- src/Faction/ui/AugmentationsPage.tsx | 6 +- src/Faction/ui/PurchaseableAugmentation.tsx | 166 -------------------- 2 files changed, 3 insertions(+), 169 deletions(-) delete mode 100644 src/Faction/ui/PurchaseableAugmentation.tsx diff --git a/src/Faction/ui/AugmentationsPage.tsx b/src/Faction/ui/AugmentationsPage.tsx index cfa9a7ed7..d86af05b0 100644 --- a/src/Faction/ui/AugmentationsPage.tsx +++ b/src/Faction/ui/AugmentationsPage.tsx @@ -197,11 +197,11 @@ export function AugmentationsPage(props: IProps): React.ReactElement { ownedAugNames={owned} player={player} canPurchase={(player, aug) => { - const augCost = aug.getCost(player).moneyCost; + const costs = aug.getCost(player); return ( hasAugmentationPrereqs(aug) && - props.faction.playerReputation >= aug.baseRepRequirement && - (augCost === 0 || player.money > augCost) + props.faction.playerReputation >= costs.repCost && + (costs.moneyCost === 0 || player.money > costs.moneyCost) ); }} purchaseAugmentation={(player, aug, showModal) => { diff --git a/src/Faction/ui/PurchaseableAugmentation.tsx b/src/Faction/ui/PurchaseableAugmentation.tsx deleted file mode 100644 index 749679d79..000000000 --- a/src/Faction/ui/PurchaseableAugmentation.tsx +++ /dev/null @@ -1,166 +0,0 @@ -/** - * React component for displaying a single augmentation for purchase through - * the faction UI - */ -import React, { useState } from "react"; - -import { hasAugmentationPrereqs, purchaseAugmentation } from "../FactionHelpers"; - -import { StaticAugmentations } from "../../Augmentation/StaticAugmentations"; -import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; -import { Faction } from "../Faction"; -import { IPlayer } from "../../PersonObjects/IPlayer"; -import { Settings } from "../../Settings/Settings"; -import { Money } from "../../ui/React/Money"; -import { Reputation } from "../../ui/React/Reputation"; - -import { Augmentation as AugFormat } from "../../ui/React/Augmentation"; -import Button from "@mui/material/Button"; -import Typography from "@mui/material/Typography"; -import Tooltip from "@mui/material/Tooltip"; -import Box from "@mui/material/Box"; -import { TableCell } from "../../ui/React/Table"; -import TableRow from "@mui/material/TableRow"; -import { use } from "../../ui/Context"; -import { PurchaseAugmentationModal } from "../../Augmentation/ui/PurchaseAugmentationModal"; - -interface IReqProps { - augName: string; - p: IPlayer; - hasReq: boolean; - rep: number; - hasRep: boolean; - cost: number; - hasCost: boolean; -} - -function Requirements(props: IReqProps): React.ReactElement { - const aug = StaticAugmentations[props.augName]; - if (!props.hasReq) { - return ( - - - Requires{" "} - {aug.prereqs.map((aug, i) => ( - - ))} - - - ); - } - - return ( - - - - - - - - - Requires faction reputation - - - - ); -} - -interface IProps { - augName: string; - faction: Faction; - p: IPlayer; - rerender: () => void; - owned?: boolean; -} - -export function PurchaseableAugmentation(props: IProps): React.ReactElement { - const player = use.Player(); - const [open, setOpen] = useState(false); - const aug = StaticAugmentations[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 repCosts = aug.getCost(player); - const moneyCost = repCosts.moneyCost; - const repCost = repCosts.repCost; - const hasReq = hasAugmentationPrereqs(aug); - const hasRep = props.faction.playerReputation >= repCost; - const hasCost = moneyCost === 0 || props.p.money > moneyCost; - - // 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 ${aug.getLevel(player)}`; - } - - 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} /> - - )} - - - {tooltip}} placement="top"> - {btnTxt} - - - - {!props.owned && ( - - )} - - ); -}