Exemple #1
0
    private void BtnItemInforClick()
    {
        string param = ItemInforController.Message;

        if (!isActiveStorageUI)
        {
            return;
        }

        if (param.Equals("UseItem"))
        {
            StartCoroutine(ServerAdapter.UseItemInShop(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero,
                                                       int.Parse(SplitDataFromServe._listItemInBag[idItemSelected].getValue("idht").ToString()), 1,
                                                       result =>
            {
                if (result.StartsWith("Error"))
                {
                    TextNotifyScript.instance.SetData(result);
                }
                else
                {
                    var N      = SimpleJSON.JSON.Parse(result);
                    int idItem = int.Parse(SplitDataFromServe._listItemInBag[idItemSelected].getValue("idit").ToString());
                    if (idItem == 31)          //dùng thẻ protect
                    {
                        long timeSticks      = long.Parse(N["timeprotection"].Value);
                        DateTime _timeActive = new DateTime(timeSticks * 10000000 + new DateTime(1969, 12, 31, 12, 0, 0).Ticks);
                        _rewardItem.SetData("Used Item: " + SplitDataFromServe._listItemInBag[idItemSelected].getValue("name").ToString(), "Time Active: " + _timeActive.ToLocalTime());
                    }
                    else if (idItem >= 65 && idItem <= 68)          //dùng thẻ
                    {
                        long timeSticks      = long.Parse(N["timedaypremium"].Value);
                        DateTime _timeActive = new DateTime(timeSticks * 10000000 + new DateTime(1969, 12, 31, 12, 0, 0).Ticks);
                        _rewardItem.SetData("Used Item: " + SplitDataFromServe._listItemInBag[idItemSelected].getValue("name").ToString(), "Time Active: " + _timeActive.ToLocalTime());
                    }
                    else if (idItem == 70)         //reset skill point
                    {
                        SplitDataFromServe._heroSkill.Clear();
                        int numberSkillPoint = N["skillpoint"].AsInt;
                        CharacterInfo._instance._skillPoints += numberSkillPoint;
                        _rewardItem.SetData("Used Item: " + SplitDataFromServe._listItemInBag[idItemSelected].getValue("name").ToString(), "Skill point return: " + numberSkillPoint);
                    }
                    SplitDataFromServe.SubItemInBag(idItemSelected, 1);
                    DisplayItemInBag();
                }
            }));
        }
        else if (param.Equals("SellItem"))
        {
            _infoItemPanel.SetData(false, SplitDataFromServe._listItemInBag[idItemSelected], _listSlotItem[idItemSelected]._iconImg.sprite);
        }
        else if (param.Equals("UpdateEquipment"))
        {
            DisplayEquipmentInBag();
        }
        else if (param.Equals("SellEquipment"))//Chọn đồ
        {
            if (SplitDataFromServe._listEquipmentInBag[idItemSelected].typeItem == TypeEquipmentCharacter.Buff)
            {
                StartCoroutine(ServerAdapter.SellBuff(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, SplitDataFromServe._listEquipmentInBag[idItemSelected].idItem,
                                                      result =>
                {
                    if (result.StartsWith("Error"))
                    {
                        TextNotifyScript.instance.SetData(result);
                    }
                    else
                    {
                        var N = SimpleJSON.JSON.Parse(result);
                        CharacterInfo._instance._baseProperties.Gold += N["plusgold"].AsInt;
                        this.PostEvent(EventID.OnPropertiesChange);

                        SplitDataFromServe._listEquipmentInBag.RemoveAt(idItemSelected);
                        DisplayEquipmentInBag();
                    }
                }));
            }
            else
            {
                StartCoroutine(ServerAdapter.SellEquipment(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, SplitDataFromServe._listEquipmentInBag[idItemSelected].idItem,
                                                           result =>
                {
                    if (result.StartsWith("Error"))
                    {
                        TextNotifyScript.instance.SetData(result);
                    }
                    else
                    {
                        var N = SimpleJSON.JSON.Parse(result);
                        CharacterInfo._instance._baseProperties.Gold += N["plusgold"].AsInt;
                        this.PostEvent(EventID.OnPropertiesChange);

                        SplitDataFromServe._listEquipmentInBag.RemoveAt(idItemSelected);
                        DisplayEquipmentInBag();
                    }
                }));
            }
        }
        else if (param.Equals("ReplaceEquipmentFromBag"))
        {
            _myEquipment = SplitDataFromServe._listEquipmentInBag[idItemSelected];
            isCanUse     = true;
            _myTypeBag   = _myEquipment.typeItem;
            if (_myEquipment.levelRequired <= _myCurrentLevel && SplitDataFromServe._listSuitableEquipment.Contains(_myEquipment.idTypeEquipment))
            {
                if (_myEquipment.typeItem == TypeEquipmentCharacter.Weapon)
                {
                    if (!CharacterInfo._instance._baseProperties._classCharacter.Equals(MappingData.GetSuitableClassForWeapon(_myEquipment.idTypeEquipment)))
                    {
                        isCanUse = false;
                    }
                }
            }
            else
            {
                isCanUse = false;
            }

            //Debug.Log("is can use this equipment " + isCanUse);
            if (isCanUse)
            {
                StartCoroutine(ServerAdapter.ExecuteChangeEquipment(_myEquipment, result =>
                {
                    if (result.StartsWith("Error"))
                    {
                        TextNotifyScript.instance.SetData(result);
                    }
                    else
                    {
                        _tempItem = _equipmentsCharacter.MappingTypeItemToItem(_myTypeBag);
                        if (_tempItem != null)
                        {
                            SplitDataFromServe._listEquipmentInBag.Add(_tempItem);
                        }
                        _equipmentsCharacter.EquipItem(_myTypeBag, _myEquipment);
                        SplitDataFromServe._listEquipmentInBag.Remove(_myEquipment);
                        //CharacterInfo._instance._baseProperties.AddBonusItem(_myEquipItems[id]);
                        DisplayEquipmentInBag();
                    }
                }));
            }
        }
    }