Exemple #1
0
        public void Tick()
        {
            if (ParentObject.OnWorldMap() || (ParentObject.InInventory != null && ParentObject.InInventory.OnWorldMap()))
            {
                return;
            }
            GetFerments();
            //IPart.AddPlayerMessage("fermentation:\n"+ferments.ToString());
            LiquidVolume volume = ParentObject.GetPart <LiquidVolume>();

            if (volume == null)
            {
                return;
            }

            if (ParentObject.pPhysics.Temperature < 15)
            {
                //IPart.AddPlayerMessage("too cold");
                return;
            }
            int bads  = 0;
            int total = 0;


            var test = volume.ComponentLiquids;

            int adram = (int)Math.Ceiling(1000f / Math.Max(volume.Volume, 1));

            foreach (string f in ferments.Keys.ToList())
            {
                IPart.AddPlayerMessage("ferments:" + f + ":" + ferments[f]);
            }

            foreach (string id in volume._ComponentLiquids.Keys.ToList())
            {
                IPart.AddPlayerMessage("checking liquid:" + id);
                if (ferments.ContainsKey(id) ||
                    ferments.Values.ToList().Contains(id))
                {
                    IPart.AddPlayerMessage("good");
                }
                else
                {
                    bads += volume._ComponentLiquids[id];

                    IPart.AddPlayerMessage("bad");
                }
                total += volume._ComponentLiquids[id];
            }
            total = Math.Max(total, 1);


            if (ParentObject.pPhysics.Temperature > 30f || Stat.Rnd2.NextDouble() < bads / total)
            {
                string result = "putrid";
                if (volume.GetPrimaryLiquid() != null)
                {
                    volume._ComponentLiquids[volume.GetPrimaryLiquid().ID] -= adram;
                }
                if (!volume._ComponentLiquids.ContainsKey(result))
                {
                    volume._ComponentLiquids[result] = 0;
                }
                volume._ComponentLiquids[result] += adram;
            }
            else
            {
                foreach (string id in volume._ComponentLiquids.Keys.ToList())
                {
                    if (LiquidVolume.getLiquid(id) != null)
                    {
                        string SourceLiquidName = id;

                        if (ferments.ContainsKey(SourceLiquidName)) //Its a liquid that ferments

                        {
                            string ResultName = ferments[SourceLiquidName];


                            if (LiquidVolume.getLiquid(SourceLiquidName) != null)
                            {
                                if (LiquidVolume.getLiquid(ResultName) != null)
                                {
                                    string ResultLiquidId = ResultName;

                                    volume._ComponentLiquids[id] = volume._ComponentLiquids[id] - adram;

                                    if (volume._ComponentLiquids[id] <= 0)
                                    {
                                        volume._ComponentLiquids.Remove(id);
                                    }

                                    if (!volume._ComponentLiquids.ContainsKey(ResultLiquidId))
                                    {
                                        volume._ComponentLiquids[ResultLiquidId] = 0;
                                    }

                                    volume._ComponentLiquids[ResultLiquidId] = volume._ComponentLiquids[ResultLiquidId] + adram;
                                }
                                else
                                {
                                    volume._ComponentLiquids[id] = volume._ComponentLiquids[id] - adram;

                                    if (volume._ComponentLiquids[id] <= 0)
                                    {
                                        volume._ComponentLiquids.Remove(id);
                                    }
                                    volume.Volume -= 1;
                                    ParentObject.GetPart <Inventory>().AddObject(GameObject.create(ResultName));
                                }
                            }
                        }
                    }
                }


                List <string> seen = new List <string>();

                foreach (GameObject GO in ParentObject.GetPart <Inventory>().GetObjects())
                {
                    if (GO.HasTag("FermentTo"))
                    {
                        string result = GO.GetTag("FermentTo");

                        if (!seen.Contains(GO.GetBlueprint().Name))
                        {
                            if (GO.Count > 1)
                            {
                                GO.RemoveOne();
                            }
                            else
                            {
                                GO.Destroy();
                            }
                            seen.Add(GO.GetBlueprint().Name);

                            if (LiquidVolume.getLiquid(result) != null)
                            {
                                volume.Volume += 1;

                                if (LiquidVolume.getLiquid(result) == null)
                                {
                                    IPart.AddPlayerMessage("ERROR: Tried to ferment " + GO.DisplayName + " but output was invalid:" + result);
                                }
                                else
                                {
                                    string LiquidID = result;

                                    if (!volume._ComponentLiquids.ContainsKey(LiquidID))
                                    {
                                        volume._ComponentLiquids[LiquidID] = 0;
                                    }

                                    volume._ComponentLiquids[LiquidID] = volume._ComponentLiquids[LiquidID] + adram;
                                }
                            }
                            else
                            {
                                ParentObject.GetPart <Inventory>().AddObject(GameObject.create(result));
                            }
                        }
                    }
                }
            }

            volume.NormalizeProportions();
            volume.RecalculatePrimary();
            volume.RecalculateProperties();
            volume.FlushWeightCaches();
        }