Trying to organize skill functions.

I’m still somewhat green on the subjects of polymorphism, interfaces, etc.
What I’m trying to accomplish is an RPG skill system within a somewhat complex damage and statistics system in where different types of damage and resistances and things are being watched/calculated.

—Basically I’m trying to get a skill to perform a function.

As in the long run there will be hundreds of skills, passive, weapon, class, etc. I was going to put them into a SkillDatabase.cs as I’ve done with WeaponDatabase, etc. using:

public static Weapon shortSword = new Weapon(dmg, speed, etc);

however I was unable to figure a way to go that route if the Skill base class contains virtual functions, for example with:

public virtual void onUse ();

I can’t then go:

public static Skill Strike = new Skill(onUse {yada yada}, etc); (right?)

So in looking for alternatives I started reading about interfaces and so changed Skill into ISkill with only { get; } for the values and gave up on the database idea, instead thinking of a script for each skill. The first test skill as follows:

public class MeleeSkillStrike : ISkill {
	public string _name {
		get { return "Strike"; }
	}
	public Classes.currentClass _classRequired {
		get { return  Classes.currentClass.Squire; }
	}
	public int _levelRequired {
		get { return 1; }
	}
	public int _currentLevel {
		get { return _currentLevel; }
		set { _currentLevel = value; }
	}
	public skillCategory _category {
		get { return skillCategory.Class; }
	}
	public skillType _type {
		get { return skillType.Offense; }
	}
	public bool _passive {
		get { return false; }
	}
	
	public void OnEffect () {
		int newDmg;
		if (Mathf.RoundToInt(PlayerData.damage() * 1.1f) == PlayerData.damage()) newDmg = PlayerData.damage() + 1;
		else newDmg = Mathf.RoundToInt(PlayerData.damage() * 1.1f);
		PlayerData.player.GetComponent<PlayerScript>().target.GetComponent<MobAi>().TakeDamage(newDmg, PlayerData.damageType());
	}
	
	public void OffEffect () {
        //used for timed buffs, etc.
	}
}

which is fine and works… but at this point the only thing the interface is really doing is throwing errors for me if I leave any of the data out or input it incorrectly… not really what an interfaces main intention is I think, and really I might as well not implement at all and just hard code each skill if that’s going to be the case…

can anyone think of a “why don’t you just…” that I’m just not aware of?

To make things easier I suppose I can still make my database and just have it return the skill after hardcoding links into the database but… just seems like there should be an easier way to organize them I’m not getting… or is making a horde of scripts in neatly ordered folders totally acceptable?

thanks for any input.

Interfaces are good because it means later you can write SomeFunction(ISkill skill) type logic that can accept any skill type.

You’re probably going to see benefit in using an abstract base class at the same time, since you can provide default values there via virtuals.

I’m not sure what you’re trying to do with the constructor. It looks to me like perhaps ISkill should have an event OnUseCallback that the parent subscribes to after instantiation.