What do you think of my approach with stats and leveling for the RPG?

Hi there everyone, I hope you guys are doing great. So I’m in the middle of the RPG course and I’m pretty excited about it. However, I would like a progression/leveling system slightly different than the one shown in the course, so I would love if could give me some feedback to see if it is a good idea I handle it like this. Here we go:

A) First off, I would like my stats to depend on attributes (like vitality, strength, etc) so here is what I did to achieve it:

  1. Created another enum for my attributes
 public enum Attribute
    {
        None,
        Vitality,
        Focus,
        Strength
    }
  1. Added serialized fields for the starting values of these attributes
        [SerializeField] int startingVitality = 1;
        [SerializeField] int startingFocus=1;
        [SerializeField] int startingStrength = 1;
  1. Built a dictionary with the values of the attributes
         Dictionary<Attribute, int> attributes = new Dictionary<Attribute, int>();

        private void Awake()
        {
            attributes[Attribute.Vitality] = startingVitality;
            attributes[Attribute.Focus] = startingFocus;
            attributes[Attribute.Strength] = startingStrength;
        }   
  1. My GetStat function looks like this now, so the enemies can still use their level to get the health. There is a new Serialized Field on the Health Component called healthAttribute, for the player it is set as Vitality and for the Enemies is set as None
public float GetStat(Stat stat, Attribute attr)
        {
            int attrValue = attr==Attribute.None ? startingLevel :  attributes[attr];
            return progression.GetStat(stat, characterClass, attrValue);
        }

B) The second major change I made was to the leveling system, I would like the player to choose an attribute, and then he/she can level up, similar to the Dark Souls Series. Here is what I did:

  1. Added a state variable for the current level in my Experience script (I intend to save this value along with the experience points)
private int currentLevel = 1;
  1. Created a function on the Experience component, given the input of the player and xp he or she has, this function will try to level up and increase the right attribute
public void TryToLevelUp(Attribute attr)
        {
            BaseStats baseStats = GetComponent<BaseStats>();
            float xpToLevelUp = baseStats.GetStat(Stat.ExperienceToLevelUp, Attribute.None);
            if (experiencePoints >= xpToLevelUp)
            {
                currentLevel++;
                baseStats.IncreaseAttribute(attr);
                experiencePoints = experiencePoints - xpToLevelUp;
            }
            else
            {
                Debug.Log("Not enough XP");
            }

        }
  1. For now just to test, I added an Update function, so the player can try to level up using the keyboard (keys 1, 2, and 3 )
private void Update()
        {
            //ONLY FOR TESTING

            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                TryToLevelUp(Attribute.Vitality);
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                TryToLevelUp(Attribute.Focus);
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                TryToLevelUp(Attribute.Strength);
            }
        }
  1. Finally, on the base stats I have a function that increases the selected attribute inside the dictionary (I am not really sure about keeping the attributes count here, since this class is called baseStats, but I really like the flexibility of the dictionary so I might move it to the Experience component)
public void IncreaseAttribute(Attribute attr)
        {
            attributes[attr]++;
        }

I hope I can get some feedback from you guys. I have tested these changes and they are all working OKish for now (except the part that you level up and since the max health goes up the percentage actually decreases, but that’s also happening to Sam so it doesn’t bother me that much yet) but I would like to know your opinions and thoughts about going this path and if you see any potential issues that I might face in the future let me know as well.

Thanks in advance and happy game development! :slight_smile:

It does look workable, though we’ll be introducing a better way to work these attributes in the final course Shops and Abilities.

The percentage decreases because while the health may be going up, the MAX health is also going up. Personally, I use the “levelling saved my bacon” approach, where gaining a level automatically restores all of your health to maxHealth.

1 Like

Privacy & Terms