Bag

Bag

Represents a container that holds items with quantities. Provides functionality for adding, removing, and querying items with support for value and encumbrance calculations. It also provides the facility to label the bag since many representations in the game are just collections of items for particular simulations.

Constructor

new Bag(dataopt)

Description:
  • Creates a new Bag instance.

Source:
Parameters:
Name Type Attributes Default Description
data Object <optional>
{}

Configuration data for the bag

Properties
Name Type Attributes Default Description
entries Array <optional>

Array of bag entries with item and count properties

uncountable boolean <optional>
false

true if the items are not counted in the bag (counts are ignored), false if they are counted individually

tags Array.<String> <optional>

Array of tags to categorize this bag

name String <optional>

a label for the bag

description String <optional>

details about the bag

Extends

Members

tags

Description:
  • An array of string tags that characterize this item.

Source:
Overrides:
Properties:
Name Type Description
tags Set

An array of string tags that characterize this item.

Methods

add(item, countopt) → {Number}

Description:
  • Adds items to the bag. If the item already exists, increases the count.

Source:
Parameters:
Name Type Attributes Default Description
item Item

The item to add

count Number <optional>
1

The number of items to add

Throws:

If no item is provided, count is negative, or item is null

Type
Error
Returns:

The new total count of this item in the bag

Type
Number

addBag(bag)

Description:
  • Adds all items from another bag to this bag.

Source:
Parameters:
Name Type Description
bag Bag

The bag whose items to add

asJSON() → {String}

Description:
  • Converts the model to JSON, converting sets to arrays.

Source:
Overrides:
Returns:

JSON

Type
String

count(itemopt) → {Number}

Description:
  • Counts the total number of items in the bag.

Source:
Parameters:
Name Type Attributes Description
item Item <optional>

Optional specific item to count

Returns:

The total count of items

Type
Number

enc(itemopt) → {Number}

Description:
  • Calculates the total encumbrance of items in the bag.

Source:
Parameters:
Name Type Attributes Description
item Item <optional>

Optional specific item to calculate encumbrance for

Returns:

The total encumbrance

Type
Number

find(name) → {Object|null}

Description:
  • Finds an entry by item name or tag.

Source:
Parameters:
Name Type Description
name String

The name or tag to search for

Returns:

The matching entry or null if not found

Type
Object | null

has(tag) → {Boolean}

Description:
  • Does this model have the given tag?

Source:
Overrides:
Parameters:
Name Type Description
tag String
Returns:

true if it does, false otherwise

Type
Boolean

is(tag) → {Boolean}

Description:
  • Does this model have the given tag?

Source:
Overrides:
Parameters:
Name Type Description
tag String
Returns:

true if it does, false otherwise

Type
Boolean

not(tag) → {Boolean}

Description:
  • Does this model not have the given tag?

Source:
Overrides:
Parameters:
Name Type Description
tag String
Returns:

true if it does not have the tag, false otherwise

Type
Boolean

remove(item, countopt) → {Number}

Description:
  • Removes items from the bag. If count reaches zero, removes the entry entirely.

Source:
Parameters:
Name Type Attributes Default Description
item Item

The item to remove

count Number <optional>
1

The number of items to remove

Throws:

If count is negative, item not in bag, or trying to remove more than available

Type
Error
Returns:

The new total count of this item in the bag

Type
Number

removeBag(bag)

Description:
  • Removes all items from another bag from this bag.

Source:
Parameters:
Name Type Description
bag Bag

The bag whose items to remove

toString() → {String}

Description:
  • Converts the bag contents to a human-readable string with proper pluralization.

Source:
Returns:

Human-readable description of bag contents

Type
String

totalEnc() → {Number}

Description:
  • Calculates the total encumbrance of all items in the bag.

Source:
Returns:

The total encumbrance of all items

Type
Number

totalValue() → {Number}

Description:
  • Calculates the total value of all items in the bag.

Source:
Returns:

The total value of all items

Type
Number

typeOf(prefix) → {String}

Description:
  • Given a prefix like ammo or media, will return the specific tag for this item, such as ammo:22 or media:35mm.

Source:
Overrides:
Parameters:
Name Type Description
prefix String

the prefix to match

Returns:

the first tag found that matches this prefix

Type
String

value(itemopt) → {Number}

Description:
  • Calculates the total value of items in the bag.

Source:
Parameters:
Name Type Attributes Description
item Item <optional>

Optional specific item to calculate value for

Returns:

The total value

Type
Number