コード例 #1
0
        private void UpdateQuantities()
        {
            //  Initialize all quantities back to zero
            foreach (Object Placeholder in PlaceholderItems)
            {
                Placeholder.Stack = 0;
            }

            //  Set quantities of the placeholder items to match the corresponding amount of the item currently stored in the bag
            foreach (Object Item in Bag.Contents)
            {
                Object Placeholder = PlaceholderItems.FirstOrDefault(x => ItemBag.AreItemsEquivalent(x, Item, false, true));
                if (Placeholder != null)
                {
                    ItemBag.ForceSetQuantity(Placeholder, Item.Stack);
                }
            }
        }
コード例 #2
0
        public void UpdateQuantities()
        {
            foreach (Object Item in ItemPlaceholders.Values)
            {
                Item.Stack = 0;
            }

            foreach (Object BagItem in Bag.Contents)
            {
                //  Find all placeholders requiring this item Id/Quality
                List <KeyValuePair <BundleItem, Object> > Placeholders = ItemPlaceholders.Where(x => ItemBag.AreItemsEquivalent(x.Value, BagItem, false))
                                                                         .OrderByDescending(x => x.Key.IsRequired).ToList();

                //  Distribute the Stack of this item to the placeholders, up to each placeholder's required quantity.
                //  EX: Suppose you have 10 Parsnips in the bag, and Task#1 requires 3 Parsnip, Task#2 Requires 12 Parsnip.
                //  Put 3/10 in Task#1, then 7/10 in Task#2. Thus Task#1 is now fulfilled, and Task#2 is at 7/12.
                int RemainingQuantity = BagItem.Stack;
                int CurrentIndex      = 0;
                while (RemainingQuantity > 0 && CurrentIndex < Placeholders.Count)
                {
                    int    RequiredQuantity = Placeholders[CurrentIndex].Key.Quantity;
                    Object Placeholder      = Placeholders[CurrentIndex].Value;

                    int Quantity = Math.Max(0, Math.Min(RemainingQuantity, RequiredQuantity));
                    Placeholder.Stack  = Quantity;
                    RemainingQuantity -= Quantity;

                    if (Quantity > 0 && BagItem.Category == Object.artisanGoodsCategory)
                    {
                        Placeholder.Price = BagItem.Price;
                    }

                    CurrentIndex++;
                }
            }
        }