From 14e50e5533d984214deea0fe1981a20b6c4567f9 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Tue, 29 Nov 2022 08:24:04 -0500 Subject: [PATCH] Some corp fixes (#236) --- src/Achievements/Achievements.ts | 7 +++---- src/NetscriptFunctions/Corporation.ts | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Achievements/Achievements.ts b/src/Achievements/Achievements.ts index ecac75b30..b90c1eaa9 100644 --- a/src/Achievements/Achievements.ts +++ b/src/Achievements/Achievements.ts @@ -462,10 +462,9 @@ export const achievements: Record = { Condition: (): boolean => { if (Player.corporation === null) return false; for (const d of Player.corporation.divisions) { - for (const o of Object.values(d.offices)) { - if (o === 0) continue; - if (o.totalEmployees >= 3000) return true; - } + let totalEmployees = 0; + for (const o of Object.values(d.offices)) if (o && o.totalEmployees) totalEmployees += o.totalEmployees; + if (totalEmployees >= 3000) return true; } return false; }, diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index d10aee45c..9e8e282df 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -233,7 +233,7 @@ export function NetscriptCorporation(): InternalAPI { const division = getDivision(divisionName); if (!checkEnum(CityName, cityName)) throw new Error(`Invalid city name '${cityName}'`); const warehouse = division.warehouses[cityName]; - if (warehouse === 0) throw new Error(`${division.name} has not expanded to '${cityName}'`); + if (warehouse === 0) throw new Error(`${division.name} does not have a warehouse in '${cityName}'`); return warehouse; } @@ -848,6 +848,8 @@ export function NetscriptCorporation(): InternalAPI { }, goPublic: (ctx) => (_numShares) => { checkAccess(ctx); + const corporation = getCorporation(); + if (corporation.public) throw helpers.makeRuntimeErrorMsg(ctx, "corporation is already public"); const numShares = helpers.number(ctx, "numShares", _numShares); return goPublic(numShares); },