Beispiel #1
0
        public IEnumerator CraftItem()
        {
            var inv  = new Dummy_Inventory(2);
            var item = new Item("Test", 4);

            inv.AddItem(item, 4);
            inv.AddItem(item, 4);
            var owner        = new Test_InventoryOwner(inv, 10);
            var craftResult  = new Item("TestC", 1);
            var itemCrafting = new ItemCrafting(new List <Item>()
            {
                craftResult
            }, new List <CraftingRecipe>()
            {
                new CraftingRecipe(new List <Item>()
                {
                    item
                }, new List <int>()
                {
                    8
                })
            });
            var crafting = new Crafting(new List <ItemCrafting>()
            {
                itemCrafting
            });

            crafting.Craft(owner, 0);

            Assert.AreEqual(craftResult, inv.GetItem(0));
            Assert.AreEqual(1, inv.GetItem(0).count);
            Assert.AreEqual(Item.Empty, inv.GetItem(1));

            yield return(null);
        }
Beispiel #2
0
        private static void AddItems(ItemCrafting itemCraft, IInventoryOwner owner)
        {
            var inventories = owner.GetInventories();
            var result      = itemCraft.GetItems();

            for (int inv = 0; inv < inventories.Count; inv++)
            {
                for (int i = 0; i < result.Count; i++)
                {
                    if (inventories[inv].HaveSpaceForItem(result[i]))
                    {
                        inventories[inv].AddItem(result[i], result[i].count);
                    }
                }
            }
        }
Beispiel #3
0
        public IEnumerator CanNotCraftItem()
        {
            var inv   = new Dummy_Inventory(2);
            var item  = new Item("Test", 4);
            var item2 = new Item("Test2", 4);

            inv.AddItem(item2, 1);
            inv.AddItem(item, 1);
            var owner        = new Test_InventoryOwner(inv, 10);
            var craftResult  = new Item("TestC", 1);
            var itemCrafting = new ItemCrafting(new List <Item>()
            {
                craftResult
            }, new List <CraftingRecipe>()
            {
                new CraftingRecipe(new List <Item>()
                {
                    item
                }, new List <int>()
                {
                    4
                }), new CraftingRecipe(new List <Item>()
                {
                    item2
                }, new List <int>()
                {
                    4
                })
            });
            var crafting = new Crafting(new List <ItemCrafting>()
            {
                itemCrafting
            });

            Assert.AreEqual(false, crafting.CanCraft(owner, 0));

            yield return(null);
        }