From 6e21f1616092ce72c34e9c354b39727ace724257 Mon Sep 17 00:00:00 2001 From: phyzical Date: Sat, 19 Feb 2022 16:05:55 +0800 Subject: [PATCH] adjustments per review comments * updated error message * used correct price for bulk purchasing check * moved onclose and rerenders outside try blocks --- dist/bitburner.d.ts | 2 ++ src/Corporation/Actions.ts | 4 +--- src/Corporation/ui/BuybackSharesModal.tsx | 4 ++-- src/Corporation/ui/PurchaseMaterialModal.tsx | 2 +- src/NetscriptFunctions/Corporation.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/bitburner.d.ts b/dist/bitburner.d.ts index 44fcd3da1..667118f5a 100644 --- a/dist/bitburner.d.ts +++ b/dist/bitburner.d.ts @@ -960,10 +960,12 @@ export declare interface Corporation extends WarehouseAPI, OfficeAPI { issueDividends(percent: number): void; /** * Buyback Shares + * @param amt - Number of shares to attempt to buyback. */ buyBackShares(amt: number): void; /** * Sell Shares + * @param amt - Number of shares to attempt to sell. */ sellShares(amt: number): void; } diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 3e32fde86..7b6a7432e 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -21,7 +21,6 @@ export function NewIndustry(corporation: ICorporation, industry: string, name: s for (let i = 0; i < corporation.divisions.length; ++i) { if (corporation.divisions[i].name === name) { throw new Error("This division name is already in use!"); - return; } } @@ -290,9 +289,8 @@ export function BuyBackShares(corporation: ICorporation, player: IPlayer, numSha if (numShares < 0) throw new Error("Invalid value for number of shares"); if (numShares > corporation.issuedShares) throw new Error("You don't have that many shares to buy!"); if (!corporation.public) throw new Error("You haven't gone public!"); - if (corporation.funds < (numShares * corporation.sharePrice)) throw new Error("You cant afford that many shares!"); - const buybackPrice = corporation.sharePrice * 1.1; + if (corporation.funds < (numShares * buybackPrice)) throw new Error("You cant afford that many shares!"); corporation.numShares += numShares; corporation.issuedShares -= numShares; player.loseMoney(numShares * buybackPrice, "corporation"); diff --git a/src/Corporation/ui/BuybackSharesModal.tsx b/src/Corporation/ui/BuybackSharesModal.tsx index 688408af2..4d6568af7 100644 --- a/src/Corporation/ui/BuybackSharesModal.tsx +++ b/src/Corporation/ui/BuybackSharesModal.tsx @@ -40,12 +40,12 @@ export function BuybackSharesModal(props: IProps): React.ReactElement { if (disabled) return; try { BuyBackShares(corp, player, shares) - props.onClose(); - props.rerender(); } catch (err) { dialogBoxCreate(err + ""); } + props.onClose(); + props.rerender(); } function CostIndicator(): React.ReactElement { diff --git a/src/Corporation/ui/PurchaseMaterialModal.tsx b/src/Corporation/ui/PurchaseMaterialModal.tsx index 8927bcb13..5c6f6bda8 100644 --- a/src/Corporation/ui/PurchaseMaterialModal.tsx +++ b/src/Corporation/ui/PurchaseMaterialModal.tsx @@ -61,10 +61,10 @@ function BulkPurchaseSection(props: IBPProps): React.ReactElement { function bulkPurchase(): void { try { BulkPurchase(corp, props.warehouse, props.mat, parseFloat(buyAmt)); - props.onClose(); } catch (err) { dialogBoxCreate(err + ""); } + props.onClose(); } function onKeyDown(event: React.KeyboardEvent): void { diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 8285e7484..c442d68c8 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -438,7 +438,7 @@ export function NetscriptCorporation( bulkPurchase: function (adivisionName: any, acityName: any, amaterialName: any, aamt: any): void { checkAccess("bulkPurchase", 7); const divisionName = helper.string("bulkPurchase", "divisionName", adivisionName); - if (!hasResearched(getDivision(adivisionName), "Bulk Purchasing")) throw new Error(`You have not researched Bulk Purchase in ${adivisionName}`) + if (!hasResearched(getDivision(adivisionName), "Bulk Purchasing")) throw new Error(`You have not researched Bulk Purchasing in ${adivisionName}`) const corporation = getCorporation(); const cityName = helper.string("bulkPurchase", "cityName", acityName); const materialName = helper.string("bulkPurchase", "materialName", amaterialName);