public void UserLogin() { EventManager.StartListening <string>("OnLoginResponse", OnLoginResponse); DataController.SaveValue("username", username.text); DataController.SaveValue("password", password.text); GS_Authentication.Login(username.text, password.text, "OnLoginResponse"); }
public static void WinSingle() { DataController.SaveValue("Rating", DataController.GetValue <int>("Rating") + RaitingSingleReward); if (DataController.GetValue <int>("LoadMode") == 2) { winExp = 200; winBread = 100; DataController.SaveValue("CurrentBossNumber", 1 + DataController.GetValue <int>("CurrentBossNumber")); } DataController.SaveValue("RatingChange", RaitingSingleReward); int expChange = 0; expChange = winExp * multDifference; DataController.SaveValue("expAdded", expChange); int breadChange = 0; breadChange = winBread; DataController.SaveValue("breadAdded", breadChange); DataController.SaveValue("Exp", DataController.GetValue <int>("Exp") + expChange); DataController.SaveValue("Bread", DataController.GetValue <int>("Bread") + breadChange); PostGameActions(true); }
private void OnSignUpResponse(string displayName) { DataController.SaveValue("displayName", displayName); UIController.SetActivePanel(UI_Element.MainMenu); EventManager.StopListening <string>("OnSignUpResponse", OnSignUpResponse); }
public static void PostGameActions(bool ifWin) { DataController.SaveValue("GSNotSynced" + DataController.GetValue <string>("username"), 2); if (ifWin) { DataController.SaveValue("WinsForChest", DataController.GetValue <int>("WinsForChest") + 1); } }
public void SpendSkillPoints(Text Title) { DataController.SaveValue("GSNotSynced" + DataController.GetValue <string>("username"), 1); if (Title.name.Contains("Attack")) { StatsName = "StatsAttack"; } else if (Title.name.Contains("Agility")) { StatsName = "StatsAgility"; } else if (Title.name.Contains("Power")) { StatsName = "StatsPower"; } else if (Title.name.Contains("Strength")) { StatsName = "StatsStrength"; } else if (Title.name.Contains("Endurance")) { StatsName = "StatsEndurance"; } else if (Title.name.Contains("Speed")) { StatsName = "StatsSpeed"; } else if (Title.name.Contains("Sleep")) { StatsName = "StatsSleep"; } else if (Title.name.Contains("Regen")) { StatsName = "StatsRegen"; } if (DataController.GetValue <int>("SkillPoints") - (DataController.GetValue <int>("AllPts") + (int)((DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine")) * 0.125 + 1)) + 0.01 > 0) { if ((int)((DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine"))) < 40) { foreach (string name in ServerNames) { if (name == StatsName) { //DataController.SaveValue("SpentPoints", (DataController.GetValue<int>("SpentPoints") + (int)((DataController.GetValue<int>(StatsName + "Incr") + DataController.GetValue<int>(StatsName + "Mine")) * 0.125 + 1 - 0.01))); DataController.SaveValue(StatsName + "Incr", 1 + DataController.GetValue <int>(StatsName + "Incr")); DataController.SaveValue("AllPts", (DataController.GetValue <int>("AllPts") + (int)((DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine")) * 0.125 + 1 - 0.01))); WasChanged = true; break; } } ; } } }
public void NewPasswordLogin() { DataController.SaveValue("password", password.text); Debug.Log(password.text); var loginRequest = new AuthenticationRequest(); GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(); data.AddString("password", DataController.GetValue <string>("password")); data.AddString("action", "resetPassword"); data.AddString("token", token.text); loginRequest.SetScriptData(data); loginRequest.SetUserName(DataController.GetValue <string>("username")); loginRequest.SetPassword(password.text); loginRequest.Send(response => { if (response.Errors.GetString("action").Contains("complete")) { Warning.SetActive(true); PopUpMessage.ActivatePopUp(delegate { }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning5")); UIController.SetActivePanel(UI_Element.Login); } if (response.Errors.GetString("action").Contains("invalid")) { Warning.SetActive(true); PopUpMessage.ActivatePopUp(delegate { }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning4") + LocalisationSystem.GetLocalisedValue("password_error")); UIController.SetActivePanel(UI_Element.ConfirmResetPassword); } Debug.Log("well done " + response.Errors.JSON.ToString()); if (!response.HasErrors) { Debug.Log("Error reseting password.../n" + response.Errors.JSON.ToString()); } }); }
public void ReturnSpentSkillPoints(Text Title) { if (Title.text.StartsWith("Attack")) { StatsName = "StatsAttack"; } else if (Title.text.StartsWith("Agility")) { StatsName = "StatsAgility"; } else if (Title.text.StartsWith("Power")) { StatsName = "StatsPower"; } else if (Title.text.StartsWith("Strength")) { StatsName = "StatsStrength"; } else if (Title.text.StartsWith("Endurance")) { StatsName = "StatsEndurance"; } else if (Title.text.StartsWith("Speed")) { StatsName = "StatsSpeed"; } else if (Title.text.StartsWith("Sleep")) { StatsName = "StatsSleep"; } else if (Title.text.StartsWith("Regen")) { StatsName = "StatsRegen"; } foreach (string name in ServerNames) { if (name == StatsName) { if (DataController.GetValue <int>(StatsName + "Incr") > 0) { DataController.SaveValue("AllPts", (DataController.GetValue <int>("AllPts") - (int)((DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine")) * 0.125 + 1 - 0.01))); DataController.SaveValue(StatsName + "Incr", -1 + DataController.GetValue <int>(StatsName + "Incr")); WasChanged = true; } break; } } ; }
private void OnSignUpResponse(string displayName) { if (displayName != null) { DataController.SaveValue("displayName", displayName); UIController.SetActivePanel(UI_Element.MainMenu); EventManager.StopListening <string>("OnSignUpResponse", OnSignUpResponse); } else { ErrorOutPut(LocalisationSystem.GetLocalisedValue("signup_error")); } }
private void OnLoginResponse(string displayName) { if (displayName.Length > 0) { DataController.SaveValue("displayName", displayName); UIController.SetActivePanel(UI_Element.MainMenu); } else { Debug.Log("Error OnLoginResponse"); } EventManager.StopListening <string>("OnLoginResponse", OnLoginResponse); }
private void OnNewPassworLoginResponse(string displayName) { if (displayName.Length > 0) { DataController.SaveValue("displayName", displayName); UIController.SetActivePanel(UI_Element.MainMenu); } else { Debug.Log("Error OnNewPasswordLoginResponse"); } EventManager.StopListening <string>("OnNewPasswordLoginResponse", OnNewPassworLoginResponse); //if (displayName.Length > 0) //{ // LoadScene.SceneLoaderForScript(1); //} }
public static void LoseOnline() { int RatingReward = 0; RatingReward = (DataController.GetValue <int>("Rating") - DataController.GetValue <int>("RatingOther")) / 4; if (RatingReward >= 0) { RatingReward += 4; RatingReward = Mathf.Min(RatingReward, 25); } else { RatingReward -= 4; RatingReward = Mathf.Min(Mathf.Abs(RatingReward), 10); } DataController.SaveValue("RatingChange", -RatingReward / 2); DataController.SaveValue("Rating", DataController.GetValue <int>("Rating") - RatingReward / 2); int expChange = 0; expChange = loseExp; DataController.SaveValue("expAdded", expChange); int breadChange = 0; breadChange = loseBread * multDifference; DataController.SaveValue("breadAdded", breadChange); DataController.SaveValue("Exp", DataController.GetValue <int>("Exp") + expChange / 2); DataController.SaveValue("Bread", DataController.GetValue <int>("Bread") + breadChange / 2); PostGameActions(false); }
public void ResetSkillPoints() { if (EquipmentManager.instance.currentEquipment[5] != null) { if ((int)EquipmentManager.instance.currentEquipment[5].equipSlot == 7) { EquipmentManager.instance.Unequip(5); } } DataController.SaveValue("SkillPoints", DataController.GetValue <int>("SkillPoints") + DataController.GetValue <int>("SpentPoints")); DataController.SaveValue("AllPts", 0); DataController.SaveValue("SpentPoints", 0); foreach (string StatsName in ServerNames) { DataController.SaveValue(StatsName + "Mine", 0); DataController.SaveValue(StatsName + "Incr", 0); } WasChanged = true; }
public static void LoseSingle() { DataController.SaveValue("RatingChange", -RaitingSingleReward); DataController.SaveValue("Rating", DataController.GetValue <int>("Rating") - RaitingSingleReward); int expChange = 0; expChange = loseExp * multDifference; DataController.SaveValue("expAdded", expChange); int breadChange = 0; breadChange = loseBread; DataController.SaveValue("breadAdded", breadChange); DataController.SaveValue("Exp", DataController.GetValue <int>("Exp") + expChange); DataController.SaveValue("Bread", DataController.GetValue <int>("Bread") + breadChange); PostGameActions(false); }
public void GetToken() { DataController.SaveValue("username", username.text); var loginRequest = new AuthenticationRequest(); GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(); data.AddString("action", "passwordRecoveryRequest"); data.AddString("email", email.text); loginRequest.SetScriptData(data); loginRequest.SetUserName(DataController.GetValue <string>("username")); loginRequest.SetPassword(""); loginRequest.Send(response => { if (!response.HasErrors) { Warning.SetActive(true); Warning.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1")); } else { Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString()); Debug.Log(response.Errors.GetString("action")); if (response.Errors.ContainsKey("action")) { Warning.SetActive(true); //Warning.GetComponentsInChildren<Button>()[1].gameObject.SetActive(false); if (response.Errors.GetString("action").Contains("complete")) { Debug.Log("warn1"); UIController.SetActivePanel(UI_Element.ConfirmResetPassword); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1")); } else if (response.Errors.GetString("action").Contains("email") || response.Errors.GetString("action").Contains("invalid")) { Debug.Log("warn2"); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning2")); } else { Debug.Log("exception"); } } } }); }
public void GetSkillPoints() { ResetSkillPoints(); DataController.SaveValue("SkillPoints", 240); DataController.SaveValue("Bread", 2400); }
/// <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, ""); } }); }
public void MoveIn(string InOrOut) { //Debug.Log(DataController.GetValue<int>("SkillPoints") + " " + DataController.GetValue<int>("SpentPoints") + " " + DataController.GetValue<int>("AllPts")); //CharacterInfo = GameObject.FindGameObjectsWithTag("PlayerInfo")[0]; StatsInf.SetActive(false); if (InOrOut == "In") { DataController.SaveValue("SpentPoints", 0); int temp; foreach (string StatsName in ServerNames) { temp = (DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine")); if (temp >= 8) { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + 8); if (temp >= 16) { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + 16); if (temp >= 24) { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + 24); if (temp >= 32) { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + 32); DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + (temp - 32) * 5); } else { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + (temp - 24) * 4); } } else { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + (temp - 16) * 3); } } else { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + (temp - 8) * 2); } } else { DataController.SaveValue("SpentPoints", (DataController.GetValue <int>("SpentPoints")) + temp); } } foreach (string StatsName in ServerNames) { DataController.DeleteValue(StatsName + "Incr"); DataController.DeleteValue("AllPts"); } WasChanged = true; if (CharacterInfo.transform.position.y > 0) { CharacterInfo.transform.position = new Vector3(-1000, -1000, 0); } else { CharacterInfo.transform.position = new Vector3(1, 1.7f, -2); } } else { if (DataController.GetValue <int>("StatsPowerMine") < 16 && EquipmentManager.instance.currentEquipment[7] != null) { EquipmentManager.instance.currentEquipment[4] = null; EquipmentManager.instance.currentEquipment[5] = null; EquipmentManager.instance.Unequip(7); } foreach (string StatsName in ServerNames) { DataController.SaveValue(StatsName + "Mine", DataController.GetValue <int>(StatsName + "Incr") + DataController.GetValue <int>(StatsName + "Mine")); DataController.DeleteValue(StatsName + "Incr"); } DataController.SaveValue("SpentPoints", DataController.GetValue <int>("SpentPoints") + DataController.GetValue <int>("AllPts")); DataController.SaveValue("SkillPoints", DataController.GetValue <int>("SkillPoints") - DataController.GetValue <int>("AllPts")); DataController.DeleteValue("AllPts"); } //Debug.Log(DataController.GetValue<int>("SkillPoints") + " " + DataController.GetValue<int>("SpentPoints") + " " + DataController.GetValue<int>("AllPts")); }