Ejemplo n.º 1
0
 public InventoryItem Inventory(string name)
 {
     return(InventoryItems
            .FirstOrDefault(x =>
                            string.Equals(x.Name, name, StringComparison.CurrentCultureIgnoreCase) ||
                            string.Equals(x.Item.PluralizedName, name, StringComparison.CurrentCultureIgnoreCase)));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementação de <see cref="IInventory.Add(int, int)"/>
        /// </summary>
        public void Add(int uid, int amount)
        {
            var item = GameService.Items.FirstOrDefault(o => o.UniqueID == uid);

            // TODO: Pensar em uma forma melhor de lidar com esses casos
            if (item == null)
            {
                return;
            }

            if (item.GetAttributeValue <bool>(Attribute.STACKABLE))
            {
                var itemInventory = InventoryItems.FirstOrDefault(o => o.UniqueID == uid);

                if (itemInventory == null)
                {
                    item = AddAmount(item, amount);

                    if (item.GetAttributeValue <int>(Attribute.AMOUNT) == 0)
                    {
                        return;
                    }

                    InventoryItems.Add(item);
                    GameUI.RefreshInventory();
                    return;
                }

                var itemInventoryIndex = InventoryItems.IndexOf(itemInventory);
                InventoryItems[itemInventoryIndex] = AddAmount(itemInventory, amount);

                GameUI.RefreshInventory();
                return;
            }

            if (!CanPick(uid, amount))
            {
                return;
            }

            for (var i = 0; i < amount; i++)
            {
                if (!CanPick(uid, 1))
                {
                    continue;
                }

                var nonStack = AddAmount(item, 1);

                if (nonStack.GetAttributeValue <int>(Attribute.AMOUNT) == 0)
                {
                    continue;
                }

                InventoryItems.Add(nonStack);
            }

            GameUI.RefreshInventory();
        }
        public static void AddPastSale(int master, DateTime duedate, double pieces)
        {
            if (duedate.Year == DateTime.Today.Year && duedate.Month == DateTime.Today.Month)
            {
                return;                                                                               //discard current month data
            }
            ForecastItem item = ForecastItems.FirstOrDefault(i => master != -1 && i.MasterID == master);

            var inv        = InventoryItems.FirstOrDefault(x => x.MasterID == master);
            var masterItem =
                ProductMasterList.FirstOrDefault(x => x.MasterID == master);

            if (masterItem != null)
            {
                double units = pieces / masterItem.PiecesPerUnit;

                if (item != null) // if tracking item already
                {
                    item.AddSale(duedate, units);
                }
                else // add tracking
                {
                    double invUnits = 0;
                    if (inv != null)
                    {
                        invUnits = inv.Units;
                    }
                    else
                    {
                        //MessageBox.Show(String.Format("No inventory for id:{0} master {1}", master, masterItem));
                    }
                    item = new ForecastItem(invUnits, masterItem);
                    item.AddSale(duedate, units);
                    ForecastItems.Add(item);
                }
            }
        }