void ExecuteBuyItemFuction() { #if UNITY_EDITOR Debug.Log("BUY item " + ShopUI._instance._cachedIDItemBuy); #endif StartCoroutine(ServerAdapter.BuyItemInShop(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, ShopUI._instance._cachedIDItemBuy, qtt, result => { if (result.StartsWith("Error")) { Debug.Log("do nothing"); } else { var N = JSON.Parse(result); if (idCurrency == 0) { CharacterInfo._instance._baseProperties.Gold -= price * qtt; } else if (idCurrency == 1) { CharacterInfo._instance._baseProperties.Diamond -= price * qtt; } if (N["typeid"].Value == "gem")//đây là runstone { Item _boughtItem = new Item(N["idhg"].AsInt, N["idig"].AsInt, N["quantity"].AsInt, 1, N["sellprice"].AsInt, N["uplevel"].AsInt); bool existedItem = false; foreach (Item _temp in SplitDataFromServe._listGemInBag) { if (int.Parse(_temp.getValue("idig").ToString()) == int.Parse(_boughtItem.getValue("idit").ToString())) { _temp.setValue("quantity", int.Parse(_boughtItem.getValue("quantity").ToString())); existedItem = true; break; } } if (!existedItem) { SplitDataFromServe._listGemInBag.Add(_boughtItem); } } else if (N["typeid"].Value == "item")// đây là item { Item _boughtItem = new Item(N["idht"].AsInt, N["idit"].AsInt, cachedItem.getValue("name").ToString(), N["quantity"].AsInt, int.Parse(cachedItem.getValue("price").ToString()), N["levelrequired"].AsInt, cachedItem.getValue("descripton").ToString(), int.Parse(cachedItem.getValue("price").ToString())); bool existedItem = false; foreach (Item _temp in SplitDataFromServe._listItemInBag) { if (int.Parse(_temp.getValue("idit").ToString()) == int.Parse(_boughtItem.getValue("idit").ToString())) { _temp.setValue("quantity", int.Parse(_boughtItem.getValue("quantity").ToString())); existedItem = true; break; } } if (!existedItem) { SplitDataFromServe._listItemInBag.Add(_boughtItem); } } this.PostEvent(EventID.OnPropertiesChange); _numberItemBound.SetActive(false); _acceptItemBound.SetActive(true); if (qtt == 1) { numberItemGet.gameObject.SetActive(false); } else if (qtt > 1) { numberItemGet.gameObject.SetActive(true); numberItemGet.text = qtt.ToString(); } } })); }