Example #1
0
        /// <summary>Generates a method that adds this inventory to a shop that matches the defined conditions and adds it to <see cref="IDisplayEvents.MenuChanged"/>.</summary>
        /// <returns>Returns the method.</returns>
        public static EventHandler <MenuChangedEventArgs> addToShop(this InventoryItem inventory, Func <ShopMenu, bool> predicate)
        {
            EventHandler <MenuChangedEventArgs> d = delegate(object sender, MenuChangedEventArgs e)
            {
                ShopMenu    shop    = (ShopMenu)e.NewMenu;
                List <Item> forSale = shop.getForSale();
                Dictionary <Item, int[]> priceAndStock = shop.getItemPriceAndStock();
                forSale.AddOrReplace(inventory.item);
                priceAndStock.AddOrReplace(inventory.item, new int[] { inventory.price, inventory.stock });
            };

            d = d.addPredicate(e => predicate.Invoke(((ShopMenu)e.NewMenu)));

            return(Game1.activeClickableMenu.onActivation <ShopMenu>(d));
        }
Example #2
0
        /// <summary>Generates a method that adds this inventory to a shop that matches the defined conditions and adds it to <see cref="IDisplayEvents.MenuChanged"/>.</summary>
        /// <returns>Returns the method.</returns>
        public static EventHandler <MenuChangedEventArgs> addToShop(this List <InventoryItem> inventory, Func <ShopMenu, bool> predicate)
        {
            EventHandler <MenuChangedEventArgs> d = delegate(object sender, MenuChangedEventArgs e)
            {
                ShopMenu    shop    = (ShopMenu)e.NewMenu;
                List <Item> forSale = shop.getForSale();
                Dictionary <Item, int[]> priceAndStock = shop.getItemPriceAndStock();
                forSale       = forSale.Union(inventory.forSale()).ToList();
                priceAndStock = priceAndStock.Union(inventory.priceAndStock()).ToDictionary(dict => dict.Key, dict => dict.Value);
            };

            d = d.addPredicate(e => predicate.Invoke(((ShopMenu)e.NewMenu)));

            return(Game1.activeClickableMenu.onActivation <ShopMenu>(d));
        }