public static void LoadLeaderboardData(int limit, Action <Task, LeaderboardData> callback) { CollectionReference collectionRef = db.Collection(leaderboardId); Query query = collectionRef.OrderByDescending(UserScoreData.USER_SCORE_PROPERTY_NAME).Limit(limit); query.GetSnapshotAsync().ContinueWithOnMainThread(task => { if (!task.IsCompleted) { return; } QuerySnapshot querySnapshot = task.Result; LeaderboardData leaderboardData = new LeaderboardData(); foreach (DocumentSnapshot docSnapshot in querySnapshot.Documents) { UserScoreData userScoreData = docSnapshot.ConvertTo <UserScoreData>(); leaderboardData.scores.Add(userScoreData); } callback?.Invoke(task, leaderboardData); }); }
public IEnumerator SubmitAllScores() { UserScoreData userScores = UserScoreData.Load(); WWWForm wwwForm = new WWWForm(); wwwForm.AddField("facebook_id", FB.UserId); wwwForm.AddField("app_token", UserDataManager.APP_TOKEN); wwwForm.AddField("scores", userScores.SerializeToJsonUsingGlobalId()); Debug.Log("facebook_id : " + FB.UserId); Debug.Log("app_token : " + UserDataManager.APP_TOKEN); Debug.Log("scores : " + userScores.SerializeToJsonUsingGlobalId()); WWW www = new WWW(UserDataManager.URL_SUBMIT_ALL_SCORE, wwwForm); yield return(www); if (www.error == null) { Debug.Log("SubmitAllScores : " + www.text); SubmitScoreStatus = true; } else { if (CountSubmitAllScores < 3) { StartCoroutine(SubmitAllScores()); CountSubmitAllScores++; } else { SubmitScoreStatus = true; } } }
public static void SendScore(UserScoreData userScoreData, Action <Task> callback) { if (!isAuthenticated || userScoreData == null) { return; } DocumentReference userDocRef = db.Collection(leaderboardId).Document(auth.CurrentUser.UserId); userDocRef.GetSnapshotAsync().ContinueWithOnMainThread(task => { if (!task.IsCompleted) { return; } if (task.Result.Exists) { UserScoreData savedScoreData = task.Result.ConvertTo <UserScoreData>(); if (userScoreData.userScore <= savedScoreData.userScore) { callback?.Invoke(task); return; } } userDocRef.SetAsync(userScoreData).ContinueWithOnMainThread(secondTask => { callback?.Invoke(secondTask); }); }); }
public static UserScoreData Load() { BinaryFormatter formater = new BinaryFormatter(); UserScoreData data; FileStream fileStream; if (!File.Exists(Application.persistentDataPath + "/userScore.dat")) { fileStream = File.Create(Application.persistentDataPath + "/userScore.dat"); data = new UserScoreData(); formater.Serialize(fileStream, data); fileStream.Close(); } else { fileStream = File.Open(Application.persistentDataPath + "/userScore.dat", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); data = (UserScoreData)formater.Deserialize(fileStream); fileStream.Close(); if (data.IdDevice != SystemInfo.deviceUniqueIdentifier) { FileStream fileStream2 = File.Create(Application.persistentDataPath + "/userScore.dat"); data = new UserScoreData(); formater.Serialize(fileStream2, data); fileStream2.Close(); } } return(data); }
public static void SendRecord(Action <Task> callback) { UserScoreData userScoreData = new UserScoreData(GPGSManager.GetUserName(), DataManager.record.GetValue()); DocumentReference userDocRef = db.Collection(leaderboardId).Document(auth.CurrentUser.UserId); userDocRef.SetAsync(userScoreData).ContinueWithOnMainThread(secondTask => { callback?.Invoke(secondTask); }); }
public IEnumerator ReadAllScores() { WWWForm wwwForm = new WWWForm(); wwwForm.AddField("facebook_id", FB.UserId); wwwForm.AddField("app_token", UserDataManager.APP_TOKEN); WWW www = new WWW(UserDataManager.URL_READ_ALL_SCORE, wwwForm); yield return(www); if (www.error == null) { Debug.Log("ReadAllScores : " + www.text); UserScoreData userScore = UserScoreData.Load(); var dict = Json.Deserialize(www.text) as Dictionary <string, object>; List <object> data = dict["data"] as List <object>; Debug.Log(data); if (data != null) { Debug.Log("Berhasil"); for (int i = 0; i < data.Count; i++) { Dictionary <string, object> scoreData = (Dictionary <string, object>)data[i]; userScore.RenewScore(int.Parse((string)scoreData["level_system_id"]), int.Parse((string)scoreData["score"])); } } else { Debug.Log("Gagal"); } ReadScoreStatus = true; if (OnReadAllScoresSuccess != null) { OnReadAllScoresSuccess(); } } else { Debug.Log("ReadAllScores : " + www.error); if (CountRequestReadAllScore < 3) { StartCoroutine(SubmitAllScores()); CountRequestReadAllScore++; } else { ReadScoreStatus = true; } } }
public StaticLevel(string Season, string Place, int level) : base(EntityManager.XMLToInstance <StaticLevel>(Resources.Load <TextAsset>(Season + "/" + Place + "/" + level.ToString()).text)) { this.Season = Season; this.Place = Place; this.Level = level; StaticLevel temp = EntityManager.XMLToInstance <StaticLevel>(Resources.Load <TextAsset>(Season + "/" + Place + "/" + level.ToString()).text); this.WhiteQuantity = temp.WhiteQuantity; this.RedQuantity = temp.RedQuantity; this.OrangeQuantity = temp.OrangeQuantity; UserScoreData userScore = UserScoreData.Load(); this.HighScore = userScore.GetScore(Place, Level); }
/*public StaticLevel(string GlobalId,string Season, string Place, int level) * : base(EntityManager.XMLToInstance<StaticLevel>(Resources.Load<TextAsset>(Season + "/" + Place + "/" + level.ToString()).text)) * { * this.GlobalId = GlobalId; * this.Season = Season; * this.Place = Place; * this.Level = level; * StaticLevel temp = EntityManager.XMLToInstance<StaticLevel>(Resources.Load<TextAsset>(Season + "/" + Place + "/" + level.ToString()).text); * this.WhiteQuantity = temp.WhiteQuantity; * this.RedQuantity = temp.RedQuantity; * this.OrangeQuantity = temp.OrangeQuantity; * UserScoreData userScore = UserScoreData.Load(); * this.HighScore = userScore.GetScore(Place, Level); * }*/ public override void Save() { UserScoreData userScore = UserScoreData.Load(); userScore.SetScore(Place, Level, HighScore); if (HighScore >= ScoreFor3Star) { userScore.SetStar(Place, Level, 3); } else if (HighScore >= ScoreFor2Star) { userScore.SetStar(Place, Level, 2); } else if (HighScore > 0) { userScore.SetStar(Place, Level, 1); } }
void Start() { userScore = UserScoreData.Load(); UserSoundConfig config = UserSoundConfig.Load(); for (int i = 0; i < audioSourcesEffect.Length; i++) { audioSourcesEffect[i].volume = config.SoundVolume; audioSourcesEffect[i].mute = !config.SoundStatus; } SceneCommunication sceneCommunication = new SceneCommunication(SceneName.ChoosePlace); List <CommunicationData> dataRecieveds = sceneCommunication.RetrieveMessages(); if (dataRecieveds.Count > 0 && (dataRecieveds[0].Sender == SceneName.ChooseLevelParbaba || dataRecieveds[0].Sender == SceneName.ChooseLevelBatuguru || dataRecieveds[0].Sender == SceneName.ChooseLevelParapat || dataRecieveds[0].Sender == SceneName.ChooseLevelTomok)) { FirstSelected = (string)dataRecieveds[0].Data; } if (FirstSelected == "Parbaba") { PanelItem.GetComponent <RectTransform>().localPosition = new Vector3(715, PanelItem.GetComponent <RectTransform>().localPosition.y, PanelItem.GetComponent <RectTransform>().localPosition.z); } else if (FirstSelected == "Batuguru") { PanelItem.GetComponent <RectTransform>().localPosition = new Vector3(276, PanelItem.GetComponent <RectTransform>().localPosition.y, PanelItem.GetComponent <RectTransform>().localPosition.z); } else if (FirstSelected == "Parapat") { PanelItem.GetComponent <RectTransform>().localPosition = new Vector3(-227, PanelItem.GetComponent <RectTransform>().localPosition.y, PanelItem.GetComponent <RectTransform>().localPosition.z); } else if (FirstSelected == "Tomok") { PanelItem.GetComponent <RectTransform>().localPosition = new Vector3(-673, PanelItem.GetComponent <RectTransform>().localPosition.y, PanelItem.GetComponent <RectTransform>().localPosition.z); } string command = "{"; command += "action:OPEN_CHOOSEPLACE"; command += "}"; ServerStatistic.DoRequest(command); }
public void Refresh() { dataLevel = new StaticLevel(Season, Place, Level); UserScoreData userScoreData = UserScoreData.Load(); if (RequiredLevel < 1) { RequiredLevel = 1; } if (userScoreData.GetScore(RequiredPlace, RequiredLevel) > 0 || (Place == "Parbaba" && Level == 1) || canPlay) { canPlay = true; Image imageComponent = GetComponent <Image>(); imageComponent.sprite = FinishedSprite; } if (dataLevel.HighScore > 0) { HideRubbishes(); } ShowStar(); }
// Use this for initialization void Start() { transform.localScale = BasicScale; textStar.text = UserScoreData.Load().GetPlaceStar(Place).ToString(); }
public void Success() { if (State != GameplayState.Success) { PlayManager.ScoreTime = (int)(1200 - (float.Parse(TimePlaying.ToString("F1")) * 10)); PlayManager.Score += PlayManager.ScoreTime; if (Score < 0) { Score = 0; } State = GameplayState.Success; if (Mode == GameplayMode.StaticLevel) { UserScoreData userScore = UserScoreData.Load(); int BintangSebelumnya = userScore.GetStar(dataStaticLevel.Place, dataStaticLevel.Level); dataStaticLevel.HighScore = Score; if (Score >= dataStaticLevel.ScoreFor3Star) { Bintang = 3; } else if (Score >= dataStaticLevel.ScoreFor2Star) { Bintang = 2; } else { Bintang = 1; } UserStockData userStockDagta = UserStockData.Load(); List <BubbleType> bubblesGet = new List <BubbleType>(); int maksGold = 0;; int goldGet = 0; if (Bintang == 3 && BintangSebelumnya == 3) { maksGold = (int)(Score / 100f); goldGet = maksGold; } else if (Bintang == 3 && BintangSebelumnya == 2) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * ((11 / 11f) - (5 / 11f))); } else if (Bintang == 3 && BintangSebelumnya == 1) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * ((11 / 11f) - (2 / 11f))); } else if (Bintang == 3 && BintangSebelumnya == 0) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * (11 / 11f)); } else if (Bintang == 2 && BintangSebelumnya >= 2) { maksGold = (int)(Score / 100f); goldGet = maksGold; } else if (Bintang == 2 && BintangSebelumnya == 1) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * ((5 / 11f) - (2 / 11f))); } else if (Bintang == 2 && BintangSebelumnya == 0) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * (5 / 11f)); } else if (Bintang == 1 && BintangSebelumnya >= 1) { maksGold = (int)(Score / 100f); goldGet = maksGold; } else if (Bintang == 1 && BintangSebelumnya == 0) { maksGold = (int)((Score / 100f) * 10); goldGet = (int)(maksGold * (2 / 11f)); } if (Bintang == 3) { int indicator = Random.Range(1, 282); if (indicator >= 1 && indicator <= 94) { bubblesGet.Add(BubbleType.White); } else if (indicator >= 95 && indicator <= 188) { bubblesGet.Add(BubbleType.Red); } else if (indicator >= 189 && indicator <= 282) { bubblesGet.Add(BubbleType.Orange); } indicator = Random.Range(1, 282); if (indicator >= 1 && indicator <= 94) { bubblesGet.Add(BubbleType.White); } else if (indicator >= 95 && indicator <= 188) { bubblesGet.Add(BubbleType.Red); } else if (indicator >= 189 && indicator <= 282) { bubblesGet.Add(BubbleType.Orange); } } else if (Bintang == 2) { int indicator = Random.Range(1, 282); if (indicator >= 1 && indicator <= 94) { bubblesGet.Add(BubbleType.White); } else if (indicator >= 95 && indicator <= 188) { bubblesGet.Add(BubbleType.Red); } else if (indicator >= 189 && indicator <= 282) { bubblesGet.Add(BubbleType.Orange); } } dataStaticLevel.Save(); userStockDagta.PlusMinGold(goldGet); int bubbleWhiteGet = 0; int bubbleRedGet = 0; int bubbleOrangeGet = 0; foreach (BubbleType typeGet in bubblesGet) { if (typeGet == BubbleType.White) { userStockDagta.PlusMinBubble(1, 0, 0); bubbleWhiteGet++; } else if (typeGet == BubbleType.Red) { userStockDagta.PlusMinBubble(0, 1, 0); bubbleRedGet++; } else if (typeGet == BubbleType.Orange) { userStockDagta.PlusMinBubble(0, 0, 1); bubbleOrangeGet++; } } //Statistik string command = "{"; command += "action:PlAY_LEVEL"; command += ",place:" + dataStaticLevel.Place; command += ",level:" + dataStaticLevel.Level; command += ",status:4_SUCCESS"; command += ",timePlaying:" + TimePlaying.ToString(); if (FB.IsLoggedIn) { command += ",facebook_id:" + FB.UserId; } command += ",score:" + Score; command += ",goldGet:" + goldGet; command += ",bubbleGetWhite:" + bubbleWhiteGet; command += ",bubbleGetRed:" + bubbleRedGet; command += ",bubbleGetOrange:" + bubbleOrangeGet; command += "}"; ServerStatistic.DoRequest(command); successPopupController.ShowForPlayingStaticLevel(Score, Bintang, goldGet, bubblesGet, SuccessCallback); } else if (Mode == GameplayMode.Edited) { if (Score > dataLevel.ScoreFor3Star) { Bintang = 3; } else if (Score > dataLevel.ScoreFor2Star) { Bintang = 2; } else { Bintang = 1; } successPopupController.ShowForPlayingEditedLevel(Score, Bintang, SuccessCallback); Debug.Log("Edited"); } else if (Mode == GameplayMode.ValidateLevel) { if (Score > dataLevel.ScoreFor3Star) { Bintang = 3; } else if (Score > dataLevel.ScoreFor2Star) { Bintang = 2; } else { Bintang = 1; } successPopupController.ShowForValidateLevel(Score, Bintang, SuccessCallback); Debug.Log("ValidateLevel"); } } Debug.Log("Score Time :" + PlayManager.ScoreTime); Debug.Log("Time Playing :" + TimePlaying); Debug.Log("Time Playing dengan 1 Decimal:" + float.Parse(TimePlaying.ToString("F1")) * 10); }
public string SerializeToJsonUsingGlobalId() { UserScoreData userScore = UserScoreData.Load(); List <Dictionary <string, string> > scores = new List <Dictionary <string, string> >(); int i = 1; bool finish = false; while (i <= 20 && !finish) { if (userScore.ParbabaScore[i - 1] != 0) { Dictionary <string, string> score = new Dictionary <string, string>(); score.Add("level", i + ""); score.Add("score", userScore.ParbabaScore[i - 1] + ""); scores.Add(score); } else { finish = true; } i++; } while (i <= 40 && !finish) { if (userScore.BatuguruScore[i - 21] != 0) { Dictionary <string, string> score = new Dictionary <string, string>(); score.Add("level", i + ""); score.Add("score", userScore.BatuguruScore[i - 21] + ""); scores.Add(score); } else { finish = true; } i++; } while (i <= 60 && !finish) { if (userScore.ParapatScore[i - 41] != 0) { Dictionary <string, string> score = new Dictionary <string, string>(); score.Add("level", i + ""); score.Add("score", userScore.ParapatScore[i - 41] + ""); scores.Add(score); } else { finish = true; } i++; } while (i <= 80 && !finish) { if (userScore.TomokScore[i - 61] != 0) { Dictionary <string, string> score = new Dictionary <string, string>(); score.Add("level", i + ""); score.Add("score", userScore.TomokScore[i - 61] + ""); scores.Add(score); } else { finish = true; } i++; } ; return(Json.Serialize(scores)); }