Пример #1
0
        public void RemoveComputerItem(ListItem item, int number)
        {
            if (interestedList.HasSelection)
            {
                TradingListItem tradingItem = (TradingListItem)item;

                //Check if the requested number exceeds the amount in the inventory
                number = (tradingItem.Quantity >= number) ? number : tradingItem.Quantity;
                tradingItem.Quantity -= number;

                //If the inventory has run out of items, remove it from the list
                if (tradingItem.Quantity <= 0)
                {
                    interestedList.RemoveItem(item);
                }

                //Check if the offered items list has the item, if it does update, otherwise add it
                TradingListItem offeredItem;
                if (!hasItem(availableItemsList, tradingItem, out offeredItem))
                {
                    offeredItem = new TradingListItem(tradingItem.Item, 0);
                    availableItemsList.AddItem(offeredItem);
                }
                offeredItem.Quantity += number;

                //Update displays
                updatePrices();
                tradingItem.UpdateDisplayInformation();
                offeredItem.UpdateDisplayInformation();
                updateScreenInformation();

                InterfaceManager.DrawStep();
            }
        }
Пример #2
0
        private bool hasItem(ScrollingList list, TradingListItem item, out TradingListItem offeredItem)
        {
            for (int i = 0; i < list.Items.Count; i++)
            {
                if ((list.Items[i] as TradingListItem).Item == item.Item)
                {
                    offeredItem = (TradingListItem)list.Items[i];
                    return(true);
                }
            }

            offeredItem = null;
            return(false);
        }