示例#1
0
    IEnumerator LoadDataDetailHero(int _idhero, string _idcode)
    {
        StartCoroutine(ServerAdapter.ListSkillOfHero(_idhero, _idcode, result =>
        {
            if (result.StartsWith("Error"))
            {
                Debug.Log("Do nothing");
            }
            else
            {
                SplitDataFromServe.ReadSkillHeroData(result.ToString());
            }
        }));


        yield return(StartCoroutine(ServerAdapter.LoadDetailHero(_idcode, _idhero, result =>
        {
            if (result.StartsWith("Error"))
            {
                Debug.Log("Do nothing");
                ShowPopupError(6);
            }
            else
            {
                SplitDataFromServe.ReadDetailDataHeroCurrentPlay(result);
                SplitDataFromServe.ReadItemInBagData(result);
                StartCoroutine(SceneLoader._instance.LoadNewScene(2));
            }
        })));
    }
示例#2
0
    private void LoadEquippedData()
    {
        _txtState.text = "Loading shop init data...";
        if (!PlayerPrefs.HasKey(Constant.SHOPINIT))
        {
            StartCoroutine(ServerAdapter.LoadShopInit(result =>
            {
                if (result.StartsWith("Error"))
                {
                    Debug.LogError("Load shopinit failed!");
                }
                else
                {
                    PlayerPrefs.SetString(Constant.SHOPINIT, result);

                    SplitDataFromServe.ReadShopInitData(result);
                    StartCoroutine(CharacterItemInGame.Instance.ExecuteGetMonsterResource());
                }
            }));
        }
        else
        {
            SplitDataFromServe.ReadShopInitData(PlayerPrefs.GetString(Constant.SHOPINIT));
            StartCoroutine(CharacterItemInGame.Instance.ExecuteGetMonsterResource());
        }
    }
示例#3
0
    IEnumerator LoadDataDetailEnemyHero(int _idhero, string _idcode)
    {
        StartCoroutine(ServerAdapter.ListSkillOfHero(_idhero, _idcode, result =>
        {
            if (result.StartsWith("Error"))
            {
                Debug.Log("Do nothing");
            }
            else
            {
                SplitDataFromServe.ReadEnemySkillData(result.ToString());
            }
        }));

        WWWForm form = new WWWForm();

        form.AddField("idh", _idhero);
        form.AddField("idcode", _idcode);
        WWW w = new WWW(Constant.urlRequest + "/api/hero/detail", form);

        yield return(w);

        string data = w.text;
        var    N    = JSONNode.Parse(data);

        if (Boolean.Parse(N["return"]))
        {
            SplitDataFromServe.ReadDetailDataHeroEnemyPlay(N["data"].ToString());
            GameObject enemy = Instantiate(CharacterItemInGame.Instance._characterPrefabs[ConvertIdClassToClassName(SplitDataFromServe._heroEnemyPlay.idclass).ToString()]);
            enemy.transform.position   = new Vector3(5.5f, -2f, 0f);
            enemy.transform.localScale = new Vector3(-1f, 1f, 1f);
            _enemyCharacter            = enemy.AddComponent <CharacterPlayer>();
            CharacterPlayer.LoadCharacterEnemy(_enemyCharacter);
            //enemy.AddComponent<AnimationController>();
            enemy.SetActive(false);
            WaitingRoomUI.Instance.SetLog("Load data nhan vat thanh cong");
            if (!SocketIOController.Instance.isReconnect)
            {
                WaitingRoomUI.Instance.SetLog("Tao timeout confirm load nhan vat thanh cong");
                this.PostEvent(EventID.CreateTimeoutConfirmLoadData);
            }
            if (SocketIOController.Instance.isReconnect)
            {
                this.PostEvent(EventID.ReconnectBattleScene);
            }
            WatingRoomController.Instance.state_waitingroom = STATEINWAITING.CONFIRM_LOADDATA;
        }
        else if (!Boolean.Parse(N["return"]))
        {
            Debug.Log("Do nothing");
        }
        // if Master create timeout for done B request
        // if Slave send done slave, create timeout for done A response
    }
示例#4
0
    void ReadDataAccount(string _data)
    {
        var N = JSON.Parse(_data);

        if (N["hero"].Count == 0)
        {
            SplitDataFromServe.ReadLoginData(_data);
            StartCoroutine(SceneLoader._instance.LoadNewScene(1));
        }
        else if (N["hero"].Count > 0)
        {
            SplitDataFromServe.ReadLoginData(_data);

            int idHero = int.Parse(SplitDataFromServe._myAccount.idhplayed);
            if (idHero == 0)
            {
                StartCoroutine(SceneLoader._instance.LoadNewScene(1));
            }
            else
            {
                StartCoroutine(LoadDataDetailHero(int.Parse(SplitDataFromServe._myAccount.idhplayed), SplitDataFromServe._myAccount.idcode));
                PlayerPrefabsController.SetStringData(Constant.IDHERO_CURRENTPLAY, SplitDataFromServe._myAccount.idhplayed);
            }
            //if (!PlayerPrefs.HasKey(Constant.IDHERO_CURRENTPLAY))
            //{
            //    StartCoroutine(LoadDataDetailHero(int.Parse(SplitDataFromServe._myAccount.idhplayed), SplitDataFromServe._myAccount.idcode));
            //    PlayerPrefabsController.SetStringData(Constant.IDHERO_CURRENTPLAY, SplitDataFromServe._myAccount.idhplayed);
            //}
            //else
            //{
            //    Debug.Log(SplitDataFromServe._myAccount.idhplayed);
            //    if (int.Parse(SplitDataFromServe._myAccount.idhplayed) == 0)
            //    {
            //        Debug.Log("vv1");
            //        StartCoroutine(SceneLoader._instance.LoadNewScene(1));
            //    }
            //    else if (int.Parse(SplitDataFromServe._myAccount.idhplayed) != 0)
            //    {
            //        Debug.Log("Load lại nhân vật đã chơi");
            //        //StartCoroutine(LoadDataDetailHero(int.Parse(PlayerPrefabsController.GetStringData(Constant.IDHERO_CURRENTPLAY)), SplitDataFromServe._myAccount.idcode));
            //        StartCoroutine(LoadDataDetailHero(int.Parse(SplitDataFromServe._myAccount.idhplayed), SplitDataFromServe._myAccount.idcode));
            //    }
            //}
        }
    }
示例#5
0
 IEnumerator LoadInitData()
 {
     _txtState.text = "Loading game init data...";
     if (!PlayerPrefs.HasKey(Constant.AllINIT))
     {
         yield return(StartCoroutine(ServerAdapter.LoadInitData(result =>
         {
             if (result.StartsWith("Error"))
             {
                 Debug.LogError("Load Init data failed!");
             }
             else
             {
                 PlayerPrefs.SetString(Constant.AllINIT, result);
                 SplitDataFromServe.ReadInitData(result);
             }
         })));
     }
     else
     {
         SplitDataFromServe.ReadInitData((PlayerPrefs.GetString(Constant.AllINIT)));
     }
     yield return(null);
 }
示例#6
0
    public void BtnStartGame()
    {
        string _txtInput = _nameInputField.text.Trim();

        if (_txtInput.Length < 6)
        {
            _txtMessage.text = "Please enter a password at least 6 characters!";
        }
        else
        {
            _txtMessage.text = "Checking name...";
            StartCoroutine(ServerAdapter.CheckNameCreateHero(_txtInput, result =>
            {
                if (result.StartsWith("Error"))
                {
                    _txtMessage.text = result;
                }
                else
                {
                    _txtMessage.text = "Creating hero...";
                    int idih         = -1;
                    for (int i = 0; i < SplitDataFromServe._heroInits.Length; i++)
                    {
                        if (SplitDataFromServe._heroInits[i].name == listClass[lastIdHeroSelected])
                        {
                            idih = int.Parse(SplitDataFromServe._heroInits[lastIdHeroSelected].idih);
                            break;
                        }
                    }
                    if (idih == -1)
                    {
                        _txtMessage.text = "Id class hero is wrong!";
                    }
                    else
                    {
                        StartCoroutine(ServerAdapter.ExecuteCreateHero(idih, _txtInput, result2 =>
                        {
                            if (result2.StartsWith("Error"))
                            {
                                _txtMessage.text = result2;
                            }
                            else
                            {
                                _txtMessage.text = "Create your hero successfully!";
                                var N            = JSON.Parse(result2);
                                PlayerPrefabsController.SetStringData(Constant.IDHERO_CURRENTPLAY, N["hero"]["idh"].Value);
                                StartCoroutine(ServerAdapter.LoadDetailHero(N["hero"]["idcode"].Value, int.Parse(N["hero"]["idh"].Value), result3 =>
                                {
                                    if (result3.StartsWith("Error"))
                                    {
                                        _txtMessage.text = result;
                                    }
                                    else
                                    {
                                        SplitDataFromServe.ReadDetailDataHeroCurrentPlay(result3);
                                        Debug.Log("Load scene MainMenu");
                                        StartCoroutine(SceneLoader._instance.LoadNewScene(2));
                                    }
                                }));
                            }
                        }));
                    }
                }
            }));
        }
    }
示例#7
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();
                    }
                }));
            }
        }
    }