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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

RPG item upgrading mechanics

Discussion in 'Game Design' started by lord_goldemort, Jul 26, 2020.

  1. lord_goldemort

    lord_goldemort

    Joined:
    Oct 5, 2017
    Posts:
    11
    Been working on an RPG for a while, and am now looking at the item upgrade mechanics. My original design was that Item A-I can be promoted to Item A-II by using accessory B. Which is fine as a simple mechanic. In pseudo-code

    Code (CSharp):
    1. virtual bool Upgrade(Item upgradeItem)
    2. {
    3.     if (_upgrades.Contains(upgradeItem.type)) {
    4.         LevelUp();
    5.         return true;
    6.     }
    7. }
    (The _upgrades fields is populated with item types (they're enums) in the inspector.) But I do want a bit more depth in there.

    So I have a container class, and although some weapons / accessories can be upgraded with a container, I also need to have the test for what the container contains. Clearly a container type for every possible content is silly. And I can do the check simply in code. But is there a better - more data-driven - way to check not just the type of the item, but some attribute of the item as well? It sounds like invoking a ton of reflection, or writing a meta-language to describe these things and I wonder if it's worth the effort?
     
  2. Peanut8

    Peanut8

    Joined:
    May 17, 2018
    Posts:
    10
    Ok I am not 100% Sure if I understand what you want to achive but I try to help you anyways :D.

    Couldn't you just use Scriptable Objects for your Items and specifies inside them what the Lvl up will change in the Item.
     
    lord_goldemort likes this.
  3. lord_goldemort

    lord_goldemort

    Joined:
    Oct 5, 2017
    Posts:
    11
    That's exactly what I have. I have an enum that describes each type of object in the game (yuk, I know this is generally bad practice, but...).

    upload_2020-7-27_17-1-54.png

    So there is an array of upgrade items and the level they become applicable at. They transform the item (in this case a piece of rail gun ammo) into another item. But notice that the Storage Bottle isn't enough in itself. The result of the upgrade will depend on what's in the bottle. Not all upgrades are like this though. Some just require an object on its own. In my code I do this sort of thing:

    Code (CSharp):
    1.         protected override void applyUpgradeInner(Item upgradeItem)
    2.         {
    3.             if (upgradeItem.SpecificType == InstanceType.StorageBottle) {
    4.                 var bottle = (StorageBottle)upgradeItem;
    5.                 if (bottle.Contents == ParticleType.Neutron) {
    6.                     // The only way to get neutronium is to have neutrons.
    7.                     Payload = RailGunPayload.Neutronium;
    8.                 }
    9.             }
    10.         }
    11.  
    but I'd ideally like this to be in the ScriptableObject inspector interface. So I'm looking for a relatively simple, elegant way of representing the upgrade system that minimises the amount of bespoke code I need to write. Does that make sense?

    Thanks for the help btw!