Пример #1
0
        // Transfers germs from one object to another using their mass ratios
        public static void TransferByMassRatio(GameObject parent, GameObject child)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }
            PrimaryElement parentElement = parent.GetComponent <PrimaryElement>(),
                           childElement  = child.GetComponent <PrimaryElement>();
            float seedMass;
            int   germs, subGerms;

            // Distribute the germs by mass ratio if there are any
            if (parentElement != null && childElement != null && (seedMass = childElement.
                                                                             Mass) > 0.0f && (germs = parentElement.DiseaseCount) > 0)
            {
                byte disease = parentElement.DiseaseIdx;
                subGerms = Mathf.RoundToInt(germs * seedMass / (seedMass +
                                                                parentElement.Mass));
                // Seed germs
                childElement.AddDisease(disease, subGerms, "TransferToChild");
                // Plant germs
                parentElement.AddDisease(disease, -subGerms, "TransferFromParent");
            }
        }
Пример #2
0
 public void AddDisease(byte disease_idx, int delta, string reason)
 {
     if (delta != 0)
     {
         if ((bool)diseaseRedirectTarget)
         {
             diseaseRedirectTarget.AddDisease(disease_idx, delta, reason);
         }
         else if (useSimDiseaseInfo)
         {
             int gameCell = Grid.PosToCell(this);
             SimMessages.ModifyDiseaseOnCell(gameCell, disease_idx, delta);
         }
         else if (diseaseHandle.IsValid())
         {
             int num = GameComps.DiseaseContainers.AddDisease(diseaseHandle, disease_idx, delta);
             if (num <= 0)
             {
                 GameComps.DiseaseContainers.Remove(base.gameObject);
                 diseaseHandle.Clear();
             }
         }
         else if (delta > 0)
         {
             diseaseHandle = GameComps.DiseaseContainers.Add(base.gameObject, disease_idx, delta);
             Trigger(-1689370368, true);
             Trigger(-283306403, null);
         }
     }
 }
Пример #3
0
    public static SubstanceChunk CreateChunk(Element element, float mass, float temperature, byte diseaseIdx, int diseaseCount, Vector3 position)
    {
        if (temperature <= 0f)
        {
            DebugUtil.LogWarningArgs("GeneratedOre.CreateChunk tried to create a chunk with a temperature <= 0");
        }
        GameObject prefab = Assets.GetPrefab(element.tag);

        if ((UnityEngine.Object)prefab == (UnityEngine.Object)null)
        {
            Debug.LogError("Could not find prefab for element " + element.id.ToString());
        }
        SubstanceChunk component = GameUtil.KInstantiate(prefab, Grid.SceneLayer.Ore, null, 0).GetComponent <SubstanceChunk>();

        component.transform.SetPosition(position);
        component.gameObject.SetActive(true);
        PrimaryElement component2 = component.GetComponent <PrimaryElement>();

        component2.Mass        = mass;
        component2.Temperature = temperature;
        component2.AddDisease(diseaseIdx, diseaseCount, "GeneratedOre.CreateChunk");
        KPrefabID component3 = component.GetComponent <KPrefabID>();

        component3.InitializeTags();
        return(component);
    }
    protected override bool OnWorkTick(Worker worker, float dt)
    {
        base.OnWorkTick(worker, dt);
        PrimaryElement component = GetComponent <PrimaryElement>();

        component.AddDisease(component.DiseaseIdx, -(int)(diseasePerSecond * dt + 0.5f), "Disinfectable.OnWorkTick");
        return(false);
    }
    protected override void OnCompleteWork(Worker worker)
    {
        base.OnCompleteWork(worker);
        PrimaryElement component = GetComponent <PrimaryElement>();

        component.AddDisease(component.DiseaseIdx, -component.DiseaseCount, "Disinfectable.OnCompleteWork");
        GetComponent <KSelectable>().RemoveStatusItem(Db.Get().MiscStatusItems.MarkedForDisinfection, this);
        chore = null;
        Game.Instance.userMenu.Refresh(base.gameObject);
    }
        public static void Postfix(Toilet __instance, ref Worker worker)
        {
            Element element = ElementLoader.FindElementByHash(__instance.solidWastePerUse.elementID);

            byte index = Db.Get().Diseases.GetIndex(__instance.diseaseId);

            Storage massConsumptionTracker = worker.GetComponents <Storage>()[1];

            GameObject go = element.substance.SpawnResource(__instance.transform.GetPosition(), massConsumptionTracker.MassStored(), __instance.solidWasteTemperature, index, __instance.diseasePerFlush, true, false, false);

            Traverse.Create(__instance).Field("storage").Method("Store", go, false, false, true, false).GetValue <GameObject>();
            PrimaryElement component = worker.GetComponent <PrimaryElement>();

            component.AddDisease(index, __instance.diseaseOnDupePerFlush, "Toilet.Flush");
            PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, string.Format(DUPLICANTS.DISEASES.ADDED_POPFX, Db.Get().Diseases[(int)index].Name, __instance.diseasePerFlush + __instance.diseaseOnDupePerFlush), __instance.transform, Vector3.up, 1.5f, false, false);
            __instance.FlushesUsed++;
            Traverse.Create(__instance).Field("meter").Method("SetPositionPercent", (float)__instance.FlushesUsed / (float)__instance.maxFlushes).GetValue();
            Tutorial.Instance.TutorialMessage(Tutorial.TutorialMessages.TM_LotsOfGerms, true);
        }
Пример #7
0
        private bool EmitCommon(int cell, PrimaryElement primary_element, EmitDelegate emit)
        {
            if (primary_element.Mass <= 0.0)
            {
                return(false);
            }
            int disease_to_item1;
            int disease_to_item2;

            CalculateDiseaseTransfer(exhaustPE, primary_element, 0.05f, out disease_to_item1, out disease_to_item2);
            primary_element.ModifyDiseaseCount(-disease_to_item1, "Exhaust transfer");
            primary_element.AddDisease(exhaustPE.DiseaseIdx, disease_to_item2, "Exhaust transfer");
            exhaustPE.ModifyDiseaseCount(-disease_to_item2, "Exhaust transfer");
            exhaustPE.AddDisease(primary_element.DiseaseIdx, disease_to_item1, "Exhaust transfer");
            emit(cell, primary_element);
            primary_element.KeepZeroMassObject = true;
            primary_element.Mass = 0.0f;
            primary_element.ModifyDiseaseCount(int.MinValue, "Exhaust.SimUpdate");
            return(true);
        }
 private bool EmitCommon(int cell, PrimaryElement primary_element, EmitDelegate emit)
 {
     if (primary_element.Mass <= 0f)
     {
         return(false);
     }
     CalculateDiseaseTransfer(exhaustPE, primary_element, 0.05f, out int disease_to_item, out int disease_to_item2);
     primary_element.ModifyDiseaseCount(-disease_to_item, "Exhaust transfer");
     primary_element.AddDisease(exhaustPE.DiseaseIdx, disease_to_item2, "Exhaust transfer");
     exhaustPE.ModifyDiseaseCount(-disease_to_item2, "Exhaust transfer");
     exhaustPE.AddDisease(primary_element.DiseaseIdx, disease_to_item, "Exhaust transfer");
     emit(cell, primary_element);
     if ((Object)vent != (Object)null)
     {
         vent.UpdateVentedMass(primary_element.ElementID, primary_element.Mass);
     }
     primary_element.KeepZeroMassObject = true;
     primary_element.Mass = 0f;
     primary_element.ModifyDiseaseCount(-2147483648, "Exhaust.SimUpdate");
     recentlyExhausted = true;
     return(true);
 }
    protected override List <GameObject> SpawnOrderProduct(ComplexRecipe recipe)
    {
        List <GameObject> list = base.SpawnOrderProduct(recipe);

        foreach (GameObject item in list)
        {
            PrimaryElement component = item.GetComponent <PrimaryElement>();
            if ((Object)component != (Object)null)
            {
                if (item.PrefabID() == (Tag)"MushBar")
                {
                    byte index = Db.Get().Diseases.GetIndex("FoodPoisoning");
                    component.AddDisease(index, 1000, "Made of mud");
                }
                if (item.GetComponent <PrimaryElement>().DiseaseCount > 0)
                {
                    Tutorial.Instance.TutorialMessage(Tutorial.TutorialMessages.TM_DiseaseCooking, true);
                }
            }
        }
        return(list);
    }
Пример #10
0
        public void Shear()
        {
            PrimaryElement component  = base.smi.GetComponent <PrimaryElement>();
            GameObject     gameObject = Util.KInstantiate(Assets.GetPrefab(base.def.itemDroppedOnShear), null, null);

            gameObject.transform.SetPosition(Grid.CellToPosCCC(Grid.CellLeft(Grid.PosToCell(this)), Grid.SceneLayer.Ore));
            PrimaryElement component2 = gameObject.GetComponent <PrimaryElement>();

            component2.Temperature = component.Temperature;
            component2.Mass        = base.def.dropMass;
            component2.AddDisease(component.DiseaseIdx, component.DiseaseCount, "Shearing");
            gameObject.SetActive(true);
            Vector2 initial_velocity = new Vector2(UnityEngine.Random.Range(-1f, 1f) * 1f, UnityEngine.Random.value * 2f + 2f);

            if (GameComps.Fallers.Has(gameObject))
            {
                GameComps.Fallers.Remove(gameObject);
            }
            GameComps.Fallers.Add(gameObject, initial_velocity);
            scaleGrowth.value = 0f;
            UpdateScales(this, 0f);
        }
Пример #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);
    }
    private void Flush(Worker worker)
    {
        ListPool <GameObject, Storage> .PooledList pooledList = ListPool <GameObject, Storage> .Allocate();

        storage.Find(WaterTag, pooledList);
        float num  = 0f;
        float num2 = massConsumedPerUse;

        foreach (GameObject item in pooledList)
        {
            PrimaryElement component = item.GetComponent <PrimaryElement>();
            float          num3      = Mathf.Min(component.Mass, num2);
            component.Mass -= num3;
            num2           -= num3;
            num            += num3 * component.Temperature;
        }
        pooledList.Recycle();
        float num4 = massEmittedPerUse - massConsumedPerUse;

        num += num4 * newPeeTemperature;
        float temperature = num / massEmittedPerUse;
        byte  index       = Db.Get().Diseases.GetIndex(diseaseId);

        storage.AddLiquid(SimHashes.DirtyWater, massEmittedPerUse, temperature, index, diseasePerFlush, false, true);
        if ((UnityEngine.Object)worker != (UnityEngine.Object)null)
        {
            PrimaryElement component2 = worker.GetComponent <PrimaryElement>();
            component2.AddDisease(index, diseaseOnDupePerFlush, "FlushToilet.Flush");
            PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, string.Format(DUPLICANTS.DISEASES.ADDED_POPFX, Db.Get().Diseases[index].Name, diseasePerFlush + diseaseOnDupePerFlush), base.transform, Vector3.up, 1.5f, false, false);
            Tutorial.Instance.TutorialMessage(Tutorial.TutorialMessages.TM_LotsOfGerms, true);
        }
        else
        {
            DebugUtil.LogWarningArgs("Tried to add disease on toilet use but worker was null");
        }
    }
Пример #13
0
 public override void EndTransition(Navigator navigator, Navigator.ActiveTransition transition)
 {
     base.EndTransition(navigator, transition);
     if (transition.end == NavType.Ladder)
     {
         int        cell       = Grid.PosToCell(navigator);
         GameObject gameObject = Grid.Objects[cell, 1];
         if ((Object)gameObject != (Object)null)
         {
             PrimaryElement component = gameObject.GetComponent <PrimaryElement>();
             if ((Object)component != (Object)null)
             {
                 PrimaryElement component2 = navigator.GetComponent <PrimaryElement>();
                 if ((Object)component2 != (Object)null)
                 {
                     SimUtil.DiseaseInfo invalid = SimUtil.DiseaseInfo.Invalid;
                     invalid.idx   = component2.DiseaseIdx;
                     invalid.count = (int)((float)component2.DiseaseCount * 0.005f);
                     SimUtil.DiseaseInfo invalid2 = SimUtil.DiseaseInfo.Invalid;
                     invalid2.idx   = component.DiseaseIdx;
                     invalid2.count = (int)((float)component.DiseaseCount * 0.005f);
                     component2.ModifyDiseaseCount(-invalid.count, "Navigator.EndTransition");
                     component.ModifyDiseaseCount(-invalid2.count, "Navigator.EndTransition");
                     if (invalid.count > 0)
                     {
                         component.AddDisease(invalid.idx, invalid.count, "TransitionDriver.EndTransition");
                     }
                     if (invalid2.count > 0)
                     {
                         component2.AddDisease(invalid2.idx, invalid2.count, "TransitionDriver.EndTransition");
                     }
                 }
             }
         }
     }
 }
Пример #14
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);
    }
Пример #15
0
        private PrimaryElement FindSuitableElement()
        {
            PrimaryElement ret = null;
            // Maybe make it buffer an extra message, that might help?

            // better version: grab stuff from our ass, I mean network - BR

            int x, y;

            Grid.CellToXY(Grid.PosToCell(this), out x, out y);

            JObject message = Z.net.get_message_for("got_packet", x, y);

            if (outstanding && message != null)
            {
                outstanding = false;
                // We have a response from the server, finally ya lazy basterd
                if (message["packet"] != null &&
                    message["packet"].Type == JTokenType.Object)
                {
                    JObject mat_packet  = (JObject)message["packet"];
                    JObject germ_packet = null;
                    if (mat_packet["germs"] != null &&
                        mat_packet["germs"].Type == JTokenType.Object)
                    {
                        germ_packet = (JObject)mat_packet["germs"];
                    }
                    if (dave == null)
                    {
                        dave = GasSourceManager.Instance.CreateChunk(
                            (SimHashes)(-1528777920), 0f, 456f,
                            255, 0, this.transform.GetPosition());
                        steve = dave.GetComponent <PrimaryElement>();
                        steve.KeepZeroMassObject = true;
                    }
                    steve.SetElement((SimHashes)((int)mat_packet["element"]));
                    steve.SetMassTemperature((float)mat_packet["mass"],
                                             (float)mat_packet["temperature"]);
                    string reason = conduitType == ConduitType.Liquid
                        ? "Storage.AddLiquid" : "Storage.AddGasChunk";
                    steve.ModifyDiseaseCount(-steve.DiseaseCount, reason);
                    if (germ_packet != null)
                    {
                        steve.AddDisease((byte)germ_packet["id"],
                                         (int)germ_packet["count"],
                                         reason);
                    }

                    message = null;

                    ret = steve;
                }
            }
            // Only ask for goodies when we are enabled
            if (!outstanding && ztransporter.is_enabled())
            {
                // Send a message to the server asking for goodies

                message = Network.make_message("recv_packet", x, y);
                message.Add("phase", this.conduitType == ConduitType.Liquid ?
                            "Liquid" : "Gas");
                Z.net.send_message(message);
                outstanding = true;
            }
            return(ret);
        }
    private void ConvertMass()
    {
        float speedMultiplier = GetSpeedMultiplier();
        float num             = 1f * speedMultiplier;
        float num2            = 1f;

        for (int i = 0; i < consumedElements.Length; i++)
        {
            ConsumedElement consumedElement = consumedElements[i];
            float           num3            = consumedElement.massConsumptionRate * num * num2;
            if (num3 <= 0f)
            {
                num2 = 0f;
                break;
            }
            float num4 = 0f;
            for (int j = 0; j < storage.items.Count; j++)
            {
                GameObject gameObject = storage.items[j];
                if (!((UnityEngine.Object)gameObject == (UnityEngine.Object)null) && gameObject.HasTag(consumedElement.tag))
                {
                    PrimaryElement component = gameObject.GetComponent <PrimaryElement>();
                    float          num5      = Mathf.Min(num3, component.Mass);
                    num4 += num5 / num3;
                }
            }
            num2 = Mathf.Min(num2, num4);
        }
        if (!(num2 <= 0f))
        {
            SimUtil.DiseaseInfo diseaseInfo = SimUtil.DiseaseInfo.Invalid;
            diseaseInfo.idx   = byte.MaxValue;
            diseaseInfo.count = 0;
            float num6 = 0f;
            float num7 = 0f;
            float num8 = 0f;
            for (int k = 0; k < consumedElements.Length; k++)
            {
                ConsumedElement consumedElement2 = consumedElements[k];
                float           num9             = consumedElement2.massConsumptionRate * num * num2;
                Game.Instance.accumulators.Accumulate(consumedElement2.accumulator, num9);
                for (int l = 0; l < storage.items.Count; l++)
                {
                    GameObject gameObject2 = storage.items[l];
                    if (!((UnityEngine.Object)gameObject2 == (UnityEngine.Object)null))
                    {
                        if (gameObject2.HasTag(consumedElement2.tag))
                        {
                            PrimaryElement component2 = gameObject2.GetComponent <PrimaryElement>();
                            component2.KeepZeroMassObject = true;
                            float num10 = Mathf.Min(num9, component2.Mass);
                            float num11 = num10 / component2.Mass;
                            int   num12 = (int)(num11 * (float)component2.DiseaseCount);
                            float num13 = num10 * component2.Element.specificHeatCapacity;
                            num8            += num13;
                            num7            += num13 * component2.Temperature;
                            component2.Mass -= num10;
                            component2.ModifyDiseaseCount(-num12, "ElementConverter.ConvertMass");
                            num6       += num10;
                            diseaseInfo = SimUtil.CalculateFinalDiseaseInfo(diseaseInfo.idx, diseaseInfo.count, component2.DiseaseIdx, num12);
                            num9       -= num10;
                            if (num9 <= 0f)
                            {
                                break;
                            }
                        }
                        if (num9 <= 0f)
                        {
                            Debug.Assert(num9 <= 0f);
                        }
                    }
                }
            }
            float num14 = (!(num8 > 0f)) ? 0f : (num7 / num8);
            if (onConvertMass != null && num6 > 0f)
            {
                onConvertMass(num6);
            }
            if (outputElements != null && outputElements.Length > 0)
            {
                for (int m = 0; m < outputElements.Length; m++)
                {
                    OutputElement       outputElement = outputElements[m];
                    SimUtil.DiseaseInfo a             = diseaseInfo;
                    if (totalDiseaseWeight <= 0f)
                    {
                        a.idx   = byte.MaxValue;
                        a.count = 0;
                    }
                    else
                    {
                        float num15 = outputElement.diseaseWeight / totalDiseaseWeight;
                        a.count = (int)((float)a.count * num15);
                    }
                    if (outputElement.addedDiseaseIdx != 255)
                    {
                        a = SimUtil.CalculateFinalDiseaseInfo(a, new SimUtil.DiseaseInfo
                        {
                            idx   = outputElement.addedDiseaseIdx,
                            count = outputElement.addedDiseaseCount
                        });
                    }
                    float num16 = outputElement.massGenerationRate * OutputMultiplier * num * num2;
                    Game.Instance.accumulators.Accumulate(outputElement.accumulator, num16);
                    float num17 = 0f;
                    num17 = ((!outputElement.useEntityTemperature && (num14 != 0f || outputElement.minOutputTemperature != 0f)) ? Mathf.Max(outputElement.minOutputTemperature, num14) : GetComponent <PrimaryElement>().Temperature);
                    Element element = ElementLoader.FindElementByHash(outputElement.elementHash);
                    if (outputElement.storeOutput)
                    {
                        PrimaryElement primaryElement = storage.AddToPrimaryElement(outputElement.elementHash, num16, num17);
                        if ((UnityEngine.Object)primaryElement == (UnityEngine.Object)null)
                        {
                            if (element.IsGas)
                            {
                                storage.AddGasChunk(outputElement.elementHash, num16, num17, a.idx, a.count, true, true);
                            }
                            else if (element.IsLiquid)
                            {
                                storage.AddLiquid(outputElement.elementHash, num16, num17, a.idx, a.count, true, true);
                            }
                            else
                            {
                                GameObject go = element.substance.SpawnResource(base.transform.GetPosition(), num16, num17, a.idx, a.count, true, false, false);
                                storage.Store(go, true, false, true, false);
                            }
                        }
                        else
                        {
                            primaryElement.AddDisease(a.idx, a.count, "ElementConverter.ConvertMass");
                        }
                    }
                    else
                    {
                        Vector3 position  = base.transform.GetPosition();
                        float   x         = position.x + outputElement.outputElementOffset.x;
                        Vector3 position2 = base.transform.GetPosition();
                        Vector3 vector    = new Vector3(x, position2.y + outputElement.outputElementOffset.y, 0f);
                        int     num18     = Grid.PosToCell(vector);
                        if (element.IsLiquid)
                        {
                            int idx = element.idx;
                            FallingWater.instance.AddParticle(num18, (byte)idx, num16, num17, a.idx, a.count, true, false, false, false);
                        }
                        else if (element.IsSolid)
                        {
                            element.substance.SpawnResource(vector, num16, num17, a.idx, a.count, false, false, false);
                        }
                        else
                        {
                            SimMessages.AddRemoveSubstance(num18, outputElement.elementHash, CellEventLogger.Instance.OxygenModifierSimUpdate, num16, num17, a.idx, a.count, true, -1);
                        }
                    }
                    if (outputElement.elementHash == SimHashes.Oxygen)
                    {
                        ReportManager.Instance.ReportValue(ReportManager.ReportType.OxygenCreated, num16, base.gameObject.GetProperName(), null);
                    }
                }
            }
            storage.Trigger(-1697596308, base.gameObject);
        }
    }
Пример #17
0
 public void DoReplaceSubstance(int cell)
 {
     if (Grid.IsValidBuildingCell(cell))
     {
         Element element = (!DebugPaintElementScreen.Instance.paintElement.isOn) ? ElementLoader.elements[Grid.ElementIdx[cell]] : ElementLoader.FindElementByHash(DebugPaintElementScreen.Instance.element);
         if (element == null)
         {
             element = ElementLoader.FindElementByHash(SimHashes.Vacuum);
         }
         byte  b    = (!DebugPaintElementScreen.Instance.paintDisease.isOn) ? Grid.DiseaseIdx[cell] : DebugPaintElementScreen.Instance.diseaseIdx;
         float num  = (!DebugPaintElementScreen.Instance.paintTemperature.isOn) ? Grid.Temperature[cell] : DebugPaintElementScreen.Instance.temperature;
         float num2 = (!DebugPaintElementScreen.Instance.paintMass.isOn) ? Grid.Mass[cell] : DebugPaintElementScreen.Instance.mass;
         int   num3 = (!DebugPaintElementScreen.Instance.paintDiseaseCount.isOn) ? Grid.DiseaseCount[cell] : DebugPaintElementScreen.Instance.diseaseCount;
         if (num == -1f)
         {
             num = element.defaultValues.temperature;
         }
         if (num2 == -1f)
         {
             num2 = element.defaultValues.mass;
         }
         if (DebugPaintElementScreen.Instance.affectCells.isOn)
         {
             SimMessages.ReplaceElement(cell, element.id, CellEventLogger.Instance.DebugTool, num2, num, b, num3, -1);
             if (DebugPaintElementScreen.Instance.set_prevent_fow_reveal)
             {
                 Grid.Visible[cell] = 0;
                 Grid.PreventFogOfWarReveal[cell] = true;
             }
             else if (DebugPaintElementScreen.Instance.set_allow_fow_reveal && Grid.PreventFogOfWarReveal[cell])
             {
                 Grid.PreventFogOfWarReveal[cell] = false;
             }
         }
         if (DebugPaintElementScreen.Instance.affectBuildings.isOn)
         {
             List <GameObject> list = new List <GameObject>();
             list.Add(Grid.Objects[cell, 1]);
             list.Add(Grid.Objects[cell, 2]);
             list.Add(Grid.Objects[cell, 9]);
             list.Add(Grid.Objects[cell, 16]);
             list.Add(Grid.Objects[cell, 12]);
             list.Add(Grid.Objects[cell, 16]);
             list.Add(Grid.Objects[cell, 26]);
             foreach (GameObject item in list)
             {
                 if ((Object)item != (Object)null)
                 {
                     PrimaryElement component = item.GetComponent <PrimaryElement>();
                     if (num > 0f)
                     {
                         component.Temperature = num;
                     }
                     if (num3 > 0 && b != 255)
                     {
                         component.ModifyDiseaseCount(-2147483648, "DebugTool.DoReplaceSubstance");
                         component.AddDisease(b, num3, "DebugTool.DoReplaceSubstance");
                     }
                 }
             }
         }
     }
 }
Пример #18
0
            public static bool Prefix(Stomach __instance, ref GameObject ___owner,
                                      ref List <CreatureCalorieMonitor.Stomach.CaloriesConsumedEntry> ___caloriesConsumed)
            {
                if (___owner.PrefabID() == FloralHatchConfig.Id || ___owner.PrefabID() == FloralHatchConfig.BabyId || ___owner.PrefabID() == WoodenHatchConfig.Id || ___owner.PrefabID() == WoodenHatchConfig.BabyId)
                {
                    float num         = 0f;//consumed calories acumulated
                    Tag   tag         = Tag.Invalid;
                    byte  disease_idx = byte.MaxValue;
                    int   num2        = 0;//total germs
                    bool  flag        = false;
                    for (int i = 0; i < ___caloriesConsumed.Count; i++)
                    {
                        CreatureCalorieMonitor.Stomach.CaloriesConsumedEntry value = ___caloriesConsumed[i];
                        if (value.calories > 0f)
                        {
                            Diet.Info dietInfo = __instance.diet.GetDietInfo(value.tag);
                            if (dietInfo != null)
                            {
                                if (!(tag != Tag.Invalid) || !(tag != dietInfo.producedElement))
                                {
                                    num                   += dietInfo.ConvertConsumptionMassToProducedMass(dietInfo.ConvertCaloriesToConsumptionMass(value.calories));
                                    tag                    = dietInfo.producedElement;
                                    disease_idx            = dietInfo.diseaseIdx;
                                    num2                   = (int)(dietInfo.diseasePerKgProduced * num);
                                    value.calories         = 0f;
                                    ___caloriesConsumed[i] = value;
                                    flag                   = (flag || dietInfo.produceSolidTile);
                                }
                            }
                        }
                    }
                    if (num <= 0f || tag == Tag.Invalid)
                    {
                        Debug.Log("tag invalid");
                        return(false);
                    }

                    Element element = ElementLoader.GetElement(tag);

                    if (element == null)
                    {
                        //for food and others
                        GameObject prefab      = Assets.GetPrefab(tag);
                        GameObject gameObject2 = GameUtil.KInstantiate(prefab, Grid.SceneLayer.Ore, null, 0);

                        int            units_c    = 0;
                        PrimaryElement component2 = null;
                        if (___owner.PrefabID() == WoodenHatchConfig.Id || ___owner.PrefabID() == WoodenHatchConfig.BabyId)
                        {
                            // EdiblesManager.FoodInfo food_info = EdiblesManager.GetFoodInfo(tag.ToString());
                            var out_put = prefab.GetComponent <PrimaryElement>();


                            units_c = (int)(num / out_put.Mass);
                            Facing component = ___owner.GetComponent <Facing>();

                            int num3 = Grid.PosToCell(___owner.transform.GetPosition());
                            var pos  = Grid.CellToPosCCC(num3, Grid.SceneLayer.Ore);
                            gameObject2.transform.SetPosition(pos);
                            component2       = gameObject2.GetComponent <PrimaryElement>();
                            component2.Units = units_c;
                        }
                        else
                        {
                            var out_put_edible = prefab.GetComponent <Edible>();

                            var out_put_food_info = out_put_edible.FoodInfo;

                            units_c = (int)(num / out_put_food_info.CaloriesPerUnit);
                            Facing component = ___owner.GetComponent <Facing>();

                            int num3 = Grid.PosToCell(___owner.transform.GetPosition());
                            var pos  = Grid.CellToPosCCC(num3, Grid.SceneLayer.Ore);
                            gameObject2.transform.SetPosition(pos);
                            component2      = gameObject2.GetComponent <PrimaryElement>();
                            component2.Mass = num;
                        }

                        float temperature = ___owner.GetComponent <PrimaryElement>().Temperature;
                        component2.Temperature = temperature;

                        gameObject2.SetActive(true);
                        component2.AddDisease(disease_idx, num2, "ComplexFabricator.CompleteOrder");

                        KPrefabID component3 = ___owner.GetComponent <KPrefabID>();
                        if (!Game.Instance.savedInfo.creaturePoopAmount.ContainsKey(component3.PrefabTag))
                        {
                            Game.Instance.savedInfo.creaturePoopAmount.Add(component3.PrefabTag, 0f);
                        }
                        Dictionary <Tag, float> creaturePoopAmount;
                        Tag prefabTag;
                        (creaturePoopAmount = Game.Instance.savedInfo.creaturePoopAmount)[prefabTag = component3.PrefabTag] = creaturePoopAmount[prefabTag] + num;
                        PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, prefab.name, ___owner.transform, 1.5f, false);
                    }
                    else
                    {
                        ///default option
                        global::Debug.Assert(element != null, "Fail at default option");
                        int   num3        = Grid.PosToCell(___owner.transform.GetPosition());
                        float temperature = ___owner.GetComponent <PrimaryElement>().Temperature;
                        if (element.IsLiquid)
                        {
                            FallingWater.instance.AddParticle(num3, element.idx, num, temperature, disease_idx, num2, true, false, false, false);
                        }
                        else if (element.IsGas)
                        {
                            SimMessages.AddRemoveSubstance(num3, (int)element.idx, CellEventLogger.Instance.ElementConsumerSimUpdate, num, temperature, disease_idx, num2, true, -1);
                        }
                        else if (flag)
                        {
                            Facing component = ___owner.GetComponent <Facing>();
                            int    num4      = component.GetFrontCell();
                            if (!Grid.IsValidCell(num4))
                            {
                                global::Debug.LogWarningFormat("{0} attemping to Poop {1} on invalid cell {2} from cell {3}",
                                                               new object[] { ___owner, element.name, num4, num3 });
                                num4 = num3;
                            }
                            SimMessages.AddRemoveSubstance(num4, (int)element.idx, CellEventLogger.Instance.ElementConsumerSimUpdate, num, temperature, disease_idx, num2, true, -1);
                        }
                        else
                        {
                            element.substance.SpawnResource(Grid.CellToPosCCC(num3, Grid.SceneLayer.Ore), num, temperature, disease_idx, num2, false, false, false);
                        }
                        KPrefabID component2 = ___owner.GetComponent <KPrefabID>();
                        if (!Game.Instance.savedInfo.creaturePoopAmount.ContainsKey(component2.PrefabTag))
                        {
                            Game.Instance.savedInfo.creaturePoopAmount.Add(component2.PrefabTag, 0f);
                        }
                        Dictionary <Tag, float> creaturePoopAmount;
                        Tag prefabTag;
                        (creaturePoopAmount = Game.Instance.savedInfo.creaturePoopAmount)[prefabTag = component2.PrefabTag] = creaturePoopAmount[prefabTag] + num;
                        PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, element.name, ___owner.transform, 1.5f, false);
                    }
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
Пример #19
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);
    }
Пример #20
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);
                }
            }