Esempio n. 1
0
        public bool Apply(MonoBehaviour sender, ReagentMix reagentMix)
        {
            if ((tempMin != null || reagentMix.Temperature >= tempMin) &&
                (tempMax != null || reagentMix.Temperature <= tempMax))
            {
                return(false);
            }

            if (!ingredients.All(reagent => reagentMix[reagent.Key] > 0))
            {
                return(false);
            }

            if (!ingredients.Any())
            {
                return(false);
            }
            var reactionAmount = ingredients.Min(i => reagentMix[i.Key] / i.Value);

            if (useExactAmounts == true)
            {
                reactionAmount = (float)Math.Floor(reactionAmount);
                if (reactionAmount == 0)
                {
                    return(false);
                }
            }

            if (!catalysts.All(catalyst =>
                               reagentMix[catalyst.Key] > catalyst.Value * reactionAmount))
            {
                return(false);
            }

            if (inhibitors.All(inhibitor => reagentMix[inhibitor.Key] > inhibitor.Value * reactionAmount))
            {
                return(false);
            }

            foreach (var ingredient in ingredients)
            {
                reagentMix.Subtract(ingredient.Key, reactionAmount * ingredient.Value);
            }

            foreach (var result in results)
            {
                var reactionResult = reactionAmount * result.Value;
                reagentMix.Add(result.Key, reactionResult);
            }

            foreach (var effect in effects)
            {
                effect.Apply(sender, reactionAmount);
            }

            return(true);
        }
Esempio n. 2
0
        public void TransferContainerToBuffer(Reagent reagent, float amount)
        {
            float      capacity     = 0;
            ReagentMix tempTransfer = GetBufferMix();
            float      currentTotal = tempTransfer.Total;

            if (BufferslotOne != null)
            {
                capacity += BufferslotOne.MaxCapacity;
            }

            if (BufferslotTwo != null)
            {
                capacity += BufferslotTwo.MaxCapacity;
            }

            //math
            float space = capacity - currentTotal;

            Logger.LogTrace($"Buffer| capacity:{capacity} total:{currentTotal} space:{space}", Category.Chemistry);

            //part one of transfer: isolate reagents, add to tempTransfer Mix
            if (space > 0)
            {
                Logger.LogTrace($"BEFORE| Mix:{Container.CurrentReagentMix}", Category.Chemistry);
                if (amount < space)
                {
                    Container.CurrentReagentMix.Remove(reagent, amount);
                    tempTransfer.Add(reagent, amount);
                }
                else
                {
                    Container.CurrentReagentMix.Remove(reagent, space);
                    tempTransfer.Add(reagent, space);
                }

                Logger.LogTrace($"AFTER|| Mix:{Container.CurrentReagentMix}", Category.Chemistry);
            }

            //part two of transfer: fill Buffer from tempTransfer Mix
            TransferMixToBuffer(tempTransfer);

            UpdateGui();
        }
Esempio n. 3
0
        public virtual bool Apply(MonoBehaviour sender, ReagentMix reagentMix)
        {
            if (HasIngredients(reagentMix) == false)
            {
                return(false);
            }

            var reactionAmount = GetReactionAmount(reagentMix);

            if (useExactAmounts)
            {
                reactionAmount = (float)Math.Floor(reactionAmount);
                if (reactionAmount == 0)
                {
                    return(false);
                }
            }

            if (CanReactionHappen(reagentMix, reactionAmount) == false)
            {
                return(false);
            }

            foreach (var ingredient in ingredients.m_dict)
            {
                reagentMix.Subtract(ingredient.Key, reactionAmount * ingredient.Value);
            }

            foreach (var result in results.m_dict)
            {
                var reactionResult = reactionAmount * result.Value;
                reagentMix.Add(result.Key, reactionResult);
            }

            foreach (var effect in effects)
            {
                if (effect != null)
                {
                    effect.Apply(sender, reactionAmount);
                }
            }

            return(true);
        }
Esempio n. 4
0
        public virtual bool Apply(MonoBehaviour sender, ReagentMix reagentMix)
        {
            tempMin = hasMinTemp ? (float?)serializableTempMin : null;
            tempMax = hasMaxTemp ? (float?)serializableTempMax : null;

            if (tempMin != null && reagentMix.Temperature <= tempMin ||
                tempMax != null && reagentMix.Temperature >= tempMax)
            {
                return(false);
            }

            if (!ingredients.m_dict.All(reagent => reagentMix[reagent.Key] > 0))
            {
                return(false);
            }

            if (!ingredients.m_dict.Any())
            {
                return(false);
            }

            var reactionAmount = ingredients.m_dict.Min(i => reagentMix[i.Key] / i.Value);

            if (useExactAmounts == true)
            {
                reactionAmount = (float)Math.Floor(reactionAmount);
                if (reactionAmount == 0)
                {
                    return(false);
                }
            }

            if (!catalysts.m_dict.All(catalyst =>
                                      reagentMix[catalyst.Key] >= catalyst.Value * reactionAmount))
            {
                return(false);
            }

            if (inhibitors.m_dict.Count > 0)
            {
                if (inhibitors.m_dict.All(inhibitor => reagentMix[inhibitor.Key] > inhibitor.Value * reactionAmount))
                {
                    return(false);
                }
            }


            foreach (var ingredient in ingredients.m_dict)
            {
                reagentMix.Subtract(ingredient.Key, reactionAmount * ingredient.Value);
            }

            foreach (var result in results.m_dict)
            {
                var reactionResult = reactionAmount * result.Value;
                reagentMix.Add(result.Key, reactionResult);
            }

            foreach (var effect in effects)
            {
                effect.Apply(sender, reactionAmount);
            }

            return(true);
        }