private void rebuildRecipes() { List <RecipeAsset> recipies = RecipeManager.Recipies; List <Stack> items = _inventory.items; //Debug.Log("aaaaaaaaaaaaaaa"+ items.Count); availableRecipies.Clear(); Debug.Log(recipies[0].Requirements.Length); Debug.Log(recipies.Count + "," + items.Count); //return; // Iterate and find the matching recipies in this inventory for (int i = 0; i < recipies.Count; i++) { RecipeAsset recipe = recipies[i]; RecipeAsset.Require[] elements = recipe.Requirements; bool recipeSuccess = false; // Iterate over all required items in the recipe for (int j = 0; j < elements.Length; j++) { bool success = false; // Compare for items in the recipe requirements for (int k = 0; k < items.Count; k++) { int id = items[k].item.id; // The recipe has a match to this item, break out if (elements[j].itemAsset.id != id) { success = true; break; } } // Did the specified item fail to match up? if (!success) { recipeSuccess = false; break; } else { recipeSuccess = true; } } // Recipe has succeeded in matching all its elements, if (recipeSuccess) { if (availableRecipies.Count < 7) { availableRecipies.Add(recipe.Result); } } } }
/* Resets everything back to normal. */ private void Reset() { recipeSelectionActive = false; selectedRecipe = 0; activeRecipe = null; possibleRecipes.Clear(); inputProducts.Clear(); cookingFinished = false; ui.Reset(); }
public static void loadRecipes() { RecipeAsset[] assets = Resources.LoadAll <RecipeAsset>("Recipes/"); Debug.Log("Registering " + assets.Length + " Recipes"); for (int i = 0; i < assets.Length; i++) { RecipeAsset asset = assets[i]; registerRecipe(asset); } }
public void StartCooking(RecipeAsset recipe) { cookingCanvasObject.SetActive(true); recipeSelectionUI.SetActive(false); recipeInputUI.SetActive(false); cookingOverlay.sprite = recipe.outputProduct.productSprite; cookingOverlay.color = quarterOpacity; cookingTime = recipe.cookingTime; timer = 0; cooking = true; fillingBar.sprite = recipe.outputProduct.productSprite; fillingBar.fillAmount = 0; }
public void CreateRecipeButton() { RecipeAsset recipe = RecipeManager.Recipies[currentRecipe]; Inventory inventory = _world.playerObj.GetComponent <InventoryController>().inventory; for (int i = 0; i < recipe.Requirements.Length; i++) { inventory.removeItem(new Item(recipe.Requirements[i].itemAsset.id), recipe.Requirements[i].quantity); } inventory.addItem(new ItemTile(recipe.Result.id, recipe.Result.tileAsset), 1); RefreshRecipe(); UpdateEquipment(); }
/* Shows the selected recipe and highlights the product, the player handed in. */ public void ShowActiveRecipe(RecipeAsset recipe, Product firstProduct) { recipeSelectionUI.SetActive(false); recipeInputUI.SetActive(true); recipeInputLength = recipe.inputProducts.Length; //Select correct background switch (recipeInputLength) { case 1: oneItemBG.color = fullOpacity; break; case 2: twoItemBG.color = fullOpacity; break; case 3: threeItemBG.color = fullOpacity; break; } //Shows input products bool occurredOnce = false; int indexOutput = 0; for (int i = 0; i < recipeInputLength; i++) { inputOverlays[i].sprite = recipe.inputProducts[i].productSprite; indexOutput = i + 1; //Full opacity only, if item was already put in (=fist product) if (recipe.inputProducts[i].Equals(firstProduct) && !occurredOnce) { inputOverlays[i].color = fullOpacity; occurredOnce = true; } else { inputOverlays[i].color = quarterOpacity; } } //Show output product inputOverlays[indexOutput].sprite = recipe.outputProduct.productSprite; inputOverlays[indexOutput].color = quarterOpacity; }
/* Select a recipe using the movement keys. */ private void SelectRecipe() { if (Input.GetKeyDown(player.keyLeft)) { selectedRecipe -= 1; if (selectedRecipe < 0) { selectedRecipe = possibleRecipes.Count - 1; } ui.ShowRecipeSelection(possibleRecipes[selectedRecipe]); } if (Input.GetKeyDown(player.keyRight)) { selectedRecipe += 1; if (selectedRecipe >= possibleRecipes.Count) { selectedRecipe = 0; } ui.ShowRecipeSelection(possibleRecipes[selectedRecipe]); } if (Input.GetKeyDown(player.keyInteract)) { activeRecipe = possibleRecipes[selectedRecipe]; recipeSelectionActive = false; player.AllowMovement(true); ui.ShowActiveRecipe(activeRecipe, inputProducts[0]); // if only one input is needed, start cooking immediatly if (activeRecipe.inputProducts.Length == 1) { StartCoroutine(WaitBeforeCooking()); return; } } }
public void ShowRecipeSelection(RecipeAsset recipe) { recipeSelectionUI.SetActive(true); recipeSelectionProductUI.sprite = recipe.outputProduct.productSprite; }
void RefreshRecipe() { prevRecipe.interactable = currentRecipe > 0; nextRecipe.interactable = currentRecipe < RecipeManager.Recipies.Count - 1; if (currentRecipe >= 0 && currentRecipe < RecipeManager.Recipies.Count) { RecipeAsset recipe = RecipeManager.Recipies[currentRecipe]; Inventory inventory = _world.playerObj.GetComponent <InventoryController>().inventory; bool canCreate = true; for (int i = 0; i < recipe.Requirements.Length; i++) { bool haveItems = false; for (int j = 0; j < inventory.items.Count; j++) { if (inventory.items[j].item.id == recipe.Requirements[i].itemAsset.id) { if (inventory.items[j].count >= recipe.Requirements[i].quantity) { haveItems = true; } break; } } if (!haveItems) { canCreate = false; } } Texture2D tex = recipe.Result.texture; createRecipeButton.image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); createRecipeButton.gameObject.SetActive(canCreate); for (int i = 0; i < recipeRequirements.Length; i++) { if (i < recipe.Requirements.Length) { Texture2D requirementTexture = recipe.Requirements[i].itemAsset.texture; recipeRequirements[i].gameObject.SetActive(true); recipeRequirements[i].sprite = Sprite.Create(requirementTexture, new Rect(0, 0, requirementTexture.width, requirementTexture.height), Vector2.zero); int quantity = recipe.Requirements[i].quantity; string quantityText; quantityText = quantity > 1 ? quantity.ToString() : ""; recipeRequirements[i].transform.FindChild("Quantity").GetComponent <Text>().text = quantityText; } else { recipeRequirements[i].gameObject.SetActive(false); } } } else { createRecipeButton.gameObject.SetActive(false); for (int i = 0; i < recipeRequirements.Length; i++) { recipeRequirements[i].gameObject.SetActive(false); } } }
public static void registerRecipe(RecipeAsset recipe) { recipies.Add(recipe); }