mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 17:43:48 +01:00
Add costs and count function for ads
This commit is contained in:
parent
42d767b443
commit
1b8c715a5e
@ -54,6 +54,9 @@ import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades";
|
||||
import { EmployeePositions } from "../Corporation/EmployeePositions";
|
||||
import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligence";
|
||||
import { Industry } from "../Corporation/Industry";
|
||||
import { IndustryStartingCosts } from "../Corporation/IndustryData";
|
||||
import { CorporationConstants } from "../Corporation/data/Constants";
|
||||
import { IndustryUpgrades } from "../Corporation/IndustryUpgrades";
|
||||
|
||||
export function NetscriptCorporation(
|
||||
player: IPlayer,
|
||||
@ -76,6 +79,53 @@ export function NetscriptCorporation(
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasUnlockUpgrade(upgradeName: string): boolean {
|
||||
const corporation = getCorporation();
|
||||
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade[2] === upgradeName);
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
const upgN = upgrade[0];
|
||||
return corporation.unlockUpgrades[upgN] === 1;
|
||||
}
|
||||
|
||||
function getUnlockUpgradeCost(upgradeName: string): number {
|
||||
const upgrade = Object.values(CorporationUnlockUpgrades).find((upgrade) => upgrade[2] === upgradeName);
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
return upgrade[1];
|
||||
}
|
||||
|
||||
function getUpgradeLevel(aupgradeName: string): number {
|
||||
const upgradeName = helper.string("levelUpgrade", "upgradeName", aupgradeName);
|
||||
const corporation = getCorporation();
|
||||
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade[4] === upgradeName);
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
const upgN = upgrade[0];
|
||||
return corporation.upgrades[upgN];
|
||||
}
|
||||
|
||||
function getUpgradeLevelCost(aupgradeName: string): number {
|
||||
const upgradeName = helper.string("levelUpgrade", "upgradeName", aupgradeName);
|
||||
const corporation = getCorporation();
|
||||
const upgrade = Object.values(CorporationUpgrades).find((upgrade) => upgrade[4] === upgradeName);
|
||||
if (upgrade === undefined) throw new Error(`No upgrade named '${upgradeName}'`);
|
||||
const upgN = upgrade[0];
|
||||
const baseCost = upgrade[1];
|
||||
const priceMult = upgrade[2];
|
||||
const level = corporation.upgrades[upgN];
|
||||
return baseCost * Math.pow(priceMult, level);
|
||||
}
|
||||
|
||||
function getExpandIndustryCost(industryName: string): number {
|
||||
const cost = IndustryStartingCosts[industryName];
|
||||
if (cost === undefined) {
|
||||
throw new Error(`Invalid industry: '${industryName}'`);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
function getExpandCityCost(): number {
|
||||
return CorporationConstants.OfficeInitialCost;
|
||||
}
|
||||
|
||||
function getCorporation(): ICorporation {
|
||||
const corporation = player.corporation;
|
||||
if (corporation === null) throw new Error("cannot be called without a corporation");
|
||||
@ -107,7 +157,8 @@ export function NetscriptCorporation(
|
||||
|
||||
function getMaterial(divisionName: any, cityName: any, materialName: any): Material {
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
const material = warehouse.materials[materialName];
|
||||
const matName = (materialName as string).replace(/ /g, "");
|
||||
const material = warehouse.materials[matName];
|
||||
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
|
||||
return material;
|
||||
}
|
||||
@ -157,6 +208,26 @@ export function NetscriptCorporation(
|
||||
}
|
||||
|
||||
const warehouseAPI: WarehouseAPI = {
|
||||
getPurchaseWarehouseCost: function (): number {
|
||||
checkAccess("getPurchaseWarehouseCost", 7);
|
||||
return CorporationConstants.WarehouseInitialCost;
|
||||
},
|
||||
getUpgradeWarehouseCost: function (adivisionName: any, acityName: any): number {
|
||||
checkAccess("upgradeWarehouse", 7);
|
||||
const divisionName = helper.string("getUpgradeWarehouseCost", "divisionName", adivisionName);
|
||||
const cityName = helper.string("getUpgradeWarehouseCost", "cityName", acityName);
|
||||
const warehouse = getWarehouse(divisionName, cityName);
|
||||
return CorporationConstants.WarehouseUpgradeBaseCost * Math.pow(1.07, warehouse.level + 1);
|
||||
},
|
||||
hasWarehouse: function (adivisionName: any, acityName: any): boolean {
|
||||
checkAccess("hasWarehouse", 7);
|
||||
const divisionName = helper.string("getWarehouse", "divisionName", adivisionName);
|
||||
const cityName = helper.string("getWarehouse", "cityName", acityName);
|
||||
const division = getDivision(divisionName);
|
||||
if (!(cityName in division.warehouses)) throw new Error(`Invalid city name '${cityName}'`);
|
||||
const warehouse = division.warehouses[cityName];
|
||||
return warehouse !== 0;
|
||||
},
|
||||
getWarehouse: function (adivisionName: any, acityName: any): NSWarehouse {
|
||||
checkAccess("getWarehouse", 7);
|
||||
const divisionName = helper.string("getWarehouse", "divisionName", adivisionName);
|
||||
@ -167,6 +238,7 @@ export function NetscriptCorporation(
|
||||
loc: warehouse.loc,
|
||||
size: warehouse.size,
|
||||
sizeUsed: warehouse.sizeUsed,
|
||||
smartSupplyEnabled: warehouse.smartSupplyEnabled
|
||||
};
|
||||
},
|
||||
getMaterial: function (adivisionName: any, acityName: any, amaterialName: any): NSMaterial {
|
||||
@ -342,6 +414,19 @@ export function NetscriptCorporation(
|
||||
};
|
||||
|
||||
const officeAPI: OfficeAPI = {
|
||||
getHireAdVertCost: function (adivisionName: string): number {
|
||||
checkAccess("hireAdVert", 8);
|
||||
const divisionName = helper.string("hireAdVert", "divisionName", adivisionName);
|
||||
const division = getDivision(divisionName);
|
||||
const upgrade = IndustryUpgrades[1];
|
||||
return upgrade[1] * Math.pow(upgrade[2], division.upgrades[1]);
|
||||
},
|
||||
getHireAdVertCount: function (adivisionName: string): number {
|
||||
checkAccess("hireAdVert", 8);
|
||||
const divisionName = helper.string("hireAdVert", "divisionName", adivisionName);
|
||||
const division = getDivision(divisionName);
|
||||
return division.upgrades[1]
|
||||
},
|
||||
assignJob: function (adivisionName: any, acityName: any, aemployeeName: any, ajob: any): Promise<void> {
|
||||
checkAccess("assignJob", 8);
|
||||
const divisionName = helper.string("assignJob", "divisionName", adivisionName);
|
||||
@ -503,9 +588,6 @@ export function NetscriptCorporation(
|
||||
const division = getDivision(divisionName);
|
||||
return getSafeDivision(division);
|
||||
},
|
||||
createCorporation: function (corporationName: string, selfFund = true): boolean {
|
||||
return createCorporation(corporationName, selfFund);
|
||||
},
|
||||
getCorporation: function (): CorporationInfo {
|
||||
checkAccess("getCorporation");
|
||||
const corporation = getCorporation();
|
||||
@ -524,5 +606,32 @@ export function NetscriptCorporation(
|
||||
divisions: corporation.divisions.map((division): NSDivision => getSafeDivision(division)),
|
||||
};
|
||||
},
|
||||
createCorporation: function (corporationName: string, selfFund = true): boolean {
|
||||
return createCorporation(corporationName, selfFund);
|
||||
},
|
||||
hasUnlockUpgrade: function (upgradeName: string): boolean {
|
||||
checkAccess("hasUnlockUpgrade");
|
||||
return hasUnlockUpgrade(upgradeName);
|
||||
},
|
||||
getUnlockUpgradeCost: function (upgradeName: string): number {
|
||||
checkAccess("getUnlockUpgradeCost");
|
||||
return getUnlockUpgradeCost(upgradeName);
|
||||
},
|
||||
getUpgradeLevel: function (upgradeName: string): number {
|
||||
checkAccess("hasUnlockUpgrade");
|
||||
return getUpgradeLevel(upgradeName);
|
||||
},
|
||||
getUpgradeLevelCost: function (upgradeName: string): number {
|
||||
checkAccess("getUpgradeLevelCost");
|
||||
return getUpgradeLevelCost(upgradeName);
|
||||
},
|
||||
getExpandIndustryCost: function (industryName: string): number {
|
||||
checkAccess("getExpandIndustryCost");
|
||||
return getExpandIndustryCost(industryName);
|
||||
},
|
||||
getExpandCityCost: function(): number {
|
||||
checkAccess("getExpandCityCost");
|
||||
return getExpandCityCost();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
66
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
66
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6140,6 +6140,18 @@ export interface OfficeAPI {
|
||||
* @returns Employee data
|
||||
*/
|
||||
getEmployee(divisionName: string, cityName: string, employeeName: string): Employee;
|
||||
/**
|
||||
* Get the cost to Hire AdVert
|
||||
* @param divisionName - Name of the division
|
||||
* @returns Cost
|
||||
*/
|
||||
getHireAdVertCost(adivisionName: string): number;
|
||||
/**
|
||||
* Get the number of times you have Hired AdVert
|
||||
* @param divisionName - Name of the division
|
||||
* @returns Number of times you have Hired AdVert
|
||||
*/
|
||||
getHireAdVertCount(adivisionName: string): number;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6308,6 +6320,21 @@ export interface WarehouseAPI {
|
||||
designInvest: number,
|
||||
marketingInvest: number,
|
||||
): void;
|
||||
/**
|
||||
* Gets the cost to purchase a warehouse
|
||||
* @returns cost
|
||||
*/
|
||||
getPurchaseWarehouseCost(): number;
|
||||
/**
|
||||
* Gets the cost to upgrade a warehouse to the next level
|
||||
* @returns cost to upgrade
|
||||
*/
|
||||
getUpgradeWarehouseCost(adivisionName: any, acityName: any): number;
|
||||
/**
|
||||
* Check if you have a warehouse in city
|
||||
* @returns true if warehouse is present, false if not
|
||||
*/
|
||||
hasWarehouse(adivisionName: any, acityName: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6320,7 +6347,42 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
||||
* @param divisionName - Name of the division
|
||||
* @returns true if created and false if not
|
||||
*/
|
||||
createCorporation(corporationName: string, selfFund: boolean): boolean;
|
||||
createCorporation(corporationName: string, selfFund: boolean): boolean;
|
||||
/**
|
||||
* Check if you have a one time unlockable upgrade
|
||||
* @param upgradeName - Name of the upgrade
|
||||
* @returns true if unlocked and false if not
|
||||
*/
|
||||
hasUnlockUpgrade(upgradeName: string): boolean;
|
||||
/**
|
||||
* Gets the cost to unlock a one time unlockable upgrade
|
||||
* @param upgradeName - Name of the upgrade
|
||||
* @returns cost of the upgrade
|
||||
*/
|
||||
getUnlockUpgradeCost(upgradeName: string): number;
|
||||
/**
|
||||
* Get the level of a levelable upgrade
|
||||
* @param upgradeName - Name of the upgrade
|
||||
* @returns the level of the upgrade
|
||||
*/
|
||||
getUpgradeLevel(upgradeName: string): number;
|
||||
/**
|
||||
* Gets the cost to unlock the next level of a levelable upgrade
|
||||
* @param upgradeName - Name of the upgrade
|
||||
* @returns cost of the upgrade
|
||||
*/
|
||||
getUpgradeLevelCost(upgradeName: string): number;
|
||||
/**
|
||||
* Gets the cost to expand into a new industry
|
||||
* @param industryName - Name of the industry
|
||||
* @returns cost
|
||||
*/
|
||||
getExpandIndustryCost(industryName: string): number;
|
||||
/**
|
||||
* Gets the cost to expand into a new city
|
||||
* @returns cost
|
||||
*/
|
||||
getExpandCityCost(): number;
|
||||
/**
|
||||
* Get corporation data
|
||||
* @returns Corporation data
|
||||
@ -6461,6 +6523,8 @@ interface Warehouse {
|
||||
size: number;
|
||||
/** Used space in the warehouse */
|
||||
sizeUsed: number;
|
||||
/** Smart Supply status in the warehouse */
|
||||
smartSupplyEnabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user