mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-27 00:17:32 +01:00
Add investments to the api
This commit is contained in:
parent
1b8c715a5e
commit
2269f79b15
@ -25,6 +25,8 @@ export const CorporationConstants: {
|
||||
BaseMaxProducts: number;
|
||||
AllCorporationStates: string[];
|
||||
AllMaterials: string[];
|
||||
FundingRoundShares: number[];
|
||||
FundingRoundMultiplier: number[];
|
||||
} = {
|
||||
INITIALSHARES: 1e9, //Total number of shares you have at your company
|
||||
SHARESPERPRICEUPDATE: 1e6, //When selling large number of shares, price is dynamically updated for every batch of this amount
|
||||
@ -71,4 +73,16 @@ export const CorporationConstants: {
|
||||
"AI Cores",
|
||||
"Real Estate",
|
||||
],
|
||||
FundingRoundShares: [
|
||||
0.1,
|
||||
0.35,
|
||||
0.25,
|
||||
0.2
|
||||
],
|
||||
FundingRoundMultiplier: [
|
||||
4,
|
||||
3,
|
||||
3,
|
||||
2.5
|
||||
],
|
||||
};
|
||||
|
@ -15,37 +15,18 @@ interface IProps {
|
||||
|
||||
// Create a popup that lets the player manage exports
|
||||
export function FindInvestorsModal(props: IProps): React.ReactElement {
|
||||
const corp = useCorporation();
|
||||
const val = corp.determineValuation();
|
||||
let percShares = 0;
|
||||
let roundMultiplier = 4;
|
||||
switch (corp.fundingRound) {
|
||||
case 0: //Seed
|
||||
percShares = 0.1;
|
||||
roundMultiplier = 4;
|
||||
break;
|
||||
case 1: //Series A
|
||||
percShares = 0.35;
|
||||
roundMultiplier = 3;
|
||||
break;
|
||||
case 2: //Series B
|
||||
percShares = 0.25;
|
||||
roundMultiplier = 3;
|
||||
break;
|
||||
case 3: //Series C
|
||||
percShares = 0.2;
|
||||
roundMultiplier = 2.5;
|
||||
break;
|
||||
default:
|
||||
return <></>;
|
||||
}
|
||||
const corporation = useCorporation();
|
||||
const val = corporation.determineValuation();
|
||||
if (corporation.fundingRound >= CorporationConstants.FundingRoundShares.length || corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length) return <></>;
|
||||
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
||||
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
||||
const funding = val * percShares * roundMultiplier;
|
||||
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
|
||||
|
||||
function findInvestors(): void {
|
||||
corp.fundingRound++;
|
||||
corp.addFunds(funding);
|
||||
corp.numShares -= investShares;
|
||||
corporation.fundingRound++;
|
||||
corporation.addFunds(funding);
|
||||
corporation.numShares -= investShares;
|
||||
props.rerender();
|
||||
props.onClose();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import {
|
||||
Division as NSDivision,
|
||||
WarehouseAPI,
|
||||
OfficeAPI,
|
||||
InvestmentOffer
|
||||
} from "../ScriptEditor/NetscriptDefinitions";
|
||||
|
||||
import {
|
||||
@ -126,6 +127,40 @@ export function NetscriptCorporation(
|
||||
return CorporationConstants.OfficeInitialCost;
|
||||
}
|
||||
|
||||
function getInvestmentOffer(): InvestmentOffer {
|
||||
const corporation = getCorporation();
|
||||
if (corporation.fundingRound >= CorporationConstants.FundingRoundShares.length || corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length)
|
||||
return {
|
||||
funds: 0,
|
||||
shares: 0,
|
||||
round: corporation.fundingRound + 1 // Make more readable
|
||||
}; // Don't throw an error here, no reason to have a second function to check if you can get investment.
|
||||
const val = corporation.determineValuation();
|
||||
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
||||
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
||||
const funding = val * percShares * roundMultiplier;
|
||||
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
|
||||
return {
|
||||
funds: funding,
|
||||
shares: investShares,
|
||||
round: corporation.fundingRound + 1 // Make more readable
|
||||
};
|
||||
}
|
||||
|
||||
function acceptInvestmentOffer(): boolean {
|
||||
const corporation = getCorporation();
|
||||
if (corporation.fundingRound >= CorporationConstants.FundingRoundShares.length || corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length) return false;
|
||||
const val = corporation.determineValuation();
|
||||
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
||||
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
||||
const funding = val * percShares * roundMultiplier;
|
||||
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
|
||||
corporation.fundingRound++;
|
||||
corporation.addFunds(funding);
|
||||
corporation.numShares -= investShares;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getCorporation(): ICorporation {
|
||||
const corporation = player.corporation;
|
||||
if (corporation === null) throw new Error("cannot be called without a corporation");
|
||||
@ -632,6 +667,14 @@ export function NetscriptCorporation(
|
||||
getExpandCityCost: function(): number {
|
||||
checkAccess("getExpandCityCost");
|
||||
return getExpandCityCost();
|
||||
}
|
||||
},
|
||||
getInvestmentOffer: function(): InvestmentOffer {
|
||||
checkAccess("getInvestmentOffer");
|
||||
return getInvestmentOffer();
|
||||
},
|
||||
acceptInvestmentOffer: function(): boolean {
|
||||
checkAccess("acceptInvestmentOffer");
|
||||
return acceptInvestmentOffer();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
25
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
25
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6383,6 +6383,18 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
||||
* @returns cost
|
||||
*/
|
||||
getExpandCityCost(): number;
|
||||
/**
|
||||
* Get an offer for investment based on you companies current valuation
|
||||
* @returns An offer of investment
|
||||
*/
|
||||
getInvestmentOffer(): InvestmentOffer;
|
||||
/**
|
||||
* Accept investment based on you companies current valuation
|
||||
* @remarks
|
||||
* Is based on current valuation and will not honer a specific Offer
|
||||
* @returns An offer of investment
|
||||
*/
|
||||
acceptInvestmentOffer(): boolean;
|
||||
/**
|
||||
* Get corporation data
|
||||
* @returns Corporation data
|
||||
@ -6597,6 +6609,19 @@ interface Division {
|
||||
cities: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Corporation investment offer
|
||||
* @public
|
||||
*/
|
||||
interface InvestmentOffer {
|
||||
/** Amount of funds you will get from this investment */
|
||||
funds: number;
|
||||
/** Amount of share you will give in exchange for this investment */
|
||||
shares: number;
|
||||
/** Current round of funding (max 4) */
|
||||
round: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface Theme
|
||||
* @internal
|
||||
|
Loading…
Reference in New Issue
Block a user