Aura.Channel.Skills.Life.Cooking.JudgeQuality C# (CSharp) Метод

JudgeQuality() приватный Метод

Calculates quality based on recipe and ingredients.
The formula used in this method is unofficial. While it does feel very similar in some test cases, it could potentially create very different results. Officials also RNG the results, which this method currently does not. The Help fields in the return value specify a tip on what went wrong with the cooking attempt, if certain requirements are fulfilled. In that case it will set the item to the item in question, and the amount to the amount the ingredient differed from the recipe. If the value is lower than 0, it was less, if it's greater, it was more. If no helpful tip could be found, item is null.
private JudgeQuality ( RecipeData recipe, List ingredients ) : Judgement
recipe RecipeData
ingredients List
Результат Judgement
		private Judgement JudgeQuality(RecipeData recipe, List<Ingredient> ingredients)
		{
			Judgement result;
			result.Quality = 0;
			result.HelpItem = null;
			result.HelpAmount = 0;

			var total = (float)recipe.MainIngredients.Sum(a => a.Amount);

			foreach (var ingredient in ingredients)
			{
				// Every item *should* only appear once in main or other.
				var ingredientData = recipe.MainIngredients.FirstOrDefault(a => a.ItemId == ingredient.Item.Info.Id);
				if (ingredientData == null)
				{
					ingredientData = recipe.OtherIngredients.FirstOrDefault(a => a.ItemId == ingredient.Item.Info.Id);
					if (ingredientData == null)
					{
						Log.Error("Cooking.JudgeQuality: Failed to get ingredient data for item '{0}' in recipe '{1},{2}'.", ingredient.Item.Info.Id, recipe.Method, recipe.ItemId);
						break;
					}
				}

				// Calculate the amount difference between the provided
				// ingredient and the recipe.
				var amount = ingredient.Amount;
				var ideal = (1f / total * ingredientData.Amount);
				var difference = ideal - amount;
				var differenceAbs = Math.Abs(difference);

				// Calculate quality
				var rate = 1f - (1f / ideal * (differenceAbs * 2f));
				var qualityAdd = ingredientData.QualityMin + rate * (ingredientData.QualityMax - ingredientData.QualityMin);

				result.Quality = Math2.Clamp(-100, 100, result.Quality + qualityAdd);

				// Save the ingredient with the biggest difference,
				// for the help message.
				if (differenceAbs > 0.05f && Math.Abs(result.HelpAmount) < differenceAbs)
				{
					result.HelpAmount = -difference;
					result.HelpItem = ingredient.Item;
				}
			}

			return result;
		}