Example #1
0
        private void OnFilterChanged(Tag tag)
        {
            FilteredTag = tag;
            Element element = ElementLoader.GetElement(FilteredTag);

            if (element != null)
            {
                FilteredElement = element.id;
            }
            GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, !IsValidFilter, null);
            GetComponent <Operational>().SetFlag(filterFlag, IsValidFilter);
            Temp = Math.Max(Temp, element.lowTemp);
            Temp = Math.Min(Temp, element.highTemp);
            Temp = Math.Max(Temp, MinAllowedTemperature);
            Temp = Math.Min(Temp, MaxAllowedTemperature);
            SetSliderValue(Temp, -1);

            /*if (DetailsScreen.Instance != null && !inUpdate)
             * {
             *  inUpdate = true;
             *  try
             *  {
             *      DetailsScreen.Instance.Refresh(gameObject);
             *  }
             *  catch (Exception) { }
             *  inUpdate = false;
             * }*/
        }
        public static GasExposure GetElementExposition(int cell, int xWidth, int yHeight)
        {
            GasExposure exp;

            exp.OxygenMass = 0;
            exp.OtherMass  = 0;
            Element oxygen = ElementLoader.GetElement(GameTags.Oxygen);

            for (int x = 0; x < xWidth; x++)
            {
                for (int y = 0; y < yHeight; y++)
                {
                    int offsetCell = Grid.OffsetCell(cell, x, y);
                    if (Grid.Element[offsetCell] == oxygen)
                    {
                        exp.OxygenMass += Grid.Mass[offsetCell];
                    }
                    else if (Grid.Element[offsetCell].IsGas)
                    {
                        exp.OtherMass += Grid.Mass[offsetCell];
                    }
                }
            }

            return(exp);
        }
Example #3
0
 public static void Postfix()
 {
     MakeRadioactive(ElementLoader.GetElement(SimHashes.Radium.ToString()));
     MakeRadioactive(ElementLoader.GetElement(SimHashes.UraniumOre.ToString()));
     MakeRadioactive(ElementLoader.GetElement(SimHashes.EnrichedUranium.ToString()));
     MakeRadioactive(ElementLoader.GetElement(SimHashes.DepletedUranium.ToString()));
 }
Example #4
0
        // формулы расчета тепла и прироста температуры для порции хладагента массой minCoolantMass
        // для правильности расчета должны быть аналогичны формулам внутри LiquidCooledRefinery.SpawnOrderProduct
        public static float CalculateEnergyDelta(this LiquidCooledRefinery @this, ComplexRecipe recipe)
        {
            var firstresult = recipe.results[0];
            var element     = ElementLoader.GetElement(firstresult.material);

            return(GameUtil.CalculateEnergyDeltaForElementChange(firstresult.amount, element.specificHeatCapacity, element.highTemp, @this.outputTemperature) * @this.thermalFudge);
        }
Example #5
0
        private void OnFilterChanged(Tag tag)
        {
            mySlider = (ISingleSliderControl)this;

            FilteredTag = tag;
            Element element = ElementLoader.GetElement(FilteredTag);

            if (element != null)
            {
                FilteredElement = element.id;
            }
            GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, !IsValidFilter, null);
            Temp = Math.Max(Temp, element.lowTemp);
            Temp = Math.Min(Temp, element.highTemp);
            Temp = Math.Max(Temp, MinAllowedTemperature);
            Temp = Math.Min(Temp, MaxAllowedTemperature);
            mySlider.SetSliderValue(Temp, -1);
            if (DetailsScreen.Instance != null && !inUpdate)
            {
                inUpdate = true;
                try
                {
                    DetailsScreen.Instance.Refresh(gameObject);
                }
                catch (Exception) { }
                inUpdate = false;
            }
        }
Example #6
0
        /// <summary>
        /// Reads a portion of a binary stream to populate this building config.
        /// </summary>
        /// <param name="binaryReader">The <see cref="BinaryReader"/> encapsulating the binary information to read</param>
        /// <returns>True if the read succeeded, false otherwise</returns>
        public bool ReadBinary(BinaryReader binaryReader)
        {
            try {
                Offset      = new Vector2I(binaryReader.ReadInt32(), binaryReader.ReadInt32());
                BuildingDef = Assets.GetBuildingDef(binaryReader.ReadString());

                int selectedElementCount = binaryReader.ReadInt32();
                for (int i = 0; i < selectedElementCount; ++i)
                {
                    Tag elementTag;

                    //Only add the tag to the list if it describes a valid element in game.
                    if (ElementLoader.GetElement(elementTag = new Tag(binaryReader.ReadInt32())) != null)
                    {
                        SelectedElements.Add(elementTag);
                    }
                }

                Orientation = (Orientation)binaryReader.ReadInt32();
                Flags       = binaryReader.ReadInt32();
                return(true);
            }

            catch (System.Exception) {
                return(false);
            }
        }
            /// <summary>
            /// Applied before GetMaterialTooltips runs.
            /// </summary>
            internal static bool Prefix(Tag tag, ref string __result)
            {
                var        text    = BUFFER;
                var        element = ElementLoader.GetElement(tag);
                GameObject prefabGO;

                text.Clear();
                text.Append(tag.ProperName());
                if (element != null)
                {
                    var descriptors = EL_DESCRIPTORS;
                    descriptors.Clear();
                    AddModifiers(element.attributeModifiers, text);
                    element.GetSignificantMaterialPropertyDescriptors(EL_DESCRIPTORS);
                    if (descriptors.Count > 0)
                    {
                        int n = descriptors.Count;
                        text.AppendLine();
                        for (int i = 0; i < n; i++)
                        {
                            text.Append(Constants.TABBULLETSTRING).Append(Util.
                                                                          StripTextFormatting(descriptors[i].text)).AppendLine();
                        }
                    }
                }
                else if ((prefabGO = Assets.TryGetPrefab(tag)) != null && prefabGO.
                         TryGetComponent(out PrefabAttributeModifiers prefabMods))
                {
                    AddModifiers(prefabMods.descriptors, text);
                }
                __result = text.ToString();
                return(false);
            }
Example #8
0
        private void OnFilterChanged(Tag tag)
        {
            if (refreshing)
            {
                return;
            }

            Element element = ElementLoader.GetElement(tag);

            if (element != null)
            {
                filteredElement = element.id;
                anim.SetSymbolTint("gasframes", element.substance.uiColour);
                anim.SetSymbolTint("liquid", element.substance.uiColour);
                anim.SetSymbolTint("liquid_top", element.substance.uiColour);

                minTemp = element.lowTemp;
                maxTemp = element.highTemp;

                Temp = Mathf.Clamp(Temp, element.lowTemp, element.highTemp);
            }

            bool invalidElement = (!tag.IsValid || tag == GameTags.Void);

            selectable.ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, invalidElement, null);
            operational.SetFlag(filterFlag, !invalidElement);
        }
Example #9
0
    public List <Descriptor> GetResultDescriptions(ComplexRecipe recipe)
    {
        List <Descriptor> list = new List <Descriptor>();

        ComplexRecipe.RecipeElement[] results = recipe.results;
        foreach (ComplexRecipe.RecipeElement recipeElement in results)
        {
            GameObject prefab         = Assets.GetPrefab(recipeElement.material);
            string     formattedByTag = GameUtil.GetFormattedByTag(recipeElement.material, recipeElement.amount, GameUtil.TimeSlice.None);
            list.Add(new Descriptor(string.Format(UI.UISIDESCREENS.FABRICATORSIDESCREEN.RECIPEPRODUCT, prefab.GetProperName(), formattedByTag), string.Format(UI.UISIDESCREENS.FABRICATORSIDESCREEN.TOOLTIPS.RECIPEPRODUCT, prefab.GetProperName(), formattedByTag), Descriptor.DescriptorType.Requirement, false));
            Element element = ElementLoader.GetElement(recipeElement.material);
            if (element != null)
            {
                List <Descriptor> materialDescriptors = GameUtil.GetMaterialDescriptors(element);
                GameUtil.IndentListOfDescriptors(materialDescriptors, 1);
                list.AddRange(materialDescriptors);
            }
            else
            {
                List <Descriptor> effectDescriptors = GameUtil.GetEffectDescriptors(GameUtil.GetAllDescriptors(prefab, false));
                GameUtil.IndentListOfDescriptors(effectDescriptors, 1);
                list.AddRange(effectDescriptors);
            }
        }
        return(list);
    }
Example #10
0
 private void OnDeserialized()
 {
     if (ElementLoader.GetElement(FilteredTag) == null)
     {
         return;
     }
     filterable.SelectedTag = FilteredTag;
     OnFilterChanged(FilteredTag);
 }
Example #11
0
    public void FillTank()
    {
        Element    element = ElementLoader.GetElement(fuelTag);
        GameObject go      = element.substance.SpawnResource(base.gameObject.transform.GetPosition(), fuelStorage.capacityKg / 2f, element.defaultValues.temperature, byte.MaxValue, 0, false, false, false);

        fuelStorage.Store(go, false, false, true, false);
        element = ElementLoader.GetElement(GameTags.OxyRock);
        go      = element.substance.SpawnResource(base.gameObject.transform.GetPosition(), fuelStorage.capacityKg / 2f, element.defaultValues.temperature, byte.MaxValue, 0, false, false, false);
        fuelStorage.Store(go, false, false, true, false);
    }
Example #12
0
        public float GetSliderMin(int index)
        {
            Element element = ElementLoader.GetElement(FilteredTag);

            if (element == null)
            {
                return(0.0f);
            }
            return(Math.Max(element.lowTemp, MinAllowedTemperature));
        }
Example #13
0
        float ISliderControl.GetSliderMax(int index)
        {
            Element element = ElementLoader.GetElement(FilteredTag);

            if (element == null)
            {
                return(100.0f);
            }
            return(Math.Min(element.highTemp, MaxAllowedTemperature));
        }
Example #14
0
        private void OnFilterChanged(Tag tag)
        {
            FilteredTag = tag;
            Element element = ElementLoader.GetElement(FilteredTag);

            if (element != null)
            {
                FilteredElement = element.id;
            }
            GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, !IsValidFilter, null);
        }
 private string GetSpawnableQuantity()
 {
     if (ElementLoader.GetElement(info.id.ToTag()) != null)
     {
         return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_ELEMENT_QUANTITY, GameUtil.GetFormattedMass(info.quantity, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"), Assets.GetPrefab(info.id).GetProperName()));
     }
     if (Game.Instance.ediblesManager.GetFoodInfo(info.id) != null)
     {
         return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_ELEMENT_QUANTITY, GameUtil.GetFormattedCaloriesForItem(info.id, info.quantity, GameUtil.TimeSlice.None, true), Assets.GetPrefab(info.id).GetProperName()));
     }
     return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_ELEMENT_COUNT, Assets.GetPrefab(info.id).GetProperName(), info.quantity.ToString()));
 }
Example #16
0
    private void OnFilterChanged(Tag tag)
    {
        bool    on      = true;
        Element element = ElementLoader.GetElement(tag);

        if (element != null)
        {
            filteredElem = element.id;
            on           = (filteredElem == SimHashes.Void || filteredElem == SimHashes.Vacuum);
        }
        GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, on, null);
    }
Example #17
0
        /// <summary>
        /// Reads a JSON object to populate this building config.
        /// </summary>
        /// <param name="rootObject">The <see cref="JObject"/> to use to read from</param>
        public void ReadJSON(JObject rootObject)
        {
            JToken offsetToken           = rootObject.SelectToken("offset");
            JToken buildingDefToken      = rootObject.SelectToken("buildingdef");
            JToken selectedElementsToken = rootObject.SelectToken("selected_elements");
            JToken orientationToken      = rootObject.SelectToken("orientation");
            JToken flagsToken            = rootObject.SelectToken("flags");

            if (offsetToken != null && offsetToken.Type == JTokenType.Object)
            {
                JToken xToken = offsetToken.SelectToken("x");
                JToken yToken = offsetToken.SelectToken("y");

                if (xToken != null && xToken.Type == JTokenType.Integer || yToken != null && yToken.Type == JTokenType.Integer)
                {
                    Offset = new Vector2I(xToken == null ? 0 : xToken.Value <int>(), yToken == null ? 0 : yToken.Value <int>());
                }
            }

            if (buildingDefToken != null && buildingDefToken.Type == JTokenType.String)
            {
                BuildingDef = Assets.GetBuildingDef(buildingDefToken.Value <string>());
            }

            if (selectedElementsToken != null && selectedElementsToken.Type == JTokenType.Array)
            {
                JArray selectedElementTokens = selectedElementsToken.Value <JArray>();

                if (selectedElementTokens != null)
                {
                    foreach (JToken selectedElement in selectedElementTokens)
                    {
                        Tag elementTag;

                        if (selectedElement.Type == JTokenType.Integer && ElementLoader.GetElement(elementTag = new Tag(selectedElement.Value <int>())) != null)
                        {
                            SelectedElements.Add(elementTag);
                        }
                    }
                }
            }

            if (orientationToken != null && orientationToken.Type == JTokenType.Integer)
            {
                Orientation = (Orientation)orientationToken.Value <int>();
            }

            if (flagsToken != null && flagsToken.Type == JTokenType.Integer)
            {
                Flags = flagsToken.Value <int>();
            }
        }
    private string GetFertilizationLabel(GameObject go)
    {
        FertilizationMonitor.Instance sMI = go.GetSMI <FertilizationMonitor.Instance>();
        string text = Db.Get().Amounts.Fertilization.Name;

        PlantElementAbsorber.ConsumeInfo[] consumedElements = sMI.def.consumedElements;
        for (int i = 0; i < consumedElements.Length; i++)
        {
            PlantElementAbsorber.ConsumeInfo consumeInfo = consumedElements[i];
            string text2 = text;
            text = text2 + "\n    • " + ElementLoader.GetElement(consumeInfo.tag).name + " " + GameUtil.GetFormattedMass(consumeInfo.massConsumptionRate, GameUtil.TimeSlice.PerCycle, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}");
        }
        return(text);
    }
 private void OnElementSelected(Tag element_tag)
 {
     if (element_tag.IsValid)
     {
         Element element = ElementLoader.GetElement(element_tag);
         bool    on      = true;
         if (element != null)
         {
             desiredElementIdx = (byte)ElementLoader.GetElementIndex(element.id);
             on = (element.id == SimHashes.Void || element.id == SimHashes.Vacuum);
         }
         GetComponent <KSelectable>().ToggleStatusItem(Db.Get().BuildingStatusItems.NoFilterElementSelected, on, null);
     }
 }
    private void OnConduitConnectionChanged(object data)
    {
        bool pause = (bool)data;

        ManualDeliveryKG[] array = deliveryComponents;
        foreach (ManualDeliveryKG manualDeliveryKG in array)
        {
            Element element = ElementLoader.GetElement(manualDeliveryKG.requestedItemTag);
            if (element != null && element.IsLiquid)
            {
                manualDeliveryKG.Pause(pause, "pipe connected");
            }
        }
    }
Example #21
0
        internal static PortDisplayOutput AddAlgaeHabitat(GameObject go)
        {
            ApplyExhaust.AddOutput(go, new CellOffset(0, 1), SimHashes.Oxygen);

            Element element = ElementLoader.GetElement(SimHashes.DirtyWater.CreateTag());
            Color32 color   = element.substance.conduitColour;

            color.a = 255;
            PortDisplayOutput     outputPort = new PortDisplayOutput(ConduitType.Liquid, new CellOffset(0, 0), null, color);
            PortDisplayController controller = go.AddOrGet <PortDisplayController>();

            controller.AssignPort(go, outputPort);

            return(outputPort);
        }
Example #22
0
        private void OnFilterChanged(Tag tag)
        {
            this.desiredElement = SimHashes.Void;
            if (!tag.IsValid)
            {
                return;
            }
            Element element = ElementLoader.GetElement(tag);

            if (element == null)
            {
                return;
            }
            this.desiredElement = element.id;
        }
Example #23
0
 /// <summary>
 /// A wrapper method used on BuildingDef.Build to avoid melting buildings built at cold
 /// temperatures.
 /// </summary>
 private static GameObject BuildAtTemp(BuildingDef def, int cell, Orientation orient,
                                       Storage storage, IList <Tag> elements, float temperature, bool sound,
                                       float timeBuilt)
 {
     if (elements != null && elements.Count > 0)
     {
         // Lower temperature to at least the element's melt point - 1 K
         var pe = ElementLoader.GetElement(elements[0]);
         if (pe != null)
         {
             temperature = Math.Min(temperature, Math.Max(1.0f, pe.highTemp - 1.0f));
         }
     }
     return(def.Build(cell, orient, storage, elements, temperature, sound, timeBuilt));
 }
Example #24
0
        internal static PortDisplayOutput AddOilWell(GameObject go)
        {
            ApplyExhaust.AddOutput(go, new CellOffset(2, 1), SimHashes.CrudeOil);

            Element element = ElementLoader.GetElement(SimHashes.Methane.CreateTag());
            Color32 color   = element.substance.conduitColour;

            color.a = 255;
            PortDisplayOutput     outputPort = new PortDisplayOutput(ConduitType.Gas, new CellOffset(1, 1), null, color);
            PortDisplayController controller = go.AddOrGet <PortDisplayController>();

            controller.AssignPort(go, outputPort);

            return(outputPort);
        }
Example #25
0
        /// <summary>
        /// Adds thermal tooltips to the descriptors shown in the product information pane
        /// (the menu when selecting a build material).
        /// </summary>
        /// <param name="effectsPane">The pane to modify.</param>
        /// <param name="elementTag">The element that is selected.</param>
        public void AddThermalInfo(DescriptorPanel effectsPane, Tag elementTag)
        {
            var element = ElementLoader.GetElement(elementTag);
            var desc    = default(Descriptor);

            if (element != null && Def != null)
            {
                var descriptors = GameUtil.GetMaterialDescriptors(element);
                // Get building mass from its def (primary element is in slot 0)
                var   masses = Def.Mass;
                float tc = element.thermalConductivity * Def.ThermalConductivity, shc =
                    element.specificHeatCapacity, mass = ThermalTranspilerPatch.
                                                         GetAdjustedMass(Def.BuildingComplete, (masses != null && masses.Length >
                                                                                                0) ? masses[0] : 0.0f), tMass = GameUtil.GetDisplaySHC(mass * shc);
                string deg = GameUtil.GetTemperatureUnitSuffix()?.Trim(), kDTU = STRINGS.UI.
                                                                                 UNITSUFFIXES.HEAT.KDTU.text.Trim();
                // GetMaterialDescriptors returns a fresh list
                desc.SetupDescriptor(STRINGS.ELEMENTS.MATERIAL_MODIFIERS.EFFECTS_HEADER,
                                     STRINGS.ELEMENTS.MATERIAL_MODIFIERS.TOOLTIP.EFFECTS_HEADER);
                descriptors.Insert(0, desc);
                // Thermal Conductivity
                desc.SetupDescriptor(string.Format(ThermalTooltipsStrings.EFFECT_CONDUCTIVITY,
                                                   tc), string.Format(ThermalTooltipsStrings.BUILDING_CONDUCTIVITY,
                                                                      Def.Name, GameUtil.GetFormattedThermalConductivity(tc), tc, deg,
                                                                      STRINGS.UI.UNITSUFFIXES.HEAT.DTU_S.text.Trim()));
                desc.IncreaseIndent();
                descriptors.Add(desc);
                // Thermal Mass
                desc.SetupDescriptor(string.Format(ThermalTooltipsStrings.EFFECT_THERMAL_MASS,
                                                   tMass, kDTU, deg), string.Format(ThermalTooltipsStrings.
                                                                                    BUILDING_THERMAL_MASS, Def.Name, tMass, kDTU, deg));
                descriptors.Add(desc);
                // Melt Temperature
                var hotElement = element.highTempTransition;
                if (hotElement.IsValidTransition(element))
                {
                    string meltTemp = GameUtil.GetFormattedTemperature(element.highTemp +
                                                                       ExtendedThermalTooltip.TRANSITION_HYSTERESIS);
                    desc.SetupDescriptor(string.Format(ThermalTooltipsStrings.
                                                       EFFECT_MELT_TEMPERATURE, meltTemp), string.Format(
                                             ThermalTooltipsStrings.BUILDING_MELT_TEMPERATURE, Def.Name, meltTemp,
                                             hotElement.FormatName(STRINGS.UI.StripLinkFormatting(element.name))));
                    descriptors.Add(desc);
                }
                effectsPane.SetDescriptors(descriptors);
                effectsPane.gameObject.SetActive(true);
            }
        }
    private string GetCurrentQuantity()
    {
        if (ElementLoader.GetElement(info.id.ToTag()) != null)
        {
            float amount = WorldInventory.Instance.GetAmount(info.id.ToTag());
            return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_CURRENT_AMOUNT, GameUtil.GetFormattedMass(amount, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")));
        }
        if (Game.Instance.ediblesManager.GetFoodInfo(info.id) != null)
        {
            float calories = RationTracker.Get().CountRationsByFoodType(info.id, true);
            return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_CURRENT_AMOUNT, GameUtil.GetFormattedCalories(calories, GameUtil.TimeSlice.None, true)));
        }
        float amount2 = WorldInventory.Instance.GetAmount(info.id.ToTag());

        return(string.Format(UI.IMMIGRANTSCREEN.CARE_PACKAGE_CURRENT_AMOUNT, amount2.ToString()));
    }
Example #27
0
        private static void Postfix(RockCrusherConfig __instance)
        {
            Debug.Log("RockCrusherConfig.ConfigureBuildingTemplate postfix loaded");
            ComplexRecipe complexRecipe;

            Tag regolith_tag = SimHashes.Regolith.CreateTag();
            Tag sand_tag     = SimHashes.Sand.CreateTag();

            List <Element> list = new List <Element>()
            {
                ElementLoader.GetElement(SimHashes.Cuprite.CreateTag()),
                ElementLoader.GetElement(SimHashes.AluminumOre.CreateTag()),
                ElementLoader.GetElement(SimHashes.GoldAmalgam.CreateTag()),
                ElementLoader.GetElement(SimHashes.IronOre.CreateTag()),
                ElementLoader.GetElement(SimHashes.Wolframite.CreateTag()),
            };

            foreach (Element element in list)
            {
                Element highTempTransition = element.highTempTransition;
                Element lowTempTransition  = highTempTransition.lowTempTransition;
                if (lowTempTransition != element)
                {
                    ComplexRecipe.RecipeElement[] inputs = new ComplexRecipe.RecipeElement[]
                    {
                        new ComplexRecipe.RecipeElement(lowTempTransition.tag, 100f),
                        new ComplexRecipe.RecipeElement(regolith_tag, 50f),
                    };
                    ComplexRecipe.RecipeElement[] outputs = new ComplexRecipe.RecipeElement[]
                    {
                        new ComplexRecipe.RecipeElement(element.tag, 100f),
                        new ComplexRecipe.RecipeElement(sand_tag, 50f),
                    };
                    string obsolete_id = ComplexRecipeManager.MakeObsoleteRecipeID("RockCrusher", element.tag);
                    string text        = ComplexRecipeManager.MakeRecipeID("RockCrusher", inputs, outputs);
                    complexRecipe             = new ComplexRecipe(text, inputs, outputs);
                    complexRecipe.time        = 40f;
                    complexRecipe.description = string.Format("Grind up {0} to create {1}.", lowTempTransition.name, element.name);
                    complexRecipe.nameDisplay = ComplexRecipe.RecipeNameDisplay.IngredientToResult;
                    complexRecipe.fabricators = new List <Tag>
                    {
                        TagManager.Create("RockCrusher")
                    };
                    ComplexRecipeManager.Get().AddObsoleteIDMapping(obsolete_id, text);
                }
            }
        }
Example #28
0
    private int ElementSorter(Tag at, Tag bt)
    {
        GameObject    gameObject    = Assets.TryGetPrefab(at);
        IHasSortOrder hasSortOrder  = (!((Object)gameObject != (Object)null)) ? null : gameObject.GetComponent <IHasSortOrder>();
        GameObject    gameObject2   = Assets.TryGetPrefab(bt);
        IHasSortOrder hasSortOrder2 = (!((Object)gameObject2 != (Object)null)) ? null : gameObject2.GetComponent <IHasSortOrder>();

        if (hasSortOrder == null || hasSortOrder2 == null)
        {
            return(0);
        }
        Element element  = ElementLoader.GetElement(at);
        Element element2 = ElementLoader.GetElement(bt);

        if (element != null && element2 != null && element.buildMenuSort == element2.buildMenuSort)
        {
            return(element.idx.CompareTo(element2.idx));
        }
        return(hasSortOrder.sortOrder.CompareTo(hasSortOrder2.sortOrder));
    }
Example #29
0
            public static void Prefix(CreatureCalorieMonitor.Instance __instance)
            {
                GameObject go = __instance.gameObject;

                if (go != null && go.name.Contains("Oilfloater")) // include modded ones
                {
                    int   higherGerms = Numbers.GetGermCount(go, Numbers.IndexZombieSpores);
                    float bonus       = Numbers.PercentOfMaxGerms(higherGerms);

                    Tag   tag    = Tag.Invalid;
                    float amount = 0.0f;
                    List <CreatureCalorieMonitor.Stomach.CaloriesConsumedEntry> caloriesConsumed;
                    caloriesConsumed = Traverse.Create(__instance.stomach).Field("caloriesConsumed").GetValue <List <CreatureCalorieMonitor.Stomach.CaloriesConsumedEntry> >();
                    if (caloriesConsumed == null || caloriesConsumed.Count == 0)
                    {
                        return;
                    }
                    for (int index = 0; index < caloriesConsumed.Count; ++index)
                    {
                        CreatureCalorieMonitor.Stomach.CaloriesConsumedEntry caloriesConsumedEntry = caloriesConsumed[index];
                        if (caloriesConsumedEntry.calories > 0)
                        {
                            Diet.Info dietInfo = __instance.stomach.diet.GetDietInfo(caloriesConsumedEntry.tag);
                            if (dietInfo != null && (!(tag != Tag.Invalid) || !(tag != dietInfo.producedElement)))
                            {
                                amount += dietInfo.ConvertConsumptionMassToProducedMass(dietInfo.ConvertCaloriesToConsumptionMass(caloriesConsumedEntry.calories));
                                tag     = dietInfo.producedElement;
                            }
                        }
                    }

                    amount *= bonus * Settings.Instance.MaxSlicksterBonus;

                    Element element     = ElementLoader.GetElement(tag);
                    float   temperature = go.GetComponent <PrimaryElement>().Temperature;
                    if (element.IsLiquid && amount > 0)
                    {
                        FallingWater.instance.AddParticle(Grid.PosToCell(go), element.idx, amount, temperature, Numbers.IndexZombieSpores, higherGerms, true);
                    }
                }
            }
            /// <summary>
            /// Applied before GetMaterialDescriptors runs.
            /// </summary>
            internal static bool Prefix(Tag tag, ref List <Descriptor> __result)
            {
                var        descriptors = EL_DESCRIPTORS;
                var        element     = ElementLoader.GetElement(tag);
                GameObject prefabGO;

                descriptors.Clear();
                if (element != null)
                {
                    // If element is defined
                    GetMaterialDescriptors(element.attributeModifiers, descriptors);
                    element.GetSignificantMaterialPropertyDescriptors(descriptors);
                }
                else if ((prefabGO = Assets.TryGetPrefab(tag)) != null && prefabGO.
                         TryGetComponent(out PrefabAttributeModifiers prefabMods))
                {
                    GetMaterialDescriptors(prefabMods.descriptors, descriptors);
                }
                __result = descriptors;
                return(false);
            }