Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RecipeElement"/> struct.
        /// </summary>
        /// <param name="in_itemTag">An <see cref="GameObjectTag"/> describing the <see cref="Item"/>.</param>
        /// <param name="in_itemAmount">In amount of the <see cref="Item"/>.  Must be positive.</param>
        public RecipeElement(GameObjectTag in_itemTag, int in_itemAmount)
        {
            Precondition.MustBePositive(in_itemAmount, nameof(in_itemAmount));

            ElementTag    = in_itemTag;
            ElementAmount = in_itemAmount;
        }
Пример #2
0
        public void MustBePositiveTest()
        {
            var testValue = 1;

            var exception = Record.Exception(() => Precondition.MustBePositive(testValue));

            Assert.Null(exception);
        }
Пример #3
0
        public Item(GameObjectID in_id, ItemType in_subtype, string in_name, string in_description, string in_comment,
                    int in_price, int in_rarity, int in_stackMax, int in_effectWhileHeld,
                    int in_effectWhenUsed, GameObjectID in_asParquet,
                    List <GameObjectTag> in_itemTags = null, GameObjectID?in_recipeID = null)
            : base(All.ItemIDs, in_id, in_name, in_description, in_comment)
        {
            Precondition.IsInRange(in_asParquet, All.ParquetIDs, nameof(in_asParquet));
            Precondition.MustBePositive(in_stackMax, nameof(in_stackMax));

            // TODO Do we need to bounds-check in_effectWhileHeld?  If so, add a unit test.
            // TODO Do we need to bounds-check in_effectWhenUsed?  If so, add a unit test.

            /* TODO This check is a good idea but it is improper to get a specific entity from All
             * during initialization of an entity.  If we are to include this functionality another
             * means of implementing it must be found.
             * if (nonNullCraftingRecipeID != CraftingRecipe.NotCraftable.ID)
             * {
             *  var craftingRecipe = All.CraftingRecipes.Get<CraftingRecipe>(nonNullCraftingRecipeID);
             *  var givenRecipeProducesGivenItem = false;
             *  foreach (var product in craftingRecipe.Products)
             *  {
             *      if (product.ItemID == in_id)
             *      {
             *          givenRecipeProducesGivenItem = true;
             *          break;
             *      }
             *  }
             *  if (!givenRecipeProducesGivenItem)
             *  {
             *      throw new ArgumentException($"The crafting recipe for {in_name} include {in_name} among its products.");
             *  }
             * }
             */

            var nonNullItemTags         = in_itemTags ?? Enumerable.Empty <GameObjectTag>().ToList();
            var nonNullCraftingRecipeID = in_recipeID ?? CraftingRecipe.NotCraftable.ID;

            Subtype         = in_subtype;
            Price           = in_price;
            Rarity          = in_rarity;
            StackMax        = in_stackMax;
            EffectWhileHeld = in_effectWhileHeld;
            EffectWhenUsed  = in_effectWhenUsed;
            AsParquet       = in_asParquet;
            ItemTags        = nonNullItemTags;
            Recipe          = nonNullCraftingRecipeID;
        }
Пример #4
0
        public void MustBePositiveThrowsOnNegativeTest()
        {
            var testValue = -1;

            Assert.Throws <ArgumentOutOfRangeException>(() => Precondition.MustBePositive(testValue));
        }