コード例 #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);
        }
コード例 #2
0
ファイル: Reaction.cs プロジェクト: PetMudstone/unitystation
        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);
        }
コード例 #3
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);
        }