mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-25 23:47:34 +01:00
Change corporatio valuation calculations
This commit is contained in:
parent
cc78d62b26
commit
d4c06eba24
@ -45,7 +45,9 @@ export class Corporation {
|
|||||||
upgrades: number[];
|
upgrades: number[];
|
||||||
upgradeMultipliers: number[];
|
upgradeMultipliers: number[];
|
||||||
|
|
||||||
avgProfit = 0;
|
cycleValuation = 0;
|
||||||
|
valuationsList = [0];
|
||||||
|
valuation = 0;
|
||||||
|
|
||||||
state = new CorporationState();
|
state = new CorporationState();
|
||||||
|
|
||||||
@ -108,8 +110,8 @@ export class Corporation {
|
|||||||
this.expenses = this.expenses + ind.lastCycleExpenses;
|
this.expenses = this.expenses + ind.lastCycleExpenses;
|
||||||
});
|
});
|
||||||
const profit = this.revenue - this.expenses;
|
const profit = this.revenue - this.expenses;
|
||||||
this.avgProfit =
|
this.cycleValuation = this.determineCycleValuation();
|
||||||
(this.avgProfit * (CorporationConstants.AvgProfitLength - 1) + profit) / CorporationConstants.AvgProfitLength;
|
this.determineValuation();
|
||||||
const cycleProfit = profit * (marketCycles * CorporationConstants.SecsPerMarketCycle);
|
const cycleProfit = profit * (marketCycles * CorporationConstants.SecsPerMarketCycle);
|
||||||
if (isNaN(this.funds) || this.funds === Infinity || this.funds === -Infinity) {
|
if (isNaN(this.funds) || this.funds === Infinity || this.funds === -Infinity) {
|
||||||
dialogBoxCreate(
|
dialogBoxCreate(
|
||||||
@ -166,9 +168,9 @@ export class Corporation {
|
|||||||
return Math.pow(dividends, 1 - this.dividendTax);
|
return Math.pow(dividends, 1 - this.dividendTax);
|
||||||
}
|
}
|
||||||
|
|
||||||
determineValuation(): number {
|
determineCycleValuation(): number {
|
||||||
let val,
|
let val,
|
||||||
profit = this.avgProfit;
|
profit = this.revenue - this.expenses;
|
||||||
if (this.public) {
|
if (this.public) {
|
||||||
// Account for dividends
|
// Account for dividends
|
||||||
if (this.dividendRate > 0) {
|
if (this.dividendRate > 0) {
|
||||||
@ -182,19 +184,25 @@ export class Corporation {
|
|||||||
val = 10e9 + Math.max(this.funds, 0) / 3; //Base valuation
|
val = 10e9 + Math.max(this.funds, 0) / 3; //Base valuation
|
||||||
if (profit > 0) {
|
if (profit > 0) {
|
||||||
val += profit * 315e3;
|
val += profit * 315e3;
|
||||||
val *= Math.pow(1.1, this.divisions.length);
|
|
||||||
} else {
|
|
||||||
val = 10e9 * Math.pow(1.1, this.divisions.length);
|
|
||||||
}
|
}
|
||||||
|
val *= Math.pow(1.1, this.divisions.length);
|
||||||
val -= val % 1e6; //Round down to nearest millionth
|
val -= val % 1e6; //Round down to nearest millionth
|
||||||
}
|
}
|
||||||
return val * BitNodeMultipliers.CorporationValuation;
|
return val * BitNodeMultipliers.CorporationValuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
determineValuation(): void {
|
||||||
|
this.valuationsList.push(this.cycleValuation); //Add current valuation to the list
|
||||||
|
if (this.valuationsList.length > CorporationConstants.ValuationLength) this.valuationsList.shift();
|
||||||
|
let val = this.valuationsList.reduce((a, b) => a + b); //Calculate valuations sum
|
||||||
|
val /= CorporationConstants.ValuationLength; //Calculate the average
|
||||||
|
this.valuation = val;
|
||||||
|
}
|
||||||
|
|
||||||
getTargetSharePrice(): number {
|
getTargetSharePrice(): number {
|
||||||
// Note: totalShares - numShares is not the same as issuedShares because
|
// Note: totalShares - numShares is not the same as issuedShares because
|
||||||
// issuedShares does not account for private investors
|
// issuedShares does not account for private investors
|
||||||
return this.determineValuation() / (2 * (this.totalShares - this.numShares) + 1);
|
return this.valuation / (2 * (this.totalShares - this.numShares) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSharePrice(): void {
|
updateSharePrice(): void {
|
||||||
@ -243,7 +251,7 @@ export class Corporation {
|
|||||||
sharesSold += sharesUntilUpdate;
|
sharesSold += sharesUntilUpdate;
|
||||||
|
|
||||||
// Calculate what new share price would be
|
// Calculate what new share price would be
|
||||||
sharePrice = this.determineValuation() / (2 * (this.totalShares + sharesSold - this.numShares));
|
sharePrice = this.valuation / (2 * (this.totalShares + sharesSold - this.numShares));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ export interface ICorporation {
|
|||||||
issuedShares: number;
|
issuedShares: number;
|
||||||
sharePrice: number;
|
sharePrice: number;
|
||||||
storedCycles: number;
|
storedCycles: number;
|
||||||
|
valuation: number;
|
||||||
|
|
||||||
unlockUpgrades: number[];
|
unlockUpgrades: number[];
|
||||||
upgrades: number[];
|
upgrades: number[];
|
||||||
@ -36,7 +37,8 @@ export interface ICorporation {
|
|||||||
getState(): string;
|
getState(): string;
|
||||||
storeCycles(numCycles: number): void;
|
storeCycles(numCycles: number): void;
|
||||||
process(player: IPlayer): void;
|
process(player: IPlayer): void;
|
||||||
determineValuation(): number;
|
determineValuation(): void;
|
||||||
|
determineCycleValuation(): number;
|
||||||
getTargetSharePrice(): number;
|
getTargetSharePrice(): number;
|
||||||
updateSharePrice(): void;
|
updateSharePrice(): void;
|
||||||
immediatelyUpdateSharePrice(): void;
|
immediatelyUpdateSharePrice(): void;
|
||||||
|
@ -32,7 +32,7 @@ export const CorporationConstants: {
|
|||||||
AllResearch: string[];
|
AllResearch: string[];
|
||||||
FundingRoundShares: number[];
|
FundingRoundShares: number[];
|
||||||
FundingRoundMultiplier: number[];
|
FundingRoundMultiplier: number[];
|
||||||
AvgProfitLength: number;
|
ValuationLength: 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
|
||||||
@ -153,5 +153,5 @@ export const CorporationConstants: {
|
|||||||
FundingRoundShares: [0.1, 0.35, 0.25, 0.2],
|
FundingRoundShares: [0.1, 0.35, 0.25, 0.2],
|
||||||
FundingRoundMultiplier: [4, 3, 3, 2.5],
|
FundingRoundMultiplier: [4, 3, 3, 2.5],
|
||||||
|
|
||||||
AvgProfitLength: 1,
|
ValuationLength: 5,
|
||||||
};
|
};
|
||||||
|
@ -244,7 +244,7 @@ function BribeButton(): React.ReactElement {
|
|||||||
const corp = useCorporation();
|
const corp = useCorporation();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const canBribe =
|
const canBribe =
|
||||||
corp.determineValuation() >= CorporationConstants.BribeThreshold &&
|
corp.valuation >= CorporationConstants.BribeThreshold &&
|
||||||
player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0;
|
player.factions.filter((f) => Factions[f].getInfo().offersWork()).length > 0;
|
||||||
|
|
||||||
function openBribe(): void {
|
function openBribe(): void {
|
||||||
|
@ -16,7 +16,7 @@ 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 corporation = useCorporation();
|
const corporation = useCorporation();
|
||||||
const val = corporation.determineValuation();
|
const val = corporation.valuation;
|
||||||
if (
|
if (
|
||||||
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
|
corporation.fundingRound >= CorporationConstants.FundingRoundShares.length ||
|
||||||
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length
|
corporation.fundingRound >= CorporationConstants.FundingRoundMultiplier.length
|
||||||
|
@ -19,10 +19,10 @@ interface IProps {
|
|||||||
export function GoPublicModal(props: IProps): React.ReactElement {
|
export function GoPublicModal(props: IProps): React.ReactElement {
|
||||||
const corp = useCorporation();
|
const corp = useCorporation();
|
||||||
const [shares, setShares] = useState<number>(NaN);
|
const [shares, setShares] = useState<number>(NaN);
|
||||||
const initialSharePrice = corp.determineValuation() / corp.totalShares;
|
const initialSharePrice = corp.valuation / corp.totalShares;
|
||||||
|
|
||||||
function goPublic(): void {
|
function goPublic(): void {
|
||||||
const initialSharePrice = corp.determineValuation() / corp.totalShares;
|
const initialSharePrice = corp.valuation / corp.totalShares;
|
||||||
if (isNaN(shares)) {
|
if (isNaN(shares)) {
|
||||||
dialogBoxCreate("Invalid value for number of issued shares");
|
dialogBoxCreate("Invalid value for number of issued shares");
|
||||||
return;
|
return;
|
||||||
|
@ -146,7 +146,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
|||||||
shares: 0,
|
shares: 0,
|
||||||
round: corporation.fundingRound + 1, // Make more readable
|
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.
|
}; // 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 val = corporation.valuation;
|
||||||
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
||||||
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
||||||
const funding = val * percShares * roundMultiplier;
|
const funding = val * percShares * roundMultiplier;
|
||||||
@ -166,7 +166,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
|||||||
corporation.public
|
corporation.public
|
||||||
)
|
)
|
||||||
return false;
|
return false;
|
||||||
const val = corporation.determineValuation();
|
const val = corporation.valuation;
|
||||||
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
const percShares = CorporationConstants.FundingRoundShares[corporation.fundingRound];
|
||||||
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
const roundMultiplier = CorporationConstants.FundingRoundMultiplier[corporation.fundingRound];
|
||||||
const funding = val * percShares * roundMultiplier;
|
const funding = val * percShares * roundMultiplier;
|
||||||
@ -179,7 +179,7 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
|||||||
|
|
||||||
function goPublic(numShares: number): boolean {
|
function goPublic(numShares: number): boolean {
|
||||||
const corporation = getCorporation();
|
const corporation = getCorporation();
|
||||||
const initialSharePrice = corporation.determineValuation() / corporation.totalShares;
|
const initialSharePrice = corporation.valuation / corporation.totalShares;
|
||||||
if (isNaN(numShares)) throw new Error("Invalid value for number of issued shares");
|
if (isNaN(numShares)) throw new Error("Invalid value for number of issued shares");
|
||||||
if (numShares < 0) throw new Error("Invalid value for number of issued shares");
|
if (numShares < 0) throw new Error("Invalid value for number of issued shares");
|
||||||
if (numShares > corporation.numShares) throw new Error("You don't have that many shares to issue!");
|
if (numShares > corporation.numShares) throw new Error("You don't have that many shares to issue!");
|
||||||
|
Loading…
Reference in New Issue
Block a user