예제 #1
0
        public override bool SpecificTest(Sim actor, WoodFireOven target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
        {
            if (isAutonomous)
            {
                if (target.InUse)
                {
                    return(false);
                }
                if (actor.IsSelectable)
                {
                    mWOFoodInfo = null;

                    List <Ingredient> simIngredients = Recipe.GetCookableIngredients(actor.Inventory);
                    List <Ingredient> lotIngredients = actor.Household != null && actor.Household.SharedFridgeInventory != null?Recipe.GetCookableIngredients(actor.Household.SharedFridgeInventory.Inventory) : new List <Ingredient>();

                    List <Ingredient> list = null;
                    Recipe.MealTime   time = Food.GetCurrentMealTime();

                    int     num   = RandomUtil.GetInt(13);
                    int     num2  = 0;
                    Cooking skill = actor.SkillManager.GetSkill <Cooking>(SkillNames.Cooking);
                    Recipe  recipe;
                    WoodFireOven.WOFoodInfo wOFoodInfo;
                    while (true)
                    {
                        wOFoodInfo = WoodFireOven.WOFoodInfos[num];
                        if (Recipe.NameToRecipeHash.TryGetValue(wOFoodInfo.mName, out recipe) && (recipe.CookingSkillLevelRequired == 0 || (skill != null && skill.SkillLevel >= recipe.CookingSkillLevelRequired)) &&
                            recipe.IsAvailableFor(time) && recipe.BuildIngredientList(simIngredients, lotIngredients, ref list, ref list).Count == 0)
                        {
                            break;
                        }
                        if (++num2 >= 14)
                        {
                            return(false);
                        }
                        if (++num >= 14)
                        {
                            num = 0;
                        }
                    }
                    target.mCurrentRecipe = recipe;
                    ChosenRecipe          = recipe;
                    mWOFoodInfo           = wOFoodInfo;
                    return(true);
                }
            }
            return(base.SpecificTest(actor, target, isAutonomous, ref greyedOutTooltipCallback) &&
                   (Cost == 0 || Food.PrepareTestResultCheckAndGrayedOutPieMenuSet(actor, ChosenRecipe, Recipe.CanMakeFoodTestResult.Fail_NeedIngredients, ref greyedOutTooltipCallback)));
        }
예제 #2
0
        public override void AddInteractions(InteractionObjectPair iop, Sim actor, WoodFireOven target, List <InteractionObjectPair> results)
        {
            List <Ingredient> simIngredients = Recipe.GetCookableIngredients(actor.Inventory);
            List <Ingredient> lotIngredients = actor.Household != null && actor.Household.SharedFridgeInventory != null?Recipe.GetCookableIngredients(actor.Household.SharedFridgeInventory.Inventory) : new List <Ingredient>();

            List <Ingredient> list = null;

            Recipe.MealTime currentMealTime = Food.GetCurrentMealTime();
            string[]        menuPath        = new string[]
            {
                WoodFireOven.LocalizeString("Serve") /*+ " " + Food.GetMealTimeString(currentMealTime)*/ + Localization.Ellipsis
            };
            foreach (WoodFireOven.WOFoodInfo info in WoodFireOven.WOFoodInfos)
            {
                Recipe current;
                if (Recipe.NameToRecipeHash.TryGetValue(info.mName, out current) && current.IsAvailableFor(currentMealTime))
                {
                    int cost = current.BuildIngredientList(simIngredients, lotIngredients, ref list, ref list).Count == 0 ? 0 : -1;
                    results.Add(new InteractionObjectPair(new OverridedWOBakeDefinition(current.GenericName, current, menuPath, target, Recipe.MealDestination.SurfaceAndCallToMeal, Recipe.MealQuantity.Group, Recipe.MealRepetition.MakeOne, false, cost), iop.Target));
                }
            }
        }
예제 #3
0
파일: AniFridge.cs 프로젝트: yakoder/NRaas
        public static Recipe ChooseRecipeRandomly(Lot lotToCookOn, Sim sim, Recipe.MealQuantity quantity, bool forTesting)
        {
            if (lotToCookOn == null)
            {
                return(null);
            }
            List <Ingredient> simIngredients = Recipe.GetCookableIngredients(sim.Inventory);
            List <Ingredient> lotIngredients = sim.Household != null && sim.Household.SharedFridgeInventory != null?Recipe.GetCookableIngredients(sim.Household.SharedFridgeInventory.Inventory) : new List <Ingredient>();

            if (GameUtils.IsInstalled(ProductVersion.EP3) && !sim.SimDescription.IsVampire)
            {
                Predicate <Ingredient> vampireFruit = (i => i.Key == "VampireFruit");
                simIngredients.RemoveAll(vampireFruit);
                lotIngredients.RemoveAll(vampireFruit);
            }
            if (simIngredients.Count + lotIngredients.Count == 0)
            {
                return(null);
            }

            List <Ingredient>  list = null;
            Predicate <Recipe> p    = (r => r.BuildIngredientList(simIngredients, lotIngredients, ref list, ref list).Count == 0);

            Recipe recipe = null;

            if (sim.SimDescription.IsVampire)
            {
                recipe = Recipe.NameToRecipeHash[GameUtils.IsInstalled(ProductVersion.EP7) ? "VampireJuiceEP7" : "VampireJuice"];
            }
            else if (sim.SimDescription.IsZombie)
            {
                recipe = Recipe.NameToRecipeHash["BrainFreeze"];
            }
            if (recipe != null)
            {
                return(p(recipe) ? recipe : null);
            }

            bool lotHasCounter   = Food.LotHasUsableCounter(lotToCookOn);
            bool lotHasMicrowave = Food.LotHasUsableMicrowave(lotToCookOn);

            //For testing purposes quicker to test snacks first since they only require 1 ingredient.
            if (forTesting)
            {
                recipe = ChooseRandomSnack(sim, lotHasCounter, lotHasMicrowave, p, true);
                if (recipe != null)
                {
                    return(recipe);
                }
            }
            if (!lotToCookOn.IsCommunityLot)
            {
                List <Recipe>   availableRecipes = new List <Recipe>();
                bool            lotHasStove      = Food.LotHasUsableStove(lotToCookOn);
                bool            lotHasGrill      = Food.LotHasUsableGrill(lotToCookOn);
                Recipe.MealTime mealTime         = Food.GetCurrentMealTime();

                bool    flag    = sim.HasTrait(TraitNames.Vegetarian);
                Cooking cooking = sim.SkillManager.GetSkill <Cooking>(SkillNames.Cooking);
                if (cooking != null && cooking.IsHiddenSkill() && cooking.SkillLevel >= 1)
                {
                    foreach (string current in cooking.KnownRecipes)
                    {
                        Recipe r;
                        if (Recipe.NameToRecipeHash.TryGetValue(current, out r) && !r.IsPetFood && (!flag || r.IsVegetarian) && Food.CanMake(r, false, true, mealTime, Recipe.MealRepetition.MakeOne, lotToCookOn, sim, Recipe.MealQuantity.DoNotCheck, lotHasCounter, lotHasStove, lotHasMicrowave, lotHasGrill, 0) == Recipe.CanMakeFoodTestResult.Pass &&
                            p(r))
                        {
                            if (forTesting)
                            {
                                return(r);
                            }
                            availableRecipes.Add(r);
                        }
                    }
                }
                else if (sim.SimDescription.TeenOrAbove && quantity == Recipe.MealQuantity.Group)
                {
                    foreach (Recipe current2 in Recipe.IntroRecipes)
                    {
                        if ((!flag || current2.IsVegetarian) && Food.CanMake(current2, false, true, mealTime, Recipe.MealRepetition.MakeOne, lotToCookOn, sim, Recipe.MealQuantity.DoNotCheck, lotHasCounter, lotHasStove, lotHasMicrowave, lotHasGrill, 0) == Recipe.CanMakeFoodTestResult.Pass &&
                            p(current2))
                        {
                            if (forTesting)
                            {
                                return(current2);
                            }
                            availableRecipes.Add(current2);
                        }
                    }
                }
                if (availableRecipes.Count > 0)
                {
                    if (RandomUtil.RandomChance(Food.kChanceOfChoosingFavoriteFood))
                    {
                        FavoriteFoodType favoriteFood = sim.SimDescription.FavoriteFood;
                        if (favoriteFood != FavoriteFoodType.None)
                        {
                            foreach (Recipe current3 in availableRecipes)
                            {
                                if (current3.Favorite == favoriteFood)
                                {
                                    return(current3);
                                }
                            }
                        }
                    }
                    if (quantity == Recipe.MealQuantity.Group)
                    {
                        p = (r => r.CanMakeGroupServing);
                    }
                    else
                    {
                        p = (r => r.CanMakeSingleServing);
                    }
                    List <Recipe> limitedRecipes = availableRecipes.FindAll(p);
                    return(RandomUtil.GetRandomObjectFromList <Recipe>(limitedRecipes.Count > 0 ? limitedRecipes : availableRecipes));
                }
            }
            if (!forTesting)
            {
                return(ChooseRandomSnack(sim, lotHasCounter, lotHasMicrowave, p, false));
            }
            return(null);
        }
예제 #4
0
        protected void AddFoodPrepInteractions(InteractionObjectPair iop, Sim sim, List <InteractionObjectPair> results, GameObject objectClickedOn)
        {
            if (sim.Household == null)
            {
                return;
            }
            Lot lotHome = sim.LotHome;

            if (lotHome == null)
            {
                return;
            }
            Type          type             = (objectClickedOn != null) ? objectClickedOn.GetType() : null;
            bool          flag             = Reflection.IsTypeAssignableFrom(typeof(Stove), type);
            bool          flag2            = Reflection.IsTypeAssignableFrom(typeof(Microwave), type);
            bool          flag3            = Reflection.IsTypeAssignableFrom(typeof(Grill), type);
            bool          flag4            = Reflection.IsTypeAssignableFrom(typeof(FoodProcessor), type);
            List <Recipe> availableRecipes = Food.GetAvailableRecipes(iop.Target.LotCurrent, sim, false, false, false);

            Recipe.MealTime mealTime = flag3 ? Recipe.MealTime.DO_NOT_CHECK : Food.GetCurrentMealTime();
            string          currentMealTimeString = Food.GetCurrentMealTimeString();

            string[] menuPath = new string[]
            {
                Localization.LocalizeString("Gameplay/Objects/CookingObjects/Food:Have", new object[]
                {
                    currentMealTimeString
                })
            };
            string[] menuPath2 = new string[]
            {
                Localization.LocalizeString("Gameplay/Objects/CookingObjects/Food:Serve", new object[]
                {
                    currentMealTimeString
                })
            };
            string[] menuPath3 = new string[]
            {
                Localization.LocalizeString("Gameplay/Objects/CookingObjects/Food:Serve", new object[]
                {
                    Food.GetString(Food.StringIndices.Dessert)
                })
            };
            string[] menuPath4 = new string[]
            {
                Localization.LocalizeString("Gameplay/Objects/CookingObjects/Food:PetFood", new object[0])
            };
            List <Ingredient> lotIngredients = null;

            if (lotHome.Household != null && lotHome.Household.SharedFridgeInventory != null && lotHome.Household.SharedFridgeInventory.Inventory != null)
            {
                lotIngredients = Recipe.GetCookableIngredients(lotHome.Household.SharedFridgeInventory.Inventory);
            }
            List <Ingredient> cookableIngredients = Recipe.GetCookableIngredients(sim.Inventory);

            foreach (Recipe current in availableRecipes)
            {
                if (type == null || (current.CookingProcessData.UsesAStove && flag) || (current.CookingProcessData.UsesAMicrowave && flag2) || (current.CookingProcessData.UsesAGrill && flag3) || (current.AllowFoodProcessor && flag4))
                {
                    int cost = 0;

                    //If sim is not in the active household, skip the check
                    if (sim.IsNPC)
                    {
                        cost = current.CalculateCost(cookableIngredients, lotIngredients);
                    }
                    else
                    {
                        cost = AniRecipe.CalculateCost(current, cookableIngredients, lotIngredients, false);
                    }

                    string menuText = sim.HasTrait(TraitNames.Vegetarian) ? current.GenericVegetarianName : current.GenericName;
                    if (current.IsDessert)
                    {
                        if (current.CanMakeGroupServing)
                        {
                            InteractionObjectPair item = new InteractionObjectPair(this.Create(menuText, current, menuPath3, objectClickedOn, Recipe.MealDestination.SurfaceOrEat, Recipe.MealQuantity.Group, Recipe.MealRepetition.MakeOne, false, cost), iop.Target);
                            results.Add(item);
                        }
                    }
                    else
                    {
                        if (current.IsPetFood)
                        {
                            InteractionObjectPair item = new InteractionObjectPair(this.Create(menuText, current, menuPath4, objectClickedOn, Recipe.MealDestination.SurfaceOnly, Recipe.MealQuantity.Single, Recipe.MealRepetition.MakeOne, false, cost), iop.Target);
                            results.Add(item);
                        }
                        else
                        {
                            if (current.IsAvailableFor(mealTime))
                            {
                                if (current.CanMakeSingleServing && !flag3 && (!sim.HasTrait(TraitNames.Vegetarian) || current.IsVegetarian || current.HasVegetarianAlternative))
                                {
                                    InteractionObjectPair item = new InteractionObjectPair(this.Create(menuText, current, menuPath, objectClickedOn, Recipe.MealDestination.SurfaceOrEat, Recipe.MealQuantity.Single, Recipe.MealRepetition.MakeOne, false, cost), iop.Target);
                                    results.Add(item);
                                }
                                if (current.CanMakeGroupServing)
                                {
                                    InteractionObjectPair item = new InteractionObjectPair(this.Create(menuText, current, menuPath2, objectClickedOn, Recipe.MealDestination.SurfaceOrEat, Recipe.MealQuantity.Group, Recipe.MealRepetition.MakeOne, false, cost), iop.Target);
                                    results.Add(item);
                                }
                            }
                        }
                    }
                }
            }
        }