Пример #1
0
    public void ChangeEquipment()
    {
        /* 3 class cần tham gia thay đổi
         * EquipmentsCharacer cần mặc trang bị mới
         * PlayerBag cần nhận thêm trang bị cũ
         * FittingRoomController cần update hình ảnh
         */
        int id = _lastIndexSelected;

        if (_equipmentsCharacter == null)
        {
            _equipmentsCharacter = CharacterInfo._instance._myEquipments;
        }
        if (_equipmentsCharacter.IsCanEquipItem(_myEquipItems[id]))
        {
            StartCoroutine(ServerAdapter.ExecuteChangeEquipment(_myEquipItems[id], result =>
            {
                if (result.StartsWith("Error"))
                {
                    TextNotifyScript.instance.SetData(result);
                }
                else
                {
                    //Debug.Log(_myTypeBag);
                    _tempItem = _equipmentsCharacter.MappingTypeItemToItem(_myTypeBag);
                    //Debug.Log(_tempItem);
                    if (_tempItem != null)
                    {
                        SplitDataFromServe._listEquipmentInBag.Add(_tempItem);
                        //CharacterInfo._instance._baseProperties.RemoveBonusItem(_tempItem);
                    }
                    _equipmentsCharacter.EquipItem(_myTypeBag, _myEquipItems[id]);
                    if (_myEquipItems[id].typeItem == TypeEquipmentCharacter.OffhandWeapon)
                    {
                        _myEquipItems[id].typeItem = TypeEquipmentCharacter.Weapon;
                    }
                    SplitDataFromServe._listEquipmentInBag.Remove(_myEquipItems[id]);
                    //CharacterInfo._instance._baseProperties.AddBonusItem(_myEquipItems[id]);

                    ItemInforController.instance.MakeEvent("UpdateEquipment");
                    this.gameObject.SetActive(false);
                }
            }));
        }
        else
        {
            MainMenuUI._instance.ShowErrorPopup(7);
        }
    }
Пример #2
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();
                    }
                }));
            }
        }
    }