コード例 #1
0
        public void InventorySwapItems_ToNonExistantSlot_False()
        {
            var  inventory = new Game.Inventory.Inventory();
            bool correctItemInContainer1 = false;
            bool correctItemInContainer2 = false;

            List <ContainerSettings> settingsList = new List <ContainerSettings>
            {
                new ContainerSettings {
                    Identifier = "1", Type = ContainerType.Storage, NumberOfSlots = 3
                },
                new ContainerSettings {
                    Identifier = "2", Type = ContainerType.Storage, NumberOfSlots = 3
                },
            };

            inventory.ContainerSettings = settingsList;
            inventory.Initialize();
            IItem item1 = new BaseItem {
                Name = "item1", UniqueId = "item1_Id", MaxStackSize = 10, CurrentStackSize = 1
            };
            IItem item2 = new BaseItem {
                Name = "item2", UniqueId = "item2_Id", MaxStackSize = 10, CurrentStackSize = 1
            };

            inventory.StoreItemAnywhere(ref item1, out var info1);
            inventory.StoreItem(ref item2, new SlotIdentifier("2", 0), out var info2);
            //inventory.DebugShowAllItems();

            var result = inventory.SwapItem(new SlotIdentifier("1", 0),
                                            new SlotIdentifier("2", 5), out var slotsInfo);

            //inventory.DebugShowAllItems();

            var info    = inventory.GetContainerInfo("1");
            var invSlot = info.InventorySlots[0];

            if (invSlot.SlotId.ContainerId == "1" && invSlot.SlotId.SlotIndex == 0 &&
                invSlot.HasItem && invSlot.Item.UniqueId == item1.UniqueId)
            {
                correctItemInContainer1 = true;
            }

            info    = inventory.GetContainerInfo("2");
            invSlot = info.InventorySlots[0];
            if (invSlot.HasItem && invSlot.Item.UniqueId == item2.UniqueId)
            {
                correctItemInContainer2 = true;
            }

            Assert.IsTrue(correctItemInContainer1 && correctItemInContainer2);
            Assert.IsFalse(result);
        }
コード例 #2
0
        public void UnEquipItem_FromInventory_True()
        {
            // Use the Assert class to test conditions.
            var  inventory        = new Game.Inventory.Inventory();
            bool isFilledInvSlot  = false;
            bool isEmptyEquipSlot = false;

            List <ContainerSettings> settingsList = new List <ContainerSettings>
            {
                new ContainerSettings {
                    Identifier = "1", Type = ContainerType.Storage, NumberOfSlots = 5
                },
                new ContainerSettings {
                    Identifier = "2", Type = ContainerType.Equiptment, NumberOfSlots = 5
                }
            };

            inventory.ContainerSettings = settingsList;
            inventory.Initialize();
            //inventory.DebugShowAllItems();

            IItem item1 = new BaseItem {
                Name = "item1", UniqueId = "item1_Id", MaxStackSize = 1, CurrentStackSize = 1
            };
            var isItemStored   = inventory.StoreItemAnywhere(ref item1, out var outInfo1);
            var isItemEquipped = inventory.EquipItem(new SlotIdentifier("1", 0),
                                                     new SlotIdentifier("2", 0), out var infoList);
            //inventory.DebugShowAllItems();
            var isItemUnequipped = inventory.UnEquipItem(new SlotIdentifier("2", 0), out var outInfo2);
            //inventory.DebugShowAllItems();

            var info    = inventory.GetContainerInfo("1");
            var invSlot = info.InventorySlots[0];

            if (invSlot.HasItem && invSlot.Item.UniqueId == item1.UniqueId)
            {
                isFilledInvSlot = true;
            }

            info    = inventory.GetContainerInfo("2");
            invSlot = info.InventorySlots[0];
            if (!invSlot.HasItem)
            {
                isEmptyEquipSlot = true;
            }

            Assert.IsTrue(isEmptyEquipSlot && isFilledInvSlot && isItemEquipped && isItemStored && isItemUnequipped);
        }
コード例 #3
0
        public void InventorySwapItems_DifferentContainer_EmptySlot_True()
        {
            var  inventory = new Game.Inventory.Inventory();
            bool correctItemInContainer1 = false;
            bool correctItemInContainer2 = false;

            List <ContainerSettings> settingsList = new List <ContainerSettings>
            {
                new ContainerSettings {
                    Identifier = "1", Type = ContainerType.Storage, NumberOfSlots = 5
                },
                new ContainerSettings {
                    Identifier = "2", Type = ContainerType.Storage, NumberOfSlots = 5
                },
            };

            inventory.ContainerSettings = settingsList;
            inventory.Initialize();
            IItem item1 = new BaseItem {
                Name = "item1", UniqueId = "item1_Id", MaxStackSize = 10, CurrentStackSize = 1
            };

            inventory.StoreItemAnywhere(ref item1, out var info1);
            //inventory.DebugShowAllItems();

            var result = inventory.SwapItem(new SlotIdentifier("1", 0),
                                            new SlotIdentifier("2", 0), out var slotsInfo);

            //inventory.DebugShowAllItems();

            var invSlot = slotsInfo[0];

            if (!invSlot.HasItem)
            {
                correctItemInContainer1 = true;
            }

            invSlot = slotsInfo[1];
            if (invSlot.HasItem && invSlot.Item.UniqueId == item1.UniqueId)
            {
                correctItemInContainer2 = true;
            }

            Assert.IsTrue(result && correctItemInContainer1 && correctItemInContainer2);
        }
コード例 #4
0
        public void Equip_UnEquipItem_MultipleTimes_True()
        {
            // Use the Assert class to test conditions.
            var  inventory        = new Game.Inventory.Inventory();
            bool isFilledInvSlot  = false;
            bool isEmptyEquipSlot = false;

            List <ContainerSettings> settingsList = new List <ContainerSettings>
            {
                new ContainerSettings {
                    Identifier = "1", Type = ContainerType.Storage, NumberOfSlots = 5
                },
                new ContainerSettings {
                    Identifier = "2", Type = ContainerType.Equiptment, NumberOfSlots = 5
                }
            };

            inventory.ContainerSettings = settingsList;
            inventory.Initialize();
            //inventory.DebugShowAllItems();

            IItem item1 = new BaseItem {
                Name = "item1", UniqueId = "item1_Id", MaxStackSize = 1, CurrentStackSize = 1
            };
            var isItemStored = inventory.StoreItemAnywhere(ref item1, out var outContainer);

            //inventory.DebugShowAllItems();

            int numOfTimes = 5;

            bool[] isItemEquippedArray   = new bool[numOfTimes];
            bool[] isItemUnequippedArray = new bool[numOfTimes];
            for (int i = 0; i < numOfTimes; i++)
            {
                isItemEquippedArray[i] = inventory.EquipItem(new SlotIdentifier("1", 0),
                                                             new SlotIdentifier("2", 0), out var infoList);
                isItemUnequippedArray[i] = inventory.UnEquipItem(new SlotIdentifier("2", 0), out var outContainer2);
            }

            //inventory.DebugShowAllItems();

            bool isItemEquipped = true;

            foreach (var boolToCheck in isItemEquippedArray)
            {
                if (!boolToCheck)
                {
                    isItemEquipped = false;
                }
            }

            bool isItemUnequipped = true;

            foreach (var boolToCheck in isItemUnequippedArray)
            {
                if (!boolToCheck)
                {
                    isItemUnequipped = false;
                }
            }


            var      containerInfo = inventory.GetContainerInfo("1");
            SlotInfo slotinfo      = containerInfo.InventorySlots[0];

            if (slotinfo.HasItem && slotinfo.Item.UniqueId == item1.UniqueId)
            {
                isFilledInvSlot = true;
            }

            containerInfo = inventory.GetContainerInfo("2");
            slotinfo      = containerInfo.InventorySlots[0];
            if (!slotinfo.HasItem)
            {
                isEmptyEquipSlot = true;
            }

            Assert.IsTrue(isEmptyEquipSlot && isFilledInvSlot && isItemUnequipped && isItemStored && isItemEquipped);
        }