Handle pre-requisite augmentations

This commit is contained in:
nickofolas 2022-03-29 17:09:36 -04:00
parent 24ede1c68d
commit 4f7b44df39
2 changed files with 54 additions and 15 deletions

@ -1,5 +1,6 @@
import { CityName } from "../Locations/data/CityNames";
import { Augmentations } from "../Augmentation/Augmentations"; import { Augmentations } from "../Augmentation/Augmentations";
import { hasAugmentationPrereqs } from "../Faction/FactionHelpers";
import { CityName } from "../Locations/data/CityNames";
import { getRamCost } from "../Netscript/RamCostGenerator"; import { getRamCost } from "../Netscript/RamCostGenerator";
import { WorkerScript } from "../Netscript/WorkerScript"; import { WorkerScript } from "../Netscript/WorkerScript";
import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation"; import { GraftableAugmentation } from "../PersonObjects/Grafting/GraftableAugmentation";
@ -70,6 +71,11 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
return false; 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.loseMoney(craftableAug.cost, "augmentations");
player.startGraftAugmentationWork(augName, craftableAug.time); player.startGraftAugmentationWork(augName, craftableAug.time);

@ -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 React, { useState } from "react";
import { Augmentation } from "../../../Augmentation/Augmentation";
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 { Augmentations } from "../../../Augmentation/Augmentations"; import { Augmentations } from "../../../Augmentation/Augmentations";
import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../../Augmentation/data/AugmentationNames";
import { Settings } from "../../../Settings/Settings"; import { CONSTANTS } from "../../../Constants";
import { IMap } from "../../../types"; import { hasAugmentationPrereqs } from "../../../Faction/FactionHelpers";
import { convertTimeMsToTimeElapsedString, formatNumber } from "../../../utils/StringHelperFunctions";
import { LocationName } from "../../../Locations/data/LocationNames"; import { LocationName } from "../../../Locations/data/LocationNames";
import { Locations } from "../../../Locations/Locations"; 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 { IPlayer } from "../../IPlayer";
import { GraftableAugmentation } from "../GraftableAugmentation"; import { GraftableAugmentation } from "../GraftableAugmentation";
const GraftableAugmentations: IMap<GraftableAugmentation> = {}; const GraftableAugmentations: IMap<GraftableAugmentation> = {};
@ -33,6 +31,36 @@ export const getAvailableAugs = (player: IPlayer): string[] => {
return augs.filter((augmentation: string) => !player.hasAugmentation(augmentation)); 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 (
<Typography color={Settings.theme.money}>
<b>Pre-Requisites:</b>
<br />
{aug.prereqs.map((preAug) => (
<span style={{ display: "flex", alignItems: "center" }}>
{player.hasAugmentation(preAug) ? <CheckBox sx={{ mr: 1 }} /> : <CheckBoxOutlineBlank sx={{ mr: 1 }} />}
{preAug}
</span>
))}
</Typography>
);
};
export const GraftingRoot = (): React.ReactElement => { export const GraftingRoot = (): React.ReactElement => {
const player = use.Player(); const player = use.Player();
const router = use.Router(); const router = use.Router();
@ -79,7 +107,7 @@ export const GraftingRoot = (): React.ReactElement => {
<Button <Button
onClick={() => setGraftOpen(true)} onClick={() => setGraftOpen(true)}
sx={{ width: "100%" }} sx={{ width: "100%" }}
disabled={player.money < GraftableAugmentations[selectedAug].cost} disabled={!canGraft(player, GraftableAugmentations[selectedAug])}
> >
Graft Augmentation ( Graft Augmentation (
<Typography> <Typography>
@ -114,6 +142,11 @@ export const GraftingRoot = (): React.ReactElement => {
)} )}
{/* Use formula so the displayed creation time is accurate to player bonus */} {/* Use formula so the displayed creation time is accurate to player bonus */}
</Typography> </Typography>
{Augmentations[selectedAug].prereqs.length > 0 && (
<AugPreReqsChecklist player={player} aug={Augmentations[selectedAug]} />
)}
<br />
<Typography sx={{ maxHeight: 305, overflowY: "scroll" }}> <Typography sx={{ maxHeight: 305, overflowY: "scroll" }}>
{(() => { {(() => {
const aug = Augmentations[selectedAug]; const aug = Augmentations[selectedAug];