public static void SaveMissionDataCache(bool submitToServer = false) { string dataSave = ""; string dataSendServer = ""; for (int i = 0; i < dataMissionCache.Length; i++) { dataSave += dataMissionCache[i].Mission + "-" + dataMissionCache[i].Score + "-" + dataMissionCache[i].Star + "-" + dataMissionCache[i].Open + ","; //Chi gui nhung mission da open len server if (dataMissionCache[i].Open == 1) { if (dataSendServer.Length > 0) { dataSendServer += ","; } dataSendServer += dataMissionCache[i].Mission + "-" + dataMissionCache[i].Score + "-" + dataMissionCache[i].Star + "-" + dataMissionCache[i].Open; } } Debug.Log("Data save " + dataSave); PlayerPrefs.SetString(Mission_data_key, dataSave); if (submitToServer) { Debug.Log("Data send server " + dataSendServer); AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfoMissionUpdate(FB.UserId, dataSendServer)); } }
void getRank(bool retry, int level) { try { StartCoroutine(DHS.GetRankingMission(level, MissionControl.IdUserFriends, www => { Debug.Log(JsonHelper.FormatJson(www.text)); IDictionary dict = Json.Deserialize(www.text) as IDictionary; if (dict != null && dict["data"] != null) { List <object> lists = dict["data"] as List <object>; for (int i = 1; i <= lists.Count; i++) { Dictionary <string, object> info = lists[i - 1] as Dictionary <string, object>; Transform rank = transform.FindChild("ItemRank" + i); rank.FindChild("Name").GetComponent <UILabel>().text = "" + info["name"]; rank.FindChild("Money").GetComponent <UILabel>().text = DString.ConvertToMoneyString("" + info["score"]); rank.gameObject.GetComponent <Avatar>().SetData(this, "" + info["fb_id"]); rank.gameObject.SetActive(true); } } }, www => { if (retry) { Debug.Log("---------------get rank error => retry ---------------"); getRank(false, level); } })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } }
public static void SaveAchievementCache(bool sendServer = false) { try { Debug.Log("-------------------SaveAchievementCache-----------------"); if (dataAchievementCache != null) { string achievement = ""; for (int i = 0; i < dataAchievementCache.Length; i++) { string s = "" + dataAchievementCache[i].Group + "-" + dataAchievementCache[i].Level + "-" + dataAchievementCache[i].Value + "-" + dataAchievementCache[i].Notify + ","; achievement += s; } //Debug.Log("----------LUU ACHIEVEMENT------------ " + achievement); PlayerPrefs.SetString(Achievement_data_key, achievement); if (FB.IsLoggedIn && sendServer) { //Nếu chưa có playerprefs thì sẽ submit lên luôn //Nếu có rồi thì phải check nó cập nhật hoàn thành từ server về thì mới cho up lên bool check = !PlayerPrefs.HasKey(DataMissionControlNew.key_update_achievement_data_from_server) || (PlayerPrefs.HasKey(DataMissionControlNew.key_update_achievement_data_from_server) && PlayerPrefs.GetInt(DataMissionControlNew.key_update_achievement_data_from_server) == 1); if (check) { AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfoUpdate(DFB.UserId, "" + VariableSystem.diamond, "" + achievement, "", (www) => { Debug.Log("----------Update achievement to server success!------------- " + achievement); })); } else { Debug.Log("----------KHONG CHO UP ACHIEVEMENT VA DIAMOND LEN SERVER------------- " + PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 0)); } } } } catch (Exception e) { Debug.Log("------------ERROR ---------------" + e.Message); if (DataMissionControlNew.test) { MobilePlugin.getInstance().ShowToast("ERROR " + e.Message); } } }
void UpdateClientToServer() { Debug.Log("----------------------Dua du lieu moi len server----------------------"); AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeCurrentMission(currentMissionClient)); string data_mission = ""; for (int i = 0; i < DataCache.dataMissionCache.Length; i++) { //Chi gui nhung mission da open len server if (DataCache.dataMissionCache[i].Open == 1) { if (data_mission.Length > 0) { data_mission += ","; } data_mission += DataCache.dataMissionCache[i].Mission + "-" + DataCache.dataMissionCache[i].Score + "-" + DataCache.dataMissionCache[i].Star + "-" + DataCache.dataMissionCache[i].Open; } DialogLoadingFB.HideFBLoading(); } AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfoMissionUpdate(FB.UserId, "" + data_mission)); DataCache.SaveAchievementCache(true); }
public void LoginButton() { AudioControl.DPlaySound("Click 1"); if (FB.IsInitialized) { if (!isShowLogin) { isShowLogin = true; if (!FB.IsLoggedIn) { DFB.FBLogin(result => { if (FB.IsLoggedIn) { if (String.IsNullOrEmpty(PlayerPrefs.GetString(DataCache.FB_ID, ""))) { FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl => { IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary; if (dict1 != null && dict1["id"] != null) { DFB.UserId = "" + dict1["id"]; DFB.UserName = "" + dict1["name"]; PlayerPrefs.SetString(DataCache.FB_ID, DFB.UserId); PlayerPrefs.SetString(DataCache.FB_USER, DFB.UserName); try { AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfo(DFB.UserId, DFB.UserName, "" + dict1["locale"], "" + dict1["last_name"])); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } } }); } else { DFB.UserId = PlayerPrefs.GetString(DataCache.FB_ID); DFB.UserName = PlayerPrefs.GetString(DataCache.FB_USER); } HideLoginDialog(); } else { isShowLogin = false; ShowCofirm(); } }); } else { HideLoginDialog(); } } } else { ShowCofirm(); } }
public void LoginButton(bool hideLoading = true) { //MobilePlugin.getInstance().ShowToast("Click login"); string error = ""; //AudioControl.DPlaySound("Click 1"); try { if (FB.IsInitialized) { if (FB.IsLoggedIn) { HideLoginDialog(); GetFriendsList(); loginButton.gameObject.SetActive(false); transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true); // transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true); // transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true); } else { DFB.FBLogin(result => { //MobilePlugin.getInstance().ShowToast("FB.IsLoggedIn " + FB.IsLoggedIn); if (FB.IsLoggedIn) { loginButton.gameObject.SetActive(false); transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true); // transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true); // transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true); //get friends list GetFriendsList(); //count message CountMessage(); //Get info user if (String.IsNullOrEmpty(PlayerPrefs.GetString(DataCache.FB_ID, ""))) { FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl => { IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary; if (dict1 != null && dict1["id"] != null) { DFB.UserId = "" + dict1["id"]; DFB.UserName = "" + dict1["name"]; PlayerPrefs.SetString(DataCache.FB_ID, DFB.UserId); PlayerPrefs.SetString(DataCache.FB_USER, DFB.UserName); try { AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfo(DFB.UserId, DFB.UserName, "" + dict1["locale"], "" + dict1["last_name"])); } catch (Exception e) { ShowConfirm(); Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); error = "" + e.Message; } } }); } else { DFB.UserId = PlayerPrefs.GetString(DataCache.FB_ID); DFB.UserName = PlayerPrefs.GetString(DataCache.FB_USER); } } else { ShowConfirm(); } }); } } else { DFB.FBInit(); ShowConfirm(); } } catch (Exception e) { ShowConfirm(); Debug.Log("--------------------Error Login FB-------------------" + e.Message); error = "" + e.Message; } //MobilePlugin.getInstance().ShowToast("error " + error); }
void UpdateServerToClient() { try { DialogLoadingFB.ShowFBLoading(); PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 0); PlayerPrefs.SetInt(DataMissionControlNew.key_update_achievement_data_from_server, 0); //Them du lieu tam thoi truoc(de phong truong hop ko truy van dc) for (int i = 0; i < currentMissionServer; i++) { DataCache.UpdateMissionScore(0, 0, i + 1, 1); } //Lay du lieu nguoi dung try { AudioControl.getMonoBehaviour().StartCoroutine(DHS.GetMeInfo(FB.UserId, www => { Debug.Log(JsonHelper.FormatJson(www.text)); IDictionary dict = Json.Deserialize(www.text) as IDictionary; if (dict != null && dict["data"] != null) { List <object> lists = dict["data"] as List <object>; if (lists.Count > 0) { Dictionary <string, object> info = lists[0] as Dictionary <string, object>; int diamond = Convert.ToInt32(info["diamond"]); string achievement = Convert.ToString(info["achievement"]); DataCache.RestoreUserData(diamond, achievement); //GameObject.Find("DialogAchievement").GetComponent<DialogAchievement>().CountAchievementFinish(); string data_mission = Convert.ToString(info["mission_data"]); //Phan tich du lieu va chi lay nhung du lieu co score, star > o client string[] dataMission = data_mission.Split(','); for (int i = 0; i < dataMission.Length; i++) { string[] info_mission = dataMission[i].Split('-'); string mission = info_mission[0]; string score = info_mission[1]; string star = info_mission[2]; string open = info_mission[3]; DataCache.UpdateMissionScore(Convert.ToInt32(score), Convert.ToInt16(star), Convert.ToInt16(mission), Convert.ToInt16(open)); } DataCache.SaveMissionDataCache(); PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 1); //Debug.Log("------ Update ------ "); ShowStarMission(); ShowCurrentMission(); DialogLoadingFB.HideFBLoading(); } } }, www => { DialogLoadingFB.HideFBLoading(); ShowRetryLoad(() => { UpdateServerToClient(); }); if (debug) { MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer"); } })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } }
//Lay current mission server void CheckDataMissionServer() { try { DialogLoadingFB.ShowFBLoading(); //Debug.Log("Truy van toi server iduser = "******"All current mission :" + JsonHelper.FormatJson(www.text)); bool postToServer = true; IDictionary dict = Json.Deserialize(www.text) as IDictionary; if (dict != null && dict["data"] != null) { List <object> lists = dict["data"] as List <object>; string data_save = ""; for (int i = 1; i <= lists.Count; i++) { Dictionary <string, object> info = lists[i - 1] as Dictionary <string, object>; string id = "" + info["fb_id"]; string mission = "" + info["mission"]; string name = "" + info["name"]; if (data_save.Length > 0) { data_save += ","; } if (id.Equals(FB.UserId)) { //Debug.Log("Mission hien tai truoc so sanh " + CurrentMissionFromClient + " mission " + mission); //neu mission tren server > mission o client moi cap nhat mission cua nguoi choi currentMissionServer = Convert.ToInt16(mission); Debug.Log("Current mission on server " + currentMissionServer); if (currentMissionServer > currentMissionClient || PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0) { //Update new current data data_save += "Me-" + name + "-" + currentMissionServer; UpdateServerToClient(); postToServer = false; if (PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0) { Debug.Log("---------------Update lai tu server do chua update day du-------------------"); } } else { data_save += "Me-" + name + "-" + currentMissionClient; } } else { data_save += id + "-" + name + "-" + mission; } } //Debug.Log("" + data_save); if (!String.IsNullOrEmpty(data_save)) { DataCache.SaveCurrentMission(data_save); } } Debug.Log("currentMissionServer " + currentMissionServer); if (postToServer && currentMissionServer < currentMissionClient) { UpdateClientToServer(); } else { Debug.Log("Du lieu cu => ko up"); if (!(currentMissionServer > currentMissionClient)) { DialogLoadingFB.HideFBLoading(); } } }, www => { DialogLoadingFB.HideFBLoading(); Debug.Log("Loi response CheckDataMissionServer"); if (debug) { MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer"); } ShowRetryLoad(() => { Debug.Log("Retry CheckDataMissionServer"); CheckDataMissionServer(); }, () => { }); })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } }
public void Show() { Time.timeScale = 1.0f; MissionControl.ResetAllItem(); LoadingScene.HideLoadingScene(); CommonObjectScript.isViewPoppup = true; //Debug.Log("Show result ----------------------------------"); missionFail.localScale = new Vector3(8, 8, 1); missionFail.gameObject.SetActive(false); TweenAlpha.Begin(missionFail.gameObject, 0, 0); star = 0; if (DialogTask.complete) { star = 1; reward = MissionData.starMission.reward[0]; if (CommonObjectScript.dollar >= MissionData.starMission.twoStar) { reward = MissionData.starMission.reward[1]; star = 2; } if (CommonObjectScript.dollar >= MissionData.starMission.threeStar) { reward = MissionData.starMission.reward[2]; star = 3; } particleWin.gameObject.SetActive(true); ///////////------------------------------------------ AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeCurrentMission(VariableSystem.mission + 1)); //Cong tim khi thang AudioControl.AddHeart(1); //Nhac thang AudioControl.DPlaySound("Thang"); } else { //Nhac thua AudioControl.DPlaySound("Thua"); } //star = 3;////////////////////////////////////////////////////// //particleWin.gameObject.SetActive(true); if (Application.loadedLevelName.Equals("Farm")) { GameObject.Find("UI Root").transform.FindChild("PanelPlant").GetComponent <PlantControlScript>().BG_Click(); } lbReward.text = "0"; //Test //VariableSystem.dollar = 1000; //Thay doi ngon ngu bgMain.FindChild("Target").GetComponent <UILabel>().text = "" + MissionControl.Language["Require"]; bgMain.FindChild("Score").GetComponent <UILabel>().text = "" + MissionControl.Language["Your_Score"]; bgMain.FindChild("Reward").GetComponent <UILabel>().text = "" + MissionControl.Language["Reward"]; bgMain.FindChild("Ok").FindChild("Label").GetComponent <UILabel>().text = "" + MissionControl.Language["Ok"]; bgMain.FindChild("TryAgain").FindChild("Label").GetComponent <UILabel>().text = "" + MissionControl.Language["Try_Again"]; bgMain.FindChild("RewardCustomer").GetComponent <UILabel>().text = "" + MissionControl.Language["Bonus_customer_rate"]; bgMain.FindChild("LbStar1").GetComponent <UILabel>().text = "" + MissionControl.Language["All_target"]; lbTitle.text = MissionControl.Language["MISSION"] + " " + VariableSystem.mission; bgMain.FindChild("LbStar2").GetComponent <UILabel>().text = DString.ConvertString(MissionData.starMission.twoStar); bgMain.FindChild("LbStar3").GetComponent <UILabel>().text = DString.ConvertString(MissionData.starMission.threeStar); bgMain.FindChild("Score").FindChild("Label").GetComponent <UILabel>().text = DString.ConvertString(CommonObjectScript.dollar); bgBlack.gameObject.SetActive(true); LeanTween.delayedCall(1.0f, () => { Time.timeScale = 0; }).setUseEstimatedTime(true); bgMain.gameObject.SetActive(true); LeanTween.scale(bgMain.gameObject, new Vector3(1, 1, 1), 0.4f).setUseEstimatedTime(true).setEase(LeanTweenType.easeOutBack).setOnComplete(() => { star1.localScale = new Vector3(8, 8, 8); star2.localScale = new Vector3(8, 8, 8); star3.localScale = new Vector3(8, 8, 8); //Dieu kien xet sao if (star > 0) { star1.gameObject.SetActive(true); LeanTween.scale(star1.gameObject, new Vector3(1, 1, 1), 0.5f).setUseEstimatedTime(true).setEase(LeanTweenType.easeOutExpo).setOnComplete(() => { //Check dieu kien de co sao thu 2 if (star > 1) { star2.gameObject.SetActive(true); LeanTween.scale(star2.gameObject, new Vector3(1, 1, 1), 0.5f).setUseEstimatedTime(true).setEase(LeanTweenType.easeOutExpo).setOnComplete(() => { //Check dieu kien de co sao thu 3 if (star > 2) { star3.gameObject.SetActive(true); LeanTween.scale(star3.gameObject, new Vector3(1, 1, 1), 0.5f).setUseEstimatedTime(true).setEase(LeanTweenType.easeOutExpo); } }); } }); } else { missionFail.gameObject.SetActive(true); LeanTween.scale(missionFail.gameObject, new Vector3(1, 1, 1), 0.5f).setUseEstimatedTime(true).setEase(LeanTweenType.easeInOutQuart); TweenAlpha.Begin(missionFail.gameObject, 0.5f, 1); } }); //Them task nhiem vu //if (VariableSystem.mission == 1) //{ // AddItemResult("" + MissionControl.Language["Control_guide"], true, null, false); //} foreach (Transform tf in dialogTask.FindChild("Grid").GetComponent <UIGrid>().GetChildList()) { AddItemResult(tf.GetComponent <ItemTask>().lbContent.text, tf.GetComponent <ItemTask>().togComplete.value, tf.GetComponent <ItemTask>().item, tf.GetComponent <ItemTask>().typeShow1); } grid.Reposition(); transform.FindChild("SpriteBlack").gameObject.SetActive(true); //An bang task khi hien thi result GameObject task = GameObject.Find("DialogTask").gameObject; if (task != null) { task.GetComponent <DialogTask>().HideButton(); } GameObject inapp = GameObject.Find("DialogInapp").gameObject; if (inapp != null) { inapp.GetComponent <DialogInapp>().HideDialog(); } //Cap nhat lai phan thuong - Neu so sao moi <= so sao hien tai => thuong 1 kim cuong if (star > 0 && star <= DataCache.dataMissionCache[VariableSystem.mission - 1].Star) { reward = 1; } VariableSystem.AddDiamond(reward); VariableSystem.AddDiamond(CommonObjectScript.rewardCustomerRate); Debug.Log("CONG KIM CUONG -------------------- reward " + reward + " CommonObjectScript.rewardCustomerRate " + CommonObjectScript.rewardCustomerRate); DataCache.UpdateMissionScore(CommonObjectScript.dollar, star, VariableSystem.mission, 1); bool sendToServer = false; if (star > 0) { if (VariableSystem.mission < DataMissionControlNew.MAX_MISSION) { DataCache.SetMeCurrentMission(VariableSystem.mission + 1); } sendToServer = true; } DataCache.SaveMissionDataCache(sendToServer); lbReward.text = "" + reward; lbRewardCustomer.text = "" + CommonObjectScript.rewardCustomerRate; }