Ejemplo n.º 1
0
    public static void SetObtainItem(int id, int count = 1)
    {
        Item obtainItem = userItems.Find(item => item.id == id || item.id.Equals(id));

        if (obtainItem != null && obtainItem.itemtype != 0)
        {
            obtainItem.enable = true;
            obtainItem.count += count;
            ItemDatabase.ItemSave(id);
        }
        else
        {
            Item newItem = items.Find(item => item.id == id || item.id.Equals(id));
            if (newItem != null)
            {
                if (newItem.itemtype == 0)
                {
                    Item[] newItems = new Item[count];
                    for (var i = 0; i < count; i++)
                    {
                        Item newCopyItem = newItem.Clone() as Item;
                        newCopyItem.customId = Common.GetRandomItemId(userItems);
                        newCopyItem.enable   = true;
                        newCopyItem.count    = 1;
                        userItems.Add(newCopyItem);
                        newItems[i] = newCopyItem;
                    }
                    MissionSystem.AddClearPoint(MissionSystem.ClearType.CollectEquipment, count);
                    foreach (var item in userItems)
                    {
                        Debugging.Log(item.customId);
                    }
                    ItemDatabase.AddItemListSave(newItems);
                }
                else
                {
                    newItem.customId = Common.GetRandomItemId(userItems);
                    newItem.enable   = true;
                    newItem.count    = count;
                    userItems.Add(newItem);
                    Debugging.Log(newItem.customId);
                    ItemDatabase.AddItemSave(newItem);
                }
            }
        }
    }