Good day, everyone!
I’m currently working on a Role-Playing combat system, and am trying to puzzle out the structure for said system. For example, one would have an Aim skill, and then subskills under that for things such as Pistol, Rifle and so on.
This thread is for my mucking about in code, but also for any suggestions folks might have as to how to implement or improve this system. My hope is to eventually create a framework that can be easily expanded upon to support additional sub/skills as it goes along, but I honestly have no idea how to get there. Yet ![]()
I don’t really understand inheritance that well, to be honest, so I am kind of operating without a rudder atm. IE, should I create a Subskill class that inherits from the Skill class, or perhaps just create each subskill as another instance of skill? Should I create and maintain a list of skills, and how would I go through that list to find a specific skill by name? IE, the third entry in a list is far less intuitive than being able to look up a specific skill or subskill by name. How might one link skills and subskills so that the system could find each of them in a reasonably easy-to-understand fashion?
Below is the current Skill class. It has been made serializable so that it will appear in the inspector.
[System.Serializable]
public class Skill {
public int skillLevel = 0;
public int usePoints = 0;
public int usePointsToAdvance = 1; // 1 point for 0-9 pts. 2 points for 10-19, and so on.
public void IncreaseUsePoints()
{
//Upon the successful use of a skill (hitting a target, for example), increase the use points,
//then evaluate the number of use points. If enough use points have been earned to advance the skill, do so.
usePoints++;
if (usePoints == usePointsToAdvance)
{
IncreaseSkill();
}
}
public void EvaluateUsePointsToAdvance()
{
//this allows each 10 skill level points to round down to the nearest integer (0-9 = 0, 10-19 = 1 and so on) and then adds 1.
//Used to determine how many use points must be earned to increase the skill value.
usePointsToAdvance = Mathf.FloorToInt((float)skillLevel * 0.1f) + 1;
}
public void IncreaseSkill()
{
//Increase the skill level, reset use points and determine how many
//use points will be required to advance the skill again.
skillLevel++;
usePoints = 0;
EvaluateUsePointsToAdvance();
}
}
So far, this works just fine. Here is where things get fun, interesting, scary, inefficient… whatever
I am trying to determine the best way to organize this data on a character summary sheet. Perhaps adding a string to the skill that determines the skill name? Or simply creating new fields for each one, as in this Test class. Perhaps, as above, one could implement a list of skills and subskills, but I have no idea how I would assign each subskill, as an example, to a parent skill. The test script inherits from MonoBehaviour for now so that I can drag it onto a game object:
public class Test : MonoBehaviour {
[Header("Character Attributes")]
//Strength, dexterity and so on will go here. Figure out skills first.
[Header("Character Skills")]
public Skill aim; //this is a parent skill and will influence all ranged attacks. Represents character's general aiming capability.
public Skill pistol; //this is a subskill, and is influenced by Aim skill when evaluating attacks using a pistol. May not exceed 1/2 of parent skill.
void Update()
{
///
/// This is testing code. Pressing N will generate random numbers for the aim skill.
/// Pressing spacebar increments the use points as though the skill was successfully performed.
///
if (Input.GetKeyDown(KeyCode.N))
{
aim.skillLevel = Generator.GenerateRandomNumber(0, 100);
aim.EvaluateUsePointsToAdvance();
}
if (Input.GetKeyDown(KeyCode.Space))
{
aim.IncreaseUsePoints();
}
}
}
I would welcome any thoughts folks might have in this regard. Right now, I’m kinda playing with a tool belt, but have only a basic idea of what a lot of things do
So my plan is to challenge the heck outta myself to learn different ways to organize, implement and go through this data. I simply have no idea what my options are, much less the drawbacks or benefits to each.