Пример #1
0
        private static void DrawLeftRectAsProgress(Rect rect, RecipeSpec current)
        {
            Widgets.DrawMenuSection(rect, false);

            GUI.BeginGroup(rect);

            var   progressRect = new Rect(35f, rect.height - 80f, rect.width - 70f, 50f);
            float percent      = (current.Progress / current.MaxProgress);

            var nameRect = new Rect(15f, 15, rect.width - 20f, 100f);

            Text.Anchor = TextAnchor.UpperCenter;
            Text.Font   = GameFont.Medium;
            Widgets.Label(nameRect, current.ProductLabel);

            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            Widgets.FillableBar(progressRect, percent);

            float remainingTicks = current.MaxProgress - current.Progress;
            var   time           = TimeSpan.FromHours(remainingTicks / 2500);

            string text = remainingTicks > 60000
                ? $"{remainingTicks/60000:0} Days"
                : $"{time.Hours} hours";

            Widgets.Label(progressRect, text);

            Text.Anchor = TextAnchor.UpperLeft;

            GUI.EndGroup();
        }
Пример #2
0
        public override void WorldLoaded()
        {
            if (!ModIsActive)
            {
                return;
            }
            _currentCache = null;

            var recipes = DefDatabase <RecipeDef> .AllDefsListForReading
                          .Where(r => r.defName.StartsWith("MateriaRecipe"))
                          .ToDictionary(r => r.defName, r => r);

            _database = UtilityWorldObjectManager.GetUtilityWorldObject <MateriaDatabase>();

            if (_database.RecipeSpecs.Count == 0)
            {
                Logger.Message($"Generating {recipes.Count} new recipe.");

                var recipeGen = new RecipesGen(_random);
                recipeGen.Populate(_database, recipes.Values.ToQueue());
                EffectsGen.PopulateEffects(_database.RecipeSpecs);
                CreateOptions();
            }

            Logger.Message($"Applying {_database.RecipeSpecs.Count} recipe specifications.");
            var cookingRecipeUsers = GetCookingRecipeUsers();

            foreach (var spec in _database.RecipeSpecs)
            {
                var recipe = recipes[spec.Name];
                spec.ApplyTo(recipe, cookingRecipeUsers);
            }

            _currentCache = _database.RecipeSpecs.FirstOrDefault(r => r.IsUnlocking);
        }
Пример #3
0
        public override void Tick(int currentTick)
        {
            if (_currentCache == null)
            {
                return;
            }

            _currentCache.Progress += 1;
            if (_currentCache.Progress < _currentCache.MaxProgress)
            {
                return;
            }

            _currentCache.Progress    = _currentCache.MaxProgress;
            _currentCache.IsUnlocking = false;
            _currentCache.IsUnlocked  = true;

            var cookingRecipeUsers = GetCookingRecipeUsers();
            var recipe             = DefDatabase <RecipeDef> .GetNamed(_currentCache.Name);

            cookingRecipeUsers.ForEach(u => u.AllRecipes.Add(recipe));

            string message = $"{_currentCache.Label} has been unlocked.";

            Find.LetterStack.ReceiveLetter("Recipe Unlocked", message, LetterType.Good);

            _currentCache = null;

            CreateOptions();
        }
Пример #4
0
        public RecipeSpec GetByLabel(string label)
        {
            if (label == null)
            {
                return(null);
            }

            RecipeSpec spec = null;

            _database?.ByLabel.TryGetValue(label, out spec);
            return(spec);
        }
Пример #5
0
        private List <RecipeSpec> GenerateTier(int tier, int rerollAttempts, List <IngredientOption> options, Queue <RecipeDef> recipeDefs)
        {
            int recipeAmount    = S.RecipeAmount / S.TierAmount;
            int ingredientCount = S.IngredientCount[tier];
            int minIngAmount    = S.MinIngredientAmounts[tier];
            int maxIngAmount    = S.MaxIngredientAmounts[tier];

            var recipes = new List <RecipeSpec>(recipeAmount);

            for (int i = 0; i < recipeAmount; i++)
            {
                if (recipeDefs.Count == 0)
                {
                    break;
                }

                var recipe = new RecipeSpec();
                recipe.Name         = recipeDefs.Dequeue().defName;
                recipe.Tier         = tier;
                recipe.DaysToRot    = _random.Next(S.DaysToRotMin[tier], S.DaysToRotMax[tier]);
                recipe.MarketValue  = _random.Next(S.MarketValueMin[tier], S.MarketValueMax[tier]);
                recipe.Mass         = NextFloat(0.05, 0.30);
                recipe.Nutrition    = NextFloat(0.7, 1.0);
                recipe.Yield        = _random.Next(S.YieldMin[tier], S.YieldMax[tier]);
                recipe.WorkToMake   = _random.Next(S.WorkToMakeMin[tier], S.WorkToMakeMax[tier]) * recipe.Yield;
                recipe.Skill        = _random.Next(S.CookingSkillMin[tier], S.CookingSkillMax[tier]);
                recipe.ProgressGain = S.ProgressGainPerTier[tier];

                var ingredients = Enumerable.Range(0, rerollAttempts)
                                  .Select(s => Roll(ingredientCount, minIngAmount, maxIngAmount, recipe.Yield, options))
                                  .Select(s => new { Guid = s.Select(g => g.Name).Aggregate((a, b) => a + b), Ing = s })
                                  .OrderByDescending(c => !_combinations.Contains(c.Guid))
                                  .ThenBy(c => c.Ing.Count(ing => _ingredients.Contains(ing.Name)))
                                  .First();

                _combinations.Add(ingredients.Guid);
                foreach (var ing in ingredients.Ing)
                {
                    _ingredients.Add(ing.Name);
                }
                recipe.Ingredients = ingredients.Ing;

                recipes.Add(recipe);
            }

            return(recipes);
        }
Пример #6
0
        public void SetChoice(string specLabel)
        {
            if (specLabel == null)
            {
                return;
            }
            var chosen = _database.RecipeSpecs.FirstOrDefault(s => s.Label == specLabel);

            if (chosen == null)
            {
                return;
            }

            foreach (var s in _database.RecipeSpecs.Where(s => s.IsOption))
            {
                s.IsOption  = false;
                s.WasOption = true;
            }

            chosen.IsUnlocking = true;
            _currentCache      = chosen;
        }
Пример #7
0
        private static void SetFlavor(int iteration, IDictionary <string, List <FlavorText> > map, RecipeSpec spec)
        {
            FlavorText flavor          = null;
            var        ingredientNames = spec.Ingredients.Select(i => i.Name).ToHashSet();

            foreach (var ing in spec.Ingredients)
            {
                List <FlavorText> list;
                if (!map.TryGetValue(ing.Name.ToLower(), out list))
                {
                    continue;
                }

                flavor = list.FirstOrDefault(f => f.Ingredients.All(i => ingredientNames.Contains(i)));
                if (flavor == null)
                {
                    continue;
                }

                list.Remove(flavor);
                break;
            }

            if (flavor != null)
            {
                spec.Label              = $"Make {flavor.Name}";
                spec.ProductLabel       = flavor.Name;
                spec.Description        = flavor.Description;
                spec.ProductDescription = flavor.Description;

                return;
            }

            spec.Label        = $"Make {spec.Ingredients.First().Label} Meal No. {iteration}";
            spec.ProductLabel = $"{spec.Ingredients.First().Label} Meal No. {iteration}";

            var description = new StringBuilder("A meal made of");

            for (int i = 0; i < spec.Ingredients.Count - 1; i++)
            {
                description.Append($" {spec.Ingredients[i].Label},");
            }

            if (spec.Ingredients.Count == 2)
            {
                description = description.Replace(",", "");
            }

            description.Append(spec.Ingredients.Count > 1
                ? $" and {spec.Ingredients[spec.Ingredients.Count - 1].Label}."
                : $" {spec.Ingredients[spec.Ingredients.Count - 1].Label}.");

            spec.Description        = description.ToString();
            spec.ProductDescription = spec.Description;
        }