mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
MISC: Add formulas API for calculating share power and move UI of sharing RAM (#2126)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
## NS.getSharePower() method
|
||||
|
||||
Share Power has a multiplicative effect on rep/second while doing work for a faction. Share Power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate.
|
||||
Share power has a multiplicative effect on rep/second while doing work for a faction. Share power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ export async function main(ns) {
|
||||
| [getServerRequiredHackingLevel(host)](./bitburner.ns.getserverrequiredhackinglevel.md) | Returns the required hacking level of the target server. |
|
||||
| [getServerSecurityLevel(host)](./bitburner.ns.getserversecuritylevel.md) | Get server security level. |
|
||||
| [getServerUsedRam(host)](./bitburner.ns.getserverusedram.md) | Get the used RAM on a server. |
|
||||
| [getSharePower()](./bitburner.ns.getsharepower.md) | Share Power has a multiplicative effect on rep/second while doing work for a faction. Share Power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate. |
|
||||
| [getSharePower()](./bitburner.ns.getsharepower.md) | Share power has a multiplicative effect on rep/second while doing work for a faction. Share power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate. |
|
||||
| [getTimeSinceLastAug()](./bitburner.ns.gettimesincelastaug.md) | Returns the amount of time in milliseconds that have passed since you last installed Augmentations. |
|
||||
| [getTotalScriptExpGain()](./bitburner.ns.gettotalscriptexpgain.md) | Get the exp gain of all scripts. |
|
||||
| [getTotalScriptIncome()](./bitburner.ns.gettotalscriptincome.md) | Get the income of all scripts. |
|
||||
@@ -161,7 +161,7 @@ export async function main(ns) {
|
||||
| [self()](./bitburner.ns.self.md) | Returns the currently running script. |
|
||||
| [serverExists(host)](./bitburner.ns.serverexists.md) | Returns a boolean denoting whether or not the specified server exists. |
|
||||
| [setTitle(title, pid)](./bitburner.ns.settitle.md) | Set the title of the tail window of a script. This function is deprecated and will be removed in a later version. |
|
||||
| [share()](./bitburner.ns.share.md) | Share the server's ram with your factions. |
|
||||
| [share()](./bitburner.ns.share.md) | Share the server's ram with your factions to increase the reputation gain rate of faction work. This boost is applied to all faction work of all factions. |
|
||||
| [sleep(millis)](./bitburner.ns.sleep.md) | Suspends the script for n milliseconds. |
|
||||
| [spawn(script, threadOrOptions, args)](./bitburner.ns.spawn.md) | Terminate current script and start another in a defined number of milliseconds. |
|
||||
| [sprintf(format, args)](./bitburner.ns.sprintf.md) | Format a string. |
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## NS.share() method
|
||||
|
||||
Share the server's ram with your factions.
|
||||
Share the server's ram with your factions to increase the reputation gain rate of faction work. This boost is applied to all faction work of all factions.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
||||
@@ -20,4 +20,5 @@ interface ReputationFormulas
|
||||
| [calculateRepToFavor(rep)](./bitburner.reputationformulas.calculatereptofavor.md) | Calculate the resulting faction favor of a total amount of reputation. (Faction favor is gained whenever you install an Augmentation.) |
|
||||
| [donationForRep(reputation, player)](./bitburner.reputationformulas.donationforrep.md) | Calculate the donation needed to gain an amount of reputation. |
|
||||
| [repFromDonation(amount, player)](./bitburner.reputationformulas.repfromdonation.md) | Calculate how much rep would be gained. |
|
||||
| [sharePower(threads, cpuCores)](./bitburner.reputationformulas.sharepower.md) | Calculate the share power if you call [ns.share](./bitburner.ns.share.md) with the specified number of threads on a server having the specified number of CPU cores. |
|
||||
|
||||
|
||||
27
markdown/bitburner.reputationformulas.sharepower.md
Normal file
27
markdown/bitburner.reputationformulas.sharepower.md
Normal file
@@ -0,0 +1,27 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [ReputationFormulas](./bitburner.reputationformulas.md) > [sharePower](./bitburner.reputationformulas.sharepower.md)
|
||||
|
||||
## ReputationFormulas.sharePower() method
|
||||
|
||||
Calculate the share power if you call [ns.share](./bitburner.ns.share.md) with the specified number of threads on a server having the specified number of CPU cores.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
sharePower(threads: number, cpuCores?: number): number;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| threads | number | Number of threads. Must be a positive integer. |
|
||||
| cpuCores | number | _(Optional)_ Number of CPU cores. Must be a positive integer. The default value is 1. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
number
|
||||
|
||||
The calculated share power.
|
||||
|
||||
@@ -22,7 +22,6 @@ import { GangButton } from "./GangButton";
|
||||
import { FactionWork } from "../../Work/FactionWork";
|
||||
import { useCycleRerender } from "../../ui/React/hooks";
|
||||
import { repNeededToDonate } from "../formulas/donation";
|
||||
import { ShareOption } from "./ShareOption";
|
||||
|
||||
type FactionRootProps = {
|
||||
faction: Faction;
|
||||
@@ -132,7 +131,6 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea
|
||||
{!isPlayersGang && factionInfo.offersWork() && (
|
||||
<DonateOption faction={faction} rerender={rerender} favorToDonate={favorToDonate} disabled={!canDonate} />
|
||||
)}
|
||||
{!isPlayersGang && factionInfo.offersWork() && <ShareOption rerender={rerender} />}
|
||||
<Option buttonText={"Purchase Augmentations"} infoText={augmentationsInfo} onClick={onAugmentations} />
|
||||
{canPurchaseSleeves && (
|
||||
<>
|
||||
|
||||
@@ -16,6 +16,7 @@ import { Requirement } from "../../ui/Components/Requirement";
|
||||
import { Faction } from "../Faction";
|
||||
import { getFactionAugmentationsFiltered, joinFaction } from "../FactionHelpers";
|
||||
import { Factions } from "../Factions";
|
||||
import { ShareOption } from "./ShareOption";
|
||||
|
||||
export const InvitationsSeen = new Set<FactionName>();
|
||||
|
||||
@@ -290,6 +291,12 @@ export function FactionsRoot(): React.ReactElement {
|
||||
</Box>
|
||||
</span>
|
||||
</Box>
|
||||
<div style={{ margin: "15px 0" }}>
|
||||
<Typography variant="h5" color="primary">
|
||||
Share RAM
|
||||
</Typography>
|
||||
<ShareOption rerender={rerender} />
|
||||
</div>
|
||||
<span className="factions-rumors">
|
||||
{rumoredFactions.length > 0 && (
|
||||
<>
|
||||
|
||||
@@ -55,9 +55,10 @@ export function ShareOption({ rerender }: { rerender: () => void }): React.React
|
||||
return (
|
||||
<Paper sx={{ my: 1, p: 1 }}>
|
||||
<Typography>
|
||||
You can share free RAM of your home computer with your faction to get a bonus multiplier for reputation gain.
|
||||
Each time you share your free RAM, you get a boost for {ShareBonusTime / 1000} seconds. You can share free RAM
|
||||
of other servers that you have admin rights by using ns.share() API.
|
||||
You can share free RAM of your home computer with your factions to get a bonus multiplier for reputation gain.
|
||||
Each time you share your free RAM, you get a boost for {ShareBonusTime / 1000} seconds. After that, you lose the
|
||||
boost and get back your shared RAM. You can share free RAM of other servers that you have admin rights on by
|
||||
using the ns.share() API.
|
||||
<br />
|
||||
Free RAM on home computer: {formatRam(home.maxRam - home.ramUsed)}.
|
||||
<br />
|
||||
|
||||
@@ -641,6 +641,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
calculateRepToFavor: 0,
|
||||
repFromDonation: 0,
|
||||
donationForRep: 0,
|
||||
sharePower: 0,
|
||||
},
|
||||
skills: {
|
||||
calculateSkill: 0,
|
||||
|
||||
@@ -53,6 +53,7 @@ import { CompanyPositions } from "../Company/CompanyPositions";
|
||||
import { findCrime } from "../Crime/CrimeHelpers";
|
||||
import { Skills } from "../Bladeburner/data/Skills";
|
||||
import type { PositiveNumber } from "../types";
|
||||
import { calculateEffectiveSharedThreads, calculateShareBonus } from "../NetworkShare/Share";
|
||||
|
||||
export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
||||
@@ -134,6 +135,14 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||
checkFormulasAccess(ctx);
|
||||
return donationForRep(reputation, person);
|
||||
},
|
||||
sharePower:
|
||||
(ctx) =>
|
||||
(_threads, _cpuCores = 1) => {
|
||||
const threads = helpers.positiveInteger(ctx, "threads", _threads);
|
||||
const cpuCores = helpers.positiveInteger(ctx, "cpuCores", _cpuCores);
|
||||
checkFormulasAccess(ctx);
|
||||
return calculateShareBonus(calculateEffectiveSharedThreads(threads, cpuCores));
|
||||
},
|
||||
},
|
||||
skills: {
|
||||
calculateSkill:
|
||||
|
||||
@@ -3,7 +3,7 @@ import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligen
|
||||
import { getCoreBonus } from "../Server/ServerHelpers";
|
||||
import { clampNumber } from "../utils/helpers/clampNumber";
|
||||
|
||||
let sharePower = 1;
|
||||
let shareThreads = 1;
|
||||
|
||||
export const ShareBonusTime = 10000;
|
||||
|
||||
@@ -26,22 +26,22 @@ export function calculateEffectiveSharedThreads(threads: number, cpuCores: numbe
|
||||
|
||||
export function startSharing(threads: number, cpuCores: number): () => void {
|
||||
const effectiveThreads = calculateEffectiveSharedThreads(threads, cpuCores);
|
||||
sharePower += effectiveThreads;
|
||||
shareThreads += effectiveThreads;
|
||||
return () => {
|
||||
/**
|
||||
* Due to floating point inaccuracy, sharePower may be slightly higher or lower than 1 after many times the player
|
||||
* Due to floating point inaccuracy, shareThreads may be slightly higher or lower than 1 after many times the player
|
||||
* shares their RAM. We need to make sure that it's not smaller than 1.
|
||||
*/
|
||||
sharePower = clampNumber(sharePower - effectiveThreads, 1);
|
||||
// sharePower may be slightly higher than 1. Reset sharePower if it's smaller than a threshold.
|
||||
if (sharePower < 1.00001) {
|
||||
sharePower = 1;
|
||||
shareThreads = clampNumber(shareThreads - effectiveThreads, 1);
|
||||
// shareThreads may be slightly higher than 1. Reset shareThreads if it's smaller than a threshold.
|
||||
if (shareThreads < 1.00001) {
|
||||
shareThreads = 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function calculateShareBonus(sharePower: number): number {
|
||||
const bonus = 1 + Math.log(sharePower) / 25;
|
||||
export function calculateShareBonus(shareThreads: number): number {
|
||||
const bonus = 1 + Math.log(shareThreads) / 25;
|
||||
if (!Number.isFinite(bonus)) {
|
||||
return 1;
|
||||
}
|
||||
@@ -49,9 +49,9 @@ function calculateShareBonus(sharePower: number): number {
|
||||
}
|
||||
|
||||
export function calculateShareBonusWithAdditionalThreads(threads: number, cpuCores: number): number {
|
||||
return calculateShareBonus(sharePower + calculateEffectiveSharedThreads(threads, cpuCores));
|
||||
return calculateShareBonus(shareThreads + calculateEffectiveSharedThreads(threads, cpuCores));
|
||||
}
|
||||
|
||||
export function calculateCurrentShareBonus(): number {
|
||||
return calculateShareBonus(sharePower);
|
||||
return calculateShareBonus(shareThreads);
|
||||
}
|
||||
|
||||
16
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
16
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -5277,6 +5277,15 @@ interface ReputationFormulas {
|
||||
* @param player - Player info, typically from {@link NS.getPlayer | getPlayer}
|
||||
*/
|
||||
donationForRep(reputation: number, player: Person): number;
|
||||
|
||||
/**
|
||||
* Calculate the share power if you call {@link NS.share | ns.share} with the specified number of threads on a server
|
||||
* having the specified number of CPU cores.
|
||||
* @param threads - Number of threads. Must be a positive integer.
|
||||
* @param cpuCores - Number of CPU cores. Must be a positive integer. The default value is 1.
|
||||
* @returns The calculated share power.
|
||||
*/
|
||||
sharePower(threads: number, cpuCores?: number): number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8355,7 +8364,8 @@ export interface NS {
|
||||
flags(schema: [string, string | number | boolean | string[]][]): { [key: string]: ScriptArg | string[] };
|
||||
|
||||
/**
|
||||
* Share the server's ram with your factions.
|
||||
* Share the server's ram with your factions to increase the reputation gain rate of faction work. This boost is
|
||||
* applied to all faction work of all factions.
|
||||
* @remarks
|
||||
* RAM cost: 2.4 GB
|
||||
*
|
||||
@@ -8365,8 +8375,8 @@ export interface NS {
|
||||
share(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Share Power has a multiplicative effect on rep/second while doing work for a faction.
|
||||
* Share Power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate.
|
||||
* Share power has a multiplicative effect on rep/second while doing work for a faction.
|
||||
* Share power increases incrementally for every thread of share running on your server network, but at a sharply decreasing rate.
|
||||
* @remarks
|
||||
* RAM cost: 0.2 GB
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user