Non stackable reward items being stacked in inventory

Hey,

If a number of non stackable items are handed out as rewards, they are stacked in the inventory. I would question WHY you would do this, but I guess it should still be fixed.

I did this in the GiveReward method:

        private void GiveReward(Quest quest)
        {
            foreach (var reward in quest.GetRewards())
            {
                if (!reward.item.IsStackable() && reward.number > 1)
                {
                    for (int i = 0; i < reward.number; i++)
                    {
                        ProcessReward(reward.item, 1);
                    }
                }
                else
                {
                    ProcessReward(reward.item, reward.number);
                }
            }
        }

        private void ProcessReward(InventoryItem reward, int number)
        {
            bool success = GetComponent<Inventory>().AddToFirstEmptySlot(reward, number);
            if (!success)
            {
                GetComponent<ItemDropper>().DropItem(reward, number);
            }
        }

Is there a more elegant way?

1 Like

No, that looks like a fairly straightforward solution.

Thanks, Brian.

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

Privacy & Terms