Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Runescape-like trainable skills, enums or something else?

Discussion in 'Scripting' started by Zefrus, Aug 30, 2022.

  1. Zefrus

    Zefrus

    Joined:
    Dec 3, 2019
    Posts:
    14
    Hey all - I just have a structure / organization question. I'm working on a very basic RPG auto battler that has trainable skills like the game Runescape. E.g., Attack, Mining, Fishing, etc. Each skill can be trained individually and needs to have an experience integer to track the players progress. Image you choose a skill to train, an enemy spawns that provides XP in that skill if defeated, rinse and repeat.

    Currently I have a list of enums that designate the skills, and I'm keeping a separate list of int's to track experience.

    E.g.,

    public enum Skill
    {
    Attack,
    Mining,
    Hitpoints
    }


    public int miningExperience;
    public int attackExperience;

    public int miningLevel;
    public int attackLevel;

    etc. etc.

    I'm using the enums to select which skill to train, then updating the experience int in a separate script. This feels inefficient because the skill enums and experience ints are separate are not really tied to each other.

    If I'm only having a dozen or so skills, I don't want to overengineer some complex yet scalable system. Should I be approaching the tracking of skills differently or does anyone think the route I'm taking is fine?

    Thanks
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,895
    Look at this thread: https://forum.unity.com/threads/enum-inventory.1323954/

    Long story short, denote the skill types with a scriptable object. You could define your skills as serialisable classes, and have a collection of these. Need to modify a skill? Run down the collection and find the one with the type you're looking for.

    You can also define information about the types in these scriptable objects as well.

    Remember, enums are an anti-pattern. C# is an object oriented programming language. Be sure to leverage that.
     
    Kurt-Dekker and Zefrus like this.
  3. Zefrus

    Zefrus

    Joined:
    Dec 3, 2019
    Posts:
    14
    Thank you :) This is exactly the type of feedback I was looking for. Much appreciated!