Jump to content
  • Advertisement
Lamentation

C# Spell System - turn based combat

Recommended Posts

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.

public abstract class SpellEffect : ScriptableObject {
    public string spellName;
    public string description;
    public Sprite icon;
    public float cost;

    public abstract void Cast();
}

And then make a sub-class for each type.

public  class StatusEffect : SpellEffect {
    public int numOfTurns;
    public float modAmount;
    public float modPerTurn;
    public StatType statType;
    public TargetType targType;
    
    public override void Cast() {
    }
}
public class DirectDamage : SpellEffect {
    public float damage;
    public Projectile projectile;
    public StatusEffect debuff;
    public bool useProjectile = false;
    public bool useDebuff = false;
    public TargetType targType;

    public override void Cast() {
    }
}

Something like that. I really don't know where or how to begin exactly. I would really appreciate some help and pointers.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

What we did for our action system in a medival farming game was to have a class per action. Those classes were registered in our ScriptableObject-Asset as some kind of database. The actions were derived from a generic interface that determined a few functions

  • Check: Test if this action can be done right now
  • Do: Activate this action
  • State: Gets the state of an action (initial, initializing, doing, done)

And we didn't care about what type an action is because everything was handled by the action and the manager keeping an eye onto

Share this post


Link to post
Share on other sites
20 minutes ago, Shaarigan said:

What we did for our action system in a medival farming game was to have a class per action. Those classes were registered in our ScriptableObject-Asset as some kind of database. The actions were derived from a generic interface that determined a few functions

  • Check: Test if this action can be done right now
  • Do: Activate this action
  • State: Gets the state of an action (initial, initializing, doing, done)

And we didn't care about what type an action is because everything was handled by the action and the manager keeping an eye onto

Thanks, but not really sure how that helps me. Do you mean like I have it up there, generic spell class with activate(Cast()) function?

Share this post


Link to post
Share on other sites

As you're not sure where to move to, try to make something minimal that works (within those limits), then expand. In that way, you get experience and understanding. From there, it is less complicated to understand how your current solution should work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!