Merge branch 'dev' into stanek-examples

This commit is contained in:
hydroflame 2022-04-13 17:38:59 -04:00 committed by GitHub
commit e2296aa963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 547 additions and 228 deletions

@ -51,13 +51,15 @@ export function NewIndustry(corporation: ICorporation, industry: string, name: s
export function NewCity(corporation: ICorporation, division: IIndustry, city: string): void { export function NewCity(corporation: ICorporation, division: IIndustry, city: string): void {
if (corporation.funds < CorporationConstants.OfficeInitialCost) { if (corporation.funds < CorporationConstants.OfficeInitialCost) {
throw new Error("You don't have enough company funds to open a new office!"); throw new Error("You don't have enough company funds to open a new office!");
} else {
corporation.funds = corporation.funds - CorporationConstants.OfficeInitialCost;
division.offices[city] = new OfficeSpace({
loc: city,
size: CorporationConstants.OfficeInitialSize,
});
} }
if (division.offices[city]) {
throw new Error(`You have already expanded into ${city} for ${division.name}`);
}
corporation.funds = corporation.funds - CorporationConstants.OfficeInitialCost;
division.offices[city] = new OfficeSpace({
loc: city,
size: CorporationConstants.OfficeInitialSize,
});
} }
export function UnlockUpgrade(corporation: ICorporation, upgrade: CorporationUnlockUpgrade): void { export function UnlockUpgrade(corporation: ICorporation, upgrade: CorporationUnlockUpgrade): void {
@ -345,10 +347,17 @@ export function PurchaseWarehouse(corp: ICorporation, division: IIndustry, city:
corp.funds = corp.funds - CorporationConstants.WarehouseInitialCost; corp.funds = corp.funds - CorporationConstants.WarehouseInitialCost;
} }
export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, warehouse: Warehouse): void { export function UpgradeWarehouseCost(warehouse: Warehouse, amt: number): number {
const sizeUpgradeCost = CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1); return Array.from(Array(amt).keys()).reduce(
(acc, index) => acc + CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1 + index),
0,
);
}
export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, warehouse: Warehouse, amt = 1): void {
const sizeUpgradeCost = UpgradeWarehouseCost(warehouse, amt);
if (corp.funds < sizeUpgradeCost) return; if (corp.funds < sizeUpgradeCost) return;
++warehouse.level; warehouse.level += amt;
warehouse.updateSize(corp, division); warehouse.updateSize(corp, division);
corp.funds = corp.funds - sizeUpgradeCost; corp.funds = corp.funds - sizeUpgradeCost;
} }
@ -416,7 +425,7 @@ export function MakeProduct(
} }
const product = new Product({ const product = new Product({
name: productName.replace(/[<>]/g, ""), //Sanitize for HTMl elements name: productName.replace(/[<>]/g, "").trim(), //Sanitize for HTMl elements
createCity: city, createCity: city,
designCost: designInvest, designCost: designInvest,
advCost: marketingInvest, advCost: marketingInvest,
@ -488,12 +497,23 @@ export function CancelExportMaterial(divisionName: string, cityName: string, mat
export function LimitProductProduction(product: Product, cityName: string, qty: number): void { export function LimitProductProduction(product: Product, cityName: string, qty: number): void {
if (qty < 0 || isNaN(qty)) { if (qty < 0 || isNaN(qty)) {
product.prdman[cityName][0] = false; product.prdman[cityName][0] = false;
product.prdman[cityName][1] = 0;
} else { } else {
product.prdman[cityName][0] = true; product.prdman[cityName][0] = true;
product.prdman[cityName][1] = qty; product.prdman[cityName][1] = qty;
} }
} }
export function LimitMaterialProduction(material: Material, qty: number): void {
if (qty < 0 || isNaN(qty)) {
material.prdman[0] = false;
material.prdman[1] = 0;
} else {
material.prdman[0] = true;
material.prdman[1] = qty;
}
}
export function SetMaterialMarketTA1(material: Material, on: boolean): void { export function SetMaterialMarketTA1(material: Material, on: boolean): void {
material.marketTa1 = on; material.marketTa1 = on;
} }

@ -8,8 +8,8 @@ import { EmployeePositions } from "../EmployeePositions";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
import { UpgradeOfficeSizeModal } from "./UpgradeOfficeSizeModal"; import { UpgradeOfficeSizeModal } from "./modals/UpgradeOfficeSizeModal";
import { ThrowPartyModal } from "./ThrowPartyModal"; import { ThrowPartyModal } from "./modals/ThrowPartyModal";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import { useCorporation, useDivision } from "./Context"; import { useCorporation, useDivision } from "./Context";

@ -7,8 +7,8 @@ import { Industries } from "../IndustryData";
import { IndustryUpgrades } from "../IndustryUpgrades"; import { IndustryUpgrades } from "../IndustryUpgrades";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
import { createProgressBarText } from "../../utils/helpers/createProgressBarText"; import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
import { MakeProductModal } from "./MakeProductModal"; import { MakeProductModal } from "./modals/MakeProductModal";
import { ResearchModal } from "./ResearchModal"; import { ResearchModal } from "./modals/ResearchModal";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import { MoneyRate } from "../../ui/React/MoneyRate"; import { MoneyRate } from "../../ui/React/MoneyRate";
import { StatsTable } from "../../ui/React/StatsTable"; import { StatsTable } from "../../ui/React/StatsTable";

@ -6,7 +6,7 @@ import { CorporationConstants } from "../data/Constants";
import { Material } from "../Material"; import { Material } from "../Material";
import { Product } from "../Product"; import { Product } from "../Product";
import { Warehouse } from "../Warehouse"; import { Warehouse } from "../Warehouse";
import { SmartSupplyModal } from "./SmartSupplyModal"; import { SmartSupplyModal } from "./modals/SmartSupplyModal";
import { ProductElem } from "./ProductElem"; import { ProductElem } from "./ProductElem";
import { MaterialElem } from "./MaterialElem"; import { MaterialElem } from "./MaterialElem";
import { MaterialSizes } from "../MaterialSizes"; import { MaterialSizes } from "../MaterialSizes";

@ -5,10 +5,10 @@ import React, { useState } from "react";
import { OfficeSpace } from "../OfficeSpace"; import { OfficeSpace } from "../OfficeSpace";
import { Material } from "../Material"; import { Material } from "../Material";
import { Warehouse } from "../Warehouse"; import { Warehouse } from "../Warehouse";
import { ExportModal } from "./ExportModal"; import { ExportModal } from "./modals/ExportModal";
import { MaterialMarketTaModal } from "./MaterialMarketTaModal"; import { MaterialMarketTaModal } from "./modals/MaterialMarketTaModal";
import { SellMaterialModal } from "./SellMaterialModal"; import { SellMaterialModal } from "./modals/SellMaterialModal";
import { PurchaseMaterialModal } from "./PurchaseMaterialModal"; import { PurchaseMaterialModal } from "./modals/PurchaseMaterialModal";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
@ -21,6 +21,7 @@ import Tooltip from "@mui/material/Tooltip";
import Paper from "@mui/material/Paper"; import Paper from "@mui/material/Paper";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { LimitMaterialProductionModal } from "./modals/LimitMaterialProductionModal";
interface IMaterialProps { interface IMaterialProps {
warehouse: Warehouse; warehouse: Warehouse;
@ -37,6 +38,8 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
const [exportOpen, setExportOpen] = useState(false); const [exportOpen, setExportOpen] = useState(false);
const [sellMaterialOpen, setSellMaterialOpen] = useState(false); const [sellMaterialOpen, setSellMaterialOpen] = useState(false);
const [materialMarketTaOpen, setMaterialMarketTaOpen] = useState(false); const [materialMarketTaOpen, setMaterialMarketTaOpen] = useState(false);
const [limitProductionOpen, setLimitProductionOpen] = useState(false);
const warehouse = props.warehouse; const warehouse = props.warehouse;
const city = props.city; const city = props.city;
const mat = props.mat; const mat = props.mat;
@ -110,6 +113,12 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
sellButtonText = <>Sell (0.000/0.000)</>; sellButtonText = <>Sell (0.000/0.000)</>;
} }
// Limit Production button
let limitMaterialButtonText = "Limit Material";
if (mat.prdman[0]) {
limitMaterialButtonText += " (" + numeralWrapper.format(mat.prdman[1], nf) + ")";
}
return ( return (
<Paper> <Paper>
<Box sx={{ display: "grid", gridTemplateColumns: "2fr 1fr", m: "5px" }}> <Box sx={{ display: "grid", gridTemplateColumns: "2fr 1fr", m: "5px" }}>
@ -194,6 +203,14 @@ export function MaterialElem(props: IMaterialProps): React.ReactElement {
/> />
</> </>
)} )}
<Button color={tutorial ? "error" : "primary"} onClick={() => setLimitProductionOpen(true)}>
{limitMaterialButtonText}
</Button>
<LimitMaterialProductionModal
material={mat}
open={limitProductionOpen}
onClose={() => setLimitProductionOpen(false)}
/>
</Box> </Box>
</Box> </Box>
</Paper> </Paper>

@ -2,13 +2,13 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { LevelableUpgrade } from "./LevelableUpgrade"; import { LevelableUpgrade } from "./LevelableUpgrade";
import { UnlockUpgrade } from "./UnlockUpgrade"; import { UnlockUpgrade } from "./UnlockUpgrade";
import { BribeFactionModal } from "./BribeFactionModal"; import { BribeFactionModal } from "./modals/BribeFactionModal";
import { SellSharesModal } from "./SellSharesModal"; import { SellSharesModal } from "./modals/SellSharesModal";
import { BuybackSharesModal } from "./BuybackSharesModal"; import { BuybackSharesModal } from "./modals/BuybackSharesModal";
import { IssueDividendsModal } from "./IssueDividendsModal"; import { IssueDividendsModal } from "./modals/IssueDividendsModal";
import { IssueNewSharesModal } from "./IssueNewSharesModal"; import { IssueNewSharesModal } from "./modals/IssueNewSharesModal";
import { FindInvestorsModal } from "./FindInvestorsModal"; import { FindInvestorsModal } from "./modals/FindInvestorsModal";
import { GoPublicModal } from "./GoPublicModal"; import { GoPublicModal } from "./modals/GoPublicModal";
import { Factions } from "../../Faction/Factions"; import { Factions } from "../../Faction/Factions";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../data/Constants";

@ -2,10 +2,11 @@ import React, { useState } from "react";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../data/Constants";
import { Product } from "../Product"; import { Product } from "../Product";
import { DiscontinueProductModal } from "./DiscontinueProductModal"; import { DiscontinueProductModal } from "./modals/DiscontinueProductModal";
import { LimitProductProductionModal } from "./LimitProductProductionModal"; import { LimitProductProductionModal } from "./modals/LimitProductProductionModal";
import { SellProductModal } from "./SellProductModal"; import { SellProductModal } from "./modals/SellProductModal";
import { ProductMarketTaModal } from "./ProductMarketTaModal"; import { ProductMarketTaModal } from "./modals/ProductMarketTaModal";
import { CancelProductModal } from "./modals/CancelProductModal";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
@ -32,6 +33,7 @@ export function ProductElem(props: IProductProps): React.ReactElement {
const [sellOpen, setSellOpen] = useState(false); const [sellOpen, setSellOpen] = useState(false);
const [limitOpen, setLimitOpen] = useState(false); const [limitOpen, setLimitOpen] = useState(false);
const [discontinueOpen, setDiscontinueOpen] = useState(false); const [discontinueOpen, setDiscontinueOpen] = useState(false);
const [cancelOpen, setCancelOpen] = useState(false);
const [marketTaOpen, setMarketTaOpen] = useState(false); const [marketTaOpen, setMarketTaOpen] = useState(false);
const city = props.city; const city = props.city;
const product = props.product; const product = props.product;
@ -111,6 +113,13 @@ export function ProductElem(props: IProductProps): React.ReactElement {
</Typography> </Typography>
<br /> <br />
<Typography>{numeralWrapper.format(product.prog, "0.00")}% complete</Typography> <Typography>{numeralWrapper.format(product.prog, "0.00")}% complete</Typography>
<Button onClick={() => setCancelOpen(true)}>Cancel</Button>
<CancelProductModal
product={product}
rerender={props.rerender}
open={cancelOpen}
onClose={() => setCancelOpen(false)}
/>
</> </>
) : ( ) : (
<> <>
@ -171,6 +180,13 @@ export function ProductElem(props: IProductProps): React.ReactElement {
<Typography>Est. Market Price: {numeralWrapper.formatMoney(product.pCost)}</Typography> <Typography>Est. Market Price: {numeralWrapper.formatMoney(product.pCost)}</Typography>
</Tooltip> </Tooltip>
</Box> </Box>
<Button onClick={() => setDiscontinueOpen(true)}>Discontinue</Button>
<DiscontinueProductModal
product={product}
rerender={props.rerender}
open={discontinueOpen}
onClose={() => setDiscontinueOpen(false)}
/>
</> </>
)} )}
@ -186,14 +202,6 @@ export function ProductElem(props: IProductProps): React.ReactElement {
open={limitOpen} open={limitOpen}
onClose={() => setLimitOpen(false)} onClose={() => setLimitOpen(false)}
/> />
<Button onClick={() => setDiscontinueOpen(true)}>Discontinue</Button>
<DiscontinueProductModal
product={product}
rerender={props.rerender}
open={discontinueOpen}
onClose={() => setDiscontinueOpen(false)}
/>
{division.hasResearch("Market-TA.I") && ( {division.hasResearch("Market-TA.I") && (
<> <>
<Button onClick={() => setMarketTaOpen(true)}>Market-TA</Button> <Button onClick={() => setMarketTaOpen(true)}>Market-TA</Button>

@ -1,11 +1,11 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Factions } from "../../Faction/Factions"; import { Factions } from "../../../Faction/Factions";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { use } from "../../ui/Context"; import { use } from "../../../ui/Context";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";

@ -1,14 +1,14 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { use } from "../../ui/Context"; import { use } from "../../../ui/Context";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { BuyBackShares } from "../Actions"; import { BuyBackShares } from "../../Actions";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;

@ -0,0 +1,34 @@
import React from "react";
import { Product } from "../../Product";
import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "../Context";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
interface IProps {
open: boolean;
onClose: () => void;
product: Product;
rerender: () => void;
}
// Create a popup that lets the player cancel a product
export function CancelProductModal(props: IProps): React.ReactElement {
const division = useDivision();
function cancel(): void {
division.discontinueProduct(props.product);
props.onClose();
props.rerender();
}
return (
<Modal open={props.open} onClose={props.onClose}>
<Typography>
Are you sure you want to do this? Canceling a product removes it completely and permanently. You will receive no
money back by doing so
</Typography>
<Button onClick={cancel}>Cancel</Button>
</Modal>
);
}

@ -1,8 +1,8 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Money } from "../../ui/React/Money"; import { Money } from "../../../ui/React/Money";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { use } from "../../ui/Context"; import { use } from "../../../ui/Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import { Product } from "../Product"; import { Product } from "../../Product";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "./Context"; import { useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";

@ -1,12 +1,12 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Material } from "../Material"; import { Material } from "../../Material";
import { Export } from "../Export"; import { Export } from "../../Export";
import { IIndustry } from "../IIndustry"; import { IIndustry } from "../../IIndustry";
import { ExportMaterial } from "../Actions"; import { ExportMaterial } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import { isRelevantMaterial } from "./Helpers"; import { isRelevantMaterial } from "../Helpers";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";

@ -1,13 +1,13 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;

@ -1,13 +1,13 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { IssueDividends } from "../Actions"; import { IssueDividends } from "../../Actions";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;

@ -1,14 +1,14 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { getRandomInt } from "../../utils/helpers/getRandomInt"; import { getRandomInt } from "../../../utils/helpers/getRandomInt";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IEffectTextProps { interface IEffectTextProps {
shares: number | null; shares: number | null;

@ -0,0 +1,53 @@
import React, { useEffect, useState } from "react";
import { LimitMaterialProduction } from "../../Actions";
import { Modal } from "../../../ui/React/Modal";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import { KEY } from "../../../utils/helpers/keyCodes";
import { Material } from "../../Material";
interface IProps {
open: boolean;
onClose: () => void;
material: Material;
}
// Create a popup that lets the player limit the production of a product
export function LimitMaterialProductionModal(props: IProps): React.ReactElement {
const [limit, setLimit] = useState<number | null>(null);
// reset modal internal state on modal close
useEffect(() => {
if (!props.open) {
setLimit(null);
}
}, [props.open]);
function limitMaterialProduction(): void {
let qty = limit;
if (qty === null) qty = -1;
LimitMaterialProduction(props.material, qty);
props.onClose();
}
function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
if (event.key === KEY.ENTER) limitMaterialProduction();
}
function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
if (event.target.value === "") setLimit(null);
else setLimit(parseFloat(event.target.value));
}
return (
<Modal open={props.open} onClose={props.onClose}>
<Typography>
Enter a limit to the amount of this material you would like to produce per second. Leave the box empty to set no
limit.
</Typography>
<TextField autoFocus={true} placeholder="Limit" type="number" onChange={onChange} onKeyDown={onKeyDown} />
<Button onClick={limitMaterialProduction}>Limit production</Button>
</Modal>
);
}

@ -1,11 +1,11 @@
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { Product } from "../Product"; import { Product } from "../../Product";
import { LimitProductProduction } from "../Actions"; import { LimitProductProduction } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
@ -18,6 +18,13 @@ interface IProps {
export function LimitProductProductionModal(props: IProps): React.ReactElement { export function LimitProductProductionModal(props: IProps): React.ReactElement {
const [limit, setLimit] = useState<number | null>(null); const [limit, setLimit] = useState<number | null>(null);
// reset modal internal state on modal close
useEffect(() => {
if (!props.open) {
setLimit(null);
}
}, [props.open]);
function limitProductProduction(): void { function limitProductProduction(): void {
let qty = limit; let qty = limit;
if (qty === null) qty = -1; if (qty === null) qty = -1;

@ -1,15 +1,15 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { Industries } from "../IndustryData"; import { Industries } from "../../IndustryData";
import { MakeProduct } from "../Actions"; import { MakeProduct } from "../../Actions";
import { useCorporation, useDivision } from "./Context"; import { useCorporation, useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import Select, { SelectChangeEvent } from "@mui/material/Select"; import Select, { SelectChangeEvent } from "@mui/material/Select";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;

@ -1,8 +1,8 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { Material } from "../Material"; import { Material } from "../../Material";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "./Context"; import { useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";

@ -1,8 +1,8 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { Product } from "../Product"; import { Product } from "../../Product";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "./Context"; import { useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";

@ -1,16 +1,16 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { MaterialSizes } from "../MaterialSizes"; import { MaterialSizes } from "../../MaterialSizes";
import { Warehouse } from "../Warehouse"; import { Warehouse } from "../../Warehouse";
import { Material } from "../Material"; import { Material } from "../../Material";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { BulkPurchase, BuyMaterial } from "../Actions"; import { BulkPurchase, BuyMaterial } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useCorporation, useDivision } from "./Context"; import { useCorporation, useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IBulkPurchaseTextProps { interface IBulkPurchaseTextProps {
warehouse: Warehouse; warehouse: Warehouse;
@ -18,37 +18,6 @@ interface IBulkPurchaseTextProps {
amount: string; amount: string;
} }
function BulkPurchaseText(props: IBulkPurchaseTextProps): React.ReactElement {
const parsedAmt = parseFloat(props.amount);
const cost = parsedAmt * props.mat.bCost;
const matSize = MaterialSizes[props.mat.name];
const maxAmount = (props.warehouse.size - props.warehouse.sizeUsed) / matSize;
if (parsedAmt * matSize > maxAmount) {
return (
<>
<Typography color={"error"}>Not enough warehouse space to purchase this amount</Typography>
</>
);
} else if (isNaN(cost) || parsedAmt < 0) {
return (
<>
<Typography color={"error"}>Invalid put for Bulk Purchase amount</Typography>
</>
);
} else {
return (
<>
<Typography>
Purchasing {numeralWrapper.format(parsedAmt, "0,0.00")} of {props.mat.name} will cost{" "}
{numeralWrapper.formatMoney(cost)}
</Typography>
</>
);
}
}
interface IBPProps { interface IBPProps {
onClose: () => void; onClose: () => void;
mat: Material; mat: Material;
@ -58,6 +27,41 @@ interface IBPProps {
function BulkPurchaseSection(props: IBPProps): React.ReactElement { function BulkPurchaseSection(props: IBPProps): React.ReactElement {
const corp = useCorporation(); const corp = useCorporation();
const [buyAmt, setBuyAmt] = useState(""); const [buyAmt, setBuyAmt] = useState("");
const [disabled, setDisabled] = useState(false);
function BulkPurchaseText(props: IBulkPurchaseTextProps): React.ReactElement {
const parsedAmt = parseFloat(props.amount);
const cost = parsedAmt * props.mat.bCost;
const matSize = MaterialSizes[props.mat.name];
const maxAmount = (props.warehouse.size - props.warehouse.sizeUsed) / matSize;
if (parsedAmt > maxAmount) {
setDisabled(true);
return (
<>
<Typography color={"error"}>Not enough warehouse space to purchase this amount</Typography>
</>
);
} else if (isNaN(cost) || parsedAmt < 0) {
setDisabled(true);
return (
<>
<Typography color={"error"}>Invalid input for Bulk Purchase amount</Typography>
</>
);
} else {
setDisabled(false);
return (
<>
<Typography>
Purchasing {numeralWrapper.format(parsedAmt, "0,0.00")} of {props.mat.name} will cost{" "}
{numeralWrapper.formatMoney(cost)}
</Typography>
</>
);
}
}
function bulkPurchase(): void { function bulkPurchase(): void {
try { try {
@ -90,7 +94,9 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement {
placeholder="Bulk Purchase amount" placeholder="Bulk Purchase amount"
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
/> />
<Button onClick={bulkPurchase}>Confirm Bulk Purchase</Button> <Button disabled={disabled} onClick={bulkPurchase}>
Confirm Bulk Purchase
</Button>
</> </>
); );
} }

@ -1,13 +1,13 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { IndustryResearchTrees } from "../IndustryData"; import { IndustryResearchTrees } from "../../IndustryData";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { IIndustry } from "../IIndustry"; import { IIndustry } from "../../IIndustry";
import { Research } from "../Actions"; import { Research } from "../../Actions";
import { Node } from "../ResearchTree"; import { Node } from "../../ResearchTree";
import { ResearchMap } from "../ResearchMap"; import { ResearchMap } from "../../ResearchMap";
import { Settings } from "../../Settings/Settings"; import { Settings } from "../../../Settings/Settings";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Tooltip from "@mui/material/Tooltip"; import Tooltip from "@mui/material/Tooltip";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";

@ -1,12 +1,12 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Material } from "../Material"; import { Material } from "../../Material";
import { SellMaterial } from "../Actions"; import { SellMaterial } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
function initialPrice(mat: Material): string { function initialPrice(mat: Material): string {
let val = mat.sCost ? mat.sCost + "" : ""; let val = mat.sCost ? mat.sCost + "" : "";

@ -1,15 +1,15 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Product } from "../Product"; import { Product } from "../../Product";
import { SellProduct } from "../Actions"; import { SellProduct } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch"; import Switch from "@mui/material/Switch";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
function initialPrice(product: Product): string { function initialPrice(product: Product): string {
let val = product.sCost ? product.sCost + "" : ""; let val = product.sCost ? product.sCost + "" : "";

@ -1,16 +1,16 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { use } from "../../ui/Context"; import { use } from "../../../ui/Context";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import { ICorporation } from "../ICorporation"; import { ICorporation } from "../../ICorporation";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { Money } from "../../ui/React/Money"; import { Money } from "../../../ui/React/Money";
import { SellShares } from "../Actions"; import { SellShares } from "../../Actions";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
@ -33,19 +33,22 @@ export function SellSharesModal(props: IProps): React.ReactElement {
function ProfitIndicator(props: { shares: number | null; corp: ICorporation }): React.ReactElement { function ProfitIndicator(props: { shares: number | null; corp: ICorporation }): React.ReactElement {
if (props.shares === null) return <></>; if (props.shares === null) return <></>;
let text = "";
if (isNaN(props.shares) || props.shares <= 0) { if (isNaN(props.shares) || props.shares <= 0) {
return <>ERROR: Invalid value entered for number of shares to sell</>; text = `ERROR: Invalid value entered for number of shares to sell`;
} else if (props.shares > corp.numShares) { } else if (props.shares > corp.numShares) {
return <>You don't have this many shares to sell!</>; text = `You don't have this many shares to sell!`;
} else { } else {
const stockSaleResults = corp.calculateShareSale(props.shares); const stockSaleResults = corp.calculateShareSale(props.shares);
const profit = stockSaleResults[0]; const profit = stockSaleResults[0];
return ( text = `Sell ${props.shares} shares for a total of ${numeralWrapper.formatMoney(profit)}`;
<>
Sell {props.shares} shares for a total of {numeralWrapper.formatMoney(profit)}
</>
);
} }
return (
<Typography>
<small>{text}</small>
</Typography>
);
} }
function sell(): void { function sell(): void {
@ -84,7 +87,6 @@ export function SellSharesModal(props: IProps): React.ReactElement {
<br /> <br />
The current price of your company's stock is {numeralWrapper.formatMoney(corp.sharePrice)} The current price of your company's stock is {numeralWrapper.formatMoney(corp.sharePrice)}
</Typography> </Typography>
<ProfitIndicator shares={shares} corp={corp} />
<br /> <br />
<TextField <TextField
variant="standard" variant="standard"
@ -97,6 +99,7 @@ export function SellSharesModal(props: IProps): React.ReactElement {
<Button disabled={disabled} onClick={sell} sx={{ mx: 1 }}> <Button disabled={disabled} onClick={sell} sx={{ mx: 1 }}>
Sell shares Sell shares
</Button> </Button>
<ProfitIndicator shares={shares} corp={corp} />
</Modal> </Modal>
); );
} }

@ -1,11 +1,11 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Warehouse } from "../Warehouse"; import { Warehouse } from "../../Warehouse";
import { SetSmartSupply, SetSmartSupplyUseLeftovers } from "../Actions"; import { SetSmartSupply, SetSmartSupplyUseLeftovers } from "../../Actions";
import { Material } from "../Material"; import { Material } from "../../Material";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useDivision } from "./Context"; import { useDivision } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import FormControlLabel from "@mui/material/FormControlLabel"; import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch"; import Switch from "@mui/material/Switch";

@ -1,16 +1,16 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { OfficeSpace } from "../OfficeSpace"; import { OfficeSpace } from "../../OfficeSpace";
import { ThrowParty } from "../Actions"; import { ThrowParty } from "../../Actions";
import { Money } from "../../ui/React/Money"; import { Money } from "../../../ui/React/Money";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { KEY } from "../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
interface IProps { interface IProps {
open: boolean; open: boolean;

@ -1,11 +1,11 @@
import React from "react"; import React from "react";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../../ui/numeralFormat";
import { CorporationConstants } from "../data/Constants"; import { CorporationConstants } from "../../data/Constants";
import { OfficeSpace } from "../OfficeSpace"; import { OfficeSpace } from "../../OfficeSpace";
import { ICorporation } from "../ICorporation"; import { ICorporation } from "../../ICorporation";
import { UpgradeOfficeSize } from "../Actions"; import { UpgradeOfficeSize } from "../../Actions";
import { Modal } from "../../ui/React/Modal"; import { Modal } from "../../../ui/React/Modal";
import { useCorporation } from "./Context"; import { useCorporation } from "../Context";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import Tooltip from "@mui/material/Tooltip"; import Tooltip from "@mui/material/Tooltip";

@ -17,7 +17,7 @@ export function DummyGrid(props: IProps): React.ReactElement {
const ghostGrid = zeros([props.width, props.height]); const ghostGrid = zeros([props.width, props.height]);
return ( return (
<Box> <Box>
<Table> <Table sx={{ width: props.width, height: props.height }}>
<Grid <Grid
width={props.width} width={props.width}
height={props.height} height={props.height}

@ -92,7 +92,7 @@ export function StaneksGiftRoot({ staneksGift }: IProps): React.ReactElement {
<br /> <br />
<DummyGrid <DummyGrid
width={4} width={3}
height={4} height={4}
fragments={[ fragments={[
new ActiveFragment({ new ActiveFragment({
@ -116,8 +116,8 @@ export function StaneksGiftRoot({ staneksGift }: IProps): React.ReactElement {
<br /> <br />
<DummyGrid <DummyGrid
width={4} width={5}
height={4} height={3}
fragments={[ fragments={[
new ActiveFragment({ new ActiveFragment({
x: 0, x: 0,

@ -10,6 +10,10 @@ import Button from "@mui/material/Button";
import { Money } from "../../ui/React/Money"; import { Money } from "../../ui/React/Money";
import { IPlayer } from "../../PersonObjects/IPlayer"; import { IPlayer } from "../../PersonObjects/IPlayer";
import { IRouter } from "../../ui/Router"; import { IRouter } from "../../ui/Router";
import { MenuItem, SelectChangeEvent, TextField, Select } from "@mui/material";
import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { GangConstants } from "../../Gang/data/Constants";
import { FactionNames } from "../../Faction/data/FactionNames";
import { checkForMessagesToSend } from "../../Message/MessageHelpers"; import { checkForMessagesToSend } from "../../Message/MessageHelpers";
interface IProps { interface IProps {
@ -19,6 +23,8 @@ interface IProps {
export function General(props: IProps): React.ReactElement { export function General(props: IProps): React.ReactElement {
const [error, setError] = useState(false); const [error, setError] = useState(false);
const [corporationName, setCorporationName] = useState("");
const [gangFaction, setGangFaction] = useState("");
function addMoney(n: number) { function addMoney(n: number) {
return function () { return function () {
@ -46,6 +52,23 @@ export function General(props: IProps): React.ReactElement {
props.router.toBitVerse(false, false); props.router.toBitVerse(false, false);
} }
function createCorporation(): void {
props.player.startCorporation(corporationName);
}
function joinBladeburner(): void {
props.player.bladeburner = new Bladeburner(props.player);
}
function startGang(): void {
const isHacking = gangFaction === FactionNames.NiteSec || gangFaction === FactionNames.TheBlackHand;
props.player.startGang(gangFaction, isHacking);
}
function setGangFactionDropdown(event: SelectChangeEvent<string>): void {
setGangFaction(event.target.value);
}
function checkMessages(): void { function checkMessages(): void {
checkForMessagesToSend(); checkForMessagesToSend();
} }
@ -87,6 +110,22 @@ export function General(props: IProps): React.ReactElement {
</Button> </Button>
<Button onClick={upgradeRam}>+ RAM</Button> <Button onClick={upgradeRam}>+ RAM</Button>
<br /> <br />
<Typography>Corporation Name:</Typography>
<TextField value={corporationName} onChange={(x) => setCorporationName(x.target.value)} />
<Button onClick={createCorporation}>Create Corporation</Button>
<br />
<Typography>Gang Faction:</Typography>
<Select value={gangFaction} onChange={setGangFactionDropdown}>
{GangConstants.Names.map((factionName) => (
<MenuItem key={factionName} value={factionName}>
{factionName}
</MenuItem>
))}
</Select>
<Button onClick={startGang}>Start Gang</Button>
<br />
<Button onClick={joinBladeburner}>Join BladeBurner</Button>
<br />
<Button onClick={quickB1tFlum3}>Quick b1t_flum3.exe</Button> <Button onClick={quickB1tFlum3}>Quick b1t_flum3.exe</Button>
<Button onClick={b1tflum3}>Run b1t_flum3.exe</Button> <Button onClick={b1tflum3}>Run b1t_flum3.exe</Button>

@ -15,7 +15,7 @@ import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { Location } from "../Location"; import { Location } from "../Location";
import { CreateCorporationModal } from "../../Corporation/ui/CreateCorporationModal"; import { CreateCorporationModal } from "../../Corporation/ui/modals/CreateCorporationModal";
import { LocationName } from "../data/LocationNames"; import { LocationName } from "../data/LocationNames";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { Factions } from "../../Faction/Factions"; import { Factions } from "../../Faction/Factions";
@ -34,6 +34,7 @@ import { HacknetServer } from "../../Hacknet/HacknetServer";
import { GetServer } from "../../Server/AllServers"; import { GetServer } from "../../Server/AllServers";
import { ArcadeRoot } from "../../Arcade/ui/ArcadeRoot"; import { ArcadeRoot } from "../../Arcade/ui/ArcadeRoot";
import { FactionNames } from "../../Faction/data/FactionNames"; import { FactionNames } from "../../Faction/data/FactionNames";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
type IProps = { type IProps = {
loc: Location; loc: Location;
@ -316,7 +317,7 @@ export function SpecialLocation(props: IProps): React.ReactElement {
return renderGrafting(); return renderGrafting();
} }
case LocationName.Sector12CityHall: { case LocationName.Sector12CityHall: {
return <CreateCorporation />; return (BitNodeMultipliers.CorporationSoftCap < 0.15 && <></>) || <CreateCorporation />;
} }
case LocationName.Sector12NSA: { case LocationName.Sector12NSA: {
return renderBladeburner(); return renderBladeburner();

@ -177,6 +177,8 @@ const singularity: IMap<any> = {
installAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), installAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
isFocused: SF4Cost(0.1), isFocused: SF4Cost(0.1),
setFocus: SF4Cost(0.1), setFocus: SF4Cost(0.1),
b1tflum3: SF4Cost(16),
destroyW0r1dD43m0n: SF4Cost(32),
}; };
// Gang API // Gang API

@ -53,6 +53,9 @@ import {
SellShares, SellShares,
BuyBackShares, BuyBackShares,
SetSmartSupplyUseLeftovers, SetSmartSupplyUseLeftovers,
LimitMaterialProduction,
LimitProductProduction,
UpgradeWarehouseCost,
} from "../Corporation/Actions"; } from "../Corporation/Actions";
import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades"; import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades";
import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades"; import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades";
@ -64,6 +67,7 @@ import { CorporationConstants } from "../Corporation/data/Constants";
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades"; import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
import { ResearchMap } from "../Corporation/ResearchMap"; import { ResearchMap } from "../Corporation/ResearchMap";
import { Factions } from "../Faction/Factions"; import { Factions } from "../Faction/Factions";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
export function NetscriptCorporation( export function NetscriptCorporation(
player: IPlayer, player: IPlayer,
@ -74,6 +78,8 @@ export function NetscriptCorporation(
if (!player.canAccessCorporation() || player.hasCorporation()) return false; if (!player.canAccessCorporation() || player.hasCorporation()) return false;
if (!corporationName) return false; if (!corporationName) return false;
if (player.bitNodeN !== 3 && !selfFund) throw new Error("cannot use seed funds outside of BitNode 3"); if (player.bitNodeN !== 3 && !selfFund) throw new Error("cannot use seed funds outside of BitNode 3");
if (BitNodeMultipliers.CorporationSoftCap < 0.15)
throw new Error(`You cannot create a corporation in Bitnode ${player.bitNodeN}`);
if (selfFund) { if (selfFund) {
if (!player.canAfford(150e9)) return false; if (!player.canAfford(150e9)) return false;
@ -311,12 +317,16 @@ export function NetscriptCorporation(
checkAccess("getPurchaseWarehouseCost", 7); checkAccess("getPurchaseWarehouseCost", 7);
return CorporationConstants.WarehouseInitialCost; return CorporationConstants.WarehouseInitialCost;
}, },
getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown): number { getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): number {
checkAccess("upgradeWarehouse", 7); checkAccess("upgradeWarehouse", 7);
const divisionName = helper.string("getUpgradeWarehouseCost", "divisionName", _divisionName); const divisionName = helper.string("getUpgradeWarehouseCost", "divisionName", _divisionName);
const cityName = helper.city("getUpgradeWarehouseCost", "cityName", _cityName); const cityName = helper.city("getUpgradeWarehouseCost", "cityName", _cityName);
const amt = helper.number("getUpgradeWarehouseCost", "amount", _amt);
if (amt < 1) {
throw helper.makeRuntimeErrorMsg(`corporation.getUpgradeWarehouseCost`, "You must provide a positive number");
}
const warehouse = getWarehouse(divisionName, cityName); const warehouse = getWarehouse(divisionName, cityName);
return CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1); return UpgradeWarehouseCost(warehouse, amt);
}, },
hasWarehouse: function (_divisionName: unknown, _cityName: unknown): boolean { hasWarehouse: function (_divisionName: unknown, _cityName: unknown): boolean {
checkAccess("hasWarehouse", 7); checkAccess("hasWarehouse", 7);
@ -348,6 +358,7 @@ export function NetscriptCorporation(
const material = getMaterial(divisionName, cityName, materialName); const material = getMaterial(divisionName, cityName, materialName);
const corporation = getCorporation(); const corporation = getCorporation();
return { return {
cost: material.bCost,
name: material.name, name: material.name,
qty: material.qty, qty: material.qty,
qlt: material.qlt, qlt: material.qlt,
@ -389,12 +400,16 @@ export function NetscriptCorporation(
const corporation = getCorporation(); const corporation = getCorporation();
PurchaseWarehouse(corporation, getDivision(divisionName), cityName); PurchaseWarehouse(corporation, getDivision(divisionName), cityName);
}, },
upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown): void { upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): void {
checkAccess("upgradeWarehouse", 7); checkAccess("upgradeWarehouse", 7);
const divisionName = helper.string("upgradeWarehouse", "divisionName", _divisionName); const divisionName = helper.string("upgradeWarehouse", "divisionName", _divisionName);
const cityName = helper.city("upgradeWarehouse", "cityName", _cityName); const cityName = helper.city("upgradeWarehouse", "cityName", _cityName);
const amt = helper.number("upgradeWarehouse", "amount", _amt);
const corporation = getCorporation(); const corporation = getCorporation();
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName)); if (amt < 1) {
throw helper.makeRuntimeErrorMsg(`corporation.upgradeWarehouse`, "You must provide a positive number");
}
UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt);
}, },
sellMaterial: function ( sellMaterial: function (
_divisionName: unknown, _divisionName: unknown,
@ -508,6 +523,19 @@ export function NetscriptCorporation(
const corporation = getCorporation(); const corporation = getCorporation();
MakeProduct(corporation, getDivision(divisionName), cityName, productName, designInvest, marketingInvest); MakeProduct(corporation, getDivision(divisionName), cityName, productName, designInvest, marketingInvest);
}, },
limitProductProduction: function (
_divisionName: unknown,
_productName: unknown,
_cityName: unknown,
_qty: unknown,
) {
checkAccess("limitProductProduction", 7);
const divisionName = helper.string("limitProductProduction", "divisionName", _divisionName);
const cityName = helper.city("limitMaterialProduction", "cityName", _cityName);
const productName = helper.string("limitProductProduction", "productName", _productName);
const qty = helper.number("limitMaterialProduction", "qty", _qty);
LimitProductProduction(getProduct(divisionName, productName), cityName, qty);
},
exportMaterial: function ( exportMaterial: function (
_sourceDivision: unknown, _sourceDivision: unknown,
_sourceCity: unknown, _sourceCity: unknown,
@ -548,6 +576,19 @@ export function NetscriptCorporation(
const amt = helper.string("cancelExportMaterial", "amt", _amt); const amt = helper.string("cancelExportMaterial", "amt", _amt);
CancelExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt + ""); CancelExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt + "");
}, },
limitMaterialProduction: function (
_divisionName: unknown,
_cityName: unknown,
_materialName: unknown,
_qty: unknown,
) {
checkAccess("limitMaterialProduction", 7);
const divisionName = helper.string("limitMaterialProduction", "divisionName", _divisionName);
const cityName = helper.city("limitMaterialProduction", "cityName", _cityName);
const materialName = helper.string("limitMaterialProduction", "materialName", _materialName);
const qty = helper.number("limitMaterialProduction", "qty", _qty);
LimitMaterialProduction(getMaterial(divisionName, cityName, materialName), qty);
},
setMaterialMarketTA1: function ( setMaterialMarketTA1: function (
_divisionName: unknown, _divisionName: unknown,
_cityName: unknown, _cityName: unknown,

@ -47,6 +47,8 @@ import { Server } from "../Server/Server";
import { netscriptCanHack } from "../Hacking/netscriptCanHack"; import { netscriptCanHack } from "../Hacking/netscriptCanHack";
import { FactionInfos } from "../Faction/FactionInfo"; import { FactionInfos } from "../Faction/FactionInfo";
import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper"; import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper";
import { BlackOperationNames } from "../Bladeburner/data/BlackOperationNames";
import { enterBitNode } from "../RedPill";
export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript): InternalAPI<ISingularity> { export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript): InternalAPI<ISingularity> {
const getAugmentation = function (_ctx: NetscriptContext, name: string): Augmentation { const getAugmentation = function (_ctx: NetscriptContext, name: string): Augmentation {
@ -1335,5 +1337,47 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
} }
return item.price; return item.price;
}, },
b1tflum3:
(_ctx: NetscriptContext) =>
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
const nextBN = _ctx.helper.number("nextBN", _nextBN);
const callbackScript = _ctx.helper.string("callbackScript", _callbackScript);
enterBitNode(Router, true, player.bitNodeN, nextBN);
if (callbackScript)
setTimeout(() => {
runAfterReset(callbackScript);
}, 0);
},
destroyW0r1dD43m0n:
(_ctx: NetscriptContext) =>
(_nextBN: unknown, _callbackScript: unknown = ""): void => {
const nextBN = _ctx.helper.number("nextBN", _nextBN);
const callbackScript = _ctx.helper.string("callbackScript", _callbackScript);
const hackingRequirements = (): boolean => {
const wd = GetServer(SpecialServers.WorldDaemon);
if (!(wd instanceof Server))
throw new Error("WorldDaemon was not a normal server. This is a bug contact dev.");
if (player.hacking < wd.requiredHackingSkill) return false;
if (!wd.hasAdminRights) return false;
return true;
};
const bladeburnerRequirements = (): boolean => {
if (!player.inBladeburner()) return false;
if (!player.bladeburner) return false;
return player.bladeburner.blackops[BlackOperationNames.OperationDaedalus];
};
if (!hackingRequirements() && !bladeburnerRequirements()) {
_ctx.log(() => "Requirements not met to destroy the world daemon");
return;
}
enterBitNode(Router, false, player.bitNodeN, nextBN);
if (callbackScript)
setTimeout(() => {
runAfterReset(callbackScript);
}, 0);
},
}; };
} }

@ -24,9 +24,4 @@ export class Program {
this.create = create; this.create = create;
this.run = run; this.run = run;
} }
htmlID(): string {
const name = this.name.endsWith(".exe") ? this.name.slice(0, -".exe".length) : this.name;
return "create-program-" + name;
}
} }

@ -2386,6 +2386,30 @@ export interface Singularity {
* purchased. Throws an error if the specified program/exploit does not exist * purchased. Throws an error if the specified program/exploit does not exist
*/ */
getDarkwebProgramCost(programName: string): number; getDarkwebProgramCost(programName: string): number;
/**
* b1t_flum3 into a different BN.
* @remarks
* RAM cost: 16 GB * 16/4/1
*
* @param nextBN - BN number to jump to
* @param callbackScript - Name of the script to launch in the next BN.
*/
b1tflum3(nextBN: number, callbackScript?: string): void;
/**
* Destroy the w0r1d_d43m0n and move on to the next BN.
* @remarks
* RAM cost: 32 GB * 16/4/1
*
* You must have the special augment installed and the required hacking level
* OR
* Completed the final black op.
*
* @param nextBN - BN number to jump to
* @param callbackScript - Name of the script to launch in the next BN.
*/
destroyW0r1dD43m0n(nextBN: number, callbackScript?: string): void;
} }
/** /**
@ -6737,8 +6761,9 @@ export interface WarehouseAPI {
* Upgrade warehouse * Upgrade warehouse
* @param divisionName - Name of the division * @param divisionName - Name of the division
* @param cityName - Name of the city * @param cityName - Name of the city
* @param amt - amount of upgrades defaults to 1
*/ */
upgradeWarehouse(divisionName: string, cityName: string): void; upgradeWarehouse(divisionName: string, cityName: string, amt?: number): void;
/** /**
* Create a new product * Create a new product
* @param divisionName - Name of the division * @param divisionName - Name of the division
@ -6754,6 +6779,22 @@ export interface WarehouseAPI {
designInvest: number, designInvest: number,
marketingInvest: number, marketingInvest: number,
): void; ): void;
/**
* Limit Material Production.
* @param divisionName - Name of the division
* @param cityName - Name of the city
* @param materialName - Name of the material
* @param qty - Amount to limit to
*/
limitMaterialProduction(divisionName: string, cityName: string, materialName: string, qty: number): void;
/**
* Limit Product Production.
* @param divisionName - Name of the division
* @param cityName - Name of the city
* @param productName - Name of the product
* @param qty - Amount to limit to
*/
limitProductProduction(divisionName: string, cityName: string, productName: string, qty: number): void;
/** /**
* Gets the cost to purchase a warehouse * Gets the cost to purchase a warehouse
* @returns cost * @returns cost
@ -6761,9 +6802,12 @@ export interface WarehouseAPI {
getPurchaseWarehouseCost(): number; getPurchaseWarehouseCost(): number;
/** /**
* Gets the cost to upgrade a warehouse to the next level * Gets the cost to upgrade a warehouse to the next level
* @param divisionName - Name of the division
* @param cityName - Name of the city
* @param amt - amount of upgrades defaults to 1
* @returns cost to upgrade * @returns cost to upgrade
*/ */
getUpgradeWarehouseCost(adivisionName: any, acityName: any): number; getUpgradeWarehouseCost(adivisionName: any, acityName: any, amt?: number): number;
/** /**
* Check if you have a warehouse in city * Check if you have a warehouse in city
* @returns true if warehouse is present, false if not * @returns true if warehouse is present, false if not
@ -7007,8 +7051,10 @@ interface Material {
cmp: number | undefined; cmp: number | undefined;
/** Amount of material produced */ /** Amount of material produced */
prod: number; prod: number;
/** Amount of material sold */ /** Amount of material sold */
sell: number; sell: number;
/** cost to buy material */
cost: number;
} }
/** /**

@ -1121,14 +1121,17 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
dfs(0, 0, left, right, data, "", res); dfs(0, 0, left, right, data, "", res);
const sanitizedPlayerAns = removeBracketsFromArrayString(ans).replace(/\s/g, ""); const sanitizedPlayerAns: string = removeBracketsFromArrayString(ans);
const sanitizedPlayerAnsArr: string[] = sanitizedPlayerAns.split(",");
const playerAnsArray: string[] = sanitizedPlayerAns.split(","); for (let i = 0; i < sanitizedPlayerAnsArr.length; ++i) {
if (playerAnsArray.length !== res.length) { sanitizedPlayerAnsArr[i] = removeQuotesFromString(sanitizedPlayerAnsArr[i]).replace(/\s/g, "");
}
if (sanitizedPlayerAnsArr.length !== res.length) {
return false; return false;
} }
for (const resultInAnswer of res) { for (const resultInAnswer of res) {
if (!playerAnsArray.includes(resultInAnswer)) { if (!sanitizedPlayerAnsArr.includes(resultInAnswer)) {
return false; return false;
} }
} }