← Back to all addons

Shop Listing - Item Conditions (level,...)🧬

Posted by Mr.Titan on May 18, 2025 at 2:23 PM

GameplayExperimentalFeature3.0 Verified
πŸ’‘ 4

Like in skyrim, you don’t go to a shop and have the top rare weapons available until you reach a certain level. I wanted all the stores to have items that are good for all the levels, instead of having a store with only rare items and the old town with dirty old things.

So with this, you still need to set the items of the store BUT you can set the condition for it, including min level of listing for items.

WHY USE CONDITIONS INSTEAD OF A LEVEL PROPERTY? I wanted to allow the maximum possibility of evolution, so now you can set specific things like missions and stuff that are required for the item!

Import

First import the the new condition IsPlayerLevel.cs to “Conditional->Conditions”.

Changes

In Item.cs, add the following:

        [Header("Shop")]
        [SerializeField] private int m_price = 50; // i changed this from it's initial place, it just makes more sence
        [SerializeField] private ICondition m_shopListingCondition = new IsPlayerLevel();


        public ICondition shopListingCondition => m_shopListingCondition ;

In Shop.cs add:

public Item[] GetItems()
{
    if (items == null)
        return System.Array.Empty<Item>();

    int playerLevel = GameManager.Player.level;
    return System.Array.FindAll(items, item => item.shopListingCondition.Evaluate());
}

Change:

//public Item[] items = null;  //to:
[SerializeField] protected Item[] items = null;

Finally change in UIShop.cs the method FillSlots() to the following:

private void FillSlots() { 
    Item[] items = m_shop.GetItems();
    int itemCount = items.Length;
    m_slots = new UIShopEntry[itemCount];

    for (int i = 0; i < itemCount; ++i)
    {
        Item item = items[i];

        GameObject itemSlot = Instantiate(m_shopEntryPrefab, m_itemSlotsRoot.transform);
        UIShopEntry inventoryBagSlot = itemSlot.GetComponent<UIShopEntry>();

        if (inventoryBagSlot)
        {
            inventoryBagSlot.Initialize(item);
            m_slots[i] = inventoryBagSlot;
        }
    }
}

How to use?

Just go to your items and you should have a property to set the condition. By default i’ve set the level condition, and it’s set to 0, so you can just leave it be and it will not take any effect.

πŸ“œ Scripts

πŸ’¬ Comments (3)

Gyvr May 18, 2025 at 02:36 PM
That’s really cool! Good idea to reuse the condition system!!
Mr.Titan May 18, 2025 at 02:55 PM
I have to say, im in love with the conditions and commands, man! It’s just too powerfull
❀️ 1
Gyvr May 18, 2025 at 03:00 PM
Me too 😝 It’s super modular!

Want to continue the conversation?