diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 520d880cd..1ba08e444 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -348,10 +348,17 @@ export function PurchaseWarehouse(corp: ICorporation, division: IIndustry, city: corp.funds = corp.funds - CorporationConstants.WarehouseInitialCost; } -export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, warehouse: Warehouse): void { - const sizeUpgradeCost = CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1); +export function UpgradeWarehouseCost(warehouse: Warehouse, amt: number): number { + 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; - ++warehouse.level; + warehouse.level += amt; warehouse.updateSize(corp, division); corp.funds = corp.funds - sizeUpgradeCost; } diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 97f6694c3..b193e558f 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -55,6 +55,7 @@ import { SetSmartSupplyUseLeftovers, LimitMaterialProduction, LimitProductProduction, + UpgradeWarehouseCost, } from "../Corporation/Actions"; import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades"; import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades"; @@ -316,12 +317,13 @@ export function NetscriptCorporation( checkAccess("getPurchaseWarehouseCost", 7); return CorporationConstants.WarehouseInitialCost; }, - getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown): number { + getUpgradeWarehouseCost: function (_divisionName: unknown, _cityName: unknown, _amt: unknown = 1): number { checkAccess("upgradeWarehouse", 7); const divisionName = helper.string("getUpgradeWarehouseCost", "divisionName", _divisionName); const cityName = helper.city("getUpgradeWarehouseCost", "cityName", _cityName); + const amt = helper.number("getUpgradeWarehouseCost", "amount", _amt); 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 { checkAccess("hasWarehouse", 7); @@ -382,12 +384,13 @@ export function NetscriptCorporation( const corporation = getCorporation(); PurchaseWarehouse(corporation, getDivision(divisionName), cityName); }, - upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown): void { + upgradeWarehouse: function (_divisionName: unknown, _cityName: unknown, _amt: unknown): void { checkAccess("upgradeWarehouse", 7); const divisionName = helper.string("upgradeWarehouse", "divisionName", _divisionName); const cityName = helper.city("upgradeWarehouse", "cityName", _cityName); + const amt = helper.number("upgradeWarehouse", "amount", _amt); const corporation = getCorporation(); - UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName)); + UpgradeWarehouse(corporation, getDivision(divisionName), getWarehouse(divisionName, cityName), amt); }, sellMaterial: function ( _divisionName: unknown, diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 4d5ecaea0..7ff55fa17 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6639,8 +6639,9 @@ export interface WarehouseAPI { * Upgrade warehouse * @param divisionName - Name of the division * @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 * @param divisionName - Name of the division @@ -6679,9 +6680,12 @@ export interface WarehouseAPI { getPurchaseWarehouseCost(): number; /** * 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 */ - getUpgradeWarehouseCost(adivisionName: any, acityName: any): number; + getUpgradeWarehouseCost(adivisionName: any, acityName: any, amt: number): number; /** * Check if you have a warehouse in city * @returns true if warehouse is present, false if not