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

Methods

findAll(optionsopt) → {Array.<Item>}

Description:
  • Finds all items matching the specified criteria.

Source:
Overrides:
Example
itemDb.findAll({ tags: "weapon sword", minValue: 10, maxValue: 100 });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Default Description
name string <optional>

Name substring to match

tags string <optional>

Tag filter string

minValue number <optional>
0

Minimum item value

maxValue number <optional>
Number.MAX_VALUE

Maximum item value

minEnc number <optional>
0

Minimum encumbrance

maxEnc number <optional>
Number.MAX_VALUE

Maximum encumbrance

Returns:

Array of matching Item objects

Type
Array.<Item>

findOne(optionsopt) → {Item|null}

Description:
  • Finds a single random item matching the specified criteria, weighted by rarity (rare items are less likely to be selected).

Source:
Overrides:
Example
itemDb.findOne({ tags: "weapon", minValue: 5 });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Default Description
name string <optional>

Name substring to match

tags string <optional>

Tag filter string

minValue number <optional>
0

Minimum item value

maxValue number <optional>
Number.MAX_VALUE

Maximum item value

minEnc number <optional>
0

Minimum encumbrance

maxEnc number <optional>
Number.MAX_VALUE

Maximum encumbrance

Returns:

A random matching Item object, or null if none found

Type
Item | null

ItemDatabase

new ItemDatabase()

Description:
  • Creates a new ItemDatabase instance.

Source:

Methods

findAll(optionsopt) → {Array.<Item>}

Description:
  • Finds all items matching the specified criteria.

Source:
Overrides:
Example
itemDb.findAll({ tags: "weapon sword", minValue: 10, maxValue: 100 });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Default Description
name string <optional>

Name substring to match

tags string <optional>

Tag filter string

minValue number <optional>
0

Minimum item value

maxValue number <optional>
Number.MAX_VALUE

Maximum item value

minEnc number <optional>
0

Minimum encumbrance

maxEnc number <optional>
Number.MAX_VALUE

Maximum encumbrance

Returns:

Array of matching Item objects

Type
Array.<Item>

findOne(optionsopt) → {Item|null}

Description:
  • Finds a single random item matching the specified criteria, weighted by rarity (rare items are less likely to be selected).

Source:
Overrides:
Example
itemDb.findOne({ tags: "weapon", minValue: 5 });
Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Search criteria

Properties
Name Type Attributes Default Description
name string <optional>

Name substring to match

tags string <optional>

Tag filter string

minValue number <optional>
0

Minimum item value

maxValue number <optional>
Number.MAX_VALUE

Maximum item value

minEnc number <optional>
0

Minimum encumbrance

maxEnc number <optional>
Number.MAX_VALUE

Maximum encumbrance

Returns:

A random matching Item object, or null if none found

Type
Item | null