_internal.classes.store.worker.WorkerStore - vladzaharia/bitburner GitHub Wiki

Class: WorkerStore

_internal/classes/store/worker.WorkerStore

Layer on top of NS to simplify worker management.

Hierarchy

  • Store<WorkerPurchaseParams, WorkerSellParams>

    WorkerStore

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new WorkerStore(ns)

Creates a new Hacknet instance which allows for purchasing and upgrading nodes.

Parameters

Name Type Description
ns NS The Netscript object.

Overrides

Store.constructor

Defined in

_internal/classes/store/worker.ts:46

Properties

_currentRAM

Private _currentRAM: number = 8

Current RAM count

Defined in

_internal/classes/store/worker.ts:38


_ns

Protected _ns: NS

The Netscript object.

Inherited from

Store._ns

Defined in

_internal/classes/store/_base.ts:15


_workers

Private _workers: string[] = []

Current number of nodes purchased.

Defined in

_internal/classes/store/worker.ts:35

Methods

_checkParams

Protected _checkParams(params): boolean

Verifies that the RAM is divisible by 8.

override

Parameters

Name Type Description
params WorkerPurchaseParams | WorkerSellParams Parameters for this transaction.

Returns

boolean

Whether the parameters are valid.

Overrides

Store._checkParams

Defined in

_internal/classes/store/worker.ts:208


_getBestRAMPurchase

Private _getBestRAMPurchase(): number

Gets best available RAM purchase.

Returns

number

The best available RAM purchase, based on available money.

Defined in

_internal/classes/store/worker.ts:183


_getWorkerName

Private _getWorkerName(): string

Returns

string

Defined in

_internal/classes/store/worker.ts:237


_purchase

Protected _purchase(params): Promise<boolean>

Purchase a new worker with params.ram.

override

async

Parameters

Name Type Description
params WorkerPurchaseParams Parameters for this transaction.

Returns

Promise<boolean>

Whether the transaction was successful.

Overrides

Store._purchase

Defined in

_internal/classes/store/worker.ts:98


_sell

Protected _sell(params): Promise<boolean>

Sell a worker with hostnmae params.hostname.

override

async

Parameters

Name Type Description
params WorkerSellParams Parameters for this sale.

Returns

Promise<boolean>

Whether the transaction was successful.

Overrides

Store._sell

Defined in

_internal/classes/store/worker.ts:129


_updateCurrentRAM

Private _updateCurrentRAM(): number

Update the current RAM of purchased workers.

Returns

number

The RAM of the first worker if available, this._currentRAM otherwise.

Defined in

_internal/classes/store/worker.ts:255


_updateWorkers

Private _updateWorkers(): string[]

Update the number of workers purchased.

Returns

string[]

The number of workers purchased.

Defined in

_internal/classes/store/worker.ts:246


canPurchase

canPurchase(params): boolean

Checks whether the user can purchase based on parameters params.

Parameters

Name Type Description
params WorkerPurchaseParams Parameters for this transaction.

Returns

boolean

Whether this transaction is possible.

Inherited from

Store.canPurchase

Defined in

_internal/classes/store/_base.ts:59


getAvailableMoney

getAvailableMoney(): number

Gets the amount of money available to this store.

Returns

number

Available money according to this._budget.

Inherited from

Store.getAvailableMoney

Defined in

_internal/classes/store/_base.ts:41


getCurrentRAM

getCurrentRAM(): number

Gets current RAM value.

Returns

number

Current RAM value based on available money.

Defined in

_internal/classes/store/worker.ts:75


getPurchaseCost

getPurchaseCost(params): number

Get cost of purchasing a new worker with params.ram.

override

Parameters

Name Type Description
params WorkerPurchaseParams Parameters for this transaction.

Returns

number

Cost of the transaction.

Overrides

Store.getPurchaseCost

Defined in

_internal/classes/store/worker.ts:65


getWorkers

getWorkers(): string[]

Gets current workers.

Returns

string[]

All purchased workers.

Defined in

_internal/classes/store/worker.ts:85


purchase

purchase(params): Promise<boolean>

Purchase an item with parameters params if there is money available.

virtual Must be overridden by implementing classes.

async

Parameters

Name Type Description
params WorkerPurchaseParams Parameters for this transaction.

Returns

Promise<boolean>

Whether the transaction was successful.

Inherited from

Store.purchase

Defined in

_internal/classes/store/_base.ts:85


sell

sell(params): Promise<boolean>

Sell an item with params params, if possible.

async

Parameters

Name Type Description
params WorkerSellParams Parameters for this sale.

Returns

Promise<boolean>

Whether the transaction was successful.

Inherited from

Store.sell

Defined in

_internal/classes/store/_base.ts:122


sellServersIfNeeded

sellServersIfNeeded(): Promise<boolean>

Check RAM level based on available money, and sell servers if needed.

async

Returns

Promise<boolean>

Whether servers were sold.

Defined in

_internal/classes/store/worker.ts:150

⚠️ **GitHub.com Fallback** ⚠️