private static void OnMassChanged(HandleVector <int> .Handle handle, object other_data)
    {
        OreSizeVisualizerData data           = GameComps.OreSizeVisualizers.GetData(handle);
        PrimaryElement        primaryElement = data.primaryElement;
        float num = primaryElement.Mass;

        if (other_data != null)
        {
            Pickupable     pickupable = (Pickupable)other_data;
            PrimaryElement component  = pickupable.GetComponent <PrimaryElement>();
            num += component.Mass;
        }
        MassTier massTier = default(MassTier);

        for (int i = 0; i < MassTiers.Length; i++)
        {
            if (num <= MassTiers[i].massRequired)
            {
                massTier = MassTiers[i];
                break;
            }
        }
        KBatchedAnimController component2 = primaryElement.GetComponent <KBatchedAnimController>();

        component2.Play(massTier.animName, KAnim.PlayMode.Once, 1f, 0f);
        KCircleCollider2D component3 = primaryElement.GetComponent <KCircleCollider2D>();

        if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
        {
            component3.radius = massTier.colliderRadius;
        }
        primaryElement.Trigger(1807976145, null);
    }
        public void Emit(float dt)
        {
            PrimaryElement firstPrimaryElement = GetFirstPrimaryElement();

            if (!((UnityEngine.Object)firstPrimaryElement == (UnityEngine.Object)null))
            {
                Storage component = GetComponent <Storage>();
                float   mass      = firstPrimaryElement.Mass;
                float   num       = Mathf.Min(mass, base.master.emptyRate * dt);
                if (!(num <= 0f))
                {
                    Tag prefabTag = firstPrimaryElement.GetComponent <KPrefabID>().PrefabTag;
                    component.ConsumeAndGetDisease(prefabTag, num, out SimUtil.DiseaseInfo disease_info, out float aggregate_temperature);
                    Vector3 position = base.transform.GetPosition();
                    position.y += 1.8f;
                    bool flag = GetComponent <Rotatable>().GetOrientation() == Orientation.FlipH;
                    position.x += ((!flag) ? 0.2f : (-0.2f));
                    int num2 = Grid.PosToCell(position) + ((!flag) ? 1 : (-1));
                    if (Grid.Solid[num2])
                    {
                        num2 += (flag ? 1 : (-1));
                    }
                    Element element = firstPrimaryElement.Element;
                    byte    idx     = element.idx;
                    if (element.IsLiquid)
                    {
                        FallingWater.instance.AddParticle(num2, idx, num, aggregate_temperature, disease_info.idx, disease_info.count, true, false, false, false);
                    }
                    else
                    {
                        SimMessages.ModifyCell(num2, idx, aggregate_temperature, num, disease_info.idx, disease_info.count, SimMessages.ReplaceType.None, false, -1);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Swap the dupes facing before starting the reactable
        /// </summary>
        static void Prefix(GameObject new_reactor, Navigator.ActiveTransition transition)
        {
            PrimaryElement dupe = new_reactor?.GetComponent <PrimaryElement>();

            if (dupe != null)
            {
                Navigator navigator = dupe.GetComponent <Navigator>();

                if (navigator != null)
                {
                    NavGrid.Transition nextTransition = navigator.GetNextTransition();

                    if (nextTransition.x < 0)
                    {
                        // Mirror dupes facing direction to the initial direction
                        dupe.GetComponent <Facing>()?.SetFacing(true);
                    }
                }
            }
        }
Пример #4
0
        static public void Postfix(GameObject go)
        {
            PrimaryElement firstPrimaryElement = this.GetFirstPrimaryElement();

            if ((UnityEngine.Object)firstPrimaryElement == (UnityEngine.Object)null)
            {
                return;
            }
            Storage component = this.GetComponent <Storage>();
            float   num       = Mathf.Min(firstPrimaryElement.Mass, this.master.emptyRate * dt);

            if ((double)num <= 0.0)
            {
                return;
            }
            Tag prefabTag = firstPrimaryElement.GetComponent <KPrefabID>().PrefabTag;

            SimUtil.DiseaseInfo disease_info;
            float aggregate_temperature;

            component.ConsumeAndGetDisease(prefabTag, num, out disease_info, out aggregate_temperature);
            Vector3 position = this.transform.GetPosition();

            position.y += 1.8f;
            bool flag = this.GetComponent <Rotatable>().GetOrientation() == Orientation.FlipH;

            position.x += !flag ? 0.2f : -0.2f;
            int index = Grid.PosToCell(position) + (!flag ? 1 : -1);

            if (Grid.Solid[index])
            {
                index += !flag ? -1 : 1;
            }
            Element element = firstPrimaryElement.Element;
            byte    idx     = element.idx;

            ConduitDispenser conduitDispenser = go.AddOrGet <ConduitDispenser>();

            if (!conduitDispenser.IsConnected)
            {
                if (element.IsLiquid)
                {
                    FallingWater.instance.AddParticle(index, idx, num, aggregate_temperature, disease_info.idx, disease_info.count, true, false, false, false);
                }
                else
                {
                    SimMessages.ModifyCell(index, (int)idx, aggregate_temperature, num, disease_info.idx, disease_info.count, SimMessages.ReplaceType.None, false, -1);
                }
            }
        }
Пример #5
0
    private unsafe static float OnGetTemperature(PrimaryElement primary_element)
    {
        SimTemperatureTransfer component = primary_element.GetComponent <SimTemperatureTransfer>();
        float result;

        if (Sim.IsValidHandle(component.simHandle))
        {
            int handleIndex = Sim.GetHandleIndex(component.simHandle);
            result            = Game.Instance.simData.elementChunks[handleIndex].temperature;
            component.deltaKJ = Game.Instance.simData.elementChunks[handleIndex].deltaKJ;
        }
        else
        {
            result = primary_element.InternalTemperature;
        }
        return(result);
    }
Пример #6
0
 private bool MatchesConduit(PrimaryElement element)
 {
     if (ConduitType == ConduitType.Gas)
     {
         return(element.Element.IsGas);
     }
     if (ConduitType == ConduitType.Liquid)
     {
         return(element.Element.IsLiquid);
     }
     //All elements can be Pickupable as long as they are in a bottle/canister
     if (ConduitType == ConduitType.Solid)
     {
         return(element.GetComponent <Pickupable>() != null);
     }
     return(false);
 }
 private static void DumpIncorrectFertilizers(Storage storage, PlantElementAbsorber.ConsumeInfo[] consumed_infos, bool validate_solids)
 {
     if (!((Object)storage == (Object)null))
     {
         for (int num = storage.items.Count - 1; num >= 0; num--)
         {
             GameObject gameObject = storage.items[num];
             if (!((Object)gameObject == (Object)null))
             {
                 PrimaryElement component = gameObject.GetComponent <PrimaryElement>();
                 if (!((Object)component == (Object)null) && !((Object)gameObject.GetComponent <ElementChunk>() == (Object)null))
                 {
                     if (validate_solids)
                     {
                         if (!component.Element.IsSolid)
                         {
                             continue;
                         }
                     }
                     else if (!component.Element.IsLiquid)
                     {
                         continue;
                     }
                     bool      flag       = false;
                     KPrefabID component2 = component.GetComponent <KPrefabID>();
                     if (consumed_infos != null)
                     {
                         for (int i = 0; i < consumed_infos.Length; i++)
                         {
                             PlantElementAbsorber.ConsumeInfo consumeInfo = consumed_infos[i];
                             if (component2.HasTag(consumeInfo.tag))
                             {
                                 flag = true;
                                 break;
                             }
                         }
                     }
                     if (!flag)
                     {
                         storage.Drop(gameObject, true);
                     }
                 }
             }
         }
     }
 }
Пример #8
0
            // Token: 0x0600004E RID: 78 RVA: 0x000034A0 File Offset: 0x000016A0
            public void Emit(float dt)
            {
                PrimaryElement firstPrimaryElement = this.GetFirstPrimaryElement();

                if (firstPrimaryElement == null)
                {
                    return;
                }
                Storage component = this.GetComponent <Storage>();
                float   num       = Mathf.Min(firstPrimaryElement.Mass, this.master.EmptyRate * dt);

                if ((double)num <= 0.0)
                {
                    return;
                }
                Tag prefabTag = firstPrimaryElement.GetComponent <KPrefabID>().PrefabTag;

                SimUtil.DiseaseInfo diseaseInfo;
                float temperature;
                float amount_consumed;

                // public void ConsumeAndGetDisease(Tag tag, float amount, out float amount_consumed, out SimUtil.DiseaseInfo disease_info, out float aggregate_temperature)
                component.ConsumeAndGetDisease(prefabTag, num, out amount_consumed, out diseaseInfo, out temperature);
                Vector3 position = this.transform.GetPosition();

                position.y += 1.8f;
                bool flag = this.GetComponent <Rotatable>().GetOrientation() == Orientation.FlipH;

                position.x += (flag ? -0.2f : 0.2f);
                int num2 = Grid.PosToCell(position) + (flag ? -1 : 1);

                if (Grid.Solid[num2])
                {
                    num2 += (flag ? 1 : -1);
                }
                Element element = firstPrimaryElement.Element;
                byte    idx     = element.idx;

                if (element.IsLiquid)
                {
                    FallingWater.instance.AddParticle(num2, idx, num, temperature, diseaseInfo.idx, diseaseInfo.count, true);
                    return;
                }
                SimMessages.ModifyCell(num2, (int)idx, temperature, num, diseaseInfo.idx, diseaseInfo.count);
            }
Пример #9
0
    private unsafe static void OnSetTemperature(PrimaryElement primary_element, float temperature)
    {
        if (temperature <= 0f)
        {
            KCrashReporter.Assert(false, "STT.OnSetTemperature - Tried to set <= 0 degree temperature");
            temperature = 293f;
        }
        SimTemperatureTransfer component = primary_element.GetComponent <SimTemperatureTransfer>();

        if (Sim.IsValidHandle(component.simHandle))
        {
            float mass          = primary_element.Mass;
            float heat_capacity = (!(mass >= 0.01f)) ? 0f : (mass * primary_element.Element.specificHeatCapacity);
            SimMessages.SetElementChunkData(component.simHandle, temperature, heat_capacity);
            int handleIndex = Sim.GetHandleIndex(component.simHandle);
            Game.Instance.simData.elementChunks[handleIndex].temperature = temperature;
        }
        else
        {
            primary_element.InternalTemperature = temperature;
        }
    }
    private bool CreateDiseaseInfo_PrimaryElement()
    {
        if ((Object)selectedTarget == (Object)null)
        {
            return(false);
        }
        PrimaryElement component = selectedTarget.GetComponent <PrimaryElement>();

        if ((Object)component == (Object)null)
        {
            return(false);
        }
        if (component.DiseaseIdx != 255 && component.DiseaseCount > 0)
        {
            Disease   disease         = Db.Get().Diseases[component.DiseaseIdx];
            int       environmentCell = Grid.PosToCell(component.transform.GetPosition());
            KPrefabID component2      = component.GetComponent <KPrefabID>();
            BuildFactorsStrings(component.DiseaseCount, component.Element.idx, environmentCell, component.Mass, component.Temperature, component2.Tags, disease);
            return(true);
        }
        return(false);
    }
Пример #11
0
    protected override bool OnWorkTick(Worker worker, float dt)
    {
        PrimaryElement component = worker.GetComponent <PrimaryElement>();

        if (component.DiseaseCount > 0)
        {
            SimUtil.DiseaseInfo diseaseInfo = default(SimUtil.DiseaseInfo);
            diseaseInfo.idx   = component.DiseaseIdx;
            diseaseInfo.count = Mathf.CeilToInt((float)component.DiseaseCount * (1f - Mathf.Pow(fractionalDiseaseRemoval, dt)) - (float)absoluteDiseaseRemoval);
            SimUtil.DiseaseInfo b = diseaseInfo;
            component.ModifyDiseaseCount(-b.count, "Shower.RemoveDisease");
            accumulatedDisease = SimUtil.CalculateFinalDiseaseInfo(accumulatedDisease, b);
            Storage        component2     = GetComponent <Storage>();
            PrimaryElement primaryElement = component2.FindPrimaryElement(outputTargetElement);
            if ((Object)primaryElement != (Object)null)
            {
                PrimaryElement component3 = primaryElement.GetComponent <PrimaryElement>();
                component3.AddDisease(accumulatedDisease.idx, accumulatedDisease.count, "Shower.RemoveDisease");
                accumulatedDisease = SimUtil.DiseaseInfo.Invalid;
            }
        }
        return(false);
    }
Пример #12
0
        private void Emit(float dt)
        {
            SoggyCarpet carpetBelow = null;

            bool doDrip = true;

            if (Grid.Solid[cellBelow])
            {
                // Do not drip if solid tile below
                doDrip = false;

                // But...
                Grid.ObjectLayers[(int)ObjectLayer.FoundationTile].TryGetValue(cellBelow, out GameObject go);
                if (go != null)
                {
                    KPrefabID prefabID = go.GetComponent <KPrefabID>();

                    // Drip if there's a mesh tile below
                    if (prefabID.PrefabTag == MeshTileConfig.ID)
                    {
                        doDrip = true;
                    }

                    // Drip if there's another tile below, mass transfer implemented below
                    carpetBelow = go.GetComponent <SoggyCarpet>();
                    if (carpetBelow != null)
                    {
                        doDrip = true;
                    }
                }
            }
            else if (Grid.Mass[cellBelow] > maxEmitPressure)
            {
                // Do not drip in non-solid tiles that are over 500kg of pressure
                doDrip = false;
            }

            if (!doDrip)
            {
                return;
            }

            PrimaryElement firstPrimaryElement = storage.FindFirstWithMass(GameTags.Liquid);

            if (firstPrimaryElement == null)
            {
                return;
            }

            Element element = firstPrimaryElement.Element;

            if (element == null)
            {
                return;
            }
            if (!element.IsLiquid)
            {
                return;
            }
            byte elementIndex = element.idx;

            float massToDrip = Mathf.Min(firstPrimaryElement.Mass, dripRate * dt);

            if (massToDrip <= 0f)
            {
                return;
            }

            Tag prefabTag = firstPrimaryElement.GetComponent <KPrefabID>().PrefabTag;

            storage.ConsumeAndGetDisease(prefabTag, massToDrip, out float mass, out SimUtil.DiseaseInfo diseaseInfo, out float temperature);

            if (carpetBelow != null)
            {
                carpetBelow.storage.AddLiquid(element.id, mass, temperature, diseaseInfo.idx, diseaseInfo.count);
            }
            else
            {
                FallingWater.instance.AddParticle(myCell, elementIndex, mass, temperature, diseaseInfo.idx, diseaseInfo.count, true, false, false, false);
            }
        }
Пример #13
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);
    }
Пример #14
0
    protected override void OnCompleteWork(Worker worker)
    {
        float num  = 0f;
        float num2 = 0f;
        bool  flag = true;

        foreach (GameObject item in storage.items)
        {
            if (!((UnityEngine.Object)item == (UnityEngine.Object)null))
            {
                PrimaryElement component = item.GetComponent <PrimaryElement>();
                if (!((UnityEngine.Object)component == (UnityEngine.Object)null))
                {
                    num  += component.Mass;
                    num2 += component.Temperature * component.Mass;
                    flag  = (flag && component.HasTag(GameTags.Liquifiable));
                }
            }
        }
        if (num <= 0f)
        {
            DebugUtil.LogWarningArgs(base.gameObject, "uhhh this constructable is about to generate a nan", "Item Count: ", storage.items.Count);
        }
        else
        {
            if (flag)
            {
                initialTemperature = Mathf.Min(num2 / num, 318.15f);
            }
            else
            {
                initialTemperature = Mathf.Clamp(num2 / num, 288.15f, 318.15f);
            }
            KAnimGraphTileVisualizer component2  = GetComponent <KAnimGraphTileVisualizer>();
            UtilityConnections       connections = (!((UnityEngine.Object)component2 == (UnityEngine.Object)null)) ? component2.Connections : ((UtilityConnections)0);
            if (IsReplacementTile)
            {
                int        cell = Grid.PosToCell(base.transform.GetLocalPosition());
                GameObject replacementCandidate = building.Def.GetReplacementCandidate(cell);
                if ((UnityEngine.Object)replacementCandidate != (UnityEngine.Object)null)
                {
                    SimCellOccupier component3 = replacementCandidate.GetComponent <SimCellOccupier>();
                    if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
                    {
                        component3.DestroySelf(delegate
                        {
                            if ((UnityEngine.Object) this != (UnityEngine.Object)null && (UnityEngine.Object)base.gameObject != (UnityEngine.Object)null)
                            {
                                FinishConstruction(connections);
                            }
                        });
                    }
                    else
                    {
                        Conduit component4 = replacementCandidate.GetComponent <Conduit>();
                        if ((UnityEngine.Object)component4 != (UnityEngine.Object)null)
                        {
                            ConduitFlow flowManager = component4.GetFlowManager();
                            flowManager.MarkForReplacement(cell);
                        }
                        BuildingComplete component5 = replacementCandidate.GetComponent <BuildingComplete>();
                        if ((UnityEngine.Object)component5 != (UnityEngine.Object)null)
                        {
                            component5.Subscribe(-21016276, delegate
                            {
                                FinishConstruction(connections);
                            });
                        }
                        else
                        {
                            Debug.LogWarning("Why am I trying to replace a: " + replacementCandidate.name);
                            FinishConstruction(connections);
                        }
                    }
                    KAnimGraphTileVisualizer component6 = replacementCandidate.GetComponent <KAnimGraphTileVisualizer>();
                    if ((UnityEngine.Object)component6 != (UnityEngine.Object)null)
                    {
                        component6.skipCleanup = true;
                    }
                    PrimaryElement component7   = replacementCandidate.GetComponent <PrimaryElement>();
                    float          mass         = component7.Mass;
                    float          temperature  = component7.Temperature;
                    byte           diseaseIdx   = component7.DiseaseIdx;
                    int            diseaseCount = component7.DiseaseCount;
                    Debug.Assert(component7.Element != null && component7.Element.tag != (Tag)null);
                    Deconstructable.SpawnItem(component7.transform.GetPosition(), component7.GetComponent <Building>().Def, component7.Element.tag, mass, temperature, diseaseIdx, diseaseCount);
                    replacementCandidate.Trigger(1606648047, building.Def.TileLayer);
                    replacementCandidate.DeleteObject();
                }
            }
            else
            {
                FinishConstruction(connections);
            }
            PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Building, GetComponent <KSelectable>().GetName(), base.transform, 1.5f, false);
        }
    }