mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 17:23:00 +02:00
CORPORATION: Add a new API to sell a division (#1210)
Also refactoring around use of "player" variable (whether it is capitalized or not).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Player, Player as player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
|
||||
import { OfficeSpace } from "../Corporation/OfficeSpace";
|
||||
import { Product } from "../Corporation/Product";
|
||||
@@ -50,6 +50,8 @@ import {
|
||||
LimitMaterialProduction,
|
||||
LimitProductProduction,
|
||||
UpgradeWarehouseCost,
|
||||
createCorporation,
|
||||
removeDivision,
|
||||
} from "../Corporation/Actions";
|
||||
import { CorpUnlocks } from "../Corporation/data/CorporationUnlocks";
|
||||
import { CorpUpgrades } from "../Corporation/data/CorporationUpgrades";
|
||||
@@ -58,7 +60,6 @@ import { IndustriesData, IndustryResearchTrees } from "../Corporation/data/Indus
|
||||
import * as corpConstants from "../Corporation/data/Constants";
|
||||
import { ResearchMap } from "../Corporation/ResearchMap";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||
import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { getEnumHelper } from "../utils/EnumHelper";
|
||||
@@ -68,24 +69,6 @@ import { PositiveInteger } from "../types";
|
||||
import { getRecordKeys } from "../Types/Record";
|
||||
|
||||
export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
function createCorporation(corporationName: string, selfFund = true): boolean {
|
||||
if (!player.canAccessCorporation() || player.corporation) return false;
|
||||
if (!corporationName) return false;
|
||||
if (player.bitNodeN !== 3 && !selfFund) throw new Error("cannot use seed funds outside of BitNode 3");
|
||||
if (currentNodeMults.CorporationSoftcap < 0.15)
|
||||
throw new Error(`You cannot create a corporation in Bitnode ${player.bitNodeN}`);
|
||||
|
||||
if (selfFund) {
|
||||
if (!player.canAfford(150e9)) return false;
|
||||
|
||||
player.startCorporation(corporationName, false);
|
||||
player.loseMoney(150e9, "corporation");
|
||||
} else {
|
||||
player.startCorporation(corporationName, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasUnlock(unlockName: CorpUnlockName): boolean {
|
||||
const corporation = getCorporation();
|
||||
return corporation.unlocks.has(unlockName);
|
||||
@@ -128,7 +111,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
const faction = Factions[factionName];
|
||||
const info = faction.getInfo();
|
||||
if (!info.offersWork()) return false;
|
||||
if (player.hasGangWith(factionName)) return false;
|
||||
if (Player.hasGangWith(factionName)) return false;
|
||||
|
||||
const repGain = amountCash / corpConstants.bribeAmountPerReputation;
|
||||
faction.playerReputation += repGain;
|
||||
@@ -138,7 +121,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
|
||||
function getCorporation(): Corporation {
|
||||
const corporation = player.corporation;
|
||||
const corporation = Player.corporation;
|
||||
if (corporation === null) throw new Error("cannot be called without a corporation");
|
||||
return corporation;
|
||||
}
|
||||
@@ -178,9 +161,9 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
}
|
||||
|
||||
function checkAccess(ctx: NetscriptContext, api?: CorpUnlockName): void {
|
||||
if (!player.corporation) throw helpers.errorMessage(ctx, "Must own a corporation.");
|
||||
if (!Player.corporation) throw helpers.errorMessage(ctx, "Must own a corporation.");
|
||||
if (!api) return;
|
||||
if (!player.corporation.unlocks.has(api)) {
|
||||
if (!Player.corporation.unlocks.has(api)) {
|
||||
throw helpers.errorMessage(ctx, "You do not have access to this API.");
|
||||
}
|
||||
}
|
||||
@@ -732,7 +715,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
(_corporationName, _selfFund = true): boolean => {
|
||||
const corporationName = helpers.string(ctx, "corporationName", _corporationName);
|
||||
const selfFund = !!_selfFund;
|
||||
return createCorporation(corporationName, selfFund);
|
||||
return createCorporation(corporationName, selfFund, false);
|
||||
},
|
||||
hasUnlock: (ctx) => (_unlockName) => {
|
||||
checkAccess(ctx);
|
||||
@@ -803,6 +786,12 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
CorporationPromise.promise = new Promise<CorpStateName>((res) => (CorporationPromise.resolve = res));
|
||||
return CorporationPromise.promise;
|
||||
},
|
||||
sellDivision: (ctx) => (_divisionName) => {
|
||||
checkAccess(ctx);
|
||||
const corporation = getCorporation();
|
||||
const divisionName = helpers.string(ctx, "divisionName", _divisionName);
|
||||
removeDivision(corporation, divisionName);
|
||||
},
|
||||
};
|
||||
|
||||
// Removed functions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { Exploit } from "../Exploits/Exploit";
|
||||
import * as bcrypt from "bcryptjs";
|
||||
import { Apr1Events as devMenu } from "../ui/Apr1";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Player as player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { calculateServerGrowth, calculateGrowMoney } from "../Server/formulas/grow";
|
||||
import { numCycleForGrowthCorrected } from "../Server/ServerHelpers";
|
||||
import {
|
||||
@@ -62,7 +62,7 @@ import { findCrime } from "../Crime/CrimeHelpers";
|
||||
|
||||
export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
||||
if (!player.hasProgram(CompletedProgramName.formulas)) {
|
||||
if (!Player.hasProgram(CompletedProgramName.formulas)) {
|
||||
throw helpers.errorMessage(ctx, `Requires Formulas.exe to run.`);
|
||||
}
|
||||
};
|
||||
@@ -325,7 +325,7 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const level = helpers.number(ctx, "level", _level);
|
||||
checkFormulasAccess(ctx);
|
||||
const upg = player.hashManager.getUpgrade(upgName);
|
||||
const upg = Player.hashManager.getUpgrade(upgName);
|
||||
if (!upg) {
|
||||
throw helpers.errorMessage(ctx, `Invalid Hash Upgrade: ${upgName}`);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Player as player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { HacknetServerConstants } from "../Hacknet/data/Constants";
|
||||
import {
|
||||
getCostOfNextHacknetNode,
|
||||
@@ -25,12 +25,12 @@ import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
// Utility function to get Hacknet Node object
|
||||
const getHacknetNode = function (ctx: NetscriptContext, i: number): HacknetNode | HacknetServer {
|
||||
if (i < 0 || i >= player.hacknetNodes.length) {
|
||||
if (i < 0 || i >= Player.hacknetNodes.length) {
|
||||
throw helpers.errorMessage(ctx, "Index specified for Hacknet Node is out-of-bounds: " + i);
|
||||
}
|
||||
|
||||
if (hasHacknetServers()) {
|
||||
const hi = player.hacknetNodes[i];
|
||||
const hi = Player.hacknetNodes[i];
|
||||
if (typeof hi !== "string") throw new Error("hacknet node was not a string");
|
||||
const hserver = GetServer(hi);
|
||||
if (!(hserver instanceof HacknetServer)) throw new Error("hacknet server was not actually hacknet server");
|
||||
@@ -43,7 +43,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
|
||||
return hserver;
|
||||
} else {
|
||||
const node = player.hacknetNodes[i];
|
||||
const node = Player.hacknetNodes[i];
|
||||
if (!(node instanceof HacknetNode)) throw new Error("hacknet node was not node.");
|
||||
return node;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
|
||||
return {
|
||||
numNodes: () => () => {
|
||||
return player.hacknetNodes.length;
|
||||
return Player.hacknetNodes.length;
|
||||
},
|
||||
maxNumNodes: () => () => {
|
||||
if (hasHacknetServers()) {
|
||||
@@ -140,7 +140,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateLevelUpgradeCost(n, player.mults.hacknet_node_level_cost);
|
||||
return node.calculateLevelUpgradeCost(n, Player.mults.hacknet_node_level_cost);
|
||||
},
|
||||
getRamUpgradeCost:
|
||||
(ctx) =>
|
||||
@@ -148,7 +148,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateRamUpgradeCost(n, player.mults.hacknet_node_ram_cost);
|
||||
return node.calculateRamUpgradeCost(n, Player.mults.hacknet_node_ram_cost);
|
||||
},
|
||||
getCoreUpgradeCost:
|
||||
(ctx) =>
|
||||
@@ -156,7 +156,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
const i = helpers.number(ctx, "i", _i);
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const node = getHacknetNode(ctx, i);
|
||||
return node.calculateCoreUpgradeCost(n, player.mults.hacknet_node_core_cost);
|
||||
return node.calculateCoreUpgradeCost(n, Player.mults.hacknet_node_core_cost);
|
||||
},
|
||||
getCacheUpgradeCost:
|
||||
(ctx) =>
|
||||
@@ -177,13 +177,13 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
if (!hasHacknetServers()) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.hashes;
|
||||
return Player.hashManager.hashes;
|
||||
},
|
||||
hashCapacity: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 0;
|
||||
}
|
||||
return player.hashManager.capacity;
|
||||
return Player.hashManager.capacity;
|
||||
},
|
||||
hashCost:
|
||||
(ctx) =>
|
||||
@@ -194,7 +194,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return player.hashManager.getUpgradeCost(upgName, count);
|
||||
return Player.hashManager.getUpgradeCost(upgName, count);
|
||||
},
|
||||
spendHashes:
|
||||
(ctx) =>
|
||||
@@ -219,7 +219,7 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
},
|
||||
getHashUpgradeLevel: (ctx) => (_upgName) => {
|
||||
const upgName = helpers.string(ctx, "upgName", _upgName);
|
||||
const level = player.hashManager.upgrades[upgName];
|
||||
const level = Player.hashManager.upgrades[upgName];
|
||||
if (level === undefined) {
|
||||
throw helpers.errorMessage(ctx, `Invalid Hash Upgrade: ${upgName}`);
|
||||
}
|
||||
@@ -229,13 +229,13 @@ export function NetscriptHacknet(): InternalAPI<IHacknet> {
|
||||
if (!hasHacknetServers()) {
|
||||
return 1;
|
||||
}
|
||||
return player.hashManager.getStudyMult();
|
||||
return Player.hashManager.getStudyMult();
|
||||
},
|
||||
getTrainingMult: () => () => {
|
||||
if (!hasHacknetServers()) {
|
||||
return 1;
|
||||
}
|
||||
return player.hashManager.getTrainingMult();
|
||||
return Player.hashManager.getTrainingMult();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Player } from "../Player";
|
||||
import { Player } from "@player";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling";
|
||||
import {
|
||||
StockMarket,
|
||||
|
||||
Reference in New Issue
Block a user