Exemple #1
0
        /// <summary>
        /// Open a user dialog which allows th user navigate through the NPCs Inventory and take Items
        /// </summary>
        public void loot()
        {
            if (!this.inventory.ContainsAnyItems())
            {
                CIO.Print(this.name + "'s inventory is empty");
                return;
            }
            GenericOption takeAllOption  = new GenericOption("take all");
            Optionhandler oh             = new Optionhandler(this.name + "'s inventory ", true);
            Option        selectedOption = null;

            //the user stays inside the inventory until all items are gon or he picks exit
            while (selectedOption != Optionhandler.Exit && this.inventory.ContainsAnyItems())
            {
                List <Item> allitems = this.inventory.GetAllItems();
                oh.ClearOptions();
                oh.AddOptions(Optionhandler.ItemToOption(allitems));
                oh.AddOption(takeAllOption);
                selectedOption = oh.selectOption();
                if (selectedOption == takeAllOption)
                {
                    foreach (Item i in allitems)
                    {
                        Inventory.transferItem(this.inventory, Player.getInstance().inventory, i);
                    }
                }
                else
                {
                    Inventory.transferItem(this.inventory, Player.getInstance().inventory, (Item)selectedOption);
                }
            }
        }