Beispiel #1
0
    public void GetScrolls()
    {
        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("GET_SCROLLS")
        .Send((scroll_response) =>
        {
            if (!scroll_response.HasErrors)
            {
                Debug.Log("Scrolls found");

                GameSparks.Core.GSData data = scroll_response.ScriptData.GetGSData("player_scrolls");
                GameSparks.Core.GSData time = scroll_response.ScriptData.GetGSData("time_now");
                SetScroll(data, (long)time.GetLong("current_time"));
            }
            else
            {
                Debug.Log("Error finding scrolls");
            }
        });
    }
        /// <summary>
        /// User Login
        /// </summary>>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="eventName"></param>
        public static void Login(string username, string password, string eventName)
        {
            if (DataController.GetValue <string>("LastValidusername") != username)
            {
                if (DataController.GetValue <string>("LastValidusername") != "")
                {
                    Login(DataController.GetValue <string>("LastValidusername"), DataController.GetValue <string>("LastValidPassword"), null);
                }
            }

            DataController.SaveValue("username", username);

            StatsList = new List <long>();

            EquipmentList = new List <long>();

            OtherStuffList = new List <long>();

            StatsList = new List <long>();

            EquipmentList = new List <long>();

            PrimaryStuffList = new List <long>();

            if (DataController.GetValue <int>("Rating") >= 0)
            {
                var newRequest = new GameSparks.Api.Requests.LogEventRequest();// DataController.GetValue<int>("Rating"));

                newRequest.SetEventKey("RATING_UPDATE").SetEventAttribute("Rating", DataController.GetValue <int>("Rating")).Send(response =>
                {
                });
            }

            var newRequest1 = new GameSparks.Api.Requests.LeaderboardDataRequest();

            newRequest1.SetLeaderboardShortCode("LeaderboardRating").SetEntryCount(35).Send(response =>
            {
                Debug.Log(response.BaseData.JSON);

                LeaderBoardsScript.Ranks = new List <long?>();

                LeaderBoardsScript.Names = new List <string>();

                LeaderBoardsScript.Ratings = new List <long?>();

                foreach (var gd in response.BaseData.GetGSDataList("data"))
                {
                    LeaderBoardsScript.Ranks.Add(gd.GetLong("rank"));

                    LeaderBoardsScript.Names.Add(gd.GetString("userName"));

                    LeaderBoardsScript.Ratings.Add(gd.GetLong("Rating"));

                    //Debug.Log(gd.GetString("userName"));

                    //Debug.Log(gd.GetLong("Rating"));
                }
            });

            Debug.Log("Authentication...");
            var loginRequest = new AuthenticationRequest();


            GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData();
            if (DataController.GetValue <int>("GSNotSynced" + username) > 0 && DataController.GetValue <string>("LastValidusername") == username)
            {
                foreach (string attr in ServerNamz)
                {
                    Debug.Log(DataController.GetValue <int>(attr + "Mine"));
                    StatsList.Add((long)DataController.GetValue <int>(attr + "Mine"));
                }
                data.AddNumberList("Stats", StatsList);

                foreach (string TypeItem in Equipment.ForInvLoad)
                {
                    foreach (string Name in EquipmentNames)
                    {
                        EquipmentList.Add((long)DataController.GetValue <int>(Name + TypeItem + "ammount"));
                    }
                }
                data.AddNumberList("Equipment", EquipmentList);

                int tempNum = 0;

                foreach (int num in CelebrationAnimation.Prices)
                {
                    Debug.Log(num);

                    if (DataController.GetValue <int>("WinAnimNumberMine" + tempNum + "ammount") > 0)
                    {
                        OtherStuffList.Add(1);
                    }
                    else
                    {
                        OtherStuffList.Add(0);
                    }
                    tempNum += 1;
                }

                PrimaryStuffList.Add(DataController.GetValue <int>("Exp"));

                PrimaryStuffList.Add(DataController.GetValue <int>("Bread"));

                PrimaryStuffList.Add(DataController.GetValue <int>("SkillPoints"));

                PrimaryStuffList.Add(DataController.GetValue <int>("Rating"));

                Debug.Log(DataController.GetValue <int>("SkillPoints"));

                data.AddNumberList("OtherStuffList", OtherStuffList);

                data.AddNumberList("PrimaryStuffList", PrimaryStuffList);
            }

            loginRequest.SetUserName(username);
            loginRequest.SetPassword(password);
            loginRequest.SetScriptData(data);


            loginRequest.Send(response =>
            {
                if (!response.HasErrors)
                {
                    GameSparks.Core.GSData GSList = response.ScriptData;
                    foreach (string atributeName in ServerNamz)
                    {
                        DataController.SaveValue(atributeName + "Mine", (int)GSList.GetInt(atributeName));
                    }
                    foreach (string TypeItem in Equipment.ForInvLoad)
                    {
                        foreach (string Name in EquipmentNames)
                        {
                            if (GSList.GetGSData("BoughtOrNot").ContainsKey(Name + TypeItem))
                            {
                                if (GSList.GetGSData("BoughtOrNot").GetInt(Name + TypeItem) > 0)
                                {
                                    DataController.SaveValue(Name + TypeItem + "ammount", 1);
                                }
                                else
                                {
                                    DataController.SaveValue(Name + TypeItem + "ammount", 0);
                                }
                            }
                            else
                            {
                                DataController.SaveValue(Name + TypeItem + "ammount", 0);
                            }
                        }
                    }
                    foreach (var vg in GSList.GetGSDataList("VirtualGoodsList"))
                    {
                        foreach (string modifier in EqModifiers)
                        {
                            if (vg.GetGSData("currencyCosts").GetInt(modifier) != null)
                            {
                                DataController.SaveValue(vg.GetString("name") + modifier, (int)vg.GetGSData("currencyCosts").GetInt(modifier));
                                //Debug.Log(vg.GetString("name"));
                            }
                        }
                        //Debug.Log(vg.GetString("name"));
                        DataController.SaveValue(vg.GetString("name") + "Price", (int)vg.GetGSData("currencyCosts").GetInt("Bread"));
                        DataController.SaveValue(vg.GetString("name") + "SellPrice", (int)vg.GetGSData("currencyCosts").GetInt("BreadPrice"));
                    }

                    int tempNum = 0;
                    long?value  = GSList.GetLong("Anim" + tempNum);
                    while (value != null)
                    {
                        DataController.SaveValue("WinAnimNumberMine" + tempNum + "ammount", (int)value);
                        tempNum += 1;
                        value    = GSList.GetLong("Anim" + tempNum);
                    }

                    for (int i = tempNum; i < CelebrationAnimation.Prices.Count; i++)
                    {
                        DataController.SaveValue("WinAnimNumberMine" + i + "ammount", 0);
                    }

                    long?Exp = GSList.GetLong("TotalExp");
                    DataController.SaveValue("Exp", (int)Exp);

                    long?Bread = GSList.GetLong("TotalBread");
                    DataController.SaveValue("Bread", (int)Bread);

                    long?SkillPoints = GSList.GetLong("TotalSkillPoints");
                    DataController.SaveValue("SkillPoints", (int)SkillPoints);

                    long?Rating = GSList.GetLong("Rating");
                    DataController.SaveValue("Rating", (int)Rating);

                    Debug.Log(DataController.GetValue <int>("SkillPoints"));


                    DataController.SaveValue("GSNotSynced" + username, 0);
                    Debug.Log("Player authenticated! \n Name:" + response.DisplayName + response.ScriptData.JSON);// + response.ScriptData);//.ScriptData.JSON.ToString());


                    IsUserLoggedIn = false;

                    EventManager.TriggerEvent(eventName, response.DisplayName);

                    DataController.SaveValue("LastValidPassword" + username, password);

                    DataController.SaveValue("LastValidusername", username);
                }
                else
                {
                    ResetPassword.instance.Warning.SetActive(true);

                    PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.Login); }, LocalisationSystem.GetLocalisedValue("loginerror1"));

                    Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString());

                    EventManager.TriggerEvent(eventName, "");
                }
            });
        }
Beispiel #3
0
    public void SetScroll(GameSparks.Core.GSData data, long time_now)
    {
        for (int i = 0; i < 4; i++)
        {
            string scroll_type_num = "scroll" + i + "_type";
            scroll_type_num = data.GetString(scroll_type_num);
            if (scroll_type_num == "r_null")
            {
                scroll_rarity[i] = rarity.r_null;
                scroll_go[i].SetActive(false);
            }
            else
            {
                if (scroll_type_num == "r_common")
                {
                    scroll_rarity[i] = rarity.r_common;
                }
                else if (scroll_type_num == "r_uncommon")
                {
                    scroll_rarity[i] = rarity.r_uncommon;
                }
                else if (scroll_type_num == "r_rare")
                {
                    scroll_rarity[i] = rarity.r_rare;
                }

                string scroll_finish = "scroll" + i + "_finish";
                string scroll_start  = "scroll" + i + "_start";

                long time_finish = (long)data.GetLong(scroll_finish);
                long time_start  = (long)data.GetLong(scroll_start);

                active_scroll_index = (int)data.GetInt("active_scroll");

                if (i == active_scroll_index)
                {
                    if (time_finish - time_now <= 0)
                    {
                        timer[i]          = 0;
                        timer_txt[i].text = "Ready";
                    }
                    else
                    {
                        timer[i] = (time_finish - time_now) / 1000;
                    }
                }
                else
                {
                    //if (time_finish != 0)
                    //{
                    //    if (time_finish - time_now <= 0)
                    //    {
                    //        timer[i] = 0;
                    //        timer_txt[i].text = "Ready";
                    //    }
                    //}
                    //else
                    //{
                    switch (scroll_rarity[i])
                    {
                    case rarity.r_common:
                        timer[i] = 3600 * 2;
                        break;

                    case rarity.r_uncommon:
                        timer[i] = 3600 * 6;
                        break;

                    case rarity.r_rare:
                        timer[i] = 3600 * 24;
                        break;
                    }
                    //}
                }

                scroll_go[i].SetActive(true);
            }
            Debug.Log("/n Rarity: " + scroll_type_num);
        }
    }
Beispiel #4
0
    public void ButtonPressed()
    {
        Debug.Log("Login attempt. User: "******"Pass: "******"" || password.text == "")
        {
            curr_text.text = "Fill all blanks before log in";

            for (int i = 0; i < to_active.Length; i++)
            {
                to_active[i].SetActive(false);
            }

            error_panel.SetActive(true);
            return;
        }

        new GameSparks.Api.Requests.AuthenticationRequest().
        SetUserName(username.text)
        .SetPassword(password.text)
        .Send((response) =>
        {
            if (response.HasErrors)
            {
                Debug.Log("Login error: " + response.Errors.JSON.ToString());

                // USE response.Errors.GetString("DETAILS"); to get the error type
                for (int i = 0; i < to_active.Length; i++)
                {
                    to_active[i].SetActive(false);
                }

                string error_message = response.Errors.GetString("DETAILS");

                if (error_message == "UNRECOGNISED")
                {
                    curr_text.text = "Wrong username/password combination";
                }

                else
                {
                    curr_text.text = "Servers unavailable. Try again later";
                }

                error_panel.SetActive(true);
            }
            else
            {
                Debug.Log("Login succes");
                game_manager.GetUIManager().DisableWindow("login_register");
                game_manager.GetUIManager().DisableWindow("register");
                game_manager.GetUIManager().EnableWindow("lobby");
                game_manager.GetUIManager().EnableWindow("scroll_ui");
                game_manager.GetUIManager().EnableWindow("global_ui");

                game_manager.playerID = response.UserId.ToString();
                name.text             = response.DisplayName.ToString();

                new GameSparks.Api.Requests.LogEventRequest()
                .SetEventKey("CREATE_SCROLLS")
                .Send((scroll_response) => {
                    if (scroll_response.HasErrors)
                    {
                        Debug.Log("Error");
                    }
                    else
                    {
                        Debug.Log("NICE");
                        new GameSparks.Api.Requests.LogEventRequest()
                        .SetEventKey("GET_SCROLLS")
                        .Send((scroll_response2) =>
                        {
                            if (!scroll_response2.HasErrors)
                            {
                                Debug.Log("Scrolls found");

                                GameSparks.Core.GSData data = scroll_response2.ScriptData.GetGSData("player_scrolls");
                                GameSparks.Core.GSData time = scroll_response2.ScriptData.GetGSData("time_now");
                                scroll.SetScroll(data, (long)time.GetLong("current_time"));
                            }
                            else
                            {
                                Debug.Log("Error finding scrolls");
                            }
                        });
                    }
                });
            }
        });
    }