Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StorageComponent

Allows an entity to store resources.

Hierarchy

Index

Constructors

constructor

Methods

addRecipe

  • addRecipe(recipe: any, times?: number): void
  • Adds a given recipe to the storage, optionally multiple times if times is specified

    Parameters

    • recipe: any
    • Default value times: number = 1

    Returns void

addUntilFull

  • addUntilFull(resource: any, amount: any): void
  • Adds a resource. If we would exceed the maximum storage, only add until its full.

    Parameters

    • resource: any
    • amount: any

    Returns void

checkResource

  • checkResource(resource: any): void
  • Checks if the given resource is known

    Parameters

    • resource: any

    Returns void

deserialize

  • deserialize(data: any): any
  • Attempts to deserialize the storages contents from a serialized payload

    Parameters

    • data: any

    Returns any

getAmount

  • getAmount(resource: any): any
  • Returns the amount of resources we have

    Parameters

    • resource: any

    Returns any

getAmountFullOnes

  • getAmountFullOnes(resource: any): number
  • Returns the amount of resources we have, but only full ones (i.e. 5.1 -> 5)

    Parameters

    • resource: any

    Returns number

getDebugString

  • getDebugString(): string

getMaximum

  • getMaximum(resource: any): any
  • Returns the maximum of a given reosurce

    Parameters

    • resource: any

    Returns any

getPendingFullOnes

  • getPendingFullOnes(resource: any): number
  • Returns the amount of pending resources, but only full ones (i.e. 5.1 -> 5)

    Parameters

    • resource: any

    Returns number

getRecipeHighestTakeAmount

  • getRecipeHighestTakeAmount(recipe: any): number
  • Returns how often we can take the given recipe from this storage. Mainly used for factories to produce as many recipes as possible.

    Parameters

    • recipe: any

    Returns number

getSpaceLeftIncludingPending

  • getSpaceLeftIncludingPending(resource: any): number
  • Returns how much space there is left, including reserved space

    Parameters

    • resource: any

    Returns number

hasAmount

  • hasAmount(resource: any, amount: any): boolean
  • Returns if we have the given amount of resources

    Parameters

    • resource: any
    • amount: any

    Returns boolean

hasRecipe

  • hasRecipe(recipe: any): boolean
  • Checks if we have all resources for the given recipe. A recipe is a combination of resources, e.g. { tree: 5, crystal: 20 }.

    Parameters

    • recipe: any

    Returns boolean

hasSpaceLeftForRecipe

  • hasSpaceLeftForRecipe(recipe: any): boolean
  • Returns if we have enough space left to store the given recipe. Used mainly by the factory system to check if the outcome can be stored

    Parameters

    • recipe: any

    Returns boolean

hasSpaceLeftIncludingPending

  • hasSpaceLeftIncludingPending(resource: any): boolean
  • Returns if there is any space left for a given resource

    Parameters

    • resource: any

    Returns boolean

increaseMaximum

  • increaseMaximum(resource: any, maximum: any): void
  • Increases the maximum amount of a resource. MUST be higher or same than the current max

    Parameters

    • resource: any
    • maximum: any

    Returns void

reservePending

  • reservePending(resource: any, amount: any): void
  • Reserves space in this storage component, so we can put in resources later. This is used for trucks, we reserve the space when we emit the truck, and it would be bad if the storage is full until we arrived, so reserve it so that the space is still free when they arrive.

    Parameters

    • resource: any
    • amount: any

    Returns void

resolvePending

  • resolvePending(resource: any, amount: any): void
  • Frees previously reserved space

    Parameters

    • resource: any
    • amount: any

    Returns void

serialize

  • serialize(): object

takeAllFullOnes

  • takeAllFullOnes(resource: any): number
  • Takes all full ones of the given resource from this storage. I.e. if we have 5.6 of crystal, takes 5 and returns that

    Parameters

    • resource: any

    Returns number

takeRecipe

  • takeRecipe(recipe: any, times?: number): void
  • Takes the recipe times from the storage. Throws exception if not enough resources are contained (check with @see getRecipeHighestTakeAmount first)

    Parameters

    • recipe: any
    • Default value times: number = 1

    Returns void

tryTakeAmount

  • tryTakeAmount(resource: any, amount: any): boolean
  • Tries to take the given amount of resources

    Parameters

    • resource: any
    • amount: any

    Returns boolean

    true if the given amount was taken, false if we had insufficient resources

Static getCachedSchema

  • getCachedSchema(): any

Static getId

  • getId(): string
  • Returns string

Static getSchema

  • getSchema(): object

Static verify

  • verify(data: any): string