mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-12 16:27:34 +01:00
Fix faction augs cost check
This commit is contained in:
parent
d0ebf5e14e
commit
2379233351
@ -197,11 +197,11 @@ export function AugmentationsPage(props: IProps): React.ReactElement {
|
|||||||
ownedAugNames={owned}
|
ownedAugNames={owned}
|
||||||
player={player}
|
player={player}
|
||||||
canPurchase={(player, aug) => {
|
canPurchase={(player, aug) => {
|
||||||
const augCost = aug.getCost(player).moneyCost;
|
const costs = aug.getCost(player);
|
||||||
return (
|
return (
|
||||||
hasAugmentationPrereqs(aug) &&
|
hasAugmentationPrereqs(aug) &&
|
||||||
props.faction.playerReputation >= aug.baseRepRequirement &&
|
props.faction.playerReputation >= costs.repCost &&
|
||||||
(augCost === 0 || player.money > augCost)
|
(costs.moneyCost === 0 || player.money > costs.moneyCost)
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
purchaseAugmentation={(player, aug, showModal) => {
|
purchaseAugmentation={(player, aug, showModal) => {
|
||||||
|
@ -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 (
|
|
||||||
<TableCell key={1} colSpan={2}>
|
|
||||||
<Typography color="error">
|
|
||||||
Requires{" "}
|
|
||||||
{aug.prereqs.map((aug, i) => (
|
|
||||||
<AugFormat key={i} name={aug} />
|
|
||||||
))}
|
|
||||||
</Typography>
|
|
||||||
</TableCell>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<React.Fragment key="f">
|
|
||||||
<TableCell key={1}>
|
|
||||||
<Typography>
|
|
||||||
<Money money={props.cost} player={props.p} />
|
|
||||||
</Typography>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell key={2}>
|
|
||||||
<Typography color={props.hasRep ? "primary" : "error"}>
|
|
||||||
Requires <Reputation reputation={props.rep} /> faction reputation
|
|
||||||
</Typography>
|
|
||||||
</TableCell>
|
|
||||||
</React.Fragment>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = (
|
|
||||||
<>
|
|
||||||
<span>{aug.info}</span>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
{aug.stats}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
} else
|
|
||||||
tooltip = (
|
|
||||||
<>
|
|
||||||
{aug.info}
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
{aug.stats}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
function handleClick(): void {
|
|
||||||
if (color === "error") return;
|
|
||||||
if (!Settings.SuppressBuyAugmentationConfirmation) {
|
|
||||||
setOpen(true);
|
|
||||||
} else {
|
|
||||||
purchaseAugmentation(aug, props.faction);
|
|
||||||
props.rerender();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TableRow>
|
|
||||||
{!props.owned && (
|
|
||||||
<TableCell key={0}>
|
|
||||||
<Button onClick={handleClick} color={color}>
|
|
||||||
Buy
|
|
||||||
</Button>
|
|
||||||
<PurchaseAugmentationModal open={open} onClose={() => setOpen(false)} aug={aug} faction={props.faction} />
|
|
||||||
</TableCell>
|
|
||||||
)}
|
|
||||||
<TableCell key={1}>
|
|
||||||
<Box display="flex">
|
|
||||||
<Tooltip title={<Typography>{tooltip}</Typography>} placement="top">
|
|
||||||
<Typography>{btnTxt}</Typography>
|
|
||||||
</Tooltip>
|
|
||||||
</Box>
|
|
||||||
</TableCell>
|
|
||||||
{!props.owned && (
|
|
||||||
<Requirements
|
|
||||||
key={2}
|
|
||||||
augName={props.augName}
|
|
||||||
p={props.p}
|
|
||||||
cost={moneyCost}
|
|
||||||
rep={repCost}
|
|
||||||
hasReq={hasReq}
|
|
||||||
hasRep={hasRep}
|
|
||||||
hasCost={hasCost}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user