diff --git a/src/NetscriptFunctions/Grafting.ts b/src/NetscriptFunctions/Grafting.ts index 4e7605acc..8057a207e 100644 --- a/src/NetscriptFunctions/Grafting.ts +++ b/src/NetscriptFunctions/Grafting.ts @@ -1,5 +1,6 @@ -import { CityName } from "../Locations/data/CityNames"; import { Augmentations } from "../Augmentation/Augmentations"; +import { hasAugmentationPrereqs } from "../Faction/FactionHelpers"; +import { CityName } from "../Locations/data/CityNames"; import { getRamCost } from "../Netscript/RamCostGenerator"; import { WorkerScript } from "../Netscript/WorkerScript"; import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation"; @@ -70,6 +71,11 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h return false; } + if (!hasAugmentationPrereqs(craftableAug.augmentation)) { + workerScript.log("grafting.graftAugmentation", () => `You don't have the pre-requisites for ${augName}`); + return false; + } + player.loseMoney(craftableAug.cost, "augmentations"); player.startGraftAugmentationWork(augName, craftableAug.time); diff --git a/src/PersonObjects/Grafting/ui/GraftingRoot.tsx b/src/PersonObjects/Grafting/ui/GraftingRoot.tsx index 280af238c..895434b82 100644 --- a/src/PersonObjects/Grafting/ui/GraftingRoot.tsx +++ b/src/PersonObjects/Grafting/ui/GraftingRoot.tsx @@ -1,22 +1,20 @@ +import { Construction, CheckBox, CheckBoxOutlineBlank } from "@mui/icons-material"; +import { Box, Button, Container, List, ListItemButton, Paper, Typography } from "@mui/material"; import React, { useState } from "react"; - -import { Typography, Container, Box, Paper, List, ListItemButton, Button } from "@mui/material"; -import { Construction } from "@mui/icons-material"; - -import { use } from "../../../ui/Context"; -import { Money } from "../../../ui/React/Money"; -import { ConfirmationModal } from "../../../ui/React/ConfirmationModal"; +import { Augmentation } from "../../../Augmentation/Augmentation"; import { Augmentations } from "../../../Augmentation/Augmentations"; import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames"; -import { Settings } from "../../../Settings/Settings"; -import { IMap } from "../../../types"; -import { convertTimeMsToTimeElapsedString, formatNumber } from "../../../utils/StringHelperFunctions"; +import { CONSTANTS } from "../../../Constants"; +import { hasAugmentationPrereqs } from "../../../Faction/FactionHelpers"; import { LocationName } from "../../../Locations/data/LocationNames"; import { Locations } from "../../../Locations/Locations"; -import { CONSTANTS } from "../../../Constants"; - +import { Settings } from "../../../Settings/Settings"; +import { IMap } from "../../../types"; +import { use } from "../../../ui/Context"; +import { ConfirmationModal } from "../../../ui/React/ConfirmationModal"; +import { Money } from "../../../ui/React/Money"; +import { convertTimeMsToTimeElapsedString, formatNumber } from "../../../utils/StringHelperFunctions"; import { IPlayer } from "../../IPlayer"; - import { GraftableAugmentation } from "../GraftableAugmentation"; const GraftableAugmentations: IMap = {}; @@ -33,6 +31,36 @@ export const getAvailableAugs = (player: IPlayer): string[] => { return augs.filter((augmentation: string) => !player.hasAugmentation(augmentation)); }; +const canGraft = (player: IPlayer, aug: GraftableAugmentation): boolean => { + if (player.money < aug.cost) { + return false; + } + return hasAugmentationPrereqs(aug.augmentation); +}; + +interface IProps { + player: IPlayer; + aug: Augmentation; +} + +const AugPreReqsChecklist = (props: IProps): React.ReactElement => { + const aug = props.aug, + player = props.player; + + return ( + + Pre-Requisites: +
+ {aug.prereqs.map((preAug) => ( + + {player.hasAugmentation(preAug) ? : } + {preAug} + + ))} +
+ ); +}; + export const GraftingRoot = (): React.ReactElement => { const player = use.Player(); const router = use.Router(); @@ -79,7 +107,7 @@ export const GraftingRoot = (): React.ReactElement => {