コード例 #1
0
    /// <summary>
    /// Get a list of Fantasy Players from game sparks
    /// </summary>
    /// <returns>A list containing Fantasy Player objects for each player</returns>
    public static List <FantasyPlayer> GetFantasyPlayerList(System.Action callbackOnComplete)
    {
        List <FantasyPlayer> players = new List <FantasyPlayer>();

        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getFantasyTeams")
        .SetEventAttribute("team", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received FantasyPlayers from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data != null)
                    {
                        List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyPlayers");
                        if (dataList == null)
                        {
                            foreach (var obj in dataList)
                            {
                                // Populate a new fantasy team based on the info pulled from the dataList
                                string name          = obj.GetString("name");
                                FantasyPlayer player = new FantasyPlayer(null, null, null, null, null);

                                // @TODO: Continue populating team info

                                players.Add(player);
                            }
                        }
                        else
                        {
                            Logging.LogError("Couldn't get FantasyPlayers GSData");
                        }
                    }
                    else
                    {
                        Logging.LogError("FantasyPlayers ScriptData is NULL");
                    }
                }
                else
                {
                    Logging.LogError("FantasyPlayers response Base Data = null");
                }
            }
            else
            {
                Logging.Log("Error retrieving FantasyPlayers from GameSparks: " + response.Errors.ToString());
            }

            if (callbackOnComplete != null)
            {
                callbackOnComplete();
            }
        });

        return(players);
    }
コード例 #2
0
 private void GSConnection_OnMessageReceived(String message)
 {
     try{
         if (_gSPlatform.ApiSecret.Contains(":"))
         {
             message = Decrypt(message);
             if (SessionId != null)
             {
                 IDictionary <string, object> parsed = (IDictionary <string, object>)GSJson.From(message);
                 GSData secureResponse = new GSData(parsed);
                 string json           = secureResponse.GetString("json");
                 if (secureResponse.GetString("hmac").Equals(_gs.GSPlatform.MakeHmac(json, GS.GSPlatform.ApiSecret + "-" + SessionId)))
                 {
                     _gs.AddRequestedAction(() => {
                         _gs.OnMessageReceived(json, this);
                     });
                 }
                 else
                 {
                     if (_gs.TraceMessages)
                     {
                         _gSPlatform.DebugMsg("SOCKET-TAMPERED:" + secureResponse.JSON);
                     }
                 }
                 return;
             }
         }
         _gs.AddRequestedAction(() => {
             _gs.OnMessageReceived(message, this);
         });
     }catch {
         //on WP8 if the app goes out of score for some reason the gs is null, so ignore this
     }
 }
コード例 #3
0
    /// <summary>
    /// Loads the inventory.
    /// </summary>
    /// <returns><c>true</c>, if inventory was loaded, <c>false</c> otherwise.</returns>
    public void LoadInventory()
    {
        //イベントリクエスト
        new LogEventRequest()
        .SetEventKey("LoadInventory")
        .Send((response) => {
            if (!response.HasErrors)
            {
                GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
                var temp = scriptData.GetGSDataList("target");

                //受信データを整形、スタティックフィールドに反映
                for (int i = 0; i < temp.Count; i++)
                {
                    Item tempItem = new Item {
                        name = temp[i].GetString("name"),
                        cnt  = (int)temp[i].GetInt("cnt")
                    };
                    StaticInfo.items.Add(tempItem);
                }

                foreach (Item tempItem in StaticInfo.items)
                {
                    Debug.Log("Load inventory (name:" + tempItem.name + "cnt:" + tempItem.cnt + ")");
                }
            }
            else
            {
                Debug.Log("Error Load Player Data");
            }
        });
    }
コード例 #4
0
 static object ToGSType(object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is IDictionary <string, object> )
     {
         value = new GSData((Dictionary <string, object>)value);
     }
     return(value);
 }
コード例 #5
0
ファイル: getVGs.cs プロジェクト: pjoconnamzn/iaptest
 // Use this for initialization
 void Start()
 {
     GameSparks.Core.GSEnumerable <ListVirtualGoodsResponse._VirtualGood> virtualGoods;
     new ListVirtualGoodsRequest()
     .SetIncludeDisabled(false)
     .Send((response) => {
         GameSparks.Core.GSData scriptData = response.ScriptData;
         virtualGoods = response.VirtualGoods;
         foreach (var i in virtualGoods)
         {
             Debug.Log(" name : " + i.Name);
             vg1.text = i.Name;
         }
     });
 }
コード例 #6
0
ファイル: ScrollSpawn.cs プロジェクト: GuraiGames/Cat-ana
    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");
            }
        });
    }
コード例 #7
0
 /// <summary>
 /// ユーザーデータをGameSparkより引き出してStaticフィールドに反映します
 /// </summary>
 /// <returns><c>true</c>, ロード成功, <c>false</c> ロード失敗.</returns>
 public void LoadUserInfo()
 {
     //とりあえず保存先ユーザー指定,認証
     new AuthenticationRequest()
     .SetPassword("0000")
     .SetUserName(StaticInfo.userInfo.userName)
     .Send((response) => {
         if (!response.HasErrors)
         {
             Debug.Log("Login successfully");
         }
         else
         {
             Debug.Log("Error login");
         }
     });
     //イベントリクエスト
     new LogEventRequest()
     .SetEventKey("LoadPlayerData")
     .Send((response) => {
         if (!response.HasErrors)
         {
             GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
             PlayerData playerData             = new PlayerData {
                 rate = (int)scriptData.GetInt("rate"),
                 gold = (int)scriptData.GetInt("gold")
             };
             //スタティックフィールドに反映
             StaticInfo.userData.rate = playerData.rate;
             StaticInfo.userData.gold = playerData.gold;
             Debug.Log("Load user data (rate:" + playerData.rate + "gold:" + playerData.gold + ")");
             StaticInfo.callback = "Loaded data";
         }
         else
         {
             Debug.Log("Error Load Player Data");
         }
     });
 }
コード例 #8
0
        /// <summary>
        /// Log the user in as a guest.
        /// </summary>
        /// <param name="eventName"></param> The event that will be called after the device authentication response
        public static void DeviceAuthentication(string eventName)
        {
            Debug.Log("Device authentication...");

            Login(DataController.GetValue <string>("username"), DataController.GetValue <string>("LastValidPassword" + DataController.GetValue <string>("username")), null);

            //DataController.GetValue<string>("LastValidPassword" + DataController.GetValue<string>("username"));

            //DataController.SaveValue("username", "");

            var deviceAuthenticationRequest = new DeviceAuthenticationRequest();

            deviceAuthenticationRequest.Send(response =>
            {
                if (!response.HasErrors)
                {
                    GameSparks.Core.GSData GSList = response.ScriptData;

                    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));
                            }
                        }
                        DataController.SaveValue(vg.GetString("name") + "Price", (int)vg.GetGSData("currencyCosts").GetInt("Bread"));
                        DataController.SaveValue(vg.GetString("name") + "SellPrice", (int)vg.GetGSData("currencyCosts").GetInt("BreadPrice"));
                    }
                    foreach (string atributeName in ServerNamz)
                    {
                        DataController.SaveValue(atributeName + "Mine", 0);
                    }
                    foreach (string TypeItem in Equipment.ForInvLoad)
                    {
                        foreach (string Name in EquipmentNames)
                        {
                            DataController.SaveValue(Name + TypeItem + "ammount", 0);
                        }
                    }
                    Debug.Log("Player autheticated!\nName: " + response.DisplayName);

                    EventManager.TriggerEvent(eventName, response.DisplayName);

                    IsUserLoggedIn = true;

                    DataController.SaveValue("GSNotSynced" + DataController.GetValue <string>("username"), 0);

                    DataController.SaveValue("Exp", 0);

                    DataController.SaveValue("Bread", 0);

                    DataController.SaveValue("SkillPoints", 0);

                    DataController.SaveValue("Rating", 0);

                    for (int i = 0; i < CelebrationAnimation.Prices.Count; i++)
                    {
                        DataController.SaveValue("WinAnimNumberMine" + i + "ammount", 0);
                    }
                }
                else
                {
                    Debug.Log("Error authenticating player... \n: " + response.Errors.JSON.ToString());

                    EventManager.TriggerEvent(eventName, "");
                }
            });
        }
コード例 #9
0
 /// <summary>
 /// Create an instance with the basedata of the given wrapper.
 /// </summary>
 public GSObject(GSData wrapper) : base(wrapper.BaseData)
 {
 }
コード例 #10
0
    private void LoadFantasyPlayersFromGameSparks(System.Action cbOnComplete)
    {
        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getPlayers")
        .SetEventAttribute("team", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received Fantasy Players full list from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data == null)
                    {
                        Logging.LogError("ScriptData is NULL");
                        return;
                    }

                    List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyPlayers");
                    if (dataList == null)
                    {
                        Logging.LogError("Couldn't get FantasyPlayers GSData");
                        return;
                    }

                    foreach (var obj in dataList)
                    {
                        FantasyPlayer player = new FantasyPlayer();

                        player.Name   = obj.GetString("name");
                        player.Team   = obj.GetString("team");
                        player.Salary = obj.GetString("salary");
                        player.Points = obj.GetString("fppg");

                        System.Action <Texture2D> imageReceivedCB = delegate(Texture2D image)
                        {
                            Sprite playerImage = null;
                            if (image != null)
                            {
                                playerImage    = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f));
                                player.Picture = playerImage;
                            }
                        };

                        FantasyManager.Instance.DownloadAnImage(obj.GetString("portraitShortCode"), imageReceivedCB);

                        FantasyPlayersList.Add(player);
                    }

                    EventManager.instance.TriggerEvent(new EventFantasyPlayersListUpdated(System.DateTime.Now));
                }
                else
                {
                    Logging.LogError("response Base Data = null");
                }

                if (cbOnComplete != null)
                {
                    cbOnComplete.Invoke();
                }
            }
        });
    }
コード例 #11
0
    void playerdata()
    {
        new AuthenticationRequest()
        .SetPassword("0000")
        .SetUserName("26337")
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Login successfully");
            }
            else
            {
                Debug.Log("Error login");
            }
        });

        //Item item = new Item { name = "test1", cnt = 1 };
        //Item item2 = new Item { name = "test2", cnt = 3 };
        //StaticInfo.userData.items = item;
        //Debug.Log(StaticInfo.userData.items.name);
        //StaticInfo.userData.items.Add(item2);
        Debug.Log("Saving");
        PlayerData player = new PlayerData {
            gold = 2,
            rate = 0
        };
        string jsonData = JsonUtility.ToJson(player);

        GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(jsonData);
        Debug.Log(jsonData);
        new LogEventRequest()
        .SetEventKey("SavePlayerData")
        .SetEventAttribute("playerData", data)
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Save data successfully");
            }
            else
            {
                Debug.Log("Error Save Player Data");
            }
        });

        new LogEventRequest()
        .SetEventKey("LoadPlayerData")
        .Send((response) => {
            if (!response.HasErrors)
            {
                GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
                PlayerData playerData             = new PlayerData {
                    rate = (int)scriptData.GetInt("rate"),
                    gold = (int)scriptData.GetInt("gold")
                };
                Debug.Log("rate:" + playerData.rate + "gold:" + playerData.gold);
            }
            else
            {
                Debug.Log("Error Load Player Data");
            }
        });
    }
コード例 #12
0
 /// <summary>
 /// Create a new request data container with the given data.
 /// </summary>
 public GSRequestData(GSData wrapper) : base(wrapper)
 {
 }
コード例 #13
0
 /// <summary>
 /// Add a child object to the container.
 /// </summary>
 public GSRequestData AddObject(String paramName, GSData child)
 {
     Add(paramName, child.BaseData);
     return(this);
 }
コード例 #14
0
ファイル: ScrollSpawn.cs プロジェクト: GuraiGames/Cat-ana
    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);
        }
    }
コード例 #15
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");
                            }
                        });
                    }
                });
            }
        });
    }
コード例 #16
0
        /// <summary>
        /// Add a data value to the request.
        /// </summary>
        public new GSRequest AddObject(String paramName, GSData child)
        {
            base.AddObject(paramName, child);

            return(this);
        }
コード例 #17
0
        /// <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, "");
                }
            });
        }
コード例 #18
0
    void inventory()
    {
        new AuthenticationRequest()
        .SetPassword("0000")
        .SetUserName("334870")
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Login successfully");
            }
            else
            {
                Debug.Log("Error login");
            }
        });

        Item item = new Item {
            name = "test1", cnt = 1
        };
        Item item2 = new Item {
            name = "test2", cnt = 3
        };

        //Debug.Log(StaticInfo.userData.items.name);
        StaticInfo.items.Add(item);
        StaticInfo.items.Add(item2);
        string jsonData = JsonUtility.ToJson(new Serialization <Item>(StaticInfo.items));

        //string jsonData = JsonUtility.ToJson(items);
        GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(jsonData);
        Debug.Log(jsonData);
        new LogEventRequest()
        .SetEventKey("SaveInventory")
        .SetEventAttribute("inventory", data)
        .Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Save inventory successfully");
            }
            else
            {
                Debug.Log("Error save inventory");
            }
        });

        new LogEventRequest()
        .SetEventKey("LoadInventory")
        .Send((response) => {
            if (!response.HasErrors)
            {
                GameSparks.Core.GSData scriptData = response.ScriptData.GetGSData("data");
                var temp = scriptData.GetGSDataList("target");

                List <Item> items = new List <Item>();
                for (int i = 0; i < temp.Count; i++)
                {
                    Item tempItem = new Item {
                        name = temp[i].GetString("name"),
                        cnt  = (int)temp[i].GetInt("cnt")
                    };
                    StaticInfo.items.Add(tempItem);
                }

                foreach (Item tempItem in StaticInfo.items)
                {
                    Debug.Log("name:" + tempItem.name + "cnt:" + tempItem.cnt);
                }
            }
            else
            {
                Debug.Log("Error Load Player Data");
            }
        });
    }
コード例 #19
0
    public static void GetContestInfoFromGameSparks(System.Action callbackOnComplete)
    {
        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getContests")
        .SetEventAttribute("contestId", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received ContestInfos from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data != null)
                    {
                        List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyContests");
                        if (dataList != null)
                        {
                            int i = 0;
                            foreach (var obj in dataList)
                            {
                                ContestInfo info      = new ContestInfo();
                                info.contestID        = obj.GetString("contestId");
                                info.contestTitle     = obj.GetString("name");
                                info.contestStartDate = obj.GetString("startdate") + " " + obj.GetString("starttime");

                                // Grab the corresponding logo image for this contest
                                System.Action <Texture2D> imageReceived = delegate(Texture2D image)
                                {
                                    i++;
                                    info.contestLogo = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f), 100.0f);
                                    ContestsView.CurrentContests[info.contestID] = info;

                                    if (i == dataList.Count)
                                    {
                                        if (callbackOnComplete != null)
                                        {
                                            callbackOnComplete();
                                        }
                                    }
                                };

                                FantasyManager.Instance.DownloadAnImage(obj.GetString("logoShortCode"), imageReceived);
                                // Populate the contest with teams list
                                string teamsCSV = obj.GetString("teamNames");
                                if (teamsCSV != null)
                                {
                                    Logging.Log("Teams: " + teamsCSV);
                                    string[] teamsSplit = teamsCSV.Split(',');
                                    if (teamsSplit.Length > 0)
                                    {
                                        info.Teams = FantasyManager.Instance.GetFantasyTeamListByNames(teamsSplit);
                                    }
                                }
                                else
                                {
                                    Logging.LogError("No teams found for contest: " + info.contestID);
                                }
                            }
                        }
                        else
                        {
                            Logging.LogError("Couldn't get FantasyContests GSData");
                        }
                    }
                    else
                    {
                        Logging.LogError("FantasyContests ScriptData is NULL");
                    }
                }
                else
                {
                    Logging.LogError("response Base Data = null");
                }
            }
        });
    }
コード例 #20
0
 /// <summary>
 ///
 /// </summary>
 public GSTypedResponse(GSData response)
 {
     this.response = response;
 }
コード例 #21
0
        private void Handshake(GSObject response, GSConnection connection)
        {
            if (response.ContainsKey("error"))
            {
                GSPlatform.DebugMsg(response.GetString("error"));

                ShutDown(null);
            }
            else if (response.ContainsKey("nonce"))
            {
                SendHandshake(response, connection);
            }
            else
            {
                if (response.ContainsKey("sessionId"))
                {
                    _sessionId = response.GetString("sessionId");

                    connection.SessionId = _sessionId;

                    if (response.ContainsKey("authToken"))
                    {
                        GSPlatform.ExecuteOnMainThread(() =>
                        {
                            GSPlatform.AuthToken = response.GetString("authToken");
                        });
                    }
                    else
                    {
                        GSPlatform.ExecuteOnMainThread(() =>
                        {
                            GSPlatform.AuthToken = "0";
                            GSPlatform.UserId    = "";
                        });
                    }

                    if (response.ContainsKey("clientConfig"))
                    {
                        GSData clientConfig = response.GetGSData("clientConfig");

                        RetryBase                 = clientConfig.GetInt("retryBase").GetValueOrDefault(GS.RetryBase);
                        RetryMax                  = clientConfig.GetInt("retryMax").GetValueOrDefault(GS.RetryMax);
                        RequestTimeout            = clientConfig.GetInt("requestTimeout").GetValueOrDefault(GS.RequestTimeout);
                        DurableConcurrentRequests = clientConfig.GetInt("durableConcurrentRequests").GetValueOrDefault(GS.DurableConcurrentRequests);
                        DurableDrainInterval      = clientConfig.GetInt("durableDrainInterval").GetValueOrDefault(GS.DurableDrainInterval);
                        HandshakeOffset           = clientConfig.GetInt("handshakeOffset").GetValueOrDefault(GS.HandshakeOffset);
                    }
                    else
                    {
                        RetryBase                 = GS.RetryBase;
                        RetryMax                  = GS.RetryMax;
                        RequestTimeout            = GS.RequestTimeout;
                        DurableConcurrentRequests = GS.DurableConcurrentRequests;
                        DurableDrainInterval      = GS.DurableDrainInterval;
                        HandshakeOffset           = GS.HandshakeOffset;
                    }

                    //We want availability to be triggered before authenticated
                    GSPlatform.DebugMsg("Available");

                    connection.Ready = true;

                    setAvailability(true);

                    if (response.ContainsKey("userId"))
                    {
                        SetUserId(response.GetString("userId"));
                    }

                    CalcNewReconnectionTimeout(0);
                }
            }
        }
コード例 #22
0
    /// <summary>
    /// Get a list of FantasyTeams from teh FantasyManager's standings dictionary
    /// </summary>
    /// <returns>A list containing FantasyTeam objects for each team</returns>
    public static void GetFantasyTeamList(System.Action callbackOnComplete)
    {
        new GameSparks.Api.Requests.LogEventRequest()
        .SetEventKey("getFantasyTeams")
        .SetEventAttribute("team", "")
        .Send((response) =>
        {
            if (!response.HasErrors)
            {
                Logging.Log("Received FantasyTeams from GameSparks: " + response.JSONString.ToString());

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data != null)
                    {
                        List <GameSparks.Core.GSData> dataList = data.GetGSDataList("fantasyTeams");
                        if (dataList != null)
                        {
                            foreach (var obj in dataList)
                            {
                                // Populate a new fantasy team based on the info pulled from the dataList
                                FantasyTeam team = new FantasyTeam();
                                team.TeamName    = obj.GetString("teamName");

                                // Continue populating team info
                                team.Players = FantasyManager.Instance.GetPlayersOnTeam(team.TeamName);
                                team.Salary  = int.Parse(obj.GetString("salary"));
                                team.FPPG    = obj.GetString("fppg");

                                // Grab the corresponding logo image for this team
                                System.Action <Texture2D> imageReceived = delegate(Texture2D image)
                                {
                                    team.Logo = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f), 100.0f);
                                };
                                FantasyManager.Instance.DownloadAnImage(obj.GetString("logoShortCode"), imageReceived);

                                // Add the fantasy team to some persistent data structure
                                if (!FantasyManager.Instance.FantasyTeams.ContainsKey(team.TeamName))
                                {
                                    FantasyManager.Instance.FantasyTeams.Add(team.TeamName, team);
                                }
                                else
                                {
                                    FantasyManager.Instance.FantasyTeams[team.TeamName] = team;
                                }
                            }
                        }
                        else
                        {
                            Logging.LogError("Couldn't get FantasyTeams GSData");
                        }
                    }
                    else
                    {
                        Logging.LogError("FantasyTeams ScriptData is NULL");
                    }
                }
                else
                {
                    Logging.LogError("FantasyTeams response Base Data = null");
                }
            }
            else
            {
                Logging.Log("Error retrieving FantasyTeams from GameSparks: " + response.Errors.ToString());
            }

            if (callbackOnComplete != null)
            {
                callbackOnComplete();
            }
        });
    }
コード例 #23
0
    public void ButtonPressed(string tag)
    {
        if (tag == "CARD")
        {
            Debug.Log("d");
        }

        for (var i = 0; i < displayed_slots.Count; i++)
        {
            Destroy(displayed_slots[i]);
        }

        displayed_slots.Clear();

        Image img = GameObject.Find("Background Panel").GetComponent <Image>();


        if (tag == "SKIN")
        {
            img.color = UnityEngine.Color.red;
        }

        else if (tag == "WEAPON")
        {
            img.color = UnityEngine.Color.blue;
        }

        else if (tag == "CARD")
        {
            img.color = UnityEngine.Color.yellow;
        }


        List <string> tags = new List <string>();

        tags.Add(tag);

        new GameSparks.Api.Requests.ListVirtualGoodsRequest()
        .SetTags(tags)
        .Send((response) =>
        {
            if (response.HasErrors)
            {
                Debug.Log("Error: skin list can not be loaded");
            }

            else
            {
                Debug.Log("Skin list loaded succesfully");

                // Here we load all the skins locked -----

                // Get the list of VGOOD and calculate the amount

                GameSparks.Core.GSData scriptData = response.ScriptData;
                GameSparks.Core.GSEnumerable <GameSparks.Api.Responses.ListVirtualGoodsResponse._VirtualGood> virtualGoods = response.VirtualGoods;

                foreach (var skin in virtualGoods)
                {
                    tot_items_amount++;
                }

                Debug.Log("TOTAL" + tag + "S: " + tot_items_amount);

                // Adjust size and position of the panel deppending on amount

                rt          = GameObject.Find("Slot Panel").GetComponent <RectTransform>();
                rt.position = GameObject.Find("Slot Panel").GetComponent <RectTransform>().localPosition = new Vector3(0, 0, 0);

                rt.sizeDelta     = new Vector2(1731 + (305 * tot_items_amount), 773);
                rt.localPosition = new Vector3(rt.localPosition.x + 245 * tot_items_amount, rt.localPosition.y, rt.localPosition.y);

                // We create every slot

                for (int i = 0; i < tot_items_amount; i++)
                {
                    GameObject new_slot         = Instantiate(item_slot, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    new_slot.transform.parent   = GameObject.Find("Slot Panel").transform;
                    new_slot.transform.position = new Vector3(curr_pos.x, 0, 0);

                    new_slot.transform.localScale = new Vector3(new_slot.transform.localScale.x / 110, new_slot.transform.localScale.y / 110, new_slot.transform.localScale.z / 110);

                    //Setting image and text

                    SetImageFromShortCode();

                    new_slot.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(item_blocked_tex_path);

                    Debug.Log("path " + test_path);

                    new_slot.GetComponentInChildren <Text>().text = "BLOCKED";

                    curr_pos.x += distance_between_slots;

                    displayed_slots.Add(new_slot);
                }

                // -----

                new GameSparks.Api.Requests.AccountDetailsRequest().Send((details_response) =>
                {
                    if (details_response.HasErrors)
                    {
                        Debug.Log("too bad :(");
                    }
                    else
                    {
                        // Here we "unlock" the ones that the player has -----

                        Debug.Log("I've got the info muahahaha");

                        GameSparks.Core.GSData VirtualGoodsData = details_response.VirtualGoods;

                        string VirtualGoodsJSON = VirtualGoodsData.JSON;

                        Debug.Log(VirtualGoodsJSON);

                        foreach (var items in details_response.VirtualGoods.BaseData)
                        {
                            string short_code = items.Key.ToString();

                            unlocked_items++;

                            Debug.Log(short_code);
                        }

                        Debug.Log("TOTAL ITEMS UNLOCKED: " + unlocked_items);

                        // -----
                    }

                    tags.Clear();
                    tot_items_amount = 0;
                    unlocked_items   = 0;
                    curr_pos         = new Vector3(0, 0, 0);
                });
            }
        });
    }
コード例 #24
0
    public void UpdateLocalPlayerContests()
    {
        ContestEntries = new Dictionary <string, ContestEntry>();

        // Load the user's fantasy contest data from the playerData collection on mongoDB
        new GameSparks.Api.Requests.LogEventRequest().SetEventKey("getPlayerContestLineups").Send((response) =>
        {
            if (response.HasErrors)
            {
                Logging.LogError("getPlayerContestLineups returned errors: " + response.Errors.JSON);
            }
            else
            {
                Logging.Log(response.JSONString);

                if (response.BaseData != null)
                {
                    GameSparks.Core.GSData data = response.ScriptData;
                    if (data == null)
                    {
                        Logging.LogError("ScriptData is NULL");
                        return;
                    }

                    List <GameSparks.Core.GSData> dataList = data.GetGSDataList("contestLineups");
                    if (dataList == null)
                    {
                        Logging.LogError("Couldn't get contestLineups GSData");
                        return;
                    }

                    // Iterate over the response of contestLineups (could be empty!)
                    foreach (var obj in dataList)
                    {
                        ContestEntry entry = new ContestEntry();
                        entry.ContestID    = obj.GetString("contestId");

                        // Convert the player strings into fantasy player objects for the ContestEntry
                        string player1 = obj.GetString("slotPlayer1");
                        if (!string.IsNullOrEmpty(player1))
                        {
                            entry.SlotPlayer1 = FantasyManager.Instance.GetPlayerFromName(player1);
                        }

                        string player2 = obj.GetString("slotPlayer2");
                        if (!string.IsNullOrEmpty(player2))
                        {
                            entry.SlotPlayer2 = FantasyManager.Instance.GetPlayerFromName(player2);
                        }

                        string player3 = obj.GetString("slotPlayer3");
                        if (!string.IsNullOrEmpty(player3))
                        {
                            entry.SlotPlayer3 = FantasyManager.Instance.GetPlayerFromName(player3);
                        }

                        string player4 = obj.GetString("slotPlayer4");
                        if (!string.IsNullOrEmpty(player4))
                        {
                            entry.SlotPlayer4 = FantasyManager.Instance.GetPlayerFromName(player4);
                        }

                        entry.SlotTeam1 = obj.GetString("slotTeam1");

                        if (ContestEntries.ContainsKey(entry.ContestID))
                        {
                            ContestEntries[entry.ContestID] = entry;
                        }
                        else
                        {
                            ContestEntries.Add(entry.ContestID, entry);
                        }
                    }

                    if (callbackOnLoadComplete != null)
                    {
                        callbackOnLoadComplete();
                    }
                }
                else
                {
                    Logging.LogError("response Base Data = null");
                }
            }
        });
    }
コード例 #25
0
 // TODO: Check if we should rather deep copy the wrapper than just use the data reference.
 /// <summary>
 /// Create a new instance and use the data of the given wrapper as BaseData.
 /// </summary>
 /// <param name="wrapper"></param>
 public GSData(GSData wrapper)
 {
     this._data = wrapper._data;
 }