示例#1
0
 public void SampleCell(int cell)
 {
     massPressureInput.text = (Grid.Pressure[cell] * 0.0100000007f).ToString();
     temperatureInput.text  = Grid.Temperature[cell].ToString();
     OnSelectElement(ElementLoader.GetElementID(Grid.Element[cell].tag));
     OnChangeMassPressure();
     OnChangeTemperature();
 }
示例#2
0
        /// <summary>
        /// Checks for pumpable media of the right type in the pump's radius.
        ///
        /// This version has the detect radius synchronized with the absorb radius.
        /// </summary>
        /// <param name="state">The media state required.</param>
        /// <param name="radius">The radius to check.</param>
        /// <returns>Whether the pump can run.</returns>
        protected override bool IsPumpable(Element.State state, int radius)
        {
            var  element      = ElementLoader.GetElementID(filterable.SelectedTag);
            bool validElement = element != SimHashes.Void && element != SimHashes.Vacuum;

            // Force sim update if the element changed
            if (validElement && element != lastElement)
            {
                consumer.elementToConsume = element;
                RecreateSimHandle();
                consumer.RefreshConsumptionRate();
                lastElement = element;
            }
            return(validElement && IsPumpableFixed(gameObject, state, element, radius));
        }
    public void FillTank()
    {
        RocketEngine rocketEngine = null;

        foreach (GameObject item in AttachableBuilding.GetAttachedNetwork(GetComponent <AttachableBuilding>()))
        {
            rocketEngine = item.GetComponent <RocketEngine>();
            if ((Object)rocketEngine != (Object)null && rocketEngine.mainEngine)
            {
                break;
            }
        }
        if ((Object)rocketEngine != (Object)null)
        {
            AddLiquid(ElementLoader.GetElementID(rocketEngine.fuelTag), targetFillMass - MassStored(), ElementLoader.GetElement(rocketEngine.fuelTag).defaultValues.temperature, 0, 0, false, true);
        }
        else
        {
            Debug.LogWarning("Fuel tank couldn't find rocket engine");
        }
    }
示例#4
0
        private void OnOccupantChanged(object data)
        {
            var elementConsumers = GetComponents <PassiveElementConsumer>();

            foreach (PassiveElementConsumer elementConsumer in elementConsumers)
            {
                elementConsumer.EnableConsumption(false);
            }

            if (data != null)
            {
                var consumed_infos = ((GameObject)data)?.GetSMI <IrrigationMonitor.Instance>()?.def.consumedElements;
                if (consumed_infos != null)
                {
                    foreach (var consumeInfo in consumed_infos)
                    {
                        foreach (var elementConsumer in elementConsumers)
                        {
                            var element = ElementLoader.FindElementByHash(elementConsumer.elementToConsume);
                            if (element != null)
                            {
                                if (element.tag != consumeInfo.tag)
                                {
                                    //var traverse = Traverse.Create(elementConsumer);
                                    //traverse.Method("SimUnregister").GetValue();
                                    SimUnregister.Invoke(elementConsumer);
                                    elementConsumer.elementToConsume = ElementLoader.GetElementID(consumeInfo.tag);
                                    //traverse.Method("SimRegister").GetValue();
                                    SimRegister.Invoke(elementConsumer);
                                }
                                elementConsumer.consumptionRate = consumeInfo.massConsumptionRate * 1.5f;
                                elementConsumer.EnableConsumption(true);
                            }
                        }
                    }
                }
            }
        }
示例#5
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);
                }
            }
示例#6
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);
    }