Hi, I’m working on a collectable card game in Unity. The long-term (3 year+) goal is to have AI’s to practice against with popular deck types, and to have the playing of the game streamline by having the rather complex rules automatically enforced. In practice, I’m not sure of the best design.
My instinctive design is to create a BaseCard class with the properties and logic shared between all cards, then have a few children of that class that are CardArchetypes (MonsterCard, MagicCard, ItemCard), then have each individual Card inheriting from its appropriate archetype. Each individual card will likely contain its own Effect(s).
The first problem is, there are thousands of cards. If I make a class for each card, is there any performance overhead to worry about with that number of classes (especially if they contain virtual functions)? I think I remember that in C++ you get a vtable call for every function, which is usually fine unless you really need it inline’d or have a ton of virtual function calls from many classes that can cause cache misses on the vtable lookup; the good news is I’d only ever have about 100 (two decks’ worth) objects instantiated from these classes so I wouldn’t expect any problems beyond the small size increase from the scripts, which is nothing in comparison to the graphics resources. I just want to see if there are any concerns or good ideas before I dive into it.
If it makes a difference, all the basic card data [id, name, attack, defense, etc.] is stored in an sqlite database that is accessible in the game (I;m using it for the Deck Builder to be able to sort through the thousands of cards quickly and easily). If I weren’t going to automate card functions, I could get away with just that, but each card needs its own logic to do that–for example a card determining if the conditions for placing it are met.
Thanks for reading and for any advice!