public PotionScriptableObject matchPotionWithSelected(PotionScriptableObject selectedPotion) { if (selectedPotion.Equals(charismaPotion)) { return(charismaPotion); } return(null); }
public void SetPotionToCraft(PotionScriptableObject potion) { potionToCraft = potion; for (int i = 0; i < potion.ingredients.Count; i++) { ingredientsSprite[i].gameObject.SetActive(true); ingredientsSprite[i].sprite = potion.ingredients[i].sprite; ingredientsText[i].text = Inventory.instance.GetAmount(potion.ingredients[i]._name, potion.amountOfIngredients[i]); } }
public bool CheckIngredients(PotionScriptableObject potion) { Debug.Log("Checking ingredients..."); List <IngredientScriptableObject> requiredIngredients = new List <IngredientScriptableObject>(potion.ingredients); if (requiredIngredients == null) { Debug.Log("no potion has been selected"); return(false); } List <int> ingredientAmount = new List <int>(potion.amountOfIngredients); //List<int> ingredientAmount = new List<int>(); int checkedIngredients = 0; for (int i = 0; i < requiredIngredients.Count; i++) { //int value; //ingredientAmount.Add(itemsToCollect.(requiredIngredients[i]._name)); //Debug.Log("amount ingredient required: " + ingredientAmount[i] + " of " + requiredIngredients[i].name); bool found = false; foreach (Item it in itemList) { if (requiredIngredients[i] == it.ingredient) { checkedIngredients++; if (it.amount >= ingredientAmount[i]) { Debug.Log("it: " + it.amount + " required: " + ingredientAmount[i]); found = true; continue; } else { Debug.Log("No enough ingredients for " + potion._name); return(false); } } } if (!(checkedIngredients > 0)) { Debug.Log("Ingredients for " + potion._name + " are missing"); return(false); //no ingredients were checked so there were none } //Debug.Log("Missing ingredient for " + potion._name); if (!found) { return(false); } } return(true); }
public void MakePotion() { PotionScriptableObject potionToCraft = ListOfPotions.instance.GetPotionToCraft(); if (!potionToCraft || potionToCraft.amountOfPotion <= 0) { Debug.Log("Already crafted"); return; } if (Inventory.instance == null) { Debug.LogError("No inventory was assigned in craftPotion component"); return; } //if have enough ingredient, enable craft if (!Inventory.instance.CheckIngredients(potionToCraft)) { Debug.Log("I don't have enough ingredients"); return; } //take away ingredients for (int i = 0; i < potionToCraft.ingredients.Count; i++) { IngredientScriptableObject ingredient = potionToCraft.ingredients[i]; int amountRequired = potionToCraft.amountOfIngredients[i]; for (int j = 0; j < amountRequired; j++) { Inventory.instance.RemoveIngredient(ingredient); Debug.Log("Removed ingredient"); } } potionToCraft.amountOfPotion--; Debug.Log("I crafted a potion"); ListOfPotions.instance.SetPotionToCraft(potionToCraft); GetComponent <AudioSource>().Play(); foreach (PotionScriptableObject p in Inventory.instance.potionsToCraft) { if (p.amountOfPotion > 0) { return; } } StartCoroutine(AllDone()); }
void DisplayOrder() { int index = Random.Range(1, Inventory.instance.potionsOrdered.Count) - 1; if (index >= 0) { potionOrder = Inventory.instance.potionsOrdered[index]; Inventory.instance.potionsOrdered.Remove(Inventory.instance.potionsOrdered[index]); } else { return; } string _order = SelectOrderPhrasing(); string _reason = SelectReasonPhrasing(); text.text = _order + " " + potionOrder._name + " " + "<sprite name=" + potionOrder._name + "> " + " " + _reason; }