Skills based system

I’ve had that for a while lel… the issue still persists for now… (Can’t believe we are both wasting an entire day getting a stupid number to show up properly…)

Show me a Debug that says TTL = 5 level = 0 … Because… once the parenthesis surround the entire equation, the sum of the skills / 5 should read 5 level = 1

There you go:

Calculating level A=1, D=1, R=2, M=1, TTL=5, level = 1
UnityEngine.Debug:Log (object)
RPG.Skills.SkillStore:GetCombatLevel () (at Assets/Project Backup/Scripts/Stats/Skills/SkillStore.cs:120)
RPG.Stats.CombatLevelDisplay:Update () (at Assets/Project Backup/Scripts/Stats/CombatLevelDisplay.cs:28)

Woop sorry, wrong debug earlier (and the Debug.LogError() works btw)

4 / 5 = 0
I thought I made it sorta clear… the first condition

is far too difficult, especially in the case of an OR… I’m not going to help on that one. I went with the 2nd condition, which is a total of 5 levels in any combination because that was achievable.

I want the second condition as well, for now, as it’s a much more interesting choice. Anyway, I went and played around with the sequence of code of ‘UpdateLevel()’, and placed the combat update under the ‘onLevelUp’, so now the entire system levels up only when the number left to next level = 4, not 5… anyway we can solve this?

I’m not exactly sure where I messed up to be frank

Edit: Don’t ask me how, don’t ask me why, but everything works well when the game is exported outside of Unity for some reason… The only issue I have left is that my combat level, prior to levelling up anything, is literally set to zero until we get an extra level, but this one doesn’t bother me that much tbh (it’s easily overtaken down the line)… Even the death glitch is gone outside of Unity…

Ok, just when I thought it would be too complicated, I worked it out (third look is the charm)…

        private int GetCombatLevelBasedOnLowestSkill()
        {
            int level = int.MaxValue;
            level = Mathf.Min(level, GetSkillLevel(Skill.Melee));
            level = Mathf.Min(level, GetSkillLevel(Skill.Defense));
            level = Mathf.Min(level, GetSkillLevel(Skill.Ranged));
            level = Mathf.Min(level, GetSkillLevel(Skill.Magic));
            return level;
        }

        private int GetCombatLevelBasedOnRuleOfFive()
        {
            return (GetSkillLevel(Skill.Melee) + GetSkillLevel(Skill.Defense) + GetSkillLevel(Skill.Ranged) + GetSkillLevel(Skill.Magic)) / 5;
        }

        public int GetCombatLevel()
        {
            return Mathf.Max(GetCombatLevelBasedOnLowestSkill(), GetCombatLevelBasedOnRuleOfFive());
        }
    }

And with that… I’m stepping away from this topic for a while.

Ahh… this one made it worse. It was working well before that, alls good though, for now it runs well outside of Unity. Whenever you’re ready next, we can try the progression system (I am certain it exists for defence for now, but I want to connect each individual progression to a skill, so I’ll probably have a list of progressions instead…)

A) I need a break from writing new systems for a bit…
B) A Progression already contains everything you need. You can do this.

Extremely fair. Thanks again for everything you did with me today :slight_smile: (I’ll give the progression a solo test run first, and I won’t ask any questions about this until tomorrow… as a little challenge for me xD)

to keep it simple, I managed to solve my problem with the weapon progression. Here is what I did:

  1. Go to fighter.cs, and create a new ‘GetDamage()’ function:
public int GetDamage() {

        if (currentWeaponConfig.GetSkill() == Skill.Attack) {
            // return (GetComponent<BaseStats>().GetStat(Stat.Attack) + GetComponent<WeaponConfig>().GetDamage()) * (1 + GetComponent<WeaponConfig>().GetPercentageBonus());
            return (int) (GetComponent<BaseStats>().GetStat(Stat.Attack) + (currentWeaponConfig.GetDamage() * (1 + currentWeaponConfig.GetPercentageBonus()/100)));
        }
        else if (currentWeaponConfig.GetSkill() == Skill.Ranged) {
                return (int) (GetComponent<BaseStats>().GetStat(Stat.Ranged) + (currentWeaponConfig.GetDamage() * (1 + currentWeaponConfig.GetPercentageBonus()/100)));
        }
        else return (int) (GetComponent<BaseStats>().GetStat(Stat.Magic) + (currentWeaponConfig.GetDamage() * (1 + currentWeaponConfig.GetPercentageBonus()/100)));
        }

The only thing I’m suspicious of here, is the mathematical formulas. They should be fine, right? They seem fine to me, but I want to double check

  1. Use that in ‘Fighter.Hit()’:
float damage = GetDamage();
  1. I reversed and brought back the ‘CalculateLevel()’ function, but under a new name, known as ‘CalculateNPCLevel()’, and I used that to calculate the NPCs’ Initial level, in ‘Awake()’ and we Started it up in ‘Start()’:
// Declaring the 'currentNPCLevel' variable
LazyValue<int> currentNPCLevel;

private void Awake() {
// some code here...
currentNPCLevel = new LazyValue<int>(CalculateNPCLevel);
// more code here...
}

public void Start() {
// some code here...
currentNPCLevel.ForceInit();
// more code here...
}

private int CalculateNPCLevel() {

            Experience experience = GetComponent<Experience>();
            if (experience == null) return startingLevel;

            float currentXP = experience.GetPoints();
            int penultimateLevel = progression.GetLevels(Stat.ExperienceToLevelUp, characterClass);

            for (int level = 0; level <= penultimateLevel; level++) {

                float XPToLevelUp = progression.GetStat(Stat.ExperienceToLevelUp, characterClass, level);

                if (XPToLevelUp > currentXP) return level;

            }

            return penultimateLevel + 1;

        }
  1. In ‘Stats.cs’, I added 3 new inputs to the Enum:
public enum Stat {

        Health,
        ExperienceReward,
        ExperienceToLevelUp,
        Damage,
        Mana,
        ManaRegenRate,
        TotalTraitPoints,
        BuyingDiscountPercentage,
        Defence,
        // Addon tests (SUCCESS)
        Attack,
        Ranged,
        Magic

The progression system now works. All it does is get the damage done by the player (I turned off the damage randomizer to be able to ensure it works), based on the associated skill attached to the weapon, and then add whatever the weapon has in store for the player on top of it, in terms of damage and bonuses (and I think that’s all I did).

Whenever you’re ready, here’s what I want to implement next:

  • A Defence variable, similar to ‘Weapon damage’ in “WeaponConfig.cs”, to manipulate the amount of protection a piece of armor can do, on top of the basic defence the player does for himself (in ‘Progression’), when his defence level grows
  • A button that, when clicked/turned on, allows the player to train Defence, instead of whatever Skill his current weapon holds, and if it is clicked to turn it off, it returns to whatever associated skill the player has, on the weapon in his hands

These are all I want to implement for my defence system, after we are clear off the ‘Progression’ system though :slight_smile:

At some point you are going to have to start understanding the code and doing things yourself. We can’t write your whole game for you. @Brian_Trotter is here to help students with problems they have with the RPG courses and he has gone way beyond his brief to help you with this. But he’s not here to write your game for you.

I get that you are excited and want to create this amazing RPG - and that’s a good thing - but from where I’m standing you are in way over your head, and it comes at the cost of other students not getting the attention they deserve. I don’t want to discourage you from making your game, I just need you to understand that.

You may have noticed that in a lot of cases both Brian and myself have started giving you less code, and just nudged you in the right direction. This is because we need you to start doing this yourself. But you need to understand what the code does in order to know how to change it.

Brian is extremely patient and I know he will continue to help you, but you have to start taking responsibility for your game.

1 Like

I just need the nudge to the right direction, that’s it. I’ll give the coding an attempt on my own and seek help from there on :slight_smile: - if I can’t solve it, I’ll ask (I won’t take any of you guys’ generously amazing help for granted any longer than that, I simply got a little lost down the line)

Anyway, I’ll be gone for a few days soon (I’m preparing for an exam soon as we speak). I think I asked for way too much recently, and I truly truly appreciate every single time the both of you took time out of your day to help me out, and I understand that’s not a good thing from my side. I apologize to the both of you for this mess :slight_smile:

There’s no rule on formulas… I don’t see anything wrong with them, but what’s important is if those formulas keep the game in balance or bring it out of balance.

Are your NPCs gaining experience and levelling? Usually, we just use startingLevel.

Defense is well covered in Shops and Abilities. You can add Stat.Defense as armor’s modifiers, and use a Stat.Defense stat in the Progression. You literally just demonstrated you can handle this.

I can’t even unwrap what you’re asking there.

I wasn’t referring to going to bed and waking up… I have a new course to review, a rewrite of the saving system that I’ve completely set aside due to lack of time, and a January full release of Spellborne Hunter that is off track. I need to focus on direct course questions for a bit.

Basically I wanted a button that switches from training whatever associated skill the weapon has, to set that skill to defence now (so now you’re training defence), and if that button gets clicked again, it switches back to whatever associated skill the weapon had on it… I’m already trying to work on this, but it’s a little hard. If that fails, I’ll just take 33% of the XP Reward and send it to defence, and 66% goes to the associated skill, and that’ll be the only way to train defence now (EDIT: I went with the 33%-66% split… I’m getting the XP, and for now it seems to be adding up the Defence levels, I’ll add it to the progression next)

OK I’ll just keep this simple. If I get stuck or need help, I’ll ask the question. Whenever you have spare time to help me (after the main course questions by students are cleared up), and you’re available, then yes we can work it through. I’m not asking you to prioritize me over everyone else (I’m not a modal :stuck_out_tongue_winking_eye: ), but please don’t forget me either :sweat_smile: - I’ll stick to one problem at a time, no more overloads :slight_smile: (and I’ll make sure I tried everything I can possibly try before asking anymore questions from now on. Thanks again for being patient with me by the way)

For this one, fortunately for the both of us, the answer is no. None of the enemies has any ‘Experience.cs’ script on them, so the ‘CalculateNPCLevel()’ returns very early with just the ‘startingLevel’, hence we can use that to safely calculate the NPC level, without worrying about them gaining experience, because they don’t have an ‘Experience.cs’ script on them to match the initial experience check

I’m trying this next

OK Umm… this one is a little off-topic, but it has something to do with the progression. I want to double check what happened so I don’t end up messing my own code up by mistake

For god knows what reason, this error started showing up out of thin air (in other words, I probably messed something up, but I can’t remember what it was):

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.CalculateNPCLevel () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:156)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Project Backup/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
RPG.Stats.BaseStats.Start () (at Assets/Project Backup/Scripts/Stats/BaseStats.cs:44)

I went to ‘Progression.GetStat()’ and changed the last return code line, in the absolute end, from this:

return levels[level - 1];

to this:

return levels[level]

And that seemed to fix the problem, but it also happened to select the second value off the arrays under ‘Progression’… What exactly happened here? (Believe me I tried reading the code and understanding it on my own, but I can’t wrap my head around it)

If it helps in anyway, my combat level starts from level zero, and needs one combat stat to get it to level 1 at the start of the game itself. I’m not sure why this happens, I probably messed up something (but it doesn’t bother me this much, neither does the problem affect my gameplay in anyway I know of (so far), but I get an error and want to investigate it :slight_smile: ), and I’m guessing that’s the source of the error

The level in this statement is the index of the levels array. You need the -1 because indexes always start at zero. That’s why without the -1, you started at 2nd level. An index of 1 will return the 2nd value in the array. I have no idea where the out of range exception is coming from. Take a look at your BaseStats.cs. That seems a likely place to look.

Doing a little bit more of tracing back, I realized the problem occurs in this line in ‘BaseStats.CalculateLevel()’ (CalculateNPCLevel() in my script). Like you said, “BaseStats.cs” seemed like a good starting point, because it’s the only suspicious script in this stack trace, and this was the only line that calls ‘Progression.GetStat()’, which fires off the error:

float XPToLevelUp = progression.GetStat(Stat.ExperienceToLevelUp, characterClass, level);

After a little more investigation, and considering that I don’t use this formula anymore, I concluded that this is an error for a system I no longer use, and my enemies don’t get this far in my code anyway, so I think it’s safe to ignore this problem overall (unless the game refuses to build because of it, or Brian has a different opinion…)

I would suggest commenting it out for now. That way you won’t get the error message and it will be easy to undo later if need be.

This was part of why I wrote a different CalculateLevel() method to begin with, because you’re not using XP (despite the original name of the topic).

so it’s safe to ignore this issue then I presume… it’s not bothering anyone

Privacy & Terms