private bool ShouldBeDiscovered(Tag food_id)
 {
     if (WorldInventory.Instance.IsDiscovered(food_id))
     {
         return(true);
     }
     foreach (Recipe recipe in RecipeManager.Get().recipes)
     {
         if (recipe.Result == food_id)
         {
             string[] fabricators = recipe.fabricators;
             foreach (string id in fabricators)
             {
                 if (Db.Get().TechItems.IsTechItemComplete(id))
                 {
                     return(true);
                 }
             }
         }
     }
     foreach (Crop item in Components.Crops.Items)
     {
         if (Grid.IsVisible(Grid.PosToCell(item.gameObject)) && item.cropId == food_id.Name)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
 public Recipe SetFabricators(string[] fabricators, float fabricationTime)
 {
     this.fabricators = fabricators;
     FabricationTime  = fabricationTime;
     RecipeManager.Get().Add(this);
     return(this);
 }
예제 #3
0
        /// <summary>
        /// Recursively iterates the recipe list looking for foods that can be made with this
        /// item.
        /// </summary>
        /// <param name="item">The item to search.</param>
        /// <param name="found">The foods found so far.</param>
        /// <param name="seen">The items already seen, to prevent recipe loops from crashing.</param>
        /// <param name="quantity">The quantity of the base item.</param>
        private void SearchForRecipe(Tag item, IList <FoodResult> found, ICollection <Tag> seen,
                                     float quantity)
        {
            var prefab = Assets.GetPrefab(item);

            if (prefab != null && quantity > 0.0f && !seen.Contains(item))
            {
                var   edible = prefab.GetComponent <Edible>();
                float kcal;
                seen.Add(item);
                // Item itself is usable as food
                if (edible != null && (kcal = edible.FoodInfo.CaloriesPerUnit) > 0.0f)
                {
                    found.Add(new FoodResult(kcal, quantity, item));
                }
                // Search for recipes using this item
                foreach (var recipe in RecipeManager.Get().recipes)
                {
                    float amount = 0.0f;
                    foreach (var ingredient in recipe.Ingredients)
                    {
                        // Search for this item in the recipe
                        if (ingredient.tag == item)
                        {
                            amount = ingredient.amount;
                            break;
                        }
                    }
                    if (amount > 0.0f)
                    {
                        SearchForRecipe(recipe.Result, found, seen, recipe.OutputUnits *
                                        quantity / amount);
                    }
                }
                // And complex ones too
                foreach (var recipe in ComplexRecipeManager.Get().recipes)
                {
                    float amount = 0.0f;
                    foreach (var ingredient in recipe.ingredients)
                    {
                        // Search for this item in the recipe
                        if (ingredient.material == item)
                        {
                            amount = ingredient.amount;
                            break;
                        }
                    }
                    if (amount > 0.0f)
                    {
                        // Check all results of the recipe
                        foreach (var result in recipe.results)
                        {
                            SearchForRecipe(result.material, found, seen, result.amount *
                                            quantity / amount);
                        }
                    }
                }
            }
        }
예제 #4
0
 public Recipe SetFabricator(string fabricator, float fabricationTime)
 {
     fabricators = new string[1]
     {
         fabricator
     };
     FabricationTime = fabricationTime;
     RecipeManager.Get().Add(this);
     return(this);
 }
예제 #5
0
        public static List <string> ControlRecipesIds(List <int> favoritIds)
        {
            List <string> errors = new List <string>();

            foreach (var id in favoritIds)
            {
                RecipeManager rm      = new RecipeManager();
                var           recipes = rm.Get(id);

                if (recipes == null)
                {
                    errors.Add("RecipeIdDoesNotExist");
                    break;
                }
            }
            return(errors);
        }
    protected override void OnPrefabInit()
    {
        instance = this;
        if (KPlayerPrefs.HasKey("TemperatureUnit"))
        {
            GameUtil.temperatureUnit = (GameUtil.TemperatureUnit)KPlayerPrefs.GetInt("TemperatureUnit");
        }
        if (KPlayerPrefs.HasKey("MassUnit"))
        {
            GameUtil.massUnit = (GameUtil.MassUnit)KPlayerPrefs.GetInt("MassUnit");
        }
        RecipeManager.DestroyInstance();
        RecipeManager.Get();
        AnimMaterial = AnimMaterialAsset;
        Prefabs      = new List <KPrefabID>(from x in PrefabAssets
                                            where (UnityEngine.Object)x != (UnityEngine.Object) null
                                            select x);
        PrefabsByTag.Clear();
        PrefabsByAdditionalTags.Clear();
        CountableTags.Clear();
        Sprites = new Dictionary <HashedString, Sprite>();
        foreach (Sprite spriteAsset in SpriteAssets)
        {
            if (!((UnityEngine.Object)spriteAsset == (UnityEngine.Object)null))
            {
                HashedString key = new HashedString(spriteAsset.name);
                Sprites.Add(key, spriteAsset);
            }
        }
        TintedSprites = (from x in TintedSpriteAssets
                         where x != null && (UnityEngine.Object)x.sprite != (UnityEngine.Object) null
                         select x).ToList();
        Materials = (from x in MaterialAssets
                     where (UnityEngine.Object)x != (UnityEngine.Object) null
                     select x).ToList();
        Textures = (from x in TextureAssets
                    where (UnityEngine.Object)x != (UnityEngine.Object) null
                    select x).ToList();
        TextureAtlases = (from x in TextureAtlasAssets
                          where (UnityEngine.Object)x != (UnityEngine.Object) null
                          select x).ToList();
        BlockTileDecorInfos = (from x in BlockTileDecorInfoAssets
                               where (UnityEngine.Object)x != (UnityEngine.Object) null
                               select x).ToList();
        Anims = (from x in AnimAssets
                 where (UnityEngine.Object)x != (UnityEngine.Object) null
                 select x).ToList();
        Anims.AddRange(ModLoadedKAnims);
        UIPrefabs = UIPrefabAssets;
        DebugFont = DebugFontAsset;
        AsyncLoadManager <IGlobalAsyncLoader> .Run();

        GameAudioSheets.Get().Initialize();
        SubstanceListHookup();
        BuildingDefs = new List <BuildingDef>();
        foreach (KPrefabID prefabAsset in PrefabAssets)
        {
            if (!((UnityEngine.Object)prefabAsset == (UnityEngine.Object)null))
            {
                AddPrefab(prefabAsset);
            }
        }
        AnimTable.Clear();
        foreach (KAnimFile anim in Anims)
        {
            if ((UnityEngine.Object)anim != (UnityEngine.Object)null)
            {
                HashedString key2 = anim.name;
                AnimTable[key2] = anim;
            }
        }
        CreatePrefabs();
    }