Exemplo n.º 1
0
        public void Apply()
        {
            if (pointsSpent < 0)
            {
                throw new WestException("Can't have a negative spent");
            }

            int upgradeSum = 0;

            foreach (var upgradePair in temporaryUpgradeMap)
            {
                //skillUpgrade[upgradePair.Key.Metric].Level += upgradePair.Value;
                upgradeSum += Math.Abs(upgradePair.Value);
            }

            if (upgradeSum != pointsSpent)
            {
                throw new WestException("Mismatch upgrade count and poitn spent");
            }

            //champion.SpecializationPoints -= pointsSpent;

            JSONObject requestField = new JSONObject();
            JSONArray  upgradeArray = new JSONArray();

            foreach (var upgradePair in temporaryUpgradeMap)
            {
                if (upgradePair.Value == 0)
                {
                    continue;
                }

                JSONObject upgrade = new JSONObject();
                upgrade["metric"] = upgradePair.Key.Metric._Id.ToString();
                upgrade["diff"]   = upgradePair.Value;
                upgradeArray.Add(upgrade);
            }
            requestField["upgrades"]    = upgradeArray;
            requestField["skill"]       = Skill()._Id.ToString();
            requestField["pointsSpent"] = pointsSpent;

            var loadingScreen = App.Resource.Prefab.LoadingCanvas();
            var request       = App.Server.Request(
                HTTPMethods.Post,
                "champion/" + champion.Json["_id"] + "/skillUpgrade",
                (JSONNode json_) =>
            {
                Debug.Log("Success");
                champion.Unload();
                SkillSpecializationSaved();
            },
                (JSONNode json_) =>
            {
                Debug.Log("Fail");
                Debug.Log(json_.ToString());
                GameObject.Destroy(loadingScreen.gameObject);
                App.Resource.Prefab.Popup().Setup("Error", "Skill upgrade failed.");
            });

            request.AddHeader("Content-Type", "application/json");
            request.RawData = System.Text.Encoding.UTF8.GetBytes(requestField.ToString());
            request.Send();
        }