ItemDatabase

ItemDatabase

new ItemDatabase()

Description:
  • Specialized database for storing and querying game items with rarity-based selection. Extends RarityDatabase to provide item-specific filtering and search capabilities.

    This class uses a specific parser when configuration data is added via the add method. The format is as follows:

    name1; name2!valueRarityEnc!tag1 tag2 tag3 ...

    One or more names in the first position should be separated with semicolons. The valueRarityEnc value should be in the format #r#, e.g. 50c5 for a value of 50, common rarity, and encumbrance of 5. Finally there can be one or more tags in the final position, that must follow the item.schema.data.

Source:

Extends

Members

models :Array

Description:
  • Array of models stored in the database.

Source:
Inherited From:

Array of models stored in the database.

Type:
  • Array

parser :function

Description:
  • Parser function used to process data before passing it to the model constructor

Source:
Inherited From:

Parser function used to process data before passing it to the model constructor

Type:
  • function

Methods

add(…data) → {Database}

Description:
  • Adds one or more data items to the database.

Source:
Inherited From:
Example
database.add(item1, item2, item3);
Parameters:
Name Type Attributes Description
data * <repeatable>

Data items to add to the database

Returns:

Returns this instance for method chaining

Type
Database

findAll(optionsopt) → {Array}

Description:
  • Finds all models that match the specified criteria. Subclasses may add additional search parameters, but all models support searching by tags.

Source:
Inherited From:
Example
database.findAll({ tags: "weapon firearm" });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Description
tags string <optional>

Tag filter string

Returns:

Array of matching models

Type
Array

findOne(optionsopt) → {*}

Description:
  • Finds a random model that matches the specified criteria. Subclasses may add additional search parameters, but all models support searching by tags.

Source:
Inherited From:
Example
database.findOne({ tags: "weapon firearm" });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Description
tags string <optional>

Tag filter string

Returns:

A random matching model, or undefined if none found

Type
*