예제 #1
0
        /// <summary>
        /// Implementation of the IInventoryManager interface
        /// </summary>
        /// <param name="inventory">Input inventory list</param>
        /// <returns>Processed inventory list</returns>
        public IList <Item> ProcessInventory(IList <Item> inventory)
        {
            var processedInventory = new List <Item>();

            foreach (var item in inventory)
            {
                MerchandiseType type = MerchandiseType.Normal;

                // Lookup in map to see if item has a specified category.
                if (!MerchandiseTypeMap.TryGetValue(item.Name, out type))
                {
                    // Unless specified in the map, apply the following assumptions
                    if (item.Name.StartsWith("Conjured"))
                    {
                        type = MerchandiseType.Conjured;
                    }
                    else if (item.Name.StartsWith("Backstage passes"))
                    {
                        type = MerchandiseType.EventPass;
                    }
                    else
                    {
                        type = MerchandiseType.Normal;
                    }
                }
                Merchandise merchandise = null;
                switch (type)
                {
                case MerchandiseType.AgedWell:
                    merchandise = new AgedWellItem(item);
                    break;

                case MerchandiseType.Conjured:
                    merchandise = new ConjuredItem(item);
                    break;

                case MerchandiseType.EventPass:
                    merchandise = new EventPassItem(item);
                    break;

                case MerchandiseType.Legendary:
                    merchandise = new LegendaryItem(item);
                    break;

                default:
                case MerchandiseType.Normal:
                    merchandise = new NormalItem(item);
                    break;
                }
                merchandise.UpdateQuality();
                processedInventory.Add(merchandise);
            }
            return(processedInventory);
        }
예제 #2
0
        public static void UpdateQuality(this Item item)
        {
            switch (item.GetType().Name)
            {
            case "NormalItem":     //case nameof(NormalItem)
                NormalItem normalItem = item as NormalItem;
                normalItem.UpdateQuality();
                break;

            case "SpecialItem":     //case nameof(SpecialItem):
                SpecialItem specialItem = item as SpecialItem;
                specialItem.UpdateQuality();
                break;
            }
        }
예제 #3
0
        public static IList <Item> UpdateQuality(IList <Item> items)
        {
            foreach (var item in items)
            {
                UpdateableItem internalItem;
                switch (item.Name)
                {
                case BackstagePasses:
                    internalItem = new BackstagePasses()
                    {
                        Name = item.Name, Quality = item.Quality, SellIn = item.SellIn
                    };
                    break;

                case Sulfuras:
                    internalItem = new Sulfuras()
                    {
                        Name = item.Name, Quality = item.Quality, SellIn = item.SellIn
                    };
                    break;

                case AgedBrie:
                    internalItem = new AgedBrie()
                    {
                        Name = item.Name, Quality = item.Quality, SellIn = item.SellIn
                    };
                    break;

                default:
                    internalItem = new NormalItem()
                    {
                        Name = item.Name, Quality = item.Quality, SellIn = item.SellIn
                    };
                    break;
                }

                internalItem.UpdateQuality();

                item.Name    = internalItem.Name;
                item.Quality = internalItem.Quality;
                item.SellIn  = internalItem.SellIn;
            }

            return(items);
        }