/// <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); }
/// <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"); } }); }
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"); } } }); }
/// <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(); } }); }
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"); } } }); }
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"); } }); }
/// <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, ""); } }); }
/// <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, ""); } }); }
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(); } } }); }