Options
All
  • Public
  • Public/Protected
  • All
Menu

Layer on top of NS to simplify worker management.

Hierarchy

  • Store<WorkerPurchaseParams, WorkerSellParams>
    • WorkerStore

Index

Constructors

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

    Parameters

    • ns: NS

      The Netscript object.

    Returns WorkerStore

Properties

_currentRAM: number = 8

Current RAM count

_ns: NS

The Netscript object.

_workers: string[] = []

Current number of nodes purchased.

Methods

  • _checkParams(params: WorkerPurchaseParams | WorkerSellParams): boolean
  • Verifies that the RAM is divisible by 8.

    override

    Parameters

    • params: WorkerPurchaseParams | WorkerSellParams

      Parameters for this transaction.

    Returns boolean

    Whether the parameters are valid.

  • _getBestRAMPurchase(): number
  • Gets best available RAM purchase.

    Returns number

    The best available RAM purchase, based on available money.

  • _getWorkerName(): string
  • Returns string

  • _purchase(params: WorkerPurchaseParams): Promise<boolean>
  • Purchase a new worker with params.ram.

    override
    async

    Parameters

    • params: WorkerPurchaseParams

      Parameters for this transaction.

    Returns Promise<boolean>

    Whether the transaction was successful.

  • _sell(params: WorkerSellParams): Promise<boolean>
  • Sell a worker with hostnmae params.hostname.

    override
    async

    Parameters

    • params: WorkerSellParams

      Parameters for this sale.

    Returns Promise<boolean>

    Whether the transaction was successful.

  • _updateCurrentRAM(): number
  • Update the current RAM of purchased workers.

    Returns number

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

  • _updateWorkers(): string[]
  • Update the number of workers purchased.

    Returns string[]

    The number of workers purchased.

  • canPurchase(params: WorkerPurchaseParams): boolean
  • Checks whether the user can purchase based on parameters params.

    Parameters

    • params: WorkerPurchaseParams

      Parameters for this transaction.

    Returns boolean

    Whether this transaction is possible.

  • getAvailableMoney(): number
  • Gets the amount of money available to this store.

    Returns number

    Available money according to this._budget.

  • getCurrentRAM(): number
  • Gets current RAM value.

    Returns number

    Current RAM value based on available money.

  • getPurchaseCost(params: WorkerPurchaseParams): number
  • Get cost of purchasing a new worker with params.ram.

    override

    Parameters

    • params: WorkerPurchaseParams

      Parameters for this transaction.

    Returns number

    Cost of the transaction.

  • getWorkers(): string[]
  • Gets current workers.

    Returns string[]

    All purchased workers.

  • purchase(params: WorkerPurchaseParams): Promise<boolean>
  • Purchase an item with parameters params if there is money available.

    virtual

    Must be overridden by implementing classes.

    async

    Parameters

    • params: WorkerPurchaseParams

      Parameters for this transaction.

    Returns Promise<boolean>

    Whether the transaction was successful.

  • sell(params: WorkerSellParams): Promise<boolean>
  • Sell an item with params params, if possible.

    async

    Parameters

    • params: WorkerSellParams

      Parameters for this sale.

    Returns Promise<boolean>

    Whether the transaction was successful.

  • sellServersIfNeeded(): Promise<boolean>
  • Check RAM level based on available money, and sell servers if needed.

    async

    Returns Promise<boolean>

    Whether servers were sold.

Generated using TypeDoc