Different ways to load/select characters in a RPG game [closed]

I am brand new here, and have been designing a two player card game where from tens of thousands of cards each player selects up to 80 cards DECK, and then fights with those cards.

For reference Yu Gi Oh

There's a lot of data and a player can have up to 3 instances of a card to play and they select the cards they want before the game starts. How do I load this information when starting the game? Any suggestions on the different ways to do it during game initialization?

Like how this is done in RPG games like League of Legends.

• Let's take a step back: How do you store the information? Have you decided on that yet? When you didn't, I think that's your actual question. – Philipp Apr 22 '14 at 8:21
• Yes I have! Using database wont help because each card can ha what you call effect which can do anything anytime based on its precondition... I am making Java class for each type of card which have super classes in 3 different types Monster, Trap and Spell and each card used by player will be an object from that class – Pratyush Dhanuka Apr 22 '14 at 13:14
• So you are going to have 10.000 classes in your project, one for each card? – Philipp Apr 22 '14 at 13:18
• I have not completed for all cards, but yes I will have a class for each because apart from some points and naming details each card has an effect where the precondition and action part is mostly different for each and I need to code those action and precondition , till now i have done for some 40 cards and later I think I will be able to generalize some but the game is evolving so there has to be option for new cards with new type of effects – Pratyush Dhanuka Apr 22 '14 at 13:26
• That's really not a good idea. You will end up with a gigantic codebase which will be really hard to maintain and deploy. You will also have to update the server for every small change in a card. Did you consider using a scripting language to describe cards like described in this question? – Philipp Apr 22 '14 at 13:39

What kind of data are you storing? You should only save references to cards for your player, unless there are some random stats that may change (in that case you'll have to store those as well).

Since you didn't specify any language, I'm assuming C++. Similar techniques can be used in other languages as well, they'll just require some different syntax.

First of all, you'll need your cards identified by some unique ID. Since there might be unassigned IDs, I'll be using a std::map for now:

std::map<unsigned int, CardInformation> cardData;


This now allows me to access the card information for any specific card. For example, let's assume you'd like to retrieve the card data for ID 50123:

const CardInformation &myCard = cardData[50123];


As you can see, this is pretty straightforward. Now, as part of your player's dataset, you'll want some collection of cards - or more specific: card IDs.

You could use a std::vector for this, which is more than sufficient. However, this makes counting cards quite cumbersome. So instead, I'm using another std::map, which would then be part of the player data:

std::map<unsigned int, unsigned char> playerDeck; // own up to 255 copies of each card!


This now allows you to do some pretty neat and simple tricks.

How about giving the player one copy of card ID 1023?

playerDeck[1023]++;


Does the player have card ID 323 in his deck? (naïve approach; will slow down/fill your map over time)

const bool hasCard = playerDeck[323] > 0;


Does the player have card ID 323 in his deck? (better approach)

const bool hasCard = (playerDeck.find(323) != playerDeck.end());


How to let the player remove card ID 50 from the deck? (Note this won't remove empty entries)

playerDeck[50]--;


So, how to store the data in a game file or submit it for a networked game? Pretty easy: Just iterate over the std::map containing the deck and store/submit values if the value is not 0. Keep in mind that submitting your deck to the enemy might not be a good idea and subject to abuse (to see the enemy's/your deck).

When you have thousands of players where each player owns hundreds of copies of thousands of different cards, you are dealing with quite a lot of information. To manage all that information, you should store it in a database.

You could either use a good old SQL database, or when you feel a bit more experimental you could use one of the many different NoSQL databases. The question which one to pick is off-topic here, so I will not elaborate further.

But no matter which database you choose, you should load the users decks and the information about each individual card from the database before the match starts and then keep it in memory during the match. The reason for this is that accessing a database is very slow compared to reading the information from memory. For that reason you should avoid any unnecessary database access while the match is running.

Details about how to store and retrieve data from a database are database-specific and a lot too broad to explain here. I would recommend you to read a tutorial on the database of your choice and ask specific questions when you are unsure about details.

An exception from this could be the cards themself (which are different from card-instances. There is only one card "Orc Warrior" but thousands of instances of that card which are owned by different players). Most trading-card games have quite complex cards which might be hard to model in a relational database. There is also the difference that the cards are changed very rarely while the decks and players are data entities which change all the time. That means it might be better to describe each individual card with a file which includes its properties and scripts. The deck database would then only reference the names, while all of the card-data is read from these files.

• I think the question is more about "how to get the deck into memory" rather than "how to store the deck on my server", but in the end both issues are essentially the same, just on a different end. – Mario Apr 22 '14 at 8:30
• @Mario I don't. So let the OP clarify what exactly he needs. – Philipp Apr 22 '14 at 8:34
• And yes I want to know how to get it into a memory, one thought I have is to make 2 deck files for each player ( which will be saved every-time they change their deck) and load it during game start but is there any different approach to this problem ? – Pratyush Dhanuka Apr 22 '14 at 13:16
• @PratyushDhanuka I added a new paragraph. I would not recommend you to store decks as flatfiles, though. – Philipp Apr 22 '14 at 13:36