public void Sell(Item item) { if (item is NonConsumable) { NonConsumable itm = item as NonConsumable; if (!itm.bought) { playerInventory.items.Add(item); playerInventory.oro -= item.price; itm.bought = false; } else { Debug.Log("Ya tienes el Item"); } } else { if (item.price < playerInventory.oro) { playerInventory.items.Add(item); playerInventory.oro -= item.price; } else { Debug.Log("Dinero insuficiente"); } } }
public void equipItem(NonConsumable _nonCons, GameObject butt) { AudioClipController.Instance.audioSource.clip = AudioClipController.Instance.consumeButton; AudioClipController.Instance.audioSource.Play(); Inventory.Instance.nonConsEquipped = _nonCons; GameObject text = butt.transform.GetChild(2).gameObject; equipped.transform.position = text.transform.position; }
private void Equip(NonConsumable item) { for (int i = 0; i < equipables.Length; i++) { if (equipables [i] == null) { equipables[i] = item; item.equiped = true; item.Equip(); break; } if (i == 2) { Debug.Log("Ya tienes 3 items equipados"); } } }
public void BuyItem(CurrencyTypes _currencyTypes, Item _item, GameObject butt) { //Button consumButt = butt.transform.GetChild(4).GetComponent<Button>(); ItemDataBase itemDB = new ItemDataBase(); int indexProduct = 0; List <Item> auxProducts = new List <Item>(); if (Singleton.Instance.mCurrencies[(int)_currencyTypes] >= _item.Curren[_currencyTypes]) { //butt.transform.GetChild(4).gameObject.SetActive(true); AudioClipController.Instance.audioSource.clip = AudioClipController.Instance.audioBuyButton; AudioClipController.Instance.audioSource.Play(); if (_item is Consumable) { Singleton.Instance.mCurrencies[(int)_currencyTypes] -= _item.Curren[_currencyTypes]; Consumable item = _item as Consumable; int index; if (item.propProducts.Count <= 0) { item.Amount--; Inventory.Instance.myItems.Remove(item); } if (Inventory.Instance.myItems.Contains(item)) { item.Amount++; foreach (Consumable p in item.propProducts) { p.Amount += p.auxAmount; } index = Inventory.Instance.myItems.IndexOf(item); Inventory.Instance.myItems[index] = item; } else { foreach (Item i in itemDB.itemList) { if (i.Name == _item.Name) { indexProduct = itemDB.itemList.IndexOf(i); auxProducts = itemDB.itemList[indexProduct].propProducts; _item.propProducts = auxProducts; } } item.Amount++; Inventory.Instance.myItems.Add(item); #region Consumir desde la tienda //consumButt.onClick.RemoveAllListeners(); /* * consumButt.onClick.AddListener(delegate * { * List<Item> cons = new List<Item>(); * * foreach (Consumable f in item.propProducts) * { * f.Amount--; * * if (f.Amount <= 0) * { * cons.Remove(f); * } * else * { * cons.Add(f); * } * * } * * item.propProducts = cons; * index = Inventory.Instance.myItems.IndexOf(item); * * if (item.propProducts.Count <= 0) * { * Inventory.Instance.myItems.Remove(item); * } * else * { * Inventory.Instance.myItems[index] = item; * } * * * /* * index = Inventory.Instance.myItems.IndexOf(item); * * * if (item.Amount > 0 && item.Amount <= 5) * { * item.Amount--; * Inventory.Instance.myItems[index] = item; * butt.transform.GetChild(5).gameObject.GetComponent<Text>().text = item.Amount.ToString(); * } * else if (item.Amount > 5) * { * consAmount.SetActive(true); * float cantidad = 0; * * consAmount.GetComponent<InputField>().onEndEdit.AddListener(delegate(string amount) { * cantidad = float.Parse(amount); * Debug.Log(cantidad.ToString()); * item.Amount -= cantidad; * butt.transform.GetChild(5).gameObject.GetComponent<Text>().text = item.Amount.ToString(); * consAmount.SetActive(false); * * }); * * } * * if (item.Amount < 1) * { * item.Amount--; * Inventory.Instance.myItems.Remove(item); * butt.transform.GetChild(5).gameObject.GetComponent<Text>().text = " "; * consumButt.gameObject.SetActive(false); * } * * });*/ #endregion } } else { butt.transform.GetChild(1).gameObject.SetActive(false); NonConsumable item = _item as NonConsumable; if (!(item.IsPurchased)) { Singleton.Instance.mCurrencies[(int)_currencyTypes] -= _item.Curren[_currencyTypes]; butt.transform.GetChild(5).gameObject.SetActive(true); butt.transform.GetChild(5).gameObject.GetComponent <Text>().text = "Purchased"; if (Inventory.Instance.myItems.Contains(item)) { return; } else { /* * consumButt.onClick.AddListener(delegate * { * //item.InInventory = true; * //butt.transform.GetChild(5).gameObject.GetComponent<Text>().text = "Equipped"; * }); */ item.IsPurchased = true; Inventory.Instance.myItems.Add(item); } } } GameController.Instance.UpdateUI(); } }
public void Sell(int index) { if (index <= 11) { NonConsumable itm = items [index]; if (itm.price <= playerInventory.oro) { if (!itm.bought) { playerInventory.items.Add(itm); playerInventory.oro -= itm.price; items[index].bought = true; ui.CompraExitosa(index); } else { ui.LoTienes(); } } else { ui.SinDinero(); } } else { if (index == 12) { if (playerInventory.powerUps [0].price < playerInventory.oro) { playerInventory.powerUps [0].cantidad += 1; playerInventory.oro -= playerInventory.powerUps [0].price; ui.CompraExitosa(index); } else { ui.SinDinero(); } } if (index == 13) { if (playerInventory.powerUps [1].price < playerInventory.oro) { playerInventory.powerUps [1].cantidad += 1; playerInventory.oro -= playerInventory.powerUps [1].price; ui.CompraExitosa(index); } else { ui.SinDinero(); } } if (index == 14) { if (playerInventory.powerUps [2].price < playerInventory.oro) { playerInventory.powerUps [2].cantidad += 1; playerInventory.oro -= playerInventory.powerUps [2].price; ui.CompraExitosa(index); } else { ui.SinDinero(); } } } }