mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Merge pull request #371 from d0sboots/hacking
NETSCRIPT: Add `additionalMsec` to BasicHGWOptions
This commit is contained in:
commit
2bd5741b22
13
markdown/bitburner.basichgwoptions.additionalmsec.md
Normal file
13
markdown/bitburner.basichgwoptions.additionalmsec.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [BasicHGWOptions](./bitburner.basichgwoptions.md) > [additionalMsec](./bitburner.basichgwoptions.additionalmsec.md)
|
||||
|
||||
## BasicHGWOptions.additionalMsec property
|
||||
|
||||
Number of additional milliseconds that will be spent waiting between the start of the function and when it completes. There will only be one, contiguous wait, which is relevant because stats such as server security level are computed at the \*start\* of the function. Must be non-negative.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
additionalMsec?: number;
|
||||
```
|
@ -16,6 +16,7 @@ interface BasicHGWOptions
|
||||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [additionalMsec?](./bitburner.basichgwoptions.additionalmsec.md) | | number | _(Optional)_ Number of additional milliseconds that will be spent waiting between the start of the function and when it completes. There will only be one, contiguous wait, which is relevant because stats such as server security level are computed at the \*start\* of the function. Must be non-negative. |
|
||||
| [stock?](./bitburner.basichgwoptions.stock.md) | | boolean | _(Optional)_ Set to true this action will affect the stock market. |
|
||||
| [threads?](./bitburner.basichgwoptions.threads.md) | | number | _(Optional)_ Number of threads to use for this function. Must be less than or equal to the number of threads the script is running with. |
|
||||
|
||||
|
@ -16,9 +16,9 @@ growPercent(server: Server, threads: number, player: Person, cores?: number): nu
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| threads | number | Amount of thread. |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| cores | number | _(Optional)_ Number of cores on the computer that will execute grow. |
|
||||
|
||||
**Returns:**
|
||||
|
29
markdown/bitburner.hackingformulas.growthreads.md
Normal file
29
markdown/bitburner.hackingformulas.growthreads.md
Normal file
@ -0,0 +1,29 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [HackingFormulas](./bitburner.hackingformulas.md) > [growThreads](./bitburner.hackingformulas.growthreads.md)
|
||||
|
||||
## HackingFormulas.growThreads() method
|
||||
|
||||
Calculate how many threads it will take to grow server to targetMoney. Starting money is server.moneyAvailable.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
growThreads(server: Server, player: Person, targetMoney: number, cores?: number): number;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| targetMoney | number | Desired final money, capped to server's moneyMax |
|
||||
| cores | number | _(Optional)_ Number of cores on the computer that will execute grow. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
number
|
||||
|
||||
The calculated grow threads as an integer, rounded up.
|
||||
|
@ -16,8 +16,8 @@ growTime(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -16,8 +16,8 @@ hackChance(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -16,8 +16,8 @@ hackExp(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -16,8 +16,8 @@ hackPercent(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -16,8 +16,8 @@ hackTime(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -17,6 +17,7 @@ interface HackingFormulas
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [growPercent(server, threads, player, cores)](./bitburner.hackingformulas.growpercent.md) | Calculate the percent a server would grow to. Not exact due to limitations of mathematics. (Ex: 3.0 would would grow the server to 300% of its current value.) |
|
||||
| [growThreads(server, player, targetMoney, cores)](./bitburner.hackingformulas.growthreads.md) | Calculate how many threads it will take to grow server to targetMoney. Starting money is server.moneyAvailable. |
|
||||
| [growTime(server, player)](./bitburner.hackingformulas.growtime.md) | Calculate grow time. |
|
||||
| [hackChance(server, player)](./bitburner.hackingformulas.hackchance.md) | Calculate hack chance. (Ex: 0.25 would indicate a 25% chance of success.) |
|
||||
| [hackExp(server, player)](./bitburner.hackingformulas.hackexp.md) | Calculate hack exp for one thread. |
|
||||
|
@ -16,8 +16,8 @@ weakenTime(server: Server, player: Person): number;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| server | [Server](./bitburner.server.md) | Server info from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| server | [Server](./bitburner.server.md) | Server info, typically from [getServer](./bitburner.ns.getserver.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -23,31 +23,35 @@ grow(host: string, opts?: BasicHGWOptions): Promise<number>;
|
||||
|
||||
Promise<number>
|
||||
|
||||
The number by which the money on the server was multiplied for the growth.
|
||||
The total effective multiplier that was applied to the server's money (after both additive and multiplicative growth).
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0.15 GB
|
||||
|
||||
Use your hacking skills to increase the amount of money available on a server. The runtime for this command depends on your hacking level and the target server’s security level. When `grow` completes, the money available on a target server will be increased by amount equal to the number of threads used and a certain, fixed percentage of current money on the server. This percentage is determined by the target server’s growth rate (which varies between servers) and security level. Generally, higher-level servers have higher growth rates. The [getServerGrowth](./bitburner.ns.getservergrowth.md) function can be used to obtain a server’s growth rate.
|
||||
Use your hacking skills to increase the amount of money available on a server.
|
||||
|
||||
Like [hack](./bitburner.ns.hack.md)<!-- -->, `grow` can be called on any server, regardless of where the script is running. The grow() command requires root access to the target server, but there is no required hacking level to run the command. It also raises the security level of the target server by 0.004.
|
||||
Once the grow is complete, $1 is added to the server's available money for every script thread. This additive growth allows for rescuing a server even after it is emptied.
|
||||
|
||||
## Example 1
|
||||
After this addition, the thread count is also used to determine a multiplier, which the server's money is then multiplied by.
|
||||
|
||||
The multiplier scales exponentially with thread count, and its base depends on the server's security level and in inherent "growth" statistic that varies between different servers.
|
||||
|
||||
[getServerGrowth](./bitburner.ns.getservergrowth.md) can be used to check the inherent growth statistic of a server.
|
||||
|
||||
[growthAnalyze](./bitburner.ns.growthanalyze.md) can be used to determine the number of threads needed for a specified multiplicative portion of server growth.
|
||||
|
||||
To determine the effect of a single grow, obtain access to the Formulas API and use [formulas.hacking.growPercent](./bitburner.hackingformulas.growpercent.md)<!-- -->, or invert [growthAnalyze](./bitburner.ns.growthanalyze.md)<!-- -->.
|
||||
|
||||
Like [hack](./bitburner.ns.hack.md)<!-- -->, `grow` can be called on any hackable server, regardless of where the script is running. Hackable servers are any servers not owned by the player.
|
||||
|
||||
The grow() command requires root access to the target server, but there is no required hacking level to run the command. It also raises the security level of the target server based on the number of threads. The security increase can be determined using [growthAnalyzeSecurity](./bitburner.ns.growthanalyzesecurity.md)<!-- -->.
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```ts
|
||||
// NS1:
|
||||
var currentMoney = getServerMoneyAvailable("foodnstuff");
|
||||
currentMoney = currentMoney * grow("foodnstuff");
|
||||
```
|
||||
|
||||
## Example 2
|
||||
|
||||
|
||||
```ts
|
||||
// NS2:
|
||||
let currentMoney = ns.getServerMoneyAvailable("foodnstuff");
|
||||
```js
|
||||
let currentMoney = ns.getServerMoneyAvailable("n00dles");
|
||||
currentMoney *= await ns.grow("foodnstuff");
|
||||
```
|
||||
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
## NS.growthAnalyze() method
|
||||
|
||||
Calculate the number of grow threads needed to grow a server by a certain multiplier.
|
||||
Calculate the number of grow threads needed for a given multiplicative growth factor.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
growthAnalyze(host: string, growthAmount: number, cores?: number): number;
|
||||
growthAnalyze(host: string, multiplier: number, cores?: number): number;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -17,42 +17,33 @@ growthAnalyze(host: string, growthAmount: number, cores?: number): number;
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| host | string | Hostname of the target server. |
|
||||
| growthAmount | number | Multiplicative factor by which the server is grown. Decimal form. |
|
||||
| cores | number | _(Optional)_ |
|
||||
| multiplier | number | Multiplier that will be applied to a server's money after applying additive growth. Decimal form. |
|
||||
| cores | number | _(Optional)_ Number of cores on the host running the grow function. Optional, defaults to 1. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
number
|
||||
|
||||
The amount of grow calls needed to grow the specified server by the specified amount.
|
||||
Decimal number of grow threads needed for the specified multiplicative growth factor (does not include additive growth).
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
This function returns the number of “growths” needed in order to increase the amount of money available on the specified server by the specified amount. The specified amount is multiplicative and is in decimal form, not percentage.
|
||||
This function returns the total decimal number of [grow](./bitburner.ns.grow.md) threads needed in order to multiply the money available on the specified server by a given multiplier, if all threads are executed at the server's current security level, regardless of how many threads are assigned to each call.
|
||||
|
||||
Due to limitations of mathematics, this function won't be the true value, but an approximation.
|
||||
Note that there is also an additive factor that is applied before the multiplier. Each [grow](./bitburner.ns.grow.md) call will add $1 to the host's money for each thread before applying the multiplier for its thread count. This means that at extremely low starting money, fewer threads would be needed to apply the same effective multiplier than what is calculated by growthAnalyze.
|
||||
|
||||
Warning: The value returned by this function isn’t necessarily a whole number.
|
||||
Like other basic hacking analysis functions, this calculation uses the current status of the player and server. To calculate using hypothetical server or player status, obtain access to the Formulas API and use [formulas.hacking.growThreads](./bitburner.hackingformulas.growthreads.md)<!-- -->.
|
||||
|
||||
## Example 1
|
||||
## Example
|
||||
|
||||
|
||||
```ts
|
||||
// NS1:
|
||||
//For example, if you want to determine how many grow calls you need to double the amount of money on foodnstuff, you would use:
|
||||
var growTimes = growthAnalyze("foodnstuff", 2);
|
||||
//If this returns 100, then this means you need to call grow 100 times in order to double the money (or once with 100 threads).
|
||||
```
|
||||
|
||||
## Example 2
|
||||
|
||||
|
||||
```ts
|
||||
// NS2:
|
||||
//For example, if you want to determine how many grow calls you need to double the amount of money on foodnstuff, you would use:
|
||||
const growTimes = ns.growthAnalyze("foodnstuff", 2);
|
||||
//If this returns 100, then this means you need to call grow 100 times in order to double the money (or once with 100 threads).
|
||||
```js
|
||||
// calculate number of grow threads to apply 2x growth multiplier on n00dles (does not include the additive growth).
|
||||
const growThreads = ns.growthAnalyze("n00dles", 2);
|
||||
|
||||
// When using the thread count to launch a script, it needs to be converted to an integer.
|
||||
ns.run("noodleGrow.js", Math.ceil(growThreads));
|
||||
```
|
||||
|
||||
|
@ -30,21 +30,12 @@ RAM cost: 1 GB
|
||||
|
||||
Returns the part of the specified server’s money you will steal with a single thread hack.
|
||||
|
||||
## Example 1
|
||||
Like other basic hacking analysis functions, this calculation uses the current status of the player and server. To calculate using hypothetical server or player status, obtain access to the Formulas API and use [formulas.hacking.hackPercent](./bitburner.hackingformulas.hackpercent.md)<!-- -->.
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```ts
|
||||
// NS1:
|
||||
//For example, assume the following returns 0.01:
|
||||
var hackAmount = hackAnalyze("foodnstuff");
|
||||
//This means that if hack the foodnstuff server using a single thread, then you will steal 1%, or 0.01 of its total money. If you hack using N threads, then you will steal N*0.01 times its total money.
|
||||
```
|
||||
|
||||
## Example 2
|
||||
|
||||
|
||||
```ts
|
||||
// NS2:
|
||||
```js
|
||||
//For example, assume the following returns 0.01:
|
||||
const hackAmount = ns.hackAnalyze("foodnstuff");
|
||||
//This means that if hack the foodnstuff server using a single thread, then you will steal 1%, or 0.01 of its total money. If you hack using N threads, then you will steal N*0.01 times its total money.
|
||||
|
@ -32,3 +32,5 @@ Returns the chance you have of successfully hacking the specified server.
|
||||
|
||||
This returned value is in decimal form, not percentage.
|
||||
|
||||
Like other basic hacking analysis functions, this calculation uses the current status of the player and server. To calculate using hypothetical server or player status, obtain access to the Formulas API and use [formulas.hacking.hackChance](./bitburner.hackingformulas.hackchance.md)<!-- -->.
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## NS.hackAnalyzeThreads() method
|
||||
|
||||
Predict the effect of hack.
|
||||
Calculate the decimal number of threads needed to hack a specified amount of money from a target host.
|
||||
|
||||
**Signature:**
|
||||
|
||||
@ -29,16 +29,17 @@ The number of threads needed to hack the server for hackAmount money.
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
This function returns the number of script threads you need when running the hack command to steal the specified amount of money from the target server. If hackAmount is less than zero or greater than the amount of money available on the server, then this function returns -1.
|
||||
|
||||
Warning: The value returned by this function isn’t necessarily a whole number.
|
||||
This function returns the decimal number of script threads you need when running the hack command to steal the specified amount of money from the target server. If hackAmount is less than zero or greater than the amount of money available on the server, then this function returns -1.
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```ts
|
||||
//For example, let’s say the foodnstuff server has $10m and you run:
|
||||
hackAnalyzeThreads("foodnstuff", 1e6);
|
||||
//If this function returns 50, this means that if your next hack call is run on a script with 50 threads, it will steal $1m from the foodnstuff server.
|
||||
// Calculate threadcount of a single hack that would take $100k from n00dles
|
||||
const hackThreads = hackAnalyzeThreads("n00dles", 1e5);
|
||||
|
||||
// Launching a script requires an integer thread count. The below would take less than the targeted $100k.
|
||||
ns.run("noodleHack.js", Math.floor(hackThreads))
|
||||
|
||||
```
|
||||
|
||||
|
@ -120,13 +120,13 @@ export async function main(ns) {
|
||||
| [getTotalScriptIncome()](./bitburner.ns.gettotalscriptincome.md) | Get the income of all scripts. |
|
||||
| [getWeakenTime(host)](./bitburner.ns.getweakentime.md) | Get the execution time of a weaken() call. |
|
||||
| [grow(host, opts)](./bitburner.ns.grow.md) | Spoof money in a server's bank account, increasing the amount available. |
|
||||
| [growthAnalyze(host, growthAmount, cores)](./bitburner.ns.growthanalyze.md) | Calculate the number of grow threads needed to grow a server by a certain multiplier. |
|
||||
| [growthAnalyze(host, multiplier, cores)](./bitburner.ns.growthanalyze.md) | Calculate the number of grow threads needed for a given multiplicative growth factor. |
|
||||
| [growthAnalyzeSecurity(threads, hostname, cores)](./bitburner.ns.growthanalyzesecurity.md) | Calculate the security increase for a number of threads. |
|
||||
| [hack(host, opts)](./bitburner.ns.hack.md) | Steal a server's money. |
|
||||
| [hackAnalyze(host)](./bitburner.ns.hackanalyze.md) | Get the part of money stolen with a single thread. |
|
||||
| [hackAnalyzeChance(host)](./bitburner.ns.hackanalyzechance.md) | Get the chance of successfully hacking a server. |
|
||||
| [hackAnalyzeSecurity(threads, hostname)](./bitburner.ns.hackanalyzesecurity.md) | Get the security increase for a number of threads. |
|
||||
| [hackAnalyzeThreads(host, hackAmount)](./bitburner.ns.hackanalyzethreads.md) | Predict the effect of hack. |
|
||||
| [hackAnalyzeThreads(host, hackAmount)](./bitburner.ns.hackanalyzethreads.md) | Calculate the decimal number of threads needed to hack a specified amount of money from a target host. |
|
||||
| [hasRootAccess(host)](./bitburner.ns.hasrootaccess.md) | Check if you have root access on a server. |
|
||||
| [hasTorRouter()](./bitburner.ns.hastorrouter.md) | Returns whether the player has access to the darkweb. |
|
||||
| [httpworm(host)](./bitburner.ns.httpworm.md) | Runs HTTPWorm.exe on a server. |
|
||||
|
@ -27,4 +27,5 @@ export interface Office
|
||||
| [maxHap](./bitburner.office.maxhap.md) | | number | Maximum happiness of the employees |
|
||||
| [maxMor](./bitburner.office.maxmor.md) | | number | Maximum morale of the employees |
|
||||
| [size](./bitburner.office.size.md) | | number | Maximum number of employee |
|
||||
| [totalExperience](./bitburner.office.totalexperience.md) | | number | Total experience of all employees |
|
||||
|
||||
|
13
markdown/bitburner.office.totalexperience.md
Normal file
13
markdown/bitburner.office.totalexperience.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Office](./bitburner.office.md) > [totalExperience](./bitburner.office.totalexperience.md)
|
||||
|
||||
## Office.totalExperience property
|
||||
|
||||
Total experience of all employees
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
totalExperience: number;
|
||||
```
|
@ -17,7 +17,7 @@ repFromDonation(amount: number, player: Person): number;
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| amount | number | Amount of money donated |
|
||||
| player | [Person](./bitburner.person.md) | Player info from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
| player | [Person](./bitburner.person.md) | Player info, typically from [getPlayer](./bitburner.ns.getplayer.md) |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -434,17 +434,22 @@ function hack(
|
||||
ctx: NetscriptContext,
|
||||
hostname: string,
|
||||
manual: boolean,
|
||||
{ threads: requestedThreads, stock }: BasicHGWOptions = {},
|
||||
{ threads: requestedThreads, stock, additionalMsec: requestedSec }: BasicHGWOptions = {},
|
||||
): Promise<number> {
|
||||
const ws = ctx.workerScript;
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
|
||||
const additionalMsec = number(ctx, "opts.additionalMsec", requestedSec ?? 0);
|
||||
if (additionalMsec < 0) {
|
||||
throw makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
|
||||
}
|
||||
const server = getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
throw makeRuntimeErrorMsg(ctx, "Cannot be executed on this server.");
|
||||
}
|
||||
|
||||
// Calculate the hacking time
|
||||
const hackingTime = calculateHackingTime(server, Player); // This is in seconds
|
||||
// This is in seconds
|
||||
const hackingTime = calculateHackingTime(server, Player) + additionalMsec / 1000.0;
|
||||
|
||||
// No root access or skill level too low
|
||||
const canHack = netscriptCanHack(server);
|
||||
|
@ -144,7 +144,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
// TODO 2.2: better type safety rework for functions using assertObjectType, then remove function.
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
return helpers.hack(ctx, hostname, false, { threads: opts.threads, stock: opts.stock });
|
||||
return helpers.hack(ctx, hostname, false, opts);
|
||||
},
|
||||
hackAnalyzeThreads: (ctx) => (_hostname, _hackAmount) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
@ -241,11 +241,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
const requestedThreads =
|
||||
opts.threads === undefined
|
||||
? ctx.workerScript.scriptRef.threads
|
||||
: helpers.number(ctx, "opts.threads", opts.threads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, opts.threads);
|
||||
const additionalMsec = helpers.number(ctx, "opts.additionalMsec", opts.additionalMsec ?? 0);
|
||||
if (additionalMsec < 0) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
|
||||
}
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
@ -264,7 +264,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
const growTime = calculateGrowTime(server, Player);
|
||||
const growTime = calculateGrowTime(server, Player) + additionalMsec / 1000.0;
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
@ -348,11 +348,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const optsValidator: BasicHGWOptions = {};
|
||||
assertObjectType(ctx, "opts", opts, optsValidator);
|
||||
const requestedThreads =
|
||||
opts.threads === undefined
|
||||
? ctx.workerScript.scriptRef.threads
|
||||
: helpers.number(ctx, "opts.threads", opts.threads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, requestedThreads);
|
||||
const threads = helpers.resolveNetscriptRequestedThreads(ctx, opts.threads);
|
||||
const additionalMsec = helpers.number(ctx, "opts.additionalMsec", opts.additionalMsec ?? 0);
|
||||
if (additionalMsec < 0) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `additionalMsec must be non-negative, got ${additionalMsec}`);
|
||||
}
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
@ -366,7 +366,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, canHack.msg || "");
|
||||
}
|
||||
|
||||
const weakenTime = calculateWeakenTime(server, Player);
|
||||
const weakenTime = calculateWeakenTime(server, Player) + additionalMsec / 1000.0;
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
|
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -256,6 +256,12 @@ interface BasicHGWOptions {
|
||||
threads?: number;
|
||||
/** Set to true this action will affect the stock market. */
|
||||
stock?: boolean;
|
||||
/** Number of additional milliseconds that will be spent waiting between the
|
||||
* start of the function and when it completes. There will only be one,
|
||||
* contiguous wait, which is relevant because stats such as server security
|
||||
* level are computed at the *start* of the function.
|
||||
* Must be non-negative. */
|
||||
additionalMsec?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user