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?