Skills based system

Since CalculateLevel() is now outdated in your scheme, try changing CalculateLevel() to be merely

private int CalculateLevel()
{
   return GetComponent<SkillStore>().GetCombatLevel()+1;
}

Doing that makes everyone non-walkable, non-attackable and basically non-interactive… Just placing a new ‘CalculateLevel()’ function anywhere on this script does that. I did a little bit of tracking down, and here’s why:

In awake, this line relies on a ‘CalculateLevel()’ function:

currentLevel = new LazyValue<int>(CalculateLevel);

That was the point… to set the level to 1… I couldn’t possibly fathom why that would make everyone non-walkable, non-attackable, non-interactive…
Are you getting errors when the script runs?

It took me a few minutes to realize my errors weren’t showing up in my compiler… anyway, here is the endlessly repeating error:

NullReferenceException: Object reference not set to an instance of an object
RPG.Stats.BaseStats.CalculateLevel () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:137)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
GameDevTV.Utils.LazyValue`1[T].get_value () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:38)
RPG.Stats.BaseStats.GetLevel () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:104)
RPG.Stats.BaseStats.GetBaseStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:98)
RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:92)
RPG.Attributes.Health.GetInitialHealth () (at Assets/Project Backup/Scripts/Attributes/Health.cs:50)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
GameDevTV.Utils.LazyValue`1[T].get_value () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:38)
RPG.Attributes.Health.IsDead () (at Assets/Project Backup/Scripts/Attributes/Health.cs:82)
RPG.Control.AIController.Update () (at Assets/Project Backup/Scripts/Control/AIController.cs:113)

and this one (they seem similar, but they differ I believe… In the last line reference):

NullReferenceException: Object reference not set to an instance of an object
RPG.Stats.BaseStats.CalculateLevel () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:137)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
GameDevTV.Utils.LazyValue`1[T].get_value () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:38)
RPG.Stats.BaseStats.GetLevel () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:104)
RPG.Stats.BaseStats.GetBaseStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:98)
RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:92)
RPG.Attributes.Health.GetInitialHealth () (at Assets/Project Backup/Scripts/Attributes/Health.cs:50)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
GameDevTV.Utils.LazyValue`1[T].get_value () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:38)
RPG.Attributes.Health.IsDead () (at Assets/Project Backup/Scripts/Attributes/Health.cs:82)
RPG.Movement.Mover.Update () (at Assets/Project Backup/Scripts/Movement/Mover.cs:53)

Oh, that might be my fault…

private int CalculateLevel()
{
   return TryGetComponent(out SkillStore skillStore)? skillStore.GetCombatLevel() :  startingLevel;
}

now the player can’t move:

IndexOutOfRangeException: Index was outside the bounds of the array.
RPG.Stats.Progression.GetStat (RPG.Stats.Stat stat, RPG.Stats.CharacterClass characterClass, System.Int32 level) (at Assets/Project Backup/Scripts/Stats/Progression.cs:37)
RPG.Stats.BaseStats.GetBaseStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:98)
RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:92)
RPG.Attributes.Health.GetInitialHealth () (at Assets/Project Backup/Scripts/Attributes/Health.cs:50)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
GameDevTV.Utils.LazyValue`1[T].get_value () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:38)
RPG.Attributes.Health.IsDead () (at Assets/Project Backup/Scripts/Attributes/Health.cs:82)
RPG.Control.PlayerController.Update () (at Assets/Project Backup/Scripts/Control/PlayerController.cs:67)

(One of these lines checks for the Players’ death, and somehow returns it as true (the one before the last… I’m guessing it has to do with the combat level starting from zero?)

So add one to to the CombatLevel in the calculation… skillStore.CombatLevel()+1 : startingLevel

yup, he’s movable now… but the combat level issue still lives to another day…

And it may stay there at this rate (this is why I’m not keen on creating many more new “features”, we’re not getting anywhere)… What happens when you take the CombatSkill to level 2 (by levelling up 5 skills)?

They both increment again together…

I don’t think any new feature will ever be as complex as this system.

This…
is…
impossible…
The only place that currentLevel is set is in the Init() and within UpdateLevel(). You may be missing the Levelling up debug. Let’s add one that will stick out like a sore thumb…

Try this Debug.Log.

private void UpdateLevel()
        {
        
            // int newLevel = CalculateLevel();
            int newLevel = GetComponent<SkillStore>().GetCombatLevel() + 1;
            Debug.Log($"Current Level = {currentLevel.value}, new level = {newLevel}");
            if (newLevel > currentLevel.value) {
                Debug.LogError("LEVEL UP");
                currentLevel.value = newLevel;
                LevelUpEffect();
                onLevelUp();    // Action call (i.e: no function), with Health.RegenerateHealth() as a subscriber
                                // (this ensures that we regenerate partially (or all of) our health when we level up, by placing it in the place where it occurs when we level up!)

            }
        
        }

Less of the issue… more that it’s taking away from my ability to help the most students…

OK so I actually hacked my way through this and did something a little bit funny, but it worked…

In the ‘if’ statement, I added +1 to the ‘newLevel’, and at combat level 2, the level up effect worked… I’ll test this a little further to level 3 and see what happens. So my ‘UpdateLevel()’ now looks like this:

private void UpdateLevel()
        {
        
            int newLevel = CalculateLevel();
            // int newLevel = GetComponent<SkillStore>().GetCombatLevel(); // + 1;
            Debug.Log($"Current Level = {currentLevel.value}, new level = {newLevel}");
            if (newLevel + 1 > currentLevel.value) {

                currentLevel.value = newLevel;
                LevelUpEffect();
                onLevelUp();    // Action call (i.e: no function), with Health.RegenerateHealth() as a subscriber
                                // (this ensures that we regenerate partially (or all of) our health when we level up, by placing it in the place where it occurs when we level up!)

            }
        
        }

Should we just leave it as it is…?

Edit: Bad idea, bad idea… it levels the player up everytime he increases a skill… scrap that :sweat_smile:

No, because you won’t be changing currentLevel.value since you’re testing newLevel+1, but setting to newLevel…
In other words, the next time you gain experience, the level up effect would work again… and again and again…

OK so here’s what I just noticed… Somehow, it works, but it’s a “Late” work. In other words, the combat evolves to the next level ONLY AFTER YOU INCREASE ONE MORE OF THE COMBAT LEVELS, AFTER YOU ORIGINALLY GOT YOUR COMBAT LEVEL UPDATED (I’m not angry, just highlighting it xD)

So let’s say you just got a new combat level. For the Combat level rise effect to work, you have to gain another skill, and this can be any of defence, ranged, magic or attack, and only then will the effect work… It’s a weird glitch, but it exists

So… you level up 5 skills… and… nothing happens until you level up the 6th?

not really, I think the counter starts from the 4th skill until the last one before it resets, and then it resets from the 4th to the 0th skill and on and on…

You still have to evolve 5 levels, but you gotta finish one of them before the effect works, so it’s not synchronized with the combat level

That didn’t make as much sense as you might have thought…

Let’s walk through how the math should be working…
You level up the first skill
sum of skills = 1
1 / 5 = 0
You level up the 2nd skill
sum of skills = 2
2 / 5 = 0
3rd skill
sum of skills = 3
3 / 5 = 0
4th skill
sum of skills = 4
4 / 5 = 0
5th skill
sum of skills = 5
5 / 5 = 1

That’s when the Combat level increases

And on the next cycle…

That’s when the ‘onLevelUp()’ event works

Let’s rewrite SkillStore.GetCombatLevel()

public int GetCombatLevel() 
{
    int attack = GetSkillLevel(Skill.Attack);
    int defense = GetSkillLevel(Skill.Defense);
    int ranged = GetSkillLevel(Skill.Ranged);
    int magic = GetSkillLevel(Skill.Magic);
    int level =  (GetSkillLevel(Skill.Attack) + GetSkillLevel(Skill.Defense) + GetSkillLevel(Skill.Ranged) + GetSkillLevel(Skill.Magic) / 5;
    Debug.Log($"Calculating level A={attack}, D={defense}, R={ranged}, M={magic}, TTL={attack+defense+ranged+magic}, level = {level}");
    return level;
}

LOL, I just spotted it…

int level =  ((GetSkillLevel(Skill.Attack) + GetSkillLevel(Skill.Defense) + GetSkillLevel(Skill.Ranged) + GetSkillLevel(Skill.Magic) )/ 5;

I forgot the surrounding parenthesis, only Magic was getting divided by 5

Privacy & Terms