Esempio n. 1
0
        private void BloodToLiver(ReagentContainerBody blood)
        {
            float tickPullProcessingAmnt = RelatedPart.TotalModified * processAmount;
            float drawnAmount            = 0;

            //debug.AppendLine("==== STAGE 1 || BLOOD TO PROCESSING ====");

            //figure out how much we are going to process or remove
            lock (blood.CurrentReagentMix.reagents)
            {
                foreach (Reagent reagent in blood.CurrentReagentMix.reagents.Keys)
                {
                    bool alcohol = Alcohols.AlcoholicReagents.Contains(reagent);
                    bool toxic   = Toxins.Contains(reagent);
                    if (alcohol || toxic)
                    {
                        float amount = Mathf.Min(tickPullProcessingAmnt, RelatedPart.BloodContainer.CurrentReagentMix[reagent]);
                        amount = Mathf.Min(amount,
                                           (processingContainer.MaxCapacity - processingContainer.ReagentMixTotal) - drawnAmount);
                        tempArray.Add(new Tuple <Reagent, float>(reagent, amount));

                        if (processingContainer.IsFull)
                        {
                            Logger.LogTrace("Liver is full, please try again. or don't.", Category.Health);
                            break;
                        }

                        drawnAmount            += amount;
                        tickPullProcessingAmnt -= amount;
                        if (tickPullProcessingAmnt <= 0)
                        {
                            break;
                        }
                    }
                }
            }

            //debug.AppendLine($"Drawn from blood to liver: {drawnAmount}");

            //take what we are gonna process or remove, out of the blood
            foreach (Tuple <Reagent, float> reagent in tempArray)
            {
                //debug.AppendLine($"{reagent.Item2.ToString(CultureInfo.DefaultThreadCurrentCulture)} of {reagent.Item1}\n");
                processingContainer.CurrentReagentMix.Add(reagent.Item1, reagent.Item2);
                blood.CurrentReagentMix.Remove(reagent.Item1, reagent.Item2);
                processingContainer.ReagentsChanged();
            }

            tempArray.Clear();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the body part as part of the circulatory system
        /// </summary>
        public void BloodInitialise()
        {
            BloodContainer = this.GetComponent <ReagentContainerBody>();
            if (BloodContainer.ContentsSet == false)
            {
                if (isBloodCirculated)
                {
                    HealthMaster.CirculatorySystem.ReadyBloodPool.TransferTo(BloodContainer.CurrentReagentMix, BloodStoredMax);
                    //BloodContainer.CurrentReagentMix.Add(Nutriment, 0.01f);
                }
                BloodContainer.ContentsSet = true;
            }
            if (bloodType == null)
            {
                bloodType = HealthMaster.CirculatorySystem.BloodType;
            }

            AddModifier(HungerModifier);
        }
Esempio n. 3
0
        public override void ImplantPeriodicUpdate()
        {
            //Liver has failed or just generally unable to process things, so don't let it.
            if (RelatedPart.TotalModified == 0)
            {
                return;
            }

            float tickPullProcessingAmnt = RelatedPart.TotalModified * processAmount;
            float tickClearAmount        = tickPullProcessingAmnt * flushMultiplier;

            ReagentContainerBody blood = RelatedPart.BloodContainer;

            List <Tuple <Reagent, float> > tempArray = new List <Tuple <Reagent, float> >();

            float drawnAmount = 0;

            //figure out how much we are going to process or remove
            lock (blood.CurrentReagentMix.reagents)
            {
                foreach (Reagent reagent in blood.CurrentReagentMix.reagents.Keys)
                {
                    if (Alcohols.AlcoholicReagents.Contains(reagent) || Toxins.Contains(reagent))
                    {
                        float amount = Mathf.Min(tickPullProcessingAmnt, RelatedPart.BloodContainer.CurrentReagentMix[reagent]);
                        amount = Mathf.Min(amount, (processingContainer.MaxCapacity - processingContainer.ReagentMixTotal) - drawnAmount);

                        tempArray.Add(new Tuple <Reagent, float>(reagent, amount));

                        if (processingContainer.IsFull)
                        {
                            Logger.LogTrace("Liver is full, please try again. or don't.", Category.Health);
                            break;
                        }

                        drawnAmount            += amount;
                        tickPullProcessingAmnt -= amount;
                        if (tickPullProcessingAmnt <= 0)
                        {
                            break;
                        }
                    }
                }
            }

            //take what we are gonna process or remove, out of the blood
            foreach (Tuple <Reagent, float> reagent in tempArray)
            {
                processingContainer.CurrentReagentMix.Add(reagent.Item1, reagent.Item2);
                blood.CurrentReagentMix.Remove(reagent.Item1, reagent.Item2);
            }
            tempArray.Clear();

            //calculate what's going to be removed, seeing as processing will happen in the reactionset
            lock (processingContainer.CurrentReagentMix.reagents)
            {
                foreach (Reagent reagent in processingContainer.CurrentReagentMix.reagents.Keys)
                {
                    //TODO: remove check for toxins when they are more integrated with reactions, with a metabolism rate, and liver damage. my intention is to do so in the pr changing alchohol
                    if (Toxins.Contains(reagent) || reagent == ethanolReagent)
                    {
                        float amount = Mathf.Min(tickClearAmount, processingContainer.CurrentReagentMix[reagent]);

                        //setup to remove from liver
                        tempArray.Add(new Tuple <Reagent, float>(reagent, amount));

                        tickClearAmount -= amount;
                        if (tickClearAmount <= 0)
                        {
                            break;
                        }
                    }
                }
            }

            //remove what's going to be removed
            foreach (Tuple <Reagent, float> reagent in tempArray)
            {
                processingContainer.CurrentReagentMix.Remove(reagent.Item1, reagent.Item2);
            }
            tempArray.Clear();
        }
Esempio n. 4
0
 public override void SetUpSystems()
 {
     circ      = bodyPart.HealthMaster.GetComponent <CirculatorySystemBase>();
     blood     = RelatedPart.BloodContainer;
     tempArray = new List <Tuple <Reagent, float> >();
 }