コード例 #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();
        }