public override void Begin(Precondition.Context context)
 {
     if ((UnityEngine.Object)context.consumerState.consumer == (UnityEngine.Object)null)
     {
         Debug.LogError("EATCHORE null context.consumer");
     }
     else
     {
         RationMonitor.Instance sMI = context.consumerState.consumer.GetSMI <RationMonitor.Instance>();
         if (sMI == null)
         {
             Debug.LogError("EATCHORE null RationMonitor.Instance");
         }
         else
         {
             Edible edible = sMI.GetEdible();
             if ((UnityEngine.Object)edible.gameObject == (UnityEngine.Object)null)
             {
                 Debug.LogError("EATCHORE null edible.gameObject");
             }
             else if (base.smi == null)
             {
                 Debug.LogError("EATCHORE null smi");
             }
             else if (base.smi.sm == null)
             {
                 Debug.LogError("EATCHORE null smi.sm");
             }
             else if (base.smi.sm.ediblesource == null)
             {
                 Debug.LogError("EATCHORE null smi.sm.ediblesource");
             }
             else
             {
                 base.smi.sm.ediblesource.Set(edible.gameObject, base.smi);
                 KCrashReporter.Assert(edible.FoodInfo.CaloriesPerUnit > 0f, edible.GetProperName() + " has invalid calories per unit. Will result in NaNs");
                 AmountInstance amountInstance = Db.Get().Amounts.Calories.Lookup(gameObject);
                 float          num            = (amountInstance.GetMax() - amountInstance.value) / edible.FoodInfo.CaloriesPerUnit;
                 KCrashReporter.Assert(num > 0f, "EatChore is requesting an invalid amount of food");
                 base.smi.sm.requestedfoodunits.Set(num, base.smi);
                 base.smi.sm.eater.Set(context.consumerState.gameObject, base.smi);
                 base.Begin(context);
             }
         }
     }
 }
Esempio n. 2
0
 public void SpawnFruit(object callbackParam)
 {
     if (!((UnityEngine.Object) this == (UnityEngine.Object)null))
     {
         CropVal cropVal = this.cropVal;
         if (!string.IsNullOrEmpty(cropVal.cropId))
         {
             GameObject gameObject = Scenario.SpawnPrefab(Grid.PosToCell(base.gameObject), 0, 0, cropVal.cropId, Grid.SceneLayer.Ore);
             if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
             {
                 float y = 0.75f;
                 gameObject.transform.SetPosition(gameObject.transform.GetPosition() + new Vector3(0f, y, 0f));
                 gameObject.SetActive(true);
                 PrimaryElement component = gameObject.GetComponent <PrimaryElement>();
                 component.Units       = (float)cropVal.numProduced;
                 component.Temperature = base.gameObject.GetComponent <PrimaryElement>().Temperature;
                 Edible component2 = gameObject.GetComponent <Edible>();
                 if ((bool)component2)
                 {
                     ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, component2.Calories, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.HARVESTED, "{0}", component2.GetProperName()), UI.ENDOFDAYREPORT.NOTES.HARVESTED_CONTEXT);
                 }
             }
             else
             {
                 DebugUtil.LogErrorArgs(base.gameObject, "tried to spawn an invalid crop prefab:", cropVal.cropId);
             }
             Trigger(-1072826864, null);
         }
     }
 }
Esempio n. 3
0
            public static bool Prefix(ComplexFabricator __instance, ref ComplexRecipe recipe, ref List <GameObject> __result)
            {
                if (recipe == GeneticSamplerConfig.RECIPE_RECOMBINATION)
                {
                    Debug.Log("Should recombinate");
                    var ingredient_0 = recipe.ingredients[0];
                    Debug.Log(ingredient_0);
                    float   amount  = ingredient_0.amount;
                    var     tag     = ingredient_0.material;
                    Storage storage = __instance.buildStorage;
                    Debug.Log(amount);
                    Debug.Log(tag);
                    Debug.Log(storage.items.Count);
                    DebugHelper.LogForEach(storage.items);
                    for (int index = 0; index < storage.items.Count && (double)amount > 0.0; ++index)
                    {
                        GameObject item_0 = storage.items[index];
                        Debug.Log(item_0);
                        Debug.Log(item_0.HasTag(tag));
                        if (!((UnityEngine.Object)item_0 == (UnityEngine.Object)null) && item_0.HasTag(tag))
                        {
                            Debug.Log("About to add traits to add");

                            var traitsToAdd = GeneticTraits.GeneticTraits.ChooseTraitsFromEggToEgg(item_0).Select(Db.Get().traits.Get);
                            //to the result



                            List <GameObject>   gameObjectList = new List <GameObject>();
                            SimUtil.DiseaseInfo diseaseInfo;
                            diseaseInfo.count = 0;
                            diseaseInfo.idx   = (byte)0;
                            float num1 = 0.0f;
                            float num2 = 0.0f;
                            foreach (ComplexRecipe.RecipeElement ingredient in recipe.ingredients)
                            {
                                num2 += ingredient.amount;
                            }
                            foreach (ComplexRecipe.RecipeElement ingredient in recipe.ingredients)
                            {
                                float num3 = ingredient.amount / num2;
                                SimUtil.DiseaseInfo disease_info;
                                float aggregate_temperature;
                                __instance.buildStorage.ConsumeAndGetDisease(ingredient.material, ingredient.amount, out disease_info, out aggregate_temperature);
                                if (disease_info.count > diseaseInfo.count)
                                {
                                    diseaseInfo = disease_info;
                                }
                                num1 += aggregate_temperature * num3;
                            }
                            foreach (ComplexRecipe.RecipeElement result in recipe.results)
                            {
                                GameObject first = __instance.buildStorage.FindFirst(result.material);
                                if ((UnityEngine.Object)first != (UnityEngine.Object)null)
                                {
                                    Edible component = first.GetComponent <Edible>();
                                    if ((bool)((UnityEngine.Object)component))
                                    {
                                        ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, -component.Calories, StringFormatter.Replace((string)UI.ENDOFDAYREPORT.NOTES.CRAFTED_USED, "{0}", component.GetProperName()), (string)UI.ENDOFDAYREPORT.NOTES.CRAFTED_CONTEXT);
                                    }
                                }
                                switch (__instance.resultState)
                                {
                                case ComplexFabricator.ResultState.PassTemperature:
                                case ComplexFabricator.ResultState.Heated:
                                    GameObject go   = GameUtil.KInstantiate(Assets.GetPrefab(result.material), Grid.SceneLayer.Ore, (string)null, 0);
                                    int        cell = Grid.PosToCell((KMonoBehaviour)__instance);
                                    go.transform.SetPosition(Grid.CellToPosCCC(cell, Grid.SceneLayer.Ore) + __instance.outputOffset);
                                    PrimaryElement component1 = go.GetComponent <PrimaryElement>();
                                    component1.Units       = result.amount;
                                    component1.Temperature = __instance.resultState != ComplexFabricator.ResultState.PassTemperature ? __instance.heatedTemperature : num1;
                                    go.SetActive(true);
                                    float num3 = result.amount / recipe.TotalResultUnits();
                                    component1.AddDisease(diseaseInfo.idx, Mathf.RoundToInt((float)diseaseInfo.count * num3), "ComplexFabricator.CompleteOrder");
                                    go.GetComponent <KMonoBehaviour>().Trigger(748399584, (object)null);

                                    var gtc = go.AddOrGet <GeneticTraitComponent>();
                                    gtc.addTraits(traitsToAdd, item_0);

                                    gameObjectList.Add(go);
                                    if (__instance.storeProduced)
                                    {
                                        __instance.outStorage.Store(go, false, false, true, false);
                                        break;
                                    }
                                    break;

                                case ComplexFabricator.ResultState.Melted:
                                    if (__instance.storeProduced)
                                    {
                                        float temperature = ElementLoader.GetElement(result.material).lowTemp + (float)(((double)ElementLoader.GetElement(result.material).highTemp - (double)ElementLoader.GetElement(result.material).lowTemp) / 2.0);
                                        __instance.outStorage.AddLiquid(ElementLoader.GetElementID(result.material), result.amount, temperature, (byte)0, 0, false, true);
                                        break;
                                    }
                                    break;
                                }
                                if (gameObjectList.Count > 0)
                                {
                                    SymbolOverrideController component2 = __instance.GetComponent <SymbolOverrideController>();
                                    if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
                                    {
                                        KAnim.Build        build  = gameObjectList[0].GetComponent <KBatchedAnimController>().AnimFiles[0].GetData().build;
                                        KAnim.Build.Symbol symbol = build.GetSymbol((KAnimHashedString)build.name);
                                        if (symbol != null)
                                        {
                                            component2.TryRemoveSymbolOverride((HashedString)"output_tracker", 0);
                                            component2.AddSymbolOverride((HashedString)"output_tracker", symbol, 0);
                                        }
                                        else
                                        {
                                            Debug.LogWarning((object)(component2.name + " is missing symbol " + build.name));
                                        }
                                    }
                                }
                            }
                            __result = gameObjectList;
                        }
                    }

                    return(false);
                }
                else
                {
                    Debug.Log("Should NO recombinate");
                    return(true);
                }
            }
Esempio n. 4
0
            private static void Postfix(Crop __instance)
            {
                if (__instance == null)
                {
                    return;
                }
                Crop.CropVal cropVal = __instance.cropVal;
                if (string.IsNullOrEmpty(cropVal.cropId))
                {
                    return;
                }
                if (cropVal.cropId != CactusFleshConfig.Id)
                {
                    return;
                }
                GameObject gameObject = Scenario.SpawnPrefab(Grid.PosToCell(__instance.gameObject), 0, 0, CactusFlowerConfig.Id, Grid.SceneLayer.Ore);

                if (gameObject != null)
                {
                    float y = 0.75f;
                    gameObject.transform.SetPosition(gameObject.transform.GetPosition() + new Vector3(0.0f, y, 0.0f));
                    gameObject.SetActive(true);
                    PrimaryElement component1 = gameObject.GetComponent <PrimaryElement>();
                    component1.Units       = 1.0f; // cactus produces 1 unit of flower to go with 5 units of flesh
                    component1.Temperature = __instance.gameObject.GetComponent <PrimaryElement>().Temperature;
                    Edible component2 = gameObject.GetComponent <Edible>();
                    if ((bool)((UnityEngine.Object)component2))
                    {
                        ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, component2.Calories, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.HARVESTED, "{0}", component2.GetProperName()), UI.ENDOFDAYREPORT.NOTES.HARVESTED_CONTEXT);
                    }
                }
                else
                {
                    DebugUtil.LogErrorArgs(__instance.gameObject, "tried to spawn an invalid crop prefab:", CactusFlowerConfig.Id);
                }
                __instance.Trigger(-1072826864, null);
            }
Esempio n. 5
0
        public static void SpawnFruit(Crop inst, string fruitId, int amount)
        {
            if (inst == null || string.IsNullOrEmpty(fruitId))
            {
                return;
            }

            GameObject gameObject = Scenario.SpawnPrefab(Grid.PosToCell(inst.gameObject), 0, 0, fruitId, Grid.SceneLayer.Ore);

            if (gameObject != null)
            {
                float y = 0.75f;
                gameObject.transform.SetPosition(gameObject.transform.GetPosition() + new Vector3(0.0f, y, 0.0f));
                gameObject.SetActive(true);
                PrimaryElement component1 = gameObject.GetComponent <PrimaryElement>();
                component1.Units       = amount;
                component1.Temperature = inst.gameObject.GetComponent <PrimaryElement>().Temperature;
                Edible component2 = gameObject.GetComponent <Edible>();
                if ((bool)component2)
                {
                    ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, component2.Calories, StringFormatter.Replace(STRINGS.UI.ENDOFDAYREPORT.NOTES.HARVESTED, "{0}", component2.GetProperName()), STRINGS.UI.ENDOFDAYREPORT.NOTES.HARVESTED_CONTEXT);
                }
            }
            else
            {
                Debug.LogWarning("Tried to spawn an invalid crop prefab: " + fruitId);
            }
        }
Esempio n. 6
0
    private GameObject CraftRecipe(Storage resource_storage, Ingredient[] ingredientTags)
    {
        SimUtil.DiseaseInfo a = SimUtil.DiseaseInfo.Invalid;
        float num             = 0f;
        float num2            = 0f;

        foreach (Ingredient ingredient in ingredientTags)
        {
            GameObject gameObject = resource_storage.FindFirst(ingredient.tag);
            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
            {
                Edible component = gameObject.GetComponent <Edible>();
                if ((bool)component)
                {
                    ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, 0f - component.Calories, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.CRAFTED_USED, "{0}", component.GetProperName()), UI.ENDOFDAYREPORT.NOTES.CRAFTED_CONTEXT);
                }
            }
            resource_storage.ConsumeAndGetDisease(ingredient, out SimUtil.DiseaseInfo disease_info, out float temperature);
            a     = SimUtil.CalculateFinalDiseaseInfo(a, disease_info);
            num   = SimUtil.CalculateFinalTemperature(num2, num, ingredient.amount, temperature);
            num2 += ingredient.amount;
        }
        GameObject prefab      = Assets.GetPrefab(Result);
        GameObject gameObject2 = null;

        if ((UnityEngine.Object)prefab != (UnityEngine.Object)null)
        {
            gameObject2 = GameUtil.KInstantiate(prefab, Grid.SceneLayer.Ore, null, 0);
            PrimaryElement component2 = gameObject2.GetComponent <PrimaryElement>();
            gameObject2.GetComponent <KSelectable>().entityName = Name;
            if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
            {
                gameObject2.GetComponent <KPrefabID>().RemoveTag(TagManager.Create("Vacuum"));
                if (ResultElementOverride != 0)
                {
                    if ((UnityEngine.Object)component2.GetComponent <ElementChunk>() != (UnityEngine.Object)null)
                    {
                        component2.SetElement(ResultElementOverride);
                    }
                    else
                    {
                        component2.ElementID = ResultElementOverride;
                    }
                }
                component2.Temperature = num;
                component2.Units       = OutputUnits;
            }
            Edible component3 = gameObject2.GetComponent <Edible>();
            if ((bool)component3)
            {
                ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, component3.Calories, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.CRAFTED, "{0}", component3.GetProperName()), UI.ENDOFDAYREPORT.NOTES.CRAFTED_CONTEXT);
            }
            gameObject2.SetActive(true);
            if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
            {
                component2.AddDisease(a.idx, a.count, "Recipe.CraftRecipe");
            }
            gameObject2.GetComponent <KMonoBehaviour>().Trigger(748399584, null);
        }
        return(gameObject2);
    }
Esempio n. 7
0
    protected virtual List <GameObject> SpawnOrderProduct(ComplexRecipe recipe)
    {
        List <GameObject> list = new List <GameObject>();

        SimUtil.DiseaseInfo diseaseInfo = default(SimUtil.DiseaseInfo);
        diseaseInfo.count = 0;
        diseaseInfo.idx   = 0;
        float num  = 0f;
        float num2 = 0f;

        ComplexRecipe.RecipeElement[] ingredients = recipe.ingredients;
        foreach (ComplexRecipe.RecipeElement recipeElement in ingredients)
        {
            num2 += recipeElement.amount;
        }
        ComplexRecipe.RecipeElement[] ingredients2 = recipe.ingredients;
        foreach (ComplexRecipe.RecipeElement recipeElement2 in ingredients2)
        {
            float num3 = recipeElement2.amount / num2;
            buildStorage.ConsumeAndGetDisease(recipeElement2.material, recipeElement2.amount, out SimUtil.DiseaseInfo disease_info, out float aggregate_temperature);
            if (disease_info.count > diseaseInfo.count)
            {
                diseaseInfo = disease_info;
            }
            num += aggregate_temperature * num3;
        }
        ComplexRecipe.RecipeElement[] results = recipe.results;
        foreach (ComplexRecipe.RecipeElement recipeElement3 in results)
        {
            GameObject gameObject = buildStorage.FindFirst(recipeElement3.material);
            if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
            {
                Edible component = gameObject.GetComponent <Edible>();
                if ((bool)component)
                {
                    ReportManager.Instance.ReportValue(ReportManager.ReportType.CaloriesCreated, 0f - component.Calories, StringFormatter.Replace(UI.ENDOFDAYREPORT.NOTES.CRAFTED_USED, "{0}", component.GetProperName()), UI.ENDOFDAYREPORT.NOTES.CRAFTED_CONTEXT);
                }
            }
            switch (resultState)
            {
            case ResultState.PassTemperature:
            case ResultState.Heated:
            {
                GameObject prefab      = Assets.GetPrefab(recipeElement3.material);
                GameObject gameObject2 = GameUtil.KInstantiate(prefab, Grid.SceneLayer.Ore, null, 0);
                int        cell        = Grid.PosToCell(this);
                gameObject2.transform.SetPosition(Grid.CellToPosCCC(cell, Grid.SceneLayer.Ore) + outputOffset);
                PrimaryElement component2 = gameObject2.GetComponent <PrimaryElement>();
                component2.Units       = recipeElement3.amount;
                component2.Temperature = ((resultState != 0) ? heatedTemperature : num);
                gameObject2.SetActive(true);
                float num4 = recipeElement3.amount / recipe.TotalResultUnits();
                component2.AddDisease(diseaseInfo.idx, Mathf.RoundToInt((float)diseaseInfo.count * num4), "ComplexFabricator.CompleteOrder");
                gameObject2.GetComponent <KMonoBehaviour>().Trigger(748399584, null);
                list.Add(gameObject2);
                if (storeProduced)
                {
                    outStorage.Store(gameObject2, false, false, true, false);
                }
                break;
            }

            case ResultState.Melted:
                if (storeProduced)
                {
                    float temperature = ElementLoader.GetElement(recipeElement3.material).lowTemp + (ElementLoader.GetElement(recipeElement3.material).highTemp - ElementLoader.GetElement(recipeElement3.material).lowTemp) / 2f;
                    outStorage.AddLiquid(ElementLoader.GetElementID(recipeElement3.material), recipeElement3.amount, temperature, 0, 0, false, true);
                }
                break;
            }
            if (list.Count > 0)
            {
                SymbolOverrideController component3 = GetComponent <SymbolOverrideController>();
                if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
                {
                    KBatchedAnimController component4 = list[0].GetComponent <KBatchedAnimController>();
                    KAnim.Build            build      = component4.AnimFiles[0].GetData().build;
                    KAnim.Build.Symbol     symbol     = build.GetSymbol(build.name);
                    if (symbol != null)
                    {
                        component3.TryRemoveSymbolOverride("output_tracker", 0);
                        component3.AddSymbolOverride("output_tracker", symbol, 0);
                    }
                    else
                    {
                        Debug.LogWarning(component3.name + " is missing symbol " + build.name);
                    }
                }
            }
        }
        return(list);
    }