more corp API

This commit is contained in:
Olivier Gagnon 2021-09-03 16:02:41 -04:00
parent eb01051ad6
commit 2866bfaa70
3 changed files with 19 additions and 7 deletions

@ -219,3 +219,10 @@ export function SellProduct(product: Product, city: string, amt: string, price:
export function SetSmartSupply(warehouse: Warehouse, smartSupply: boolean): void {
warehouse.smartSupplyEnabled = smartSupply;
}
export function BuyMaterial(material: Material, amt: number): void {
if (isNaN(amt)) {
throw new Error(`Invalid amount '${amt}' to buy material '${material.name}'`);
}
material.buy = amt;
}

@ -7,6 +7,7 @@ import { Material } from "../Material";
import { IIndustry } from "../IIndustry";
import { ICorporation } from "../ICorporation";
import { numeralWrapper } from "../../ui/numeralFormat";
import { BuyMaterial } from "../Actions";
interface IBulkPurchaseTextProps {
warehouse: Warehouse;
@ -94,13 +95,13 @@ export function PurchaseMaterialPopup(props: IProps): React.ReactElement {
function purchaseMaterial(): void {
if(buyAmt === null) return;
if (isNaN(buyAmt)) {
dialogBoxCreate("Invalid amount");
} else {
props.mat.buy = buyAmt;
if (isNaN(props.mat.buy)) props.mat.buy = 0;
removePopup(props.popupId);
try {
BuyMaterial(props.mat, buyAmt)
} catch(err) {
dialogBoxCreate(err+'');
}
removePopup(props.popupId);
}
function clearPurchase(): void {

@ -28,7 +28,8 @@ import {
IssueDividends,
SellMaterial,
SellProduct,
SetSmartSupply } from "./Corporation/Actions";
SetSmartSupply,
BuyMaterial } from "./Corporation/Actions";
import { CorporationUnlockUpgrades } from "./Corporation/data/CorporationUnlockUpgrades";
import { CorporationUpgrades } from "./Corporation/data/CorporationUpgrades";
import {
@ -4176,6 +4177,9 @@ function NetscriptFunctions(workerScript) {
const warehouse = getWarehouse(divisionName, cityName);
SetSmartSupply(warehouse, enabled);
},
BuyMaterial: function(divisionName, cityName, materialName, amt) {
},
}, // End Corporation API
// Coding Contract API