cards

Virtual card decks
CardDeck() constructor
CardDeck.prototype.toString()
CardDeck.createItemDeck( itemType, [expansions] ) static
CardDeck.createFromArray( arrayLikeObject ) static
CardDeck.prototype.shuffle()
CardDeck.prototype.draw()
CardDeck.prototype.drawFirst( matchFunction )
CardDeck.MATCH_TOME static
CardDeck.MATCH_MASK static
CardDeck.MATCH_MISSION static
CardDeck.MATCH_WEAPON static
CardDeck.prototype.discard( card, [copies] )
CardDeck.prototype.peek( [index] )
CardDeck.prototype.pull( [index] )
CardDeck.prototype.size()

Virtual card decks

Adds a CardDeck class that can be shuffled, drawn from, discarded to, and so forth. This can simulate existing card decks from the game or arbitrary deck-like collections of objects.

Although a CardDeck may hold any kind of object, the class provides special support for GameItem objects.

CardDeck() constructor

Create a new, empty deck of cards.

CardDeck.prototype.toString()

Returns a string consisting of a comma separated list of the cards in this card deck.

returns a string listing the contents of this CardDeck

CardDeck.createItemDeck( itemType, [expansions] ) static

Create a deck of cards that contains all of the cards in a standard item deck of the type specified by itemType, which must be one of the following values:

resources.GameData.ITEM_COMMON
resources.GameData.ITEM_UNIQUE
resources.GameData.ITEM_EXHIBIT
resources.GameData.ITEM_SPELL
resources.GameData.ITEM_ALLY
resources.GameData.ITEM_SKILL

The expansions variable controls which expansions are included using an array of boolean flags. If the flag value at a given index is true, then the cards from the expansion at the same index in resources.GameData.getExpansions() will be included in the deck. If expansions contains fewer entries than there are expansions, a value of false is assumed for all missing entries. If expansions is not defined, all expansions are included.

Example: Print an unshuffled common item deck for the base game with no expansions.

 println( CardDeck.createItemDeck( resources.GameData.ITEM_COMMON, [true] ) );
itemType the type of item deck to create
expansions an array of flags indicating the expansions to include

returns a CardDeck which includes the requested cards

CardDeck.createFromArray( arrayLikeObject ) static

Create a new deck, using items from an array to populate it.

arrayLikeObject an array or array-like object to copy from

returns a card deck consisting of objects copied from arrayLikeObject

CardDeck.prototype.shuffle()

Shuffle the cards in a deck into random order.

CardDeck.prototype.draw()

Draw the top card off the deck. This removes the card from the deck; to return the card, use CardDeck.discard. Drawing from an empty deck throws an exception.

removes and returns the top card from the deck

CardDeck.prototype.drawFirst( matchFunction )

Search the deck for the first card for which matchFunction(card) returns true. If a matching card is found, remove it from the deck and return it. If there is no matching card, return null.

matchFunction a function that takes a card and returns true if it is the type of card you wish to draw

returns the matching card (which is removed from the deck), or null

CardDeck.MATCH_TOME static

A match function that can be used with CardDeck.drawFirst to draw the first Tome in a deck of GameItems.

CardDeck.MATCH_MASK static

A match function that can be used with CardDeck.drawFirst to draw the first Mask in a deck of GameItems.

CardDeck.MATCH_MISSION static

A match function that can be used with CardDeck.drawFirst to draw the first Task or Mission in a deck of GameItems.

CardDeck.MATCH_WEAPON static

A match function that can be used with CardDeck.drawFirst to draw the first Weapon in a deck of GameItems.

CardDeck.prototype.discard( card, [copies] )

Adds card to the bottom of the deck. It is not required that card have previously been drawn from the deck. If copies is defined, then that many copies are added, all identical. The default value is 1.

card the card to add to the deck
copies the optional number of copies to add to the deck

places card(s) on the bottom of the deck

CardDeck.prototype.peek( [index] )

Return a card from the deck without removing it. If index is not defined, then the card at the top of the deck is returned. Otherwise, if index is 0 or positive, then the card at position index is returned, where a position of 0 is the top of the deck, 1 is the next card from the top, and so on. If index is negative, then the cards are counted from the bottom of the deck: -1 is the last card, -2 is the penultimate card, and so on.

index the position of the card to peek at within the deck

returns the card at index

CardDeck.prototype.pull( [index] )

Pull a card from the deck from any position. The card at the requested position is removed from the deck and returned. As with CardDeck.peek(), a negative index may be used to count from the bottom of the deck. If called without an index argument, this method is equivalent to CardDeck.draw().

index the optional position of the card to remove from the deck

returns and removes the card at index

CardDeck.prototype.size()

Returns the number of cards currently in this deck.

Index    Contents