コード例 #1
0
        /// <summary>
        /// Gets the ingredients required for the recipe.
        /// </summary>
        /// <param name="recipe">The recipe to describe.</param>
        /// <param name="target">The fabricator requesting the recipe.</param>
        /// <param name="result">The location where the ingredients will be stored.</param>
        private static void GetIngredientDescriptions(ComplexRecipe recipe,
                                                      KMonoBehaviour target, IList <DescriptorWithSprite> result)
        {
            var ingredients = recipe.ingredients;
            int n           = ingredients.Length;
            var inventory   = target.GetMyWorld().worldInventory;
            var text        = CACHED_BUILDER;

            for (int i = 0; i < n; i++)
            {
                var   item      = ingredients[i];
                var   material  = item.material;
                var   prefab    = Assets.GetPrefab(material);
                float available = inventory.GetAmount(material, true);
                text.Clear().Append(available >= item.amount ? RECIPE_REQUIREMENT :
                                    RECIPE_REQUIREMENT_UNAVAILABLE).Replace("{0}", prefab.GetProperName()).
                Replace("{1}", GameUtil.GetFormattedByTag(material, item.amount)).
                Replace("{2}", GameUtil.GetFormattedByTag(material, available));
                string description = text.ToString();
                result.Add(new DescriptorWithSprite(new Descriptor(description, description,
                                                                   Descriptor.DescriptorType.Requirement), Def.GetUISprite(material,
                                                                                                                           "ui"), prefab.TryGetComponent(out MutantPlant _)));
            }
            if (recipe.consumedHEP > 0 && target.TryGetComponent(
                    out HighEnergyParticleStorage component))
            {
                string consumed = recipe.consumedHEP.ToString();
                text.Clear().Append(consumed).Append(" / ");
                component.Particles.ToRyuHardString(text, 1);
                string requirements = text.ToString();
                // The concatenated strings had to be created anyways, so manipulating the
                // string builder again does not save memory
                result.Add(new DescriptorWithSprite(new Descriptor(HEP_FORMAT + requirements,
                                                                   HEP_FORMAT + requirements, Descriptor.DescriptorType.Requirement),
                                                    RADBOLT_ICON));
            }
        }