public void PlayerReset() { Debug.LogError("<color=red> Reseting player prefs </color>"); //SVE SE INICIJALIZUJE NA NULU App.score.InitializeBestScoresToZero(); App.player.uid = ""; // App.player.password = ""; // App.player.username = ""; //App.gc.gcId = ""; // App.device.apnToken = ""; // App.fb.fbid = ""; // App.fb.fbUsername = ""; // App.fb.fbEmail = ""; //App.player.birthday = ""; //App.player.gender = ""; // App.sound.sound = "on"; // App.sound.music = "on"; //App.notif.notifications = "on"; //App.player.diamondCount = Crypting.EncryptInt(0); App.player.coinsCount = Crypting.EncryptInt(0); //App.shop.itemDictionary.Clear(); //App.player.lives = Crypting.EncryptInt(App.player.maxLives); //InitializationHelper.stage.lastLevel = Crypting.EncryptInt(0); //InitializationHelper.stage.lastCheckpoint = Crypting.EncryptInt(0); //App.inv.inventory = new Dictionary<string, object>(); //Debug.Log("GAME PROGRESS " + PlayerPrefs.GetString("gameProgress")); ResetFromScripts(); PlayerSave(); }
public void PlayerLoad() { // Debug.Log("<color=blue>Local DB - Player Load</color>"); PrintPP(); //POKUSAJ UCITAVANJA STRINGA, PROVERA DA LI PP POSTOJI string loadedString = PlayerPrefs.GetString("gameProgress"); //IGRAC NIJE PRVI PUT U IGRI if (loadedString != "") { //Debug.Log("<color=blue>Local DB - Player was in game before</color>"); //UCITAVANJE PP U STRING PROMENLJIVE string uid = PlayerPrefs.GetString("uid"); string gcid = PlayerPrefs.GetString("gcid"); string apnToken = PlayerPrefs.GetString("apnToken"); string username = PlayerPrefs.GetString("username"); string password = PlayerPrefs.GetString("password"); string diamondCount = PlayerPrefs.GetString("diamonds"); string coinsCount = PlayerPrefs.GetString("coins"); //Debug.Log(coinsCount + " " + diamondCount); string fbid = PlayerPrefs.GetString("fbid"); string fbName = PlayerPrefs.GetString("fbName"); string fbEmail = PlayerPrefs.GetString("fbEmail"); string birthday = PlayerPrefs.GetString("birthday"); string gender = PlayerPrefs.GetString("gender"); string lives = PlayerPrefs.GetString("lives"); string lastLevel = PlayerPrefs.GetString("lastLevel"); string lastCheckPoint = PlayerPrefs.GetString("lastCheckpoint"); string inventory = PlayerPrefs.GetString("Inventory"); string sound = PlayerPrefs.GetString("sound"); string music = PlayerPrefs.GetString("music"); //string notifications = PlayerPrefs.GetString("notifications"); //UCITAVANJE SKOROVA for (int i = 0; i < bestScores.Count; i++) { bestScores[i].score = PlayerPrefs.GetString(bestScores[i].scoreName); if (bestScores[i].score == "") { bestScores[i].score = Crypting.EncryptInt(0); } // Debug.Log("BEST SCORES " + bestScores[i].score); } for (int i = 0; i < totalScores.Count; i++) { totalScores[i].score = PlayerPrefs.GetString(totalScores[i].scoreName); if (totalScores[i].score == "") { totalScores[i].score = Crypting.EncryptInt(0); } // Debug.Log("TOTAL SCORES " + totalScores[i].score); } string shop = PlayerPrefs.GetString("shop"); string prehash = secretKey + diamondCount + coinsCount; for (int i = 0; i < bestScores.Count; i++) { prehash += bestScores[i].score; } string hashed = mdFiveSum(prehash); // Debug.Log("PREHASH " + prehash); // Debug.Log("HASHED STRING IS " + hashed); // Debug.Log("LOADED STRING IS " + loadedString); // // Debug.Log("GAME PROGRESS " + PlayerPrefs.GetString("gameProgress")); //Debug.Log("<color=blue>Local DB - PP Loaded</color>"); //PROVERA DA LI JE PETLJANO SA PLAYER PREFS //AKO JESTE, RESETUJ IGRACA if (hashed != loadedString && false) { Debug.LogError("CHEATEEEEEEEEEEEEER! :)"); //PlayerReset(); } //AKO NIJE, UPISI SVE GDE TREBA else { //Debug.Log("Loading..."); //App.player.diamondCount = diamondCount; App.player.coinsCount = coinsCount; App.player.uid = uid; //App.sound.sound = sound; //App.sound.music = music; //App.notif.notifications = notifications; //DESERIJALIZACIJA SHOPA //App.shop.itemDictionary = Json.Deserialize(shop) as Dictionary<string, object>; //if(shop == "null") App.shop.itemDictionary = new Dictionary<string, object>(); //Debug.Log("OK"); //App.player.lives = lives; //InitializationHelper.stage.lastLevel = lastLevel; //InitializationHelper.stage.lastCheckpoint = lastCheckPoint; //Debug.Log("Inventory in localdb is " + inventory); //Debug.Log("OK"); Debug.Log(inventory); //DESERIJALIZACIJA INVENTARA if (inventory == "null" || inventory == "") { //Debug.Log("OK"); //App.inv.inventory = new Dictionary<string, object>(); //App.inv.bag = new Dictionary<string, object>(); } //else App.inv.inventory = Json.Deserialize(inventory) as Dictionary<string, object>; //Debug.Log("OK"); //INICIJALIZUJE SE TORBA //App.inv.InitializeBag(); //Debug.Log("OK"); //Debug.Log("Inventory in inventory script is " + InitializationHelper.inventory.inventory.ToString()); //POSTAVLJAJU SE BEST SCOROVI App.score.SetBestScores(bestScores); App.score.SetTotalScores(totalScores); //Debug.Log("<color=blue>Local DB - Info sent to Game Data, calling Merge</color>"); //Debug.Log("GAME PROGRESS " + PlayerPrefs.GetString("gameProgress")); LoadFromScripts(); //NAKON USPESNOG UCITAVANJA, POZIVA SE MERGE FUNKCIJA } localDBReady = true; } //AKO JE PRVI PUT U IGRI, KREIRAJ NALOG NA SERVERU I AZURIRAJ PLAYER PREFS else { //Debug.Log("<color=blue>Local DB - First time in game, initialize PP, call PlayerSave and Merge</color>"); //PlayerPrefs.SetString("gameProgress", "None"); //SVE SE POSTAVLJA NA INICIJALNE VREDNOSTI //string prehash2 = secretKey + App.player.diamondCount + App.player.coinsCount; //string shop = Json.Serialize(App.shop.itemDictionary); // for(int i=0; i<bestScores.Count;i++) // prehash2 += bestScores[i].score; // //string hashed2 = mdFiveSum(prehash2); //PlayerPrefs.SetString("gameProgress", hashed2); PlayerPrefs.SetString("deviceModel", deviceModel); PlayerPrefs.SetString("deviceType", deviceType); PlayerPrefs.SetString("deviceId", deviceId); PlayerPrefs.SetString("deviceName", deviceName); PlayerPrefs.SetString("diamonds", Crypting.EncryptInt(0).ToString()); PlayerPrefs.SetString("coins", Crypting.EncryptInt(0).ToString()); PlayerPrefs.SetString("timeZone", timeZone); //PlayerPrefs.SetString("lives", Crypting.EncryptInt(App.player.maxLives)); PlayerPrefs.SetString("lastLevel", Crypting.EncryptInt(0)); PlayerPrefs.SetString("lastCheckpoint", Crypting.EncryptInt(0)); PlayerPrefs.SetString("sound", "on"); //App.sound.sound = "on"; PlayerPrefs.SetString("music", "on"); //App.sound.music = "on"; //PlayerPrefs.SetString("notifications", "on"); //INVENTAR I TRANSAKCIJE SE POSTAVLJAJU NA INICIJALNE VREDNOSTI //App.inv.inventory = new Dictionary<string, object>(); PlayerPrefs.SetString("Inventory", ""); //App.inv.bag = new Dictionary<string, object>(); //App.shop.itemDictionary = new Dictionary<string, object>(); PlayerPrefs.SetString("shop", ""); //PlayerPrefs.SetString("lives", player.maxLives.ToString()); //App.player.diamondCount = Crypting.EncryptInt(0); App.player.coinsCount = Crypting.EncryptInt(0); //App.shop.UpdateCoinsLabels("0"); //InitializationHelper.stage.lastLevel = Crypting.EncryptInt(0); //InitializationHelper.stage.lastCheckpoint = Crypting.EncryptInt(0); ResetFromScripts(); for (int i = 0; i < bestScores.Count; i++) { PlayerPrefs.SetString(bestScores[i].scoreName, bestScores[i].score); } for (int i = 0; i < totalScores.Count; i++) { PlayerPrefs.SetString(totalScores[i].scoreName, totalScores[i].score); } //Debug.Log("GAME PROGRESS " + PlayerPrefs.GetString("gameProgress")); //PAMTI SE SVE U PP I ZOVE SE MERGE PlayerSave(); SaveFromScripts(); //Debug.Log("GAME PROGRESS " + PlayerPrefs.GetString("gameProgress")); } //App.sound.CheckButtons (); //PrintPP(); //gameData.localDBReady = true; //Debug.Log ("<color=blue>Local DB is ready</color>"); //App.server.Merge(); }