Terraria.ModLoader.RecipeFinder.FindExactRecipe C# (CSharp) Method

FindExactRecipe() public method

public FindExactRecipe ( ) : Recipe
return Recipe
		public Recipe FindExactRecipe()
		{
			for (int k = 0; k < Recipe.numRecipes; k++)
			{
				Recipe recipe = Main.recipe[k];
				bool matches = true;
				List<Item> checkItems = new List<Item>(items);
				for (int i = 0; i < Recipe.maxRequirements; i++)
				{
					Item item = recipe.requiredItem[i];
					if (item.type == 0)
					{
						break;
					}
					bool itemMatched = false;
					for (int j = 0; j < checkItems.Count; j++)
					{
						if (item.type == checkItems[j].type && item.stack == checkItems[j].stack)
						{
							itemMatched = true;
							checkItems.RemoveAt(j);
							break;
						}
					}
					if (!itemMatched)
					{
						matches = false;
						break;
					}
				}
				if (checkItems.Count > 0)
				{
					matches = false;
				}
				List<int> checkGroups = new List<int>(groups);
				List<int> acceptedGroups = GetAcceptedGroups(recipe);
				for (int i = 0; i < acceptedGroups.Count; i++)
				{
					int group = acceptedGroups[i];
					bool groupMatched = false;
					for (int j = 0; j < checkGroups.Count; j++)
					{
						if (group == checkGroups[j])
						{
							groupMatched = true;
							checkGroups.RemoveAt(j);
							break;
						}
					}
					if (!groupMatched)
					{
						matches = false;
						break;
					}
				}
				if (checkGroups.Count > 0)
				{
					matches = false;
				}
				if (result.type != recipe.createItem.type || result.stack != recipe.createItem.stack)
				{
					matches = false;
				}
				List<int> checkTiles = new List<int>(tiles);
				for (int i = 0; i < Recipe.maxRequirements; i++)
				{
					int tile = recipe.requiredTile[i];
					if (tile == -1)
					{
						break;
					}
					bool tileMatched = false;
					for (int j = 0; j < checkTiles.Count; j++)
					{
						if (tile == checkTiles[j])
						{
							tileMatched = true;
							checkTiles.RemoveAt(j);
							break;
						}
					}
					if (!tileMatched)
					{
						matches = false;
						break;
					}
				}
				if (checkTiles.Count > 0)
				{
					matches = false;
				}
				if (needWater != recipe.needWater)
				{
					matches = false;
				}
				else if (needLava != recipe.needLava)
				{
					matches = false;
				}
				else if (needHoney != recipe.needHoney)
				{
					matches = false;
				}
				if (matches)
				{
					return recipe;
				}
			}
			return null;
		}

Usage Example

Exemplo n.º 1
0
        public static void TestRecipeEditor(Mod mod)
        {
            RecipeFinder finder = new RecipeFinder();
            finder.AddIngredient(ItemID.Chain);
            foreach (Recipe recipe in finder.SearchRecipes())
            {
                RecipeEditor editor = new RecipeEditor(recipe);
                editor.DeleteIngredient(ItemID.Chain);
            }

            finder = new RecipeFinder();
            finder.AddRecipeGroup("IronBar");
            finder.AddTile(TileID.Anvils);
            finder.SetResult(ItemID.Chain, 10);
            Recipe recipe2 = finder.FindExactRecipe();
            if (recipe2 != null)
            {
                RecipeEditor editor = new RecipeEditor(recipe2);
                editor.DeleteRecipe();
            }
        }