_internal.classes.store.worker.WorkerStore - vladzaharia/bitburner GitHub Wiki
_internal/classes/store/worker.WorkerStore
Layer on top of NS to simplify worker management.
-
Store<WorkerPurchaseParams,WorkerSellParams>↳
WorkerStore
- _checkParams
- _getBestRAMPurchase
- _getWorkerName
- _purchase
- _sell
- _updateCurrentRAM
- _updateWorkers
- canPurchase
- getAvailableMoney
- getCurrentRAM
- getPurchaseCost
- getWorkers
- purchase
- sell
- sellServersIfNeeded
• new WorkerStore(ns)
Creates a new Hacknet instance which allows for purchasing and upgrading nodes.
| Name | Type | Description |
|---|---|---|
ns |
NS |
The Netscript object. |
_internal/classes/store/worker.ts:46
• Private _currentRAM: number = 8
Current RAM count
_internal/classes/store/worker.ts:38
• Protected _ns: NS
The Netscript object.
_internal/classes/store/_base.ts:15
• Private _workers: string[] = []
Current number of nodes purchased.
_internal/classes/store/worker.ts:35
▸ Protected _checkParams(params): boolean
Verifies that the RAM is divisible by 8.
override
| Name | Type | Description |
|---|---|---|
params |
WorkerPurchaseParams | WorkerSellParams
|
Parameters for this transaction. |
boolean
Whether the parameters are valid.
_internal/classes/store/worker.ts:208
▸ Private _getBestRAMPurchase(): number
Gets best available RAM purchase.
number
The best available RAM purchase, based on available money.
_internal/classes/store/worker.ts:183
▸ Private _getWorkerName(): string
string
_internal/classes/store/worker.ts:237
▸ Protected _purchase(params): Promise<boolean>
Purchase a new worker with params.ram.
override
async
| Name | Type | Description |
|---|---|---|
params |
WorkerPurchaseParams |
Parameters for this transaction. |
Promise<boolean>
Whether the transaction was successful.
_internal/classes/store/worker.ts:98
▸ Protected _sell(params): Promise<boolean>
Sell a worker with hostnmae params.hostname.
override
async
| Name | Type | Description |
|---|---|---|
params |
WorkerSellParams |
Parameters for this sale. |
Promise<boolean>
Whether the transaction was successful.
_internal/classes/store/worker.ts:129
▸ Private _updateCurrentRAM(): number
Update the current RAM of purchased workers.
number
The RAM of the first worker if available, this._currentRAM otherwise.
_internal/classes/store/worker.ts:255
▸ Private _updateWorkers(): string[]
Update the number of workers purchased.
string[]
The number of workers purchased.
_internal/classes/store/worker.ts:246
▸ canPurchase(params): boolean
Checks whether the user can purchase based on parameters params.
| Name | Type | Description |
|---|---|---|
params |
WorkerPurchaseParams |
Parameters for this transaction. |
boolean
Whether this transaction is possible.
_internal/classes/store/_base.ts:59
▸ getAvailableMoney(): number
Gets the amount of money available to this store.
number
Available money according to this._budget.
_internal/classes/store/_base.ts:41
▸ getCurrentRAM(): number
Gets current RAM value.
number
Current RAM value based on available money.
_internal/classes/store/worker.ts:75
▸ getPurchaseCost(params): number
Get cost of purchasing a new worker with params.ram.
override
| Name | Type | Description |
|---|---|---|
params |
WorkerPurchaseParams |
Parameters for this transaction. |
number
Cost of the transaction.
_internal/classes/store/worker.ts:65
▸ getWorkers(): string[]
Gets current workers.
string[]
All purchased workers.
_internal/classes/store/worker.ts:85
▸ purchase(params): Promise<boolean>
Purchase an item with parameters params if there is money available.
virtual Must be overridden by implementing classes.
async
| Name | Type | Description |
|---|---|---|
params |
WorkerPurchaseParams |
Parameters for this transaction. |
Promise<boolean>
Whether the transaction was successful.
_internal/classes/store/_base.ts:85
▸ sell(params): Promise<boolean>
Sell an item with params params, if possible.
async
| Name | Type | Description |
|---|---|---|
params |
WorkerSellParams |
Parameters for this sale. |
Promise<boolean>
Whether the transaction was successful.
_internal/classes/store/_base.ts:122
▸ sellServersIfNeeded(): Promise<boolean>
Check RAM level based on available money, and sell servers if needed.
async
Promise<boolean>
Whether servers were sold.