Exemple #1
0
    public static List <ItemWithAmount> Drop(IEnumerable <DropItemInfo> DropItems)
    {
        List <ItemWithAmount> lootItems         = new List <ItemWithAmount>();
        Dictionary <string, ItemWithAmount> map = new Dictionary <string, ItemWithAmount>();

        foreach (DropItemInfo di in DropItems)
        {
            if (ZetanUtility.Probability(di.DropRate))
            {
                if (!di.OnlyDropForQuest || QuestManager.Instance.HasOngoingQuest(di.BindedQuest.ID))
                {
                    if (di.item.StackAble)
                    {
                        if (map.TryGetValue(di.ItemID, out var find))
                        {
                            find.amount += Random.Range(di.MinAmount, di.MaxAmount + 1);
                        }
                        else
                        {
                            var iaw = new ItemWithAmount(di.item.CreateData(), Random.Range(di.MinAmount, di.MaxAmount + 1));
                            map.Add(di.ItemID, iaw);
                            lootItems.Add(iaw);
                        }
                    }
                    else
                    {
                        lootItems.Add(new ItemWithAmount(di.item.CreateData(), Random.Range(di.MinAmount, di.MaxAmount + 1)));
                    }
                }
            }
        }
        return(lootItems);
    }
Exemple #2
0
 public bool PeekGet(IEnumerable <ItemInfoBase> infos, out InventoryError errorType, params ItemWithAmount[] simulLoseItems)
 {
     if (infos == null)
     {
         errorType = InventoryError.Invalid;
         return(false);
     }
     return(PeekGet(ItemWithAmount.Convert(infos), out errorType, simulLoseItems));
 }
 public RecipeIO(BaseFlowNode parent, ItemWithAmount myItem)
 {
     Parent = parent;
     MyItem = myItem;
     Parent.PropertyChanged += (sender, arg) =>
     {
         if (arg.PropertyName == nameof(Recipe.Speed))
         {
             OnPropertyChanged(nameof(Rate));
         }
         if (arg.PropertyName == nameof(Recipe.BaseSpeed))
         {
             OnPropertyChanged(nameof(BaseRate));
         }
     };
 }
Exemple #4
0
    /// <summary>
    /// 按原型放入道具
    /// </summary>
    /// <param name="model">道具原型</param>
    /// <param name="amount">数量</param>
    /// <param name="simulLoseItems">同时失去的道具</param>
    public void Get(ItemBase model, int amount, params ItemWithAmount[] simulLoseItems)
    {
        if (customGetAction != null && customGetAction(new ItemData(model, false), amount))
        {
            return;
        }

        if (!model || amount < 1)
        {
            return;
        }
        WeightCost += model.Weight * amount;
        if (simulLoseItems != null && simulLoseItems.Length > 0)
        {
            Lose(simulLoseItems);
        }
        ItemData item      = null;
        int      oldAmount = 0;

        if (keyedSlots.TryGetValue(model.ID, out var find))
        {
            ItemWithAmount iwa = null;
            foreach (var slot in find)
            {
                oldAmount += slot.amount;
                if (!item)
                {
                    item = slot.item;
                    if (item)
                    {
                        items.TryGetValue(item.ID, out iwa);
                    }
                }
                int take = slot.Put(amount);
                if (iwa)
                {
                    iwa.amount += take;
                }
                amount -= take;
            }
        }
        else
        {
            find = new List <ItemSlotData>();
            keyedSlots.Add(model.ID, find);
        }
        CostEmptySlot(find);
        OnItemAmountChanged?.Invoke(model, oldAmount, oldAmount + amount);

        void CostEmptySlot(List <ItemSlotData> collection)
        {
            if (amount <= 0 || collection == null)
            {
                return;
            }
            if (model.StackAble && item == null)
            {
                item = model.CreateData();                                 //如果物品可叠加但没有在背包中找到,则这个是新物品
            }
            ItemSlotData temp;

            for (int i = 0; i < amount / model.StackNum; i++)
            {
                temp = PutIntoEmptySlot(model.StackAble ? item : model.CreateData(), model.StackNum);
                if (temp)
                {
                    collection.Add(temp);
                }
            }
            if (model.StackAble)
            {
                temp = PutIntoEmptySlot(item, amount % model.StackNum);
                if (temp)
                {
                    collection.Add(temp);
                }
            }
        }
    }
Exemple #5
0
    public List <ItemWithAmount> GetMaterialsFromInventory(IEnumerable <MaterialInfo> targetMaterials)
    {
        if (!Inventory || targetMaterials == null)
        {
            return(null);
        }

        List <ItemWithAmount> items      = new List <ItemWithAmount>();
        HashSet <string>      itemsToken = new HashSet <string>();

        if (targetMaterials.Count() < 1)
        {
            return(items);
        }

        var materialEnum = targetMaterials.GetEnumerator();

        while (materialEnum.MoveNext())
        {
            if (materialEnum.Current.MakingType == MakingType.SingleItem)
            {
                if (materialEnum.Current.Item.StackAble)
                {
                    if (Inventory.TryGetData(materialEnum.Current.Item, out var item, out var amount))
                    {
                        int need       = materialEnum.Current.Amount;
                        int takeAmount = 0;
                        if (itemsToken.Contains(item.ID))//被选取过了
                        {
                            var find = items.Find(x => x.source == item);
                            int left = amount - find.amount;
                            left       = left > need ? need : left;
                            takeAmount = left;
                        }
                        else
                        {
                            takeAmount = amount > need ? need : amount;
                        }
                        TakeItem(item, takeAmount);
                    }
                }
                else
                {
                    int need = materialEnum.Current.Amount;
                    Inventory.TryGetDatas(materialEnum.Current.Item, out var finds);
                    foreach (var find in finds)
                    {
                        if (need > 0)
                        {
                            if (!itemsToken.Contains(find.source.ID))
                            {
                                TakeItem(find.source, 1);
                                need--;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                Inventory.TryGetDatas(x => x.Model_old.MaterialType == materialEnum.Current.MaterialType, out var finds);
                if (finds.Count > 0)
                {
                    int need = materialEnum.Current.Amount;
                    foreach (var find in finds)
                    {
                        int takeAmount = 0;
                        int leftAmount = find.amount;
                        if (itemsToken.Contains(find.source.ID))
                        {
                            if (!find.source.Model_old.StackAble)
                            {
                                continue;                                  //不可叠加且选取过了,则跳过选取
                            }
                            else
                            {
                                ItemWithAmount find2 = items.Find(x => x.source == find);
                                leftAmount = find.amount - find2.amount;
                            }
                        }
                        if (leftAmount < need)
                        {
                            takeAmount = leftAmount;
                            need      -= takeAmount;
                        }
                        else
                        {
                            takeAmount = need;
                            need       = 0;
                        }
                        TakeItem(find.source, takeAmount);
                    }
                }
            }
        }
        return(items);

        void TakeItem(ItemData item, int amount)
        {
            if (itemsToken.Contains(item.ID))
            {
                if (item.Model_old.StackAble)
                {
                    var find = items.Find(x => x.source == item);
                    find.amount += amount;
                }
            }
            else
            {
                items.Add(new ItemWithAmount(item, amount));
                itemsToken.Add(item.ID);
            }
        }
    }