Skip to content

Collection, Decks and Packs

One Collection Settings asset (Create > TCG Kit > Collection Settings) describes the game around the matches:

  • Game: the Game Definition.
  • Starter Decks: each is added to a new player’s decks, and its cards to their collection.
  • Currencies: what players earn and spend, each with a Starting Amount.
  • Own Everything: gives a new player every collectible card. Handy while building a game.
  • Packs: the packs on sale in the shop.
  • Reward Currency, Reward For Win and Reward For Loss: paid after matches against the computer.
  • Profile File Name: the save file’s name inside Application.persistentDataPath.

Assign it to the MatchBootstrap’s Collection to have players use their chosen deck and earn rewards, and to the deck builder and shop screens.

A Rarity has a colour, shown on cards with a rarity mark, and an optional Max Copies In Deck that overrides the game’s normal limit.

A Pack has a Currency, a Price, and Slots. Each slot gives Count cards, each of a rarity picked by weight: with Common 75 and Rare 25, three cards in four from that slot are common. A slot of only Rare, Epic and Legendary guarantees a rare or better. Card Pool limits which cards the pack can contain; leave it empty for every collectible card. Rarities with no cards in the pool are skipped, so a pack is never short.

  • DeckBuilderScreen: the player’s decks and collection. Click a card in the collection to add it to the deck being edited and a line of the deck to take one out. Problems are listed under the deck in plain words, and only a legal deck can be chosen for play.
  • PackShopScreen: buy packs and watch the cards turn over.

Both derive from ProfileScreen, which loads the profile when the screen starts and saves it after every change. Screens in different scenes always agree because they share the save file, not static state.

Profiles are saved as JSON by JsonFileProfileStore. It writes to a temporary file and then moves it into place, so a crash mid-save cannot corrupt the save. A file that cannot be read is kept as .corrupt and the player starts afresh.

The save file is on the player’s device and is trusted: a player who edits it can give themselves cards. For anything that matters, keep profiles on a server: implement IProfileStore and override CollectionSettings.CreateStore.

All of the collection’s rules go through one class, CollectionService: what may be added to a deck, buying packs, and paying rewards. Subclass it and override CollectionSettings.CreateService to change any of them: crafting, discounts, daily rewards. Its Opener decides what comes out of packs (IPackOpener) and its Validator checks decks (DeckValidator).