Skills based system

This won’t get you there…
In fact, my original damagePerSkill.Keys.First would fail because you could start with one magic punch, and then do an equal amount of Melee and Ranged, and these would be the winner…

You’d have to have yet another tracking system

private List<Skill> damageOrder = new List<Skill>();

        private void AddDamage(Skill skill, float damage)
        {
            damageOrder.AddUnique(skill); //This will make a list in order from the first skill used to the last
            if (!damagePerSkill.ContainsKey(skill)) damagePerSkill[skill] = damage;
            else damagePerSkill[skill] += damage;
        }

       private Skill GetMostUsedSkill()
       {
            var pairs = damagePerSkill.OrderByDescending().ToList<>();
            if(pairs.Count==1) return pairs.Key;
            if(pairs[0]==pairs[1])
            {
                 for(int i=-;i<damageOrder;i++)
                 if(damageOrder[i] == pairs[0].Key) return pairs[0].Key);
                 if(damageOrder[i] == pairs[1].Key) return pairs[1].Key);
            }
            return pairs[0].Key; //It should never get here, but won't compile without it
       }

Here is where you gain experience from my error… :slight_smile:
The way to allocate proportion in a reward based on a proportion in effort is

ratio = effort/totalEffort;  (this will always be a value between 0 and 1, it's a percentage
reward = totalReward * ratio; (as Ratio is a percentage of the effort, award that percentage

Hence my error… That line should have read

 skillExperience.GainExperience(pair.Key, Mathf.RoundToInt(totalAward*relativeValue));

Now… when you add these numbers together, you are likely to be off anywhere from 1-3 points in total experience rewarded. This is because we’re rounding the numbers to the nearest integer. I wouldn’t be terribly concerned about this… in the beginning, it may look like a big deal, but when you get to the point where you’re dividing up 1000 experience for killing the big bad Jabberwock, a couple points in the total isn’t even slightly significant.

‘AddUnique’ returns an error…

Give me one second to try code this, there’s one more…

Why so it does… I’ve been working in C++ all day. (See, you just gained more experience from MY mistake). :stuck_out_tongue:
Try this:

if(damageOrder.IndexOf(skill)<0) damageOrder.Add(skill);

OK OK Fine lel… I’ll implement the system xD (I laughed so hard when I realized exactly what you just did to me…)

OK Serious note though… there’s a ton of errors. I’m not very familiar with dictionary context just yet, now is probably the worst time to test me on dictionaries… :sweat_smile: (can we please fix it, xD)

Not without knowing what the ton of errors are…

99.99999999% of them are syntax errors, here’s a picture:

There’s a missing “}” I couldn’t fit in the screenshot (this is a seriously fun way for you to convince students of your idea… (takes notes))

Where did you get ‘effort’ and ‘totalEffort’ from…?

And I’m guessing ‘reward’ is the ‘rewardXP’, right?

The first one, damageOrder.AddUnique(skill), I covered in a previous reply…

For the second… there is great value in typing out code in a compiler instead of on the fly in the editor. (See, more experience points for both of us) I know this one compiles because I just rewrote it in Rider, and corrected a silly issue with the floating point comparison (floats are almost -=never=- “equal”)

        private Skill GetMostDamagingSkill()
        {
            var pairs = damagePerSkill.OrderByDescending(s => s.Value).ToList();
            if (pairs.Count == 1) return pairs[0].Key;
            if (Math.Abs(pairs[0].Value - pairs[1].Value) < .01f)
            {
                for (int i = 0; i < damageOrder.Count; i++)
                {
                    if (damageOrder[i] == pairs[0].Key) return damageOrder[i];
                    if (damageOrder[i] == pairs[1].Key) return damageOrder[i];
                }
            }
            return pairs[0].Key;
        }

That is merely an example equation. You look to it, and replace your actual values into it.
The TL:DR is that once you get the percentage (ratio) of total damage done, you multiply that times the reward. By dividing, you are actually greatly multiplying the reward.

the math still isn’t mathing up… the result is still the same whacky errors. Can you please check my ‘AwardExperience()’ function for me:

private void AwardExperience(GameObject instigator, Skill skill, Skill otherSkill = Skill.Defence)
        {

            if (instigator.TryGetComponent(out SkillExperience skillExperience))
            {

                if (instigator.TryGetComponent(out Health otherHealth) && !otherHealth.IsDead())
                {

                    float totalReward = GetComponent<AIController>().GetXPReward();
                    float totalDamage = damagePerSkill.Values.Sum();

                    // float ratio = GetComponent<Fighter>().GetDamage()/totalDamage;
                    // float reward = totalReward * ratio;

                    foreach (var pair in damagePerSkill) {
                        float relativeValue = pair.Value / totalDamage;
                        skillExperience.GainExperience(pair.Key, 2*Mathf.RoundToInt(totalReward/relativeValue)/3);
                    }

                    // This line sends 2/3rd of the XP Reward to whichever skill is associated to the Players' weapon:
                    // skillExperience.GainExperience(skill, 2 * Mathf.RoundToInt(GetComponent<AIController>().GetXPReward() / 3));
                    // This line sends 1/3rd of the XP Reward to the defence XP, which is always 1/3rd of whatever the AI Reward XP is assigned to:
                    skillExperience.GainExperience(otherSkill, Mathf.RoundToInt(GetComponent<AIController>().GetXPReward() / 3));
                    // skillExperience.GainExperience(otherSkill, Mathf.RoundToInt(totalAward/3));

                }

            }

        }

You never changed this line… You’re dividing by relativeValue instead of Multiplying…

OK that actually worked… Boy oh boy do I have SO MUCH to go back and read now, all in ‘health.cs’… (+1 XP for me)

Anyway, I have a new topic (they’re two, similar to resource gathering, but polar opposites) for tomorrow coming soon :slight_smile: , let me just properly verbalize it. Thanks again Brian for tonight

Not done here yet, I’m still trying something out solo before this one :upside_down_face:

Making this a Talk, or it will keep showing up on the unsolved list clogging up all the other TA’s Inbox.

1 Like

Sure, no worries. I’ll tag you here again when we return to this topic :slightly_smiling_face:

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

Privacy & Terms