public void ItemCatalogue_GetRandomItem()
        {
            String itemStr1 = "ID:1,Name:TestItem,Amount:1,Description:test item 1,ActiveEffect,PassiveEffect,Requirements,Icon:test.png";
            String itemStr2 = "ID:2,Name:TestItem,Amount:1,Description:test item 2,"
                              + "ActiveEffect:" + ActiveEffect.TAG + ":" + PlayerCharacter.HEALTH + ":" + "10"
                              + ":" + ActiveEffect.TAG + ":" + PlayerCharacter.THIRST + ":" + "10"
                              + ",PassiveEffect:" + PassiveEffect.TAG + ":" + PlayerCharacter.HEALTH + ":" + "0.8"
                              + ",Requirements:2,Icon:test.png";
            String itemStr3 = "ID:3,Name:TestItem,Amount:1,Description:test item 3,"
                              + "ActiveEffect:" + ActiveEffect.TAG + ":" + PlayerCharacter.HEALTH + ":" + "10"
                              + ":" + ActiveEffect.TAG + ":" + PlayerCharacter.THIRST + ":" + "10"
                              + ",PassiveEffect:" + PassiveEffect.TAG + ":" + PlayerCharacter.HEALTH + ":" + "0.8"
                              + ":" + PassiveEffect.TAG + ":" + PlayerCharacter.SANITY + ":" + "0.9"
                              + ":" + PassiveEffect.TAG + ":" + PlayerCharacter.HUNGER + ":" + "0.8"
                              + ":" + PassiveEffect.TAG + ":" + PlayerCharacter.THIRST + ":" + "0.8"
                              + ",Requirements:2,Icon:test.png";

            String catalogueStr = ItemCatalogue.TAG + ";" + itemStr1 + ";" + itemStr2 + ";" + itemStr3;

            for (int i = 4; i <= 1000; i++)
            {
                String loopItem = "ID:" + i + ",Name:TestItem,Amount:1,Description:test item" + i + ",ActiveEffect,PassiveEffect,Requirements";
                catalogueStr += ";" + loopItem;
            }

            var catalogue = new ItemCatalogue(catalogueStr);

            for (int i = 0; i < 10; i++)
            {
                var item1 = catalogue.GetRandomItem();
                var item2 = catalogue.GetRandomItem();

                Assert.AreNotSame(item1, item2, "Two randomly selected items should not be the same");
            }

            for (int i = 0; i < 1000; i++)
            {
                var item3 = catalogue.GetRandomItem(-1, 10001);
                Assert.IsInstanceOfType(item3, typeof(Item));
            }

            for (int i = 0; i < 100; i++)
            {
                var item5 = catalogue.GetRandomItem(100, 200);
                Assert.IsTrue(item5.GetID() >= 100 && item5.GetID() <= 200, "Random items should be in range, ID was " + item5.GetID());
            }
        }
Exemple #2
0
        /// <summary>
        /// Scavenges a sublocation putting found items into the inventory of this PC
        /// </summary>
        /// <param name="gs">The game state to modify</param>
        /// <returns>List of scavenged items</returns>
        public List <Item> ScavangeSubLocation(GameState gs)
        {
            LocationModel lm             = gs.GetLM();
            PCModel       pcm            = gs.GetPCM();
            ItemCatalogue ic             = pcm.GetItemCatalogue();
            List <Item>   scavengedItems = new List <Item>();

            if (lm.IsScavenged() || pcm.GetInventory().IsInventoryFull())
            {
                return(scavengedItems);
            }
            List <Item> itemSelection = new List <Item>();

            for (int i = 0; i < 100; i++)
            {
                itemSelection.Add(ic.GetRandomItem());
            }
            scavengedItems = lm.Scavenge(itemSelection);
            foreach (Item item in scavengedItems)
            {
                pcm.ModifyInventory(item, item.GetAmount());
            }
            return(scavengedItems);
        }