Add investments to the api

This commit is contained in:
pigalot 2022-01-13 11:42:23 +00:00
parent 1b8c715a5e
commit 2269f79b15
4 changed files with 91 additions and 28 deletions

@ -25,6 +25,8 @@ export const CorporationConstants: {
BaseMaxProducts: number; BaseMaxProducts: number;
AllCorporationStates: string[]; AllCorporationStates: string[];
AllMaterials: string[]; AllMaterials: string[];
FundingRoundShares: number[];
FundingRoundMultiplier: number[];
} = { } = {
INITIALSHARES: 1e9, //Total number of shares you have at your company 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 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", "AI Cores",
"Real Estate", "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 // Create a popup that lets the player manage exports
export function FindInvestorsModal(props: IProps): React.ReactElement { export function FindInvestorsModal(props: IProps): React.ReactElement {
const corp = useCorporation(); const corporation = useCorporation();
const val = corp.determineValuation(); const val = corporation.determineValuation();
let percShares = 0; if (corporation.fundingRound >= CorporationConstants.FundingRoundShares.length || corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length) return <></>;
let roundMultiplier = 4; const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
switch (corp.fundingRound) { const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.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 funding = val * percShares * roundMultiplier; const funding = val * percShares * roundMultiplier;
const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares); const investShares = Math.floor(CorporationConstants.INITIALSHARES * percShares);
function findInvestors(): void { function findInvestors(): void {
corp.fundingRound++; corporation.fundingRound++;
corp.addFunds(funding); corporation.addFunds(funding);
corp.numShares -= investShares; corporation.numShares -= investShares;
props.rerender(); props.rerender();
props.onClose(); props.onClose();
} }

@ -21,6 +21,7 @@ import {
Division as NSDivision, Division as NSDivision,
WarehouseAPI, WarehouseAPI,
OfficeAPI, OfficeAPI,
InvestmentOffer
} from "../ScriptEditor/NetscriptDefinitions"; } from "../ScriptEditor/NetscriptDefinitions";
import { import {
@ -126,6 +127,40 @@ export function NetscriptCorporation(
return CorporationConstants.OfficeInitialCost; 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 { function getCorporation(): ICorporation {
const corporation = player.corporation; const corporation = player.corporation;
if (corporation === null) throw new Error("cannot be called without a corporation"); if (corporation === null) throw new Error("cannot be called without a corporation");
@ -632,6 +667,14 @@ export function NetscriptCorporation(
getExpandCityCost: function(): number { getExpandCityCost: function(): number {
checkAccess("getExpandCityCost"); checkAccess("getExpandCityCost");
return getExpandCityCost(); return getExpandCityCost();
} },
getInvestmentOffer: function(): InvestmentOffer {
checkAccess("getInvestmentOffer");
return getInvestmentOffer();
},
acceptInvestmentOffer: function(): boolean {
checkAccess("acceptInvestmentOffer");
return acceptInvestmentOffer();
},
}; };
} }

@ -6383,6 +6383,18 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
* @returns cost * @returns cost
*/ */
getExpandCityCost(): number; 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 * Get corporation data
* @returns Corporation data * @returns Corporation data
@ -6597,6 +6609,19 @@ interface Division {
cities: string[]; 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 * Interface Theme
* @internal * @internal