Example #1
0
 public void LevelUp()
 {
     this.controller.SendGetRequest(string.Format("api/pokemon/{0}", this.pokemon.id), (pokemonRequest) =>
     {
         PokemonSimple pokemon    = JsonUtility.FromJson <PokemonSimple>(pokemonRequest.downloadHandler.text);
         pokemon.constitution    += int.Parse(this.ConstitutionInput.text);
         pokemon.attack          += int.Parse(this.AttackInput.text);
         pokemon.defense         += int.Parse(this.DefenseInput.text);
         pokemon.special_attack  += int.Parse(this.SpecialAttackInput.text);
         pokemon.special_defense += int.Parse(this.SpecialDefenseInput.text);
         pokemon.speed           += int.Parse(this.SpeedInput.text);
         this.controller.SendPutRequest(string.Format("api/pokemon/{0}", pokemon.id), JsonUtility.ToJson(pokemon), (levelRequest) => {}, (levelRequest) => {});
         List <int> newAttacks = new List <int>();
         for (int i = 0; i < this.moves.Count; i++)
         {
             if (this.moves[i].GetComponentInChildren <Toggle>().isOn)
             {
                 newAttacks.Add(this.attacks[i]);
             }
         }
         string data = string.Format("{{\"pokemon\": {0}, \"attacks\": [{1}]}}", pokemon.id, string.Join(",", newAttacks));
         this.controller.SendPostRequest("api/addPokemonAttack", data, (levelRequest) => { this.controller.Reload(); }, (levelRequest) => { });
         Destroy(this.gameObject);
         this.controller.Reload();
     }, (pokemonRequest) =>
     {
     });
 }
Example #2
0
    public void UpdateHP(InputField input)
    {
        int newHP = int.Parse(input.text);

        this.pokemon.current_hp = newHP;
        this.controller.SendGetRequest(string.Format("api/pokemon/{0}", this.pokemon.id), (pokemonRequest) => {
            PokemonSimple pokemon = JsonUtility.FromJson <PokemonSimple>(pokemonRequest.downloadHandler.text);
            pokemon.current_hp    = newHP;
            this.controller.SendPutRequest(string.Format("api/pokemon/{0}", pokemon.id), JsonUtility.ToJson(pokemon), (request) => { }, (request) => { });
        }, (request) => {
        });
    }
Example #3
0
    public void UpdateSpecialDefense(InputField input)
    {
        int newCS = int.Parse(input.text);

        this.pokemon.special_defense_cs = newCS;
        this.UpdatePokemon();
        this.controller.SendGetRequest(string.Format("api/pokemon/{0}", this.pokemon.id), (pokemonRequest) =>
        {
            PokemonSimple pokemon      = JsonUtility.FromJson <PokemonSimple>(pokemonRequest.downloadHandler.text);
            pokemon.special_defense_cs = newCS;
            this.controller.SendPutRequest(string.Format("api/pokemon/{0}", pokemon.id), JsonUtility.ToJson(pokemon), (request) => { }, (request) => { });
        }, (request) =>
        {
        });
    }
Example #4
0
 public void AddExp()
 {
     try
     {
         int exp = int.Parse(this.ExpInput.text);
         this.controller.SendGetRequest(string.Format("api/pokemon/{0}", this.pokemon.id), (pokemonRequest) =>
         {
             PokemonSimple pokemon = JsonUtility.FromJson <PokemonSimple>(pokemonRequest.downloadHandler.text);
             pokemon.experience   += exp;
             string data           = JsonUtility.ToJson(pokemon);
             this.controller.SendPutRequest(string.Format("api/pokemon/{0}", this.pokemon.id), data, (updateRequest) =>
             {
                 Pokemon updated = JsonUtility.FromJson <Pokemon>(updateRequest.downloadHandler.text);
                 if (updated.level > pokemon.level)
                 {
                     GameObject canvas    = GameObject.FindGameObjectWithTag("Canvas");
                     this.levelUpPanelObj = Instantiate(this.LevelUpPanel);
                     this.levelUpPanelObj.transform.SetParent(canvas.transform);
                     this.levelUpPanelObj.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
                     this.levelUpPanelObj.GetComponent <PokemonLevelUp>().Set(this.pokemon);
                 }
                 else
                 {
                     this.controller.Reload();
                 }
             }, (updateRequest) =>
             {
             });
         }, (pokemonRequest) =>
         {
         });
     }
     catch (FormatException)
     {
     }
 }