CCG cards abilities - script perspective

Hi,
Working on my project and playing Hearthstone I was wondering, how to nicely organise my work. I found 3 questions to be discussed over:

  1. Overall mechanics flow - every character/card works on their own, or literally everything is happening in game manager and what we see is only a visual represantation?
  2. Special events, like “when a character dies, […]” for all characters in-game. How to achieve such an effect?
  3. How to even make cards properly? Is making a prefab for each one card is a good idea? Also does making a script for each one card even makes sense? Normally, I make general prefab, only changing the textures and scripts on object, but in game where every card has so many different uses, I find it hard to manage.

Discussion, suggestions or referencing some sources for data would be appreciated.

Thanks!

Though I haven’t played Hearthstone specifically, I’m going to assume it works like most computerized card games I’ve played (e.g. Dominion), which is to say, it’s fully turn-based and very precise in the way those turns are played. This is a major pain to accomplish if every card is running independently. I’d say that (aside from animation/effects maybe) your card class probably shouldn’t have an Update function at all - its functions would be 100% called by the game manager, not by the engine.

C#'s events and delegates are awesome. Learn them, use them, love them. Your game manager would have a “OnCharacterDies” event, and cards with relevant effects would register themselves with that event.

This is a harder question to answer, because it can go any way really. If you aren’t 100% confident of what you’d be doing otherwise, I’d say that one prefab per card is a reasonable way to go. Put these prefabs in a Resources folder and you can easily get lists of available cards and load them. Expansions and such could be done via AssetBundles, when you get to that point.

One script per card would be a bad idea, though. I assume that many cards will have functionality that differs only slightly (e.g. deal 2 damage vs. deal 3 damage), and any such cards should use the same script.

Better yet, if you structure your scripts correctly, you could probably make a single Card script. Try this: Have an array of CardAction objects in your Card script representing the sequence of actions that that card executes. CardAction would be an abstract class or an interface which you would inherit for each kind of action a card could take (DealDamageAction, DrawCardsAction, etc). You could then attach multiple other CardAction-derived scripts to your prefab (maybe on different GameObjects as children, if that helps organization) that contain the functions that your card executes.

3 Likes