# How should I manage my data that needs to be associated with rank (Unity)

So I am making a game with a similar content progression to Clash Royale. Essentially u have ranking points (Identified as Trophies), and the number of trophies you have will determine what content you will have access to in the game. So for example every 100 ranking points, you will be able to find new types of cards in chests, new chests in general or new maps. In my game, I want it to be somewhat similar, but I also have some other data that changes based on rank points that is more specific to my game, such as army supply. I'm trying to figure out how I can implement this in a manageable way.

Maybe this is overkill, but this is my design so far:

Basically I have my RankContentItemBase class which has a ranking points int and an IsUnlocked method that returns whether or not the passed in rank is > than the rank passed in. Then I extend this with classes with classes that add the data type I wanna work with (Int, Troop, Map, w/e).

I then have a Generic base container class that has a method for getting all unlocked item in the list of T contents that is extended to contain the concrete RankUnlockItembase types.

I've basically structured things this way so it's easy for me to add new types of items that I want unlocked by rank without having to do much work. Also it prevents things from being coupled together.

Just curious what ppl think of this setup, and what kinda setup you would go with? One concern I have with this design was that if I wanted to see whether a troop was unlocked or not, I can't just say troop.IsUnlocked(). Instead I have to create a new means of determining whether or not a troop is unlocked yet, like for example maybe a method on the RankUnlockedTroopContainer that determines this. Maybe this is ok? I feel like I'm sacrificing simplicity for the sake of maintainability/flexibility.

Thanks

• It looks to me like you have a working solution here. Have you experienced any specific pain points with this solution that we can help you solve? If not, and the code is performing its task correctly as-is, and you just want open-ended feedback on your approach, the Code Review StackExchange would be a more appropriate place to ask instead. Jul 9, 2020 at 0:19
• @DMGregory Hi DMGregory, I probably would have posted in code review, however since my question was unity specific, I thought it wouldn't get much attention there. One concern I have with this design was that if I wanted to see whether a troop was unlocked or not, I can't just say troop.IsUnlocked(). Instead I have to create a new means of determining whether or not a troop is unlocked yet, like for example maybe a method on the RankUnlockedTroopContainer that determines this. Maybe this is ok? I feel like I'm sacrificing simplicity for the sake of maintainability/flexibility. Jul 9, 2020 at 1:09

You can easily enumerate that information at startup by going through all the ranks and determining the unlock-rank for each item. That information could be stored in RankUnlockedItemBase, or it could be stored in a lookup-table (Dictionary<RankUnlockedItemBase, int>).