Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Spell System - turn based combat

Discussion in 'Game Design' started by Varjacic, Aug 12, 2019 at 2:10 PM.

  1. Varjacic

    Varjacic

    Joined:
    Dec 26, 2015
    Posts:
    2
    Hello everyone. For the last few days I've been trying to come up with a good way to implement spell system for my turn-based (grid) game. I recently found out about Scriptable Objects and they seem like a perfect tool for implementing this system. First I started with thinking about different types of spells and effects that I'd have in a game. So what I came up with is, buffs and debuffs (single and multi target, last through X turns), auras, direct damage spells (single target, aoe(multiple tiles)) with or without projectiles and on-hit effects. I believe SOs would be a good idea because they would make it easy(hopefully) to customize different spells just through inspector.

    I'm having a hard time with starting all of this. I have an idea but I feel like it's very inefficient and just a mess overall. Ok, so direct dmg spells seem like an easiest thing of the bunch, but for buff/debuffs, I think I should have an array of those in each Unit class so I can add them when they are cast and check at the start of turn if they should be removed or not. First thing that came to my mind is make a base abstract class for all spells.
    Code (CSharp):
    1. public abstract class SpellEffect : ScriptableObject {
    2.     public float cost;
    3.  
    4.     public abstract void Cast();
    5. }
    And then make a sub-class for each type.
    Code (CSharp):
    1. public  class StatusEffect : SpellEffect {
    2.  
    3.     public int numOfTurns;
    4.     public float modAmount;
    5.     public float modPerTurn;
    6.     public StatType statType;
    7.     public TargetType targType;
    8.  
    9.     public override void Cast() {
    10.     }
    11. }
    12. public class DirectDamage : SpellEffect {
    13.     public float damage;
    14.     public Projectile projectile;
    15.     public StatusEffect debuff;
    16.     public bool useProjectile = false;
    17.     public bool useDebuff = false;
    18.     public TargetType targType;
    19.  
    20.     public override void Cast() {
    21.     }
    22. }
    23.  
    24. public enum StatType {
    25.     critChance,
    26.     dodgeChance,
    27.     health,
    28.     armor,
    29.     attackDamage
    30. }
    31. public enum TargetType {
    32.     SELF,
    33.     TARGET,
    34.     AOE,
    35. }
    Something like that.
    I really don't know where or how to begin exactly. I would really appreciate some help and pointers.

    Thanks.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,056
    This seems like more of a code design problem than a game design one. You need to separate "how should I store the data?" from "what should the class hierarchy look like?" — these are two independent issues.

    For data storage, I generally prefer to use text files (in GRFON format, but that's just me). This allows me to do things like change the data while the game is running (assuming of course I have code that checks and reloads the files). Of course to some extent that can be done with ScriptableObjects too, as long as you're running within the editor.

    For the code design, yes, you'll probably want a base class, or at least an interface, for all your spells, and probably one for all your buffs/debuffs. For anything that has state (i.e. is not just an instant one-time effect), you'll also need to keep track of the state of the spell, probably separate from the code that defines the spell.

    But as this is the wrong forum to go into all that, I'm going to quit while I'm not too far behind. :)
     
    BIGTIMEMASTER likes this.
  3. Varjacic

    Varjacic

    Joined:
    Dec 26, 2015
    Posts:
    2
    Thanks. And yeah, I picked SOs since they can be easily modified on the fly while running the game.
    If this is the wrong forum, is there a way to ask mods to move this thread?