示例#1
0
 void LearnNewSkill()
 {
     if (!isLearningSkill)
     {
         isLearningSkill = true;
         bool skillLeard = false;
         foreach (NewSkill _tempSkill in SplitDataFromServe._heroSkill)
         {
             if (_tempSkill.data["idk"].AsInt == _skillDataInfo.data["idInit"].AsInt)
             {
                 skillLeard = true;
                 break;
             }
         }
         if (skillLeard == false)
         {
             int SPRequire = getSPRequiredToLearn(_skillDataInfo);
             if (CharacterInfo._instance._baseProperties.SkillPoint >= SPRequire)
             {
                 StartCoroutine(ServerAdapter.LearnSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, _skillDataInfo.data["idInit"].AsInt, _skillDataInfo.data["type"].Value, SPRequire, result =>
                 {
                     if (result.StartsWith("Error"))
                     {
                         isLearningSkill = false;
                         Debug.Log("Do nothing");
                         if (ScrollviewDontDestroy.Instance != null)
                         {
                             ScrollviewDontDestroy.Instance.SetLog("Learn skill fail, result return is " + result);
                         }
                     }
                     else
                     {
                         CharacterInfo._instance._baseProperties.SkillPoint -= SPRequire;
                         var N = SimpleJSON.JSON.Parse(result.ToString());
                         _skillDataInfo.addField("idhk", N["idhk"].AsInt);
                         _skillDataInfo.addField("idk", N["idk"].AsInt);
                         _skillDataInfo.addField("typewear", N["typewear"].AsInt);
                         _skillDataInfo.addField("level", 1);
                         SplitDataFromServe._heroSkill.Add(_skillDataInfo);
                         ShowInfoSkill(_skillDataInfo);
                         //_skillInfoObj.SetActive(false);
                         ListSkillEachClass(ConverClassCharacterEnumToId(CharacterInfo._instance._baseProperties._classCharacter));
                         isLearningSkill = false;
                         if (ScrollviewDontDestroy.Instance != null)
                         {
                             ScrollviewDontDestroy.Instance.SetLog("Learn skill successfully");
                         }
                     }
                 }));
             }
             else
             {
                 PopupErrorController.Instance.ShowErrorWithContent("Don't have enought skillpoint to learn!!");
                 isLearningSkill = false;
             }
         }
         else if (skillLeard == true)
         {
             Debug.Log("Upgrade Skill");
             int SPRequire = getSPRequiredToUpgrade(_skillDataInfo);
             Debug.Log("sp learn skill" + SPRequire);
             if (CharacterInfo._instance._baseProperties.SkillPoint >= SPRequire)
             {
                 StartCoroutine(ServerAdapter.UpLevelSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, _skillDataInfo.data["idhk"].AsInt, _skillDataInfo.data["level"].AsInt, SPRequire, result =>
                 {
                     if (result.StartsWith("Error"))
                     {
                         Debug.Log("Do nothing");
                         isLearningSkill = false;
                         if (ScrollviewDontDestroy.Instance != null)
                         {
                             ScrollviewDontDestroy.Instance.SetLog("Upgrade skill fail, result return is " + result);
                         }
                     }
                     else
                     {
                         CharacterInfo._instance._baseProperties.SkillPoint -= SPRequire;
                         var N = SimpleJSON.JSON.Parse(result.ToString());
                         _skillDataInfo.addField("level", _skillDataInfo.data["level"].AsInt + 1);
                         ShowInfoSkill(_skillDataInfo);
                         ListSkillEachClass(ConverClassCharacterEnumToId(CharacterInfo._instance._baseProperties._classCharacter));
                         isLearningSkill = false;
                         if (ScrollviewDontDestroy.Instance != null)
                         {
                             ScrollviewDontDestroy.Instance.SetLog("Upgrade skill successfully");
                         }
                     }
                 }));
             }
             else
             {
                 PopupErrorController.Instance.ShowErrorWithContent("Don't have enought skillpoint to learn!!");
                 isLearningSkill = false;
             }
         }
     }
 }