Damage progression

Hi,

I’m getting this weird issue. My damage progression progress by the Heallth levels, not the Damage levels.

Here is code for progression:

using System.Collections.Generic;
using UnityEngine;

namespace RPG.Stats
{
    [CreateAssetMenu(fileName = "Progression", menuName = "Stats/New Progression", order = 0)]
    public class Progression : ScriptableObject
    {
        [SerializeField] ProgressionCharacterClass[] characterClasses = null;

        Dictionary<CharacterClass, Dictionary<Stat, float[]>> lookupTable = null;

        public float GetStat(Stat stat, CharacterClass characterClass, int level)
        {
            BuildLookup();
            float[] levels = lookupTable[characterClass][stat];
            if (levels.Length < level) return 0;
            return levels[level - 1];
        }

        public int GetLevels(Stat stat, CharacterClass characterClass)
        {
            BuildLookup();
            float[] levels = lookupTable[characterClass][stat];
            return levels.Length;
        }   

        private void BuildLookup()
        {
            if (lookupTable != null) return;
            lookupTable = new Dictionary<CharacterClass, Dictionary<Stat, float[]>>();
            foreach (ProgressionCharacterClass progressionCharacterClass in characterClasses)
            {
                var statLookupTable = new Dictionary<Stat, float[]>();
                foreach (ProgressionStat progressionStat in progressionCharacterClass.stats)
                {
                   statLookupTable[progressionStat.stat] = progressionStat.levels;
                }
                lookupTable[progressionCharacterClass.characterClass] = statLookupTable;
            }
        }

        [System.Serializable]
        class ProgressionCharacterClass
        {
            [SerializeField] public CharacterClass characterClass;
            public ProgressionStat[] stats;
        }

        [System.Serializable]
        class ProgressionStat
        {
            public Stat stat;
            public float[] levels;
        }
    }
}

And code for Hit() in Fighter.cs

        void Hit()
        {
            if (target == null) return;
            float damage = GetComponent<BaseStats>().GetStat(Stat.Damage);
            if (currentWeapon.HasProjectile())
            {
                currentWeapon.LaunchProjectile(
                    rightHandTransform,
                    leftHandTransform,
                    target.GetComponent<Health>(),
                    gameObject,
                    damage);
            }
            else
            {
                target.GetComponent<Health>().TakeDamage(gameObject, damage);
            }
        }

I’ve tried to create new Progression SO and assigning it to base character prefab. Didn’t work.

These look right, so far. What I’m not seeing is BaseStats.GetStat… Paste in your BaseStats.cs and we’ll take a further look.

1 Like

I was looking everywhere but not there.

        public float GetStat(Stat stat)
        {
            return progression.GetStat(Stat.Health, characterClass, GetLevel());
        }

This is why i got Health Stat as a damage :stuck_out_tongue:

Solution

       public float GetStat(Stat stat)
        {
            return progression.GetStat(stat, characterClass, GetLevel());
        }

Case closed!

1 Like

I had a sneaking suspicion. Great job finding that!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms