few more api break

This commit is contained in:
Olivier Gagnon 2022-07-20 17:03:08 -04:00
commit ef42ee7232
14 changed files with 79 additions and 101 deletions

4
dist/main.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -263,6 +263,11 @@ v2.0.0 - 2022-07-19 Work rework
* commitCrime now has 'focus' optional parameter
* using getScriptIncome to get total income has been separated to getTotalScriptIncome.
* using getScriptExpGain to get total income has been separated to getTotalScriptExpGain.
* scp has it's 2 last argument reversed, the signature is now (files, destination, optional_source)
* ns.connect and other singularity function are no longer available at the top level.
They were already hidden from documentation but now they're gone.
* stock.buy and stock.sell were renamed to stock.buyStock and stock.sellStock because 'buy' and 'sell'
are very common tokens.
Multipliers

@ -84,12 +84,12 @@ export function LevelUpgrade(corporation: ICorporation, upgrade: CorporationUpgr
}
}
export function IssueDividends(corporation: ICorporation, percent: number): void {
if (isNaN(percent) || percent < 0 || percent > CorporationConstants.DividendMaxPercentage) {
throw new Error(`Invalid value. Must be an integer between 0 and ${CorporationConstants.DividendMaxPercentage}`);
export function IssueDividends(corporation: ICorporation, rate: number): void {
if (isNaN(rate) || rate < 0 || rate > CorporationConstants.DividendMaxRate) {
throw new Error(`Invalid value. Must be an number between 0 and ${CorporationConstants.DividendMaxRate}`);
}
corporation.dividendPercentage = percent * 100;
corporation.dividendRate = rate;
}
export function SellMaterial(mat: Material, amt: string, price: string): void {

@ -35,8 +35,8 @@ export class Corporation {
shareSalesUntilPriceUpdate = CorporationConstants.SHARESPERPRICEUPDATE;
shareSaleCooldown = 0; // Game cycles until player can sell shares again
issueNewSharesCooldown = 0; // Game cycles until player can issue shares again
dividendPercentage = 0;
dividendTaxPercentage = 50;
dividendRate = 0;
dividendTax = 1 - BitNodeMultipliers.CorporationSoftcap + 0.15;
issuedShares = 0;
sharePrice = 0;
storedCycles = 0;
@ -121,18 +121,19 @@ export class Corporation {
}
// Process dividends
if (this.dividendPercentage > 0 && cycleProfit > 0) {
this.updateDividendTax();
if (this.dividendRate > 0 && cycleProfit > 0) {
// Validate input again, just to be safe
if (
isNaN(this.dividendPercentage) ||
this.dividendPercentage < 0 ||
this.dividendPercentage > CorporationConstants.DividendMaxPercentage * 100
isNaN(this.dividendRate) ||
this.dividendRate < 0 ||
this.dividendRate > CorporationConstants.DividendMaxRate
) {
console.error(`Invalid Corporation dividend percentage: ${this.dividendPercentage}`);
console.error(`Invalid Corporation dividend rate: ${this.dividendRate}`);
} else {
const totalDividends = (this.dividendPercentage / 100) * cycleProfit;
const totalDividends = this.dividendRate * cycleProfit;
const retainedEarnings = cycleProfit - totalDividends;
player.gainMoney(this.getDividends(), "corporation");
player.gainMoney(this.getCycleDividends(), "corporation");
this.addFunds(retainedEarnings);
}
} else {
@ -146,20 +147,23 @@ export class Corporation {
}
}
getDividends(): number {
const profit = this.revenue - this.expenses;
const cycleProfit = profit * CorporationConstants.SecsPerMarketCycle;
const totalDividends = (this.dividendPercentage / 100) * cycleProfit;
const dividendsPerShare = totalDividends / this.totalShares;
const dividends = this.numShares * dividendsPerShare;
let upgrades = -0.15;
updateDividendTax(): void {
this.dividendTax = 1 - BitNodeMultipliers.CorporationSoftcap + 0.15;
if (this.unlockUpgrades[5] === 1) {
upgrades += 0.05;
this.dividendTax -= 0.05;
}
if (this.unlockUpgrades[6] === 1) {
upgrades += 0.1;
this.dividendTax -= 0.1;
}
return Math.pow(dividends, BitNodeMultipliers.CorporationSoftcap + upgrades);
}
getCycleDividends(): number {
const profit = this.revenue - this.expenses;
const cycleProfit = profit * CorporationConstants.SecsPerMarketCycle;
const totalDividends = this.dividendRate * cycleProfit;
const dividendsPerShare = totalDividends / this.totalShares;
const dividends = this.numShares * dividendsPerShare;
return Math.pow(dividends, 1 - this.dividendTax);
}
determineValuation(): number {
@ -167,8 +171,8 @@ export class Corporation {
profit = this.avgProfit;
if (this.public) {
// Account for dividends
if (this.dividendPercentage > 0) {
profit *= (100 - this.dividendPercentage) / 100;
if (this.dividendRate > 0) {
profit *= 1 - this.dividendRate;
}
val = this.funds + profit * 85e3;
@ -277,11 +281,7 @@ export class Corporation {
this.funds = this.funds - price;
// Apply effects for one-time upgrades
if (upgN === 5) {
this.dividendTaxPercentage -= 5;
} else if (upgN === 6) {
this.dividendTaxPercentage -= 10;
}
this.updateDividendTax();
}
//Levelable upgrades

@ -20,8 +20,8 @@ export interface ICorporation {
shareSalesUntilPriceUpdate: number;
shareSaleCooldown: number;
issueNewSharesCooldown: number;
dividendPercentage: number;
dividendTaxPercentage: number;
dividendRate: number;
dividendTax: number;
issuedShares: number;
sharePrice: number;
storedCycles: number;
@ -55,6 +55,7 @@ export interface ICorporation {
getSalesMultiplier(): number;
getScientificResearchMultiplier(): number;
getStarterGuide(player: IPlayer): void;
updateDividendTax(): void;
getCycleDividends(): number;
toJSON(): IReviverValue;
getDividends(): number;
}

@ -19,7 +19,7 @@ export const CorporationConstants: {
BribeThreshold: number;
BribeToRepRatio: number;
ProductProductionCostRatio: number;
DividendMaxPercentage: number;
DividendMaxRate: number;
EmployeeSalaryMultiplier: number;
CyclesPerEmployeeRaise: number;
EmployeeRaiseAmount: number;
@ -61,7 +61,7 @@ export const CorporationConstants: {
ProductProductionCostRatio: 5, //Ratio of material cost of a product to its production cost
DividendMaxPercentage: 1,
DividendMaxRate: 1,
EmployeeSalaryMultiplier: 3, // Employee stats multiplied by this to determine initial salary
CyclesPerEmployeeRaise: 400, // All employees get a raise every X market cycles

@ -275,17 +275,18 @@ interface IDividendsStatsProps {
}
function DividendsStats({ profit }: IDividendsStatsProps): React.ReactElement {
const corp = useCorporation();
if (corp.dividendPercentage <= 0 || profit <= 0) return <></>;
const totalDividends = (corp.dividendPercentage / 100) * profit;
if (corp.dividendRate <= 0 || profit <= 0) return <></>;
const totalDividends = corp.dividendRate * profit;
const retainedEarnings = profit - totalDividends;
const dividendsPerShare = totalDividends / corp.totalShares;
const playerEarnings = corp.getCycleDividends() / CorporationConstants.SecsPerMarketCycle;
return (
<StatsTable
rows={[
["Retained Profits (after dividends):", <MoneyRate money={retainedEarnings} />],
["Dividend Percentage:", numeralWrapper.format(corp.dividendPercentage / 100, "0%")],
["Dividend Percentage:", numeralWrapper.format(corp.dividendRate, "0%")],
["Dividends per share:", <MoneyRate money={dividendsPerShare} />],
["Your earnings as a shareholder:", <MoneyRate money={corp.getDividends()} />],
["Your earnings as a shareholder:", <MoneyRate money={playerEarnings} />],
]}
/>
);

@ -19,7 +19,7 @@ export function IssueDividendsModal(props: IProps): React.ReactElement {
const corp = useCorporation();
const [percent, setPercent] = useState(0);
const canIssue = !isNaN(percent) && percent >= 0 && percent <= CorporationConstants.DividendMaxPercentage * 100;
const canIssue = !isNaN(percent) && percent >= 0 && percent <= CorporationConstants.DividendMaxRate * 100;
function issueDividends(): void {
if (!canIssue) return;
if (percent === null) return;

@ -1,8 +1 @@
- getScriptExp
- getScriptIncome
- commitCrime
- Change scp to be (files, destination, source)
- Remove top level sing
- Rename stock.buy and stock.sell
- https://github.com/danielyxie/bitburner/pull/3802
- https://github.com/danielyxie/bitburner/pull/3812

@ -135,8 +135,8 @@ const stock = {
getMaxShares: RamCostConstants.ScriptGetStockRamCost,
getPurchaseCost: RamCostConstants.ScriptGetStockRamCost,
getSaleGain: RamCostConstants.ScriptGetStockRamCost,
buy: RamCostConstants.ScriptBuySellStockRamCost,
sell: RamCostConstants.ScriptBuySellStockRamCost,
buyStock: RamCostConstants.ScriptBuySellStockRamCost,
sellStock: RamCostConstants.ScriptBuySellStockRamCost,
short: RamCostConstants.ScriptBuySellStockRamCost,
sellShort: RamCostConstants.ScriptBuySellStockRamCost,
placeOrder: RamCostConstants.ScriptBuySellStockRamCost,

@ -922,14 +922,15 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
},
issueDividends:
(ctx: NetscriptContext) =>
(_percent: unknown): void => {
(_rate: unknown): void => {
checkAccess(ctx);
const percent = ctx.helper.number("percent", _percent);
if (percent < 0 || percent > 100)
throw new Error("Invalid value for percent field! Must be numeric, greater than 0, and less than 100");
const rate = ctx.helper.number("rate", _rate);
const max = CorporationConstants.DividendMaxRate;
if (rate < 0 || rate > max)
throw new Error(`Invalid value for rate field! Must be numeric, greater than 0, and less than ${max}`);
const corporation = getCorporation();
if (!corporation.public) throw ctx.makeRuntimeErrorMsg(`Your company has not gone public!`);
IssueDividends(corporation, percent);
IssueDividends(corporation, rate);
},
// If you modify these objects you will affect them for real, it's not
@ -956,6 +957,9 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
shareSaleCooldown: corporation.shareSaleCooldown,
issuedShares: corporation.issuedShares,
sharePrice: corporation.sharePrice,
dividendRate: corporation.dividendRate,
dividendTax: corporation.dividendTax,
dividendEarnings: corporation.getCycleDividends() / CorporationConstants.SecsPerMarketCycle,
state: corporation.state.getState(),
divisions: corporation.divisions.map((division): NSDivision => getSafeDivision(division)),
};

@ -144,7 +144,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res;
},
buy:
buyStock:
(ctx: NetscriptContext) =>
(_symbol: unknown, _shares: unknown): number => {
const symbol = ctx.helper.string("symbol", _symbol);
@ -154,7 +154,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
const res = buyStock(stock, shares, workerScript, {});
return res ? stock.getAskPrice() : 0;
},
sell:
sellStock:
(ctx: NetscriptContext) =>
(_symbol: unknown, _shares: unknown): number => {
const symbol = ctx.helper.string("symbol", _symbol);

@ -1304,7 +1304,7 @@ export interface TIX {
* @param shares - Number of shares to purchased. Must be positive. Will be rounded to nearest integer.
* @returns The stock price at which each share was purchased, otherwise 0 if the shares weren't purchased.
*/
buy(sym: string, shares: number): number;
buyStock(sym: string, shares: number): number;
/**
* Sell stocks.
@ -1328,7 +1328,7 @@ export interface TIX {
* @param shares - Number of shares to sell. Must be positive. Will be rounded to nearest integer.
* @returns The stock price at which each share was sold, otherwise 0 if the shares weren't sold.
*/
sell(sym: string, shares: number): number;
sellStock(sym: string, shares: number): number;
/**
* Short stocks.
@ -5399,67 +5399,35 @@ export interface NS {
* ```ts
* // NS1:
* //Copies foo.lit from the helios server to the home computer:
* scp("foo.lit", "helios", "home");
* scp("foo.lit", "home", "helios");
*
* //Tries to copy three files from rothman-uni to home computer:
* files = ["foo1.lit", "foo2.script", "foo3.script"];
* scp(files, "rothman-uni", "home");
* scp(files, "home", "rothman-uni");
* ```
* @example
* ```ts
* // NS2:
* //Copies foo.lit from the helios server to the home computer:
* await ns.scp("foo.lit", "helios", "home");
* await ns.scp("foo.lit", "home", "helios" );
*
* //Tries to copy three files from rothman-uni to home computer:
* files = ["foo1.lit", "foo2.script", "foo3.script"];
* await ns.scp(files, "rothman-uni", "home");
* await ns.scp(files, "home", "rothman-uni");
* ```
* @example
* ```ts
* //ns2, copies files from home to a target server
* const server = ns.args[0];
* const files = ["hack.js","weaken.js","grow.js"];
* await ns.scp(files, "home", server);
* await ns.scp(files, server, "home");
* ```
* @param files - Filename or an array of filenames of script/literature files to copy.
* @param source - Host of the source server, which is the server from which the file will be copied. This argument is optional and if its omitted the source will be the current server.
* @param destination - Host of the destination server, which is the server to which the file will be copied.
* @returns True if the script/literature file is successfully copied over and false otherwise. If the files argument is an array then this function will return true if at least one of the files in the array is successfully copied.
*/
scp(files: string | string[], destination: string): Promise<boolean>;
/**
* {@inheritDoc NS.(scp:1)}
* @example
* ```ts
* // NS1:
* //Copies foo.lit from the helios server to the home computer:
* scp("foo.lit", "helios", "home");
*
* //Tries to copy three files from rothman-uni to home computer:
* files = ["foo1.lit", "foo2.script", "foo3.script"];
* scp(files, "rothman-uni", "home");
* ```
* @example
* ```ts
* // NS2:
* //Copies foo.lit from the helios server to the home computer:
* await ns.scp("foo.lit", "helios", "home");
*
* //Tries to copy three files from rothman-uni to home computer:
* files = ["foo1.lit", "foo2.script", "foo3.script"];
* await ns.scp(files, "rothman-uni", "home");
* ```
* @example
* ```ts
* //ns2, copies files from home to a target server
* const server = ns.args[0];
* const files = ["hack.js","weaken.js","grow.js"];
* await ns.scp(files, "home", server);
* ```
*/
scp(files: string | string[], source: string, destination: string): Promise<boolean>;
scp(files: string | string[], destination: string, source?: string): Promise<boolean>;
/**
* List files on a server.
@ -7051,9 +7019,9 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
levelUpgrade(upgradeName: string): void;
/**
* Issue dividends
* @param percent - Percent of profit to issue as dividends.
* @param rate - Fraction of profit to issue as dividends.
*/
issueDividends(percent: number): void;
issueDividends(rate: number): void;
/**
* Buyback Shares
* @param amount - Amount of shares to buy back.
@ -7103,6 +7071,12 @@ interface CorporationInfo {
issuedShares: number;
/** Price of the shares */
sharePrice: number;
/** Fraction of profits issued as dividends */
dividendRate: number;
/** Tax applied on your earnings as a shareholder */
dividendTax: number;
/** Your earnings as a shareholder per second this cycle */
dividendEarnings: number;
/** State of the corporation. Possible states are START, PURCHASE, PRODUCTION, SALE, EXPORT. */
state: string;
/** Array of all divisions */