// Envia a conexao ao servidor public void send(GameJsonAuthConnection.ConnectionAnswerWithState callback) { if (!semaphore.WaitOne(0)) { //Debug.Log("Pero no."); return; } //Debug.Log("Yaarrrrr."); GameJsonAuthConnection conn = new GameJsonAuthConnection(url, callback); // Cria o header Hashtable table = new Hashtable(headers.Count); foreach (DictionaryEntry entry in headers) table.Add(entry.Key, entry.Value); // Decide se e uma conexao binaria string delimiter; if (!table.Contains("Content-Type")) delimiter = "&"; else { Match match = Regex.Match(table["Content-Type"].ToString(), @"boundary=\""(.*)"""); if (match.Success) delimiter = match.Groups[1].Value; else delimiter = "&"; } byte[] fdata = (byte[]) data.Clone(); string adata = null; if (delimiter == "&") { adata = ""; if (data.Length != 0) adata += "&"; adata += "device=" + WWW.EscapeURL(SystemInfo.deviceUniqueIdentifier.Replace("-","")) + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())); } else { adata = @" Content-Type: text/plain; charset=""utf-8"" Content-disposition: form-data; name=""device"" " + SystemInfo.deviceUniqueIdentifier.Replace("-","") + @" --" + delimiter + @" Content-Type: text/plain; charset=""utf-8"" Content-disposition: form-data; name=""token"" " + Save.GetString(PlayerPrefsKeys.TOKEN.ToString()) + @" --" + delimiter + @"-- "; System.Array.Resize<byte>(ref fdata, fdata.Length - 4); } byte[] bdata = System.Text.Encoding.ASCII.GetBytes(adata); int size = fdata.Length; System.Array.Resize<byte>(ref fdata, fdata.Length + bdata.Length); bdata.CopyTo(fdata, size); conn.connect(fdata, table, id); }
public void AddFriendConnection(string friendID) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/sharestage.php", OnShareStage); WWWForm form = new WWWForm(); form.AddField("stageName", Flow.currentRank.name); form.AddField("stageID", Flow.currentRank.id); form.AddField("friendID", friendID); int firstWorld = 9999; foreach (KeyValuePair <int, World> w in Flow.worldDict) { if (w.Key < firstWorld) { firstWorld = w.Key; } } form.AddField("world", (firstWorld + Flow.currentRank.world).ToString()); string tileset = ""; foreach (List <int> listInt in Flow.currentRank.tileset) { foreach (int i in listInt) { tileset += i; } } Debug.Log(tileset); form.AddField("tileset", tileset); conn.connect(form); }
private void postActionFacebook() { Debug.Log("postActionFacebook"); int firstWorld = 9999; int firstLevel = 9999; foreach (KeyValuePair <int, World> w in Flow.worldDict) { if (w.Key < firstWorld) { firstWorld = w.Key; } } firstLevel = 9999; foreach (KeyValuePair <int, Level> l in Flow.worldDict[firstWorld].levelDict) { if (l.Key < firstLevel) { firstLevel = l.Key; } } GameJsonAuthConnection postFb = new GameJsonAuthConnection(Flow.URL_BASE + "mines/publish_single.php", actionResponse); WWWForm form = new WWWForm(); form.AddField("world", Flow.currentGame.world.id - firstWorld + 1); form.AddField("level", Flow.currentGame.level.id - firstLevel - (Flow.currentGame.world.id - firstWorld) * 9 + 1); form.AddField("time", Mathf.CeilToInt(timeCounter)); form.AddField("deaths", Flow.hpLevel + 3 - currentHp); postFb.connect(form); }
/*string TextChanged(UITextField field, string text, ref int insertion) * { * Debug.Log("TO DO: FAZER O SEARCH"); * ///Debug.Log(text); * * //Debug.Log(scroll.Count); * * for(int i = 0 ; i < removedScroll.Count ; i++) * { * if(removedScroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text.Contains(text)) * { * scroll.InsertItem(removedScroll.GetItem(i),removedScroll.GetItem(i).transform.GetComponent<Friend>().index); * removedScroll.RemoveItem(removedScroll.GetItem(i),false); * } * } * * for(int i = 0 ; i < scroll.Count ; i++) * { * if(scroll.GetItem(i).transform.tag != "Letter") * { * //Debug.Log(scroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text); * if(!scroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text.Contains(text)) * { * scroll.GetItem(i).transform.GetComponent<Friend>().index = i; * removedScroll.AddItem(scroll.GetItem(i)); * scroll.RemoveItem(scroll.GetItem(i),false); * } * } * } * * * return text; * }*/ public void GetFriends() { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/list.php", HandleGetFriends); conn.connect(null, 10); }
// Obtem as informacoes dos amigos do usuario void HandleGetFriends(string error, IJSonObject data, object counter_o) { Debug.Log(data); int counter = (int)counter_o; Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (error != null || data == null) { if (counter > 0) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/list.php", HandleGetFriends); conn.connect(null, counter - 1); return; } Flow.game_native.showMessage("Error", error); return; } string allLetter = ""; string playingLetter = ""; if (data.Count > 0) { allLetter = data[0]["name"].StringValue.Substring(0, 1).ToUpper(); GameObject firstL = GameObject.Instantiate(letterPrefab) as GameObject; firstL.transform.FindChild("Letter").GetComponent <SpriteText>().Text = allLetter.ToUpper(); scroll.AddItem(firstL); } foreach (IJSonObject friend in data.ArrayItems) { GameObject allContainer = CreateFriendContainer(friend); if (friend["name"].StringValue.Substring(0, 1).ToUpper() != allLetter) { allLetter = friend["name"].StringValue.Substring(0, 1).ToUpper(); GameObject l = GameObject.Instantiate(letterPrefab) as GameObject; l.transform.FindChild("Letter").GetComponent <SpriteText>().Text = allLetter.ToUpper(); scroll.AddItem(l); } scroll.AddItem(allContainer); } if (data.Count == 0) { noFriendsLabel.gameObject.SetActive(true); } else { noFriendsLabel.gameObject.SetActive(false); } }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable", "Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (didSucceed) { if (inapp.isPackOfCoins) { //int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); Flow.header.coins += inapp.coinsCount; //Save.Set(PlayerPrefsKeys.COINS,coinStock); //Save.SaveAll(); } callback(ShopResultStatus.Success, id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/coins.php", BuyingConfirmation); WWWForm form = new WWWForm(); form.AddField("coins", Flow.header.coins); conn.connect(form); } } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); * purchaseDialog.Show(); * purchaseDialog.SetMessage("Purchase failed"); * purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); * cashMachineSound.audio.Play();*/ }); }
public void GetTotal(int userId, Coins.CoinsCallback callback) { GameJsonAuthConnection request = new GameJsonAuthConnection( Flow.URL_BASE + "login/items/get_user_coins.php", OnReceiveTotal); request.connect( (userId > 0) ? new WWWForm().Add("user_id", userId) : new WWWForm().Add("_", "empty"), new CoinsConnection(userId, callback) ); }
void EndGame() { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE+"base/managegame.php", HandleEndGame); WWWForm form = new WWWForm(); for(int i = 0; i<Flow.ROUNDS_PER_TURN; i++) { form.AddField("times["+i+"]", Flow.currentGame.myRoundList[i].time.ToString()); } form.AddField("friendID", Flow.currentGame.friend.id); form.AddField("worldID", Flow.currentGame.worldID); conn.connect(form); }
public void Connect() { scroll.ClearList(true); containerCounter = 0; GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/getranking.php", OnGetRanking); WWWForm form = new WWWForm(); form.AddField("customLevelID", Flow.currentRank.id); conn.connect(form); }
public void ConfirmDeletion() { Debug.Log("deletando"); messageOkCancelWindow.SetActive(false); Flow.game_native.startLoading(); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/delete.php", handleDeleteFriendConnection); WWWForm form = new WWWForm(); form.AddField("friend_id", id); conn.connect(form); }
// Adiciona Feature na database void SetFeature(string feature, string platform = null) { // Seta Feature nao global (por plataforma) if (platform != null && platform != "") { feature += " | " + platform; } // Faz a conexao com o servidor enviando a feature GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/items/set_feature.php", OnSetFeature); WWWForm form = new WWWForm(); form.Add("feature", feature); conn.connect(form); }
public void AddFriendConnection(string friendID) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/sharestage.php", OnShareStage); WWWForm form = new WWWForm(); form.AddField("stageName", Flow.currentRank.name); form.AddField("stageID", Flow.currentRank.id); form.AddField("friendID", friendID); int firstWorld = 9999; foreach(KeyValuePair<int,World> w in Flow.worldDict) {if(w.Key < firstWorld) firstWorld = w.Key;} form.AddField("world", (firstWorld+Flow.currentRank.world).ToString()); string tileset = ""; foreach(List<int> listInt in Flow.currentRank.tileset) foreach(int i in listInt) tileset += i; Debug.Log(tileset); form.AddField("tileset", tileset); conn.connect(form); }
void ChooseFriend() { // Se ja tem identificador, retorna if (id != null) { AssignDataToFlow(); return; } Debug.Log("nao tem id, vamos criar..."); //Flow.game_native.startLoading(); // Cria o identificador para o usuario GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/create.php", HandleChoose); WWWForm form = new WWWForm(); form.AddField("facebook_id", facebook_id); conn.connect(form); }
public void NextLevel() { if (Flow.currentMode == GameMode.Multiplayer && Flow.currentCustomStage == -1) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/managegame.php", GameSent); WWWForm form = new WWWForm(); form.AddField("worldID", Flow.currentGame.world.id); form.AddField("levelID", Flow.currentGame.level.id); form.AddField("friendID", Flow.currentGame.friend.id); form.AddField("deaths", Flow.currentGame.myRoundList[0].deaths); form.AddField("time", Flow.currentGame.myRoundList[0].time.ToString()); conn.connect(form); } else if (Flow.currentMode == GameMode.Multiplayer && Flow.currentCustomStage != -1) { Debug.Log("currentCustomGame (Gameplay) " + Flow.currentCustomGame); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/updatechallenge.php", UpdateChallenge); WWWForm form = new WWWForm(); form.AddField("gameID", Flow.currentCustomGame); form.AddField("deaths", Flow.currentGame.myRoundList[0].deaths); form.AddField("time", Flow.currentGame.myRoundList[0].time.ToString()); conn.connect(form); } else if (Flow.currentMode == GameMode.SinglePlayer && Flow.currentCustomStage == -1) { if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) { postActionFacebook(); } tommyMaterial.mainTexture = tommyTextures[0]; Flow.nextPanel = PanelToLoad.EndLevel; Application.LoadLevel("Mainmenu"); } else if (Flow.currentMode == GameMode.SinglePlayer && Flow.currentCustomStage != -1) { //Flow.currentCustomStage = -1; Flow.nextPanel = PanelToLoad.EndLevel; Application.LoadLevel("Mainmenu"); } }
// Convida os amigos a partir do canvas public void inviteFriendsFromCanvas(string request) { if (request.IsEmpty()) { Debug.Log("empty request"); //Scene.First.Load(); return; } JSonReader reader = new JSonReader(); IJSonObject json = null; // Tenta ler o retorno try { json = reader.ReadAsJSonObject(request); } catch (JSonReaderException e) { Debug.Log("exception: " + e.Message); //Scene.First.Load(); return; } GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/facebook/invite.php", handleInviteFriendsFromCanvas); WWWForm form = new WWWForm(); form.AddField("request", json["request"].StringValue); form.AddField("redirect", "no"); int i = 0; foreach (IJSonObject friend in json["to"].ArrayItems) { form.AddField("to[" + i + "]", friend.StringValue); i++; } conn.connect(form); }
void ConfirmLogout() { loggingOut = false; Flow.messageOkCancelDialog.SetActive(false); if (Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) { bool opened = Flow.game_native.openAuthUrlInline(Flow.URL_BASE + "login/logout.php?"); if (!opened) { return; } Flow.OnLogoutFromServer(); firstNameField.Text = firstNamePlaceholder; lastNameField.Text = lastNamePlaceholder; countryField.Text = locationPlaceholder; maleFemaleToggle.SetState(0); emailField.Text = "Email"; dayField.Text = dayPlaceholder; monthField.Text = monthPlaceholder; yearField.Text = yearPlaceholder; facebookButton.Text = "Login with Facebook"; Flow.playerPhoto = null; gamesScroll.ClearList(true); UIPanelManager.instance.BringIn("MenuScenePanel", UIPanelManager.MENU_DIRECTION.Backwards); return; } // Desloga com o servidor Flow.game_native.startLoading(); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/logout.php", HandleUserLogoutConnection); conn.connect(); }
public void UpdateOfflineItems() { Debug.Log("chamou"); if(!Save.GetString(PlayerPrefsKeys.TOKEN).IsEmpty()) { Debug.Log("o cara ta logado, pega us iti deli"); // Manda para o servidor as compras offline que o usuario daquele app fez GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/updateuseritems.php",OnUpdateOfflineItems); WWWForm form = new WWWForm(); int key = 0; // Adicionar nesse form os ids dos itens que o usuario comprou, salvos no Save #if !UNITY_WEBPLAYER ShopItem[] allItems = Flow.config.GetComponent<ConfigManager>().shopItems; for(int i = 0 ; i < allItems.Length ; i++) { if(Save.HasKey(PlayerPrefsKeys.ITEM+allItems[i].id)) { form.AddField("items["+key+"][id]",allItems[i].id); form.AddField("items["+key+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+allItems[i].id)); key++; } } #endif conn.connect(form); // Se a foto do usuario estiver nula, abrir conexao pra baixar ela if(Flow.playerPhoto == null && !Flow.isDownloadingPlayerPhoto) { GameRawAuthConnection conn2 = new GameRawAuthConnection(Flow.URL_BASE + "login/picture.php", Flow.getPlayerPhoto); WWWForm form2 = new WWWForm(); form2.AddField("user_id", "me"); conn2.connect(form2); Flow.isDownloadingPlayerPhoto = true; } } }
void ConfirmChangeEmail() { // Mensagens de erro da conexao Dictionary <string, string> messages = new Dictionary <string, string>(); messages.Add("empty_password", "Please inform your password."); messages.Add("empty_email", "Please. Inform a new e-mail."); messages.Add("invalid_email", "Your e-mail is invalid. Please, try another account."); messages.Add("no_facebook_connected", "You have to link your Facebook to change your e-mail."); messages.Add("wrong_password", "Wrong password. Please try again."); messages.Add("cant_send_email", "We couldn't check your e-mail. Please try again later."); // Informa ao servidor a troca de email GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/email.php", HandleChangeEmail, messages); WWWForm form = new WWWForm(); form.AddField("password", changeEmailPasswordField.Text); form.AddField("email", changeEmailNewMailField.Text); conn.connect(form); }
void InviteNewFriends() { for (int r = 0; r < inviteFriendScroll.Count; r++) { if (inviteFriendScroll.GetItem(r).transform.FindChild("TextField").GetComponent <UITextField>().Text == "Friend E-mail") { inviteFriendScroll.RemoveItem(r, true); } } GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/invite.php", HandleInviteFriends); WWWForm form = new WWWForm(); for (int i = 0; i < inviteFriendScroll.Count; i++) { form.AddField("emails[" + i + "]", inviteFriendScroll.GetItem(i).transform.FindChild("TextField").GetComponent <UITextField>().Text); } Flow.game_native.startLoading(); conn.connect(form); }
public void UpdateOfflineItems() { Debug.Log("chamou"); if (!Save.GetString(PlayerPrefsKeys.TOKEN).IsEmpty()) { Debug.Log("o cara ta logado, pega us iti deli"); // Manda para o servidor as compras offline que o usuario daquele app fez GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/updateuseritems.php", OnUpdateOfflineItems); WWWForm form = new WWWForm(); int key = 0; // Adicionar nesse form os ids dos itens que o usuario comprou, salvos no Save #if !UNITY_WEBPLAYER ShopItem[] allItems = Flow.config.GetComponent <ConfigManager>().shopItems; for (int i = 0; i < allItems.Length; i++) { if (Save.HasKey(PlayerPrefsKeys.ITEM + allItems[i].id)) { form.AddField("items[" + key + "][id]", allItems[i].id); form.AddField("items[" + key + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + allItems[i].id)); key++; } } #endif conn.connect(form); // Se a foto do usuario estiver nula, abrir conexao pra baixar ela if (Flow.playerPhoto == null && !Flow.isDownloadingPlayerPhoto) { GameRawAuthConnection conn2 = new GameRawAuthConnection(Flow.URL_BASE + "login/picture.php", Flow.getPlayerPhoto); WWWForm form2 = new WWWForm(); form2.AddField("user_id", "me"); conn2.connect(form2); Flow.isDownloadingPlayerPhoto = true; } } }
void ConfirmChangePassword() { // Mensagens de erro da conexao Dictionary <string, string> messages = new Dictionary <string, string>(); messages.Add("empty_password", "Please inform your password."); messages.Add("inform_password", "Please inform a new password."); messages.Add("differ_password", "Your passwords are different."); messages.Add("short_password", "Your new password is too short."); messages.Add("wrong_password", "Your current password is incorrect."); messages.Add("cant_send_email", "We couldn't send you a confirmation e-mail."); // Informa ao servidor a troca de senha GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/password.php", HandleChangePassword, messages); WWWForm form = new WWWForm(); form.AddField("password", changePasswordOldPassword.Text); form.AddField("new_password", changePasswordNewPassword.Text); form.AddField("new2_password", changePasswordConfirmPassword.Text); conn.connect(form); }
void ConfirmChangeEmail() { // Mensagens de erro da conexao Dictionary <string, string> messages = new Dictionary<string, string>(); messages.Add("empty_password", "Please inform your password."); messages.Add("empty_email", "Please. Inform a new e-mail."); messages.Add("invalid_email", "Your e-mail is invalid. Please, try another account."); messages.Add("no_facebook_connected", "You have to link your Facebook to change your e-mail."); messages.Add("wrong_password", "Wrong password. Please try again."); messages.Add("cant_send_email", "We couldn't check your e-mail. Please try again later."); // Informa ao servidor a troca de email GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/email.php", HandleChangeEmail, messages); WWWForm form = new WWWForm(); form.AddField("password", changeEmailPasswordField.Text); form.AddField("email", changeEmailNewMailField.Text); conn.connect(form); }
void ConfirmChangePassword() { // Mensagens de erro da conexao Dictionary <string, string> messages = new Dictionary<string, string>(); messages.Add("empty_password", "Please inform your password."); messages.Add("inform_password", "Please inform a new password."); messages.Add("differ_password", "Your passwords are different."); messages.Add("short_password", "Your new password is too short."); messages.Add("wrong_password", "Your current password is incorrect."); messages.Add("cant_send_email", "We couldn't send you a confirmation e-mail."); // Informa ao servidor a troca de senha GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/password.php", HandleChangePassword, messages); WWWForm form = new WWWForm(); form.AddField("password", changePasswordOldPassword.Text); form.AddField("new_password", changePasswordNewPassword.Text); form.AddField("new2_password", changePasswordConfirmPassword.Text); conn.connect(form); }
void ConfirmLogout() { loggingOut = false; Flow.messageOkCancelDialog.SetActive(false); if(Save.HasKey(PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) { bool opened = Flow.game_native.openAuthUrlInline(Flow.URL_BASE + "login/logout.php?"); if(!opened) return; Flow.OnLogoutFromServer(); firstNameField.Text = firstNamePlaceholder; lastNameField.Text = lastNamePlaceholder; countryField.Text = locationPlaceholder; maleFemaleToggle.SetState(0); emailField.Text = "Email"; dayField.Text = dayPlaceholder; monthField.Text = monthPlaceholder; yearField.Text = yearPlaceholder; facebookButton.Text = "Login with Facebook"; Flow.playerPhoto = null; gamesScroll.ClearList(true); UIPanelManager.instance.BringIn("MenuScenePanel", UIPanelManager.MENU_DIRECTION.Backwards); return; } // Desloga com o servidor Flow.game_native.startLoading(); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/logout.php", HandleUserLogoutConnection); conn.connect(); }
void Connect() { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/getcustomgames.php", OnGetCustomGames); conn.connect(); }
void DoneButton() { //Debug.Log("save "+Save.GetString(PlayerPrefsKeys.GENDER.ToString())); //Debug.Log("field "+maleFemaleToggle.StateName); if (Save.HasKey(PlayerPrefsKeys.FIRST_NAME.ToString()) && firstNameField.Text != Save.GetString(PlayerPrefsKeys.FIRST_NAME.ToString())) { changed = true; Debug.Log("first != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.FIRST_NAME.ToString()) && firstNameField.Text != firstNamePlaceholder && firstNameField.Text != "") { changed = true; Debug.Log("first != 2"); } if (Save.HasKey(PlayerPrefsKeys.LAST_NAME.ToString()) && lastNameField.Text != Save.GetString(PlayerPrefsKeys.LAST_NAME.ToString())) { changed = true; Debug.Log("last != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.LAST_NAME.ToString()) && lastNameField.Text != lastNamePlaceholder && lastNameField.Text != "") { changed = true; Debug.Log("last != 2"); } if (Save.HasKey(PlayerPrefsKeys.LOCATION.ToString()) && countryField.Text != Save.GetString(PlayerPrefsKeys.LOCATION.ToString())) { changed = true; Debug.Log("loc != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.LOCATION.ToString()) && countryField.Text != locationPlaceholder && countryField.Text != "") { changed = true; Debug.Log("loc != 2"); } if (Save.HasKey(PlayerPrefsKeys.DATE_DAY.ToString()) && dayField.Text != Save.GetString(PlayerPrefsKeys.DATE_DAY.ToString())) { changed = true; Debug.Log("day != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.DATE_DAY.ToString()) && dayField.Text != dayPlaceholder && dayField.Text != "") { changed = true; Debug.Log("day != 2"); } if (Save.HasKey(PlayerPrefsKeys.DATE_MONTH.ToString()) && monthField.Text != Save.GetString(PlayerPrefsKeys.DATE_MONTH.ToString())) { changed = true; Debug.Log("month != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.DATE_MONTH.ToString()) && monthField.Text != monthPlaceholder && monthField.Text != "") { changed = true; Debug.Log("month != 2"); } if (Save.HasKey(PlayerPrefsKeys.DATE_YEAR.ToString()) && yearField.Text != Save.GetString(PlayerPrefsKeys.DATE_YEAR.ToString())) { changed = true; Debug.Log("year != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.DATE_YEAR.ToString()) && yearField.Text != yearPlaceholder && yearField.Text != "") { changed = true; Debug.Log("year != 2"); } Debug.Log("Save: " + Save.GetString(PlayerPrefsKeys.GENDER)); Debug.Log("Toggle: " + maleFemaleToggle.StateName); if (Save.HasKey(PlayerPrefsKeys.GENDER.ToString()) && maleFemaleToggle.StateName != Save.GetString(PlayerPrefsKeys.GENDER.ToString())) { changed = true; Debug.Log("gender != 1"); } else if (!Save.HasKey(PlayerPrefsKeys.GENDER.ToString()) && maleFemaleToggle.StateName != "Male") { changed = true; Debug.Log("gender != 2"); } if (photoChanged) { Debug.Log("photo changed"); changed = true; } if (changed) { Flow.game_native.startLoading(); Save.Set(PlayerPrefsKeys.DATE_DAY.ToString(), dayField.Text, true); Save.Set(PlayerPrefsKeys.DATE_MONTH.ToString(), monthField.Text, true); Save.Set(PlayerPrefsKeys.DATE_YEAR.ToString(), yearField.Text, true); Save.Set(PlayerPrefsKeys.LOCATION.ToString(), countryField.Text, true); Save.Set(PlayerPrefsKeys.FIRST_NAME.ToString(), firstNameField.Text, true); Save.Set(PlayerPrefsKeys.LAST_NAME.ToString(), lastNameField.Text, true); Save.Set(PlayerPrefsKeys.GENDER.ToString(), maleFemaleToggle.StateName, true); Dictionary <string, string> messages = new Dictionary <string, string>(); messages.Add("invalid_date", "Invalid date. Please, try again."); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/set.php", HandleSaveOnServer, messages); WWWForm form = new WWWForm(); if (monthField.Text != monthPlaceholder) { form.AddField("month", monthField.Text); } if (dayField.Text != dayPlaceholder) { form.AddField("day", dayField.Text); } if (yearField.Text != yearPlaceholder) { form.AddField("year", yearField.Text); } if (countryField.Text != locationPlaceholder) { form.AddField("location", countryField.Text); } if (firstNameField.Text != firstNamePlaceholder) { form.AddField("first_name", firstNameField.Text); } if (lastNameField.Text != lastNamePlaceholder) { form.AddField("last_name", lastNameField.Text); } form.AddField("gender", maleFemaleToggle.StateName); if (Flow.playerPhoto != null && photoChanged) { form.AddBinaryData("photo", Flow.playerPhoto.EncodeToPNG(), PHOTO_NAME, "image/png"); } conn.connect(form); } else { UIPanelManager.instance.BringIn("MenuScenePanel", UIPanelManager.MENU_DIRECTION.Backwards); } }
public void NextLevel() { if(Flow.currentMode == GameMode.Multiplayer && Flow.currentCustomStage == -1) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/managegame.php", GameSent); WWWForm form = new WWWForm(); form.AddField("worldID",Flow.currentGame.world.id); form.AddField("levelID",Flow.currentGame.level.id); form.AddField("friendID", Flow.currentGame.friend.id); form.AddField("deaths", Flow.currentGame.myRoundList[0].deaths); form.AddField("time", Flow.currentGame.myRoundList[0].time.ToString()); conn.connect(form); } else if(Flow.currentMode == GameMode.Multiplayer && Flow.currentCustomStage != -1) { Debug.Log("currentCustomGame (Gameplay) " + Flow.currentCustomGame); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "mines/updatechallenge.php", UpdateChallenge); WWWForm form = new WWWForm(); form.AddField("gameID", Flow.currentCustomGame); form.AddField("deaths", Flow.currentGame.myRoundList[0].deaths); form.AddField("time", Flow.currentGame.myRoundList[0].time.ToString()); conn.connect(form); } else if(Flow.currentMode == GameMode.SinglePlayer && Flow.currentCustomStage == -1) { if(Save.HasKey (PlayerPrefsKeys.FACEBOOK_TOKEN.ToString())) postActionFacebook(); tommyMaterial.mainTexture = tommyTextures[0]; Flow.nextPanel = PanelToLoad.EndLevel; Application.LoadLevel("Mainmenu"); } else if(Flow.currentMode == GameMode.SinglePlayer && Flow.currentCustomStage != -1) { //Flow.currentCustomStage = -1; Flow.nextPanel = PanelToLoad.EndLevel; Application.LoadLevel("Mainmenu"); } }
void InviteNewFriends() { for (int r = 0 ; r < inviteFriendScroll.Count ; r++) { if(inviteFriendScroll.GetItem(r).transform.FindChild("TextField").GetComponent<UITextField>().Text == "Friend E-mail") { inviteFriendScroll.RemoveItem(r, true); } } GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/invite.php", HandleInviteFriends); WWWForm form = new WWWForm(); for(int i = 0; i<inviteFriendScroll.Count; i++) { form.AddField("emails[" + i + "]", inviteFriendScroll.GetItem(i).transform.FindChild("TextField").GetComponent<UITextField>().Text); } Flow.game_native.startLoading(); conn.connect(form); }
public void GetFriends() { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/list.php", HandleGetFriends); conn.connect(null, 10); }
// Obtem as informacoes dos amigos do usuario void HandleGetFriends(string error, IJSonObject data, object counter_o) { Debug.Log(data); int counter = (int) counter_o; Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (error != null || data == null) { if (counter > 0) { GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/list.php", HandleGetFriends); conn.connect(null, counter - 1); return; } Flow.game_native.showMessage("Error", error); return; } string allLetter = ""; string playingLetter = ""; if(data.Count>0) { allLetter = data[0]["name"].StringValue.Substring(0,1).ToUpper(); GameObject firstL = GameObject.Instantiate(letterPrefab) as GameObject; firstL.transform.FindChild("Letter").GetComponent<SpriteText>().Text = allLetter.ToUpper (); scroll.AddItem(firstL); } foreach (IJSonObject friend in data.ArrayItems) { GameObject allContainer = CreateFriendContainer(friend); if(friend["name"].StringValue.Substring(0,1).ToUpper() != allLetter) { allLetter = friend["name"].StringValue.Substring(0,1).ToUpper(); GameObject l = GameObject.Instantiate(letterPrefab) as GameObject; l.transform.FindChild("Letter").GetComponent<SpriteText>().Text = allLetter.ToUpper (); scroll.AddItem(l); } scroll.AddItem(allContainer); } if(data.Count==0) { noFriendsLabel.gameObject.SetActive(true); } else { noFriendsLabel.gameObject.SetActive(false); } }
public void BuyItem(ShopDelegate callback, ShopItem item) { Debug.Log(item.id); foreach (ShopItem itemWithin in item.itemsWithin) { if (Save.HasKey(PlayerPrefsKeys.ITEM + itemWithin.id) && itemWithin.type == ShopItemType.NonConsumable) { // ja tem o item Flow.game_native.showMessage("Already has item", "You already have this item."); callback(ShopResultStatus.Failed, item.id); return; } //else if(itemWithin.forFree } //Flow.game_native.startLoading(); if (item.coinPrice > Flow.header.coins) { // nao tem coins OfferCoinPackAndBuyItem(callback, item); } else { Debug.Log("tem coins, soma eh: " + item.coinPrice); // tem coins Flow.header.coins -= item.coinPrice; foreach (ShopItem iw in item.itemsWithin) { Debug.Log(iw.id); Debug.Log(Save.HasKey(PlayerPrefsKeys.ITEM + iw.id)); Debug.Log(iw.type.ToString()); if (Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM + iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM + iw.id, userStock); Debug.Log("tem item, eh consumivel"); } else if (!Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM + iw.id, 1); Debug.Log("nao tem item, eh nao consumivel"); } else { Save.Set(PlayerPrefsKeys.ITEM + iw.id, iw.count); Debug.Log("nao tem item, eh consumivel"); } } if (item.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEMSPACK + item.id, true); } //Save.Set(PlayerPrefsKeys.COINS,Flow.header.coins); Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for (int i = 0; i < item.itemsWithin.Length; i++) { form.AddField("items[" + i + "][id]", item.itemsWithin[i].id); form.AddField("items[" + i + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(didSucceed) { if(inapp.isPackOfCoins) { //int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); Flow.header.coins += inapp.coinsCount; //Save.Set(PlayerPrefsKeys.COINS,coinStock); //Save.SaveAll(); } callback(ShopResultStatus.Success, id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/coins.php", BuyingConfirmation); WWWForm form = new WWWForm(); form.AddField("coins", Flow.header.coins); conn.connect(form); } } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); purchaseDialog.Show(); purchaseDialog.SetMessage("Purchase failed"); purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); cashMachineSound.audio.Play();*/ }); }
// Adiciona Feature na database void SetFeature(string feature, string platform = null) { // Seta Feature nao global (por plataforma) if (platform != null && platform != "") feature += " | " + platform; // Faz a conexao com o servidor enviando a feature GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/items/set_feature.php", OnSetFeature); WWWForm form = new WWWForm(); form.Add("feature", feature); conn.connect(form); }
private void postActionFacebook() { Debug.Log ("postActionFacebook"); int firstWorld = 9999; int firstLevel = 9999; foreach(KeyValuePair<int,World> w in Flow.worldDict) { if(w.Key < firstWorld) firstWorld = w.Key; } firstLevel = 9999; foreach(KeyValuePair<int,Level> l in Flow.worldDict[firstWorld].levelDict) { if(l.Key < firstLevel) firstLevel = l.Key; } GameJsonAuthConnection postFb = new GameJsonAuthConnection (Flow.URL_BASE + "mines/publish_single.php", actionResponse); WWWForm form = new WWWForm(); form.AddField ("world", Flow.currentGame.world.id - firstWorld + 1); form.AddField ("level", Flow.currentGame.level.id - firstLevel - (Flow.currentGame.world.id - firstWorld)*9 + 1); form.AddField ("time", Mathf.CeilToInt(timeCounter)); form.AddField ("deaths", Flow.hpLevel + 3 - currentHp); postFb.connect (form); }
void Awake() { DontDestroyOnLoad(gameObject); conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/push/reset.php", handleBadgeReset); }
// Convida os amigos a partir do canvas public void inviteFriendsFromCanvas(string request) { if (request.IsEmpty()) { Debug.Log("empty request"); //Scene.First.Load(); return; } JSonReader reader = new JSonReader(); IJSonObject json = null; // Tenta ler o retorno try { json = reader.ReadAsJSonObject(request); } catch (JSonReaderException e) { Debug.Log("exception: "+e.Message); //Scene.First.Load(); return; } GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/facebook/invite.php", handleInviteFriendsFromCanvas); WWWForm form = new WWWForm(); form.AddField("request", json["request"].StringValue); form.AddField("redirect", "no"); int i = 0; foreach (IJSonObject friend in json["to"].ArrayItems) { form.AddField("to[" + i + "]", friend.StringValue); i++; } conn.connect(form); }
// Envia a conexao ao servidor public void send(GameJsonAuthConnection.ConnectionAnswerWithState callback) { if (!semaphore.WaitOne(0)) { //Debug.Log("Pero no."); return; } //Debug.Log("Yaarrrrr."); GameJsonAuthConnection conn = new GameJsonAuthConnection(url, callback); // Cria o header Hashtable table = new Hashtable(headers.Count); foreach (DictionaryEntry entry in headers) { table.Add(entry.Key, entry.Value); } // Decide se e uma conexao binaria string delimiter; if (!table.Contains("Content-Type")) { delimiter = "&"; } else { Match match = Regex.Match(table["Content-Type"].ToString(), @"boundary=\""(.*)"""); if (match.Success) { delimiter = match.Groups[1].Value; } else { delimiter = "&"; } } byte[] fdata = (byte[])data.Clone(); string adata = null; if (delimiter == "&") { adata = ""; if (data.Length != 0) { adata += "&"; } adata += "device=" + WWW.EscapeURL(SystemInfo.deviceUniqueIdentifier.Replace("-", "")) + "&token=" + WWW.EscapeURL(Save.GetString(PlayerPrefsKeys.TOKEN.ToString())); } else { adata = @" Content-Type: text/plain; charset=""utf-8"" Content-disposition: form-data; name=""device"" " + SystemInfo.deviceUniqueIdentifier.Replace("-", "") + @" --" + delimiter + @" Content-Type: text/plain; charset=""utf-8"" Content-disposition: form-data; name=""token"" " + Save.GetString(PlayerPrefsKeys.TOKEN.ToString()) + @" --" + delimiter + @"-- "; System.Array.Resize <byte>(ref fdata, fdata.Length - 4); } byte[] bdata = System.Text.Encoding.ASCII.GetBytes(adata); int size = fdata.Length; System.Array.Resize <byte>(ref fdata, fdata.Length + bdata.Length); bdata.CopyTo(fdata, size); conn.connect(fdata, table, id); }
/*string TextChanged(UITextField field, string text, ref int insertion) { Debug.Log("TO DO: FAZER O SEARCH"); ///Debug.Log(text); //Debug.Log(scroll.Count); for(int i = 0 ; i < removedScroll.Count ; i++) { if(removedScroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text.Contains(text)) { scroll.InsertItem(removedScroll.GetItem(i),removedScroll.GetItem(i).transform.GetComponent<Friend>().index); removedScroll.RemoveItem(removedScroll.GetItem(i),false); } } for(int i = 0 ; i < scroll.Count ; i++) { if(scroll.GetItem(i).transform.tag != "Letter") { //Debug.Log(scroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text); if(!scroll.GetItem(i).transform.FindChild("Name").GetComponent<SpriteText>().Text.Contains(text)) { scroll.GetItem(i).transform.GetComponent<Friend>().index = i; removedScroll.AddItem(scroll.GetItem(i)); scroll.RemoveItem(scroll.GetItem(i),false); } } } return text; }*/ public void GetFriends() { Flow.game_native.startLoading(); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/friends/list.php", HandleGetFriends); conn.connect(null, 10); }
void DoneButton() { //Debug.Log("save "+Save.GetString(PlayerPrefsKeys.GENDER.ToString())); //Debug.Log("field "+maleFemaleToggle.StateName); if(Save.HasKey(PlayerPrefsKeys.FIRST_NAME.ToString()) && firstNameField.Text != Save.GetString(PlayerPrefsKeys.FIRST_NAME.ToString())) { changed = true; Debug.Log("first != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.FIRST_NAME.ToString()) && firstNameField.Text != firstNamePlaceholder && firstNameField.Text != "") { changed = true; Debug.Log("first != 2"); } if(Save.HasKey(PlayerPrefsKeys.LAST_NAME.ToString()) && lastNameField.Text != Save.GetString(PlayerPrefsKeys.LAST_NAME.ToString())) { changed = true; Debug.Log("last != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.LAST_NAME.ToString()) && lastNameField.Text != lastNamePlaceholder && lastNameField.Text != "") { changed = true; Debug.Log("last != 2"); } if(Save.HasKey(PlayerPrefsKeys.LOCATION.ToString()) && countryField.Text != Save.GetString(PlayerPrefsKeys.LOCATION.ToString())) { changed = true; Debug.Log("loc != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.LOCATION.ToString()) && countryField.Text != locationPlaceholder && countryField.Text != "") { changed = true; Debug.Log("loc != 2"); } if(Save.HasKey(PlayerPrefsKeys.DATE_DAY.ToString()) && dayField.Text != Save.GetString(PlayerPrefsKeys.DATE_DAY.ToString())) { changed = true; Debug.Log("day != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.DATE_DAY.ToString()) && dayField.Text != dayPlaceholder && dayField.Text != "") { changed = true; Debug.Log("day != 2"); } if(Save.HasKey(PlayerPrefsKeys.DATE_MONTH.ToString()) && monthField.Text != Save.GetString(PlayerPrefsKeys.DATE_MONTH.ToString())) { changed = true; Debug.Log("month != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.DATE_MONTH.ToString()) && monthField.Text != monthPlaceholder && monthField.Text != "") { changed = true; Debug.Log("month != 2"); } if(Save.HasKey(PlayerPrefsKeys.DATE_YEAR.ToString()) && yearField.Text != Save.GetString(PlayerPrefsKeys.DATE_YEAR.ToString())) { changed = true; Debug.Log("year != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.DATE_YEAR.ToString()) && yearField.Text != yearPlaceholder && yearField.Text != "") { changed = true; Debug.Log("year != 2"); } Debug.Log("Save: "+Save.GetString(PlayerPrefsKeys.GENDER)); Debug.Log("Toggle: "+maleFemaleToggle.StateName); if(Save.HasKey(PlayerPrefsKeys.GENDER.ToString()) && maleFemaleToggle.StateName != Save.GetString(PlayerPrefsKeys.GENDER.ToString())) { changed = true; Debug.Log("gender != 1"); } else if(!Save.HasKey(PlayerPrefsKeys.GENDER.ToString()) && maleFemaleToggle.StateName != "Male") { changed = true; Debug.Log("gender != 2"); } if(photoChanged) { Debug.Log("photo changed"); changed = true; } if(changed) { Flow.game_native.startLoading(); Save.Set (PlayerPrefsKeys.DATE_DAY.ToString(), dayField.Text, true); Save.Set (PlayerPrefsKeys.DATE_MONTH.ToString(), monthField.Text, true); Save.Set (PlayerPrefsKeys.DATE_YEAR.ToString(), yearField.Text, true); Save.Set (PlayerPrefsKeys.LOCATION.ToString(), countryField.Text, true); Save.Set (PlayerPrefsKeys.FIRST_NAME.ToString(), firstNameField.Text, true); Save.Set (PlayerPrefsKeys.LAST_NAME.ToString(), lastNameField.Text, true); Save.Set (PlayerPrefsKeys.GENDER.ToString(), maleFemaleToggle.StateName, true); Dictionary <string, string> messages = new Dictionary<string, string>(); messages.Add("invalid_date", "Invalid date. Please, try again."); GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/settings/set.php", HandleSaveOnServer, messages); WWWForm form = new WWWForm(); if(monthField.Text != monthPlaceholder) form.AddField("month", monthField.Text); if(dayField.Text != dayPlaceholder) form.AddField("day", dayField.Text); if(yearField.Text != yearPlaceholder) form.AddField("year", yearField.Text); if(countryField.Text != locationPlaceholder) form.AddField("location", countryField.Text); if(firstNameField.Text != firstNamePlaceholder) form.AddField("first_name", firstNameField.Text); if(lastNameField.Text != lastNamePlaceholder) form.AddField("last_name", lastNameField.Text); form.AddField("gender", maleFemaleToggle.StateName); if(Flow.playerPhoto != null && photoChanged) form.AddBinaryData("photo", Flow.playerPhoto.EncodeToPNG(), PHOTO_NAME, "image/png"); conn.connect(form); } else { UIPanelManager.instance.BringIn("MenuScenePanel",UIPanelManager.MENU_DIRECTION.Backwards); } }
public void BuyItem(ShopDelegate callback, ShopItem item) { Debug.Log(item.id); foreach(ShopItem itemWithin in item.itemsWithin) { if(Save.HasKey(PlayerPrefsKeys.ITEM+itemWithin.id) && itemWithin.type == ShopItemType.NonConsumable) { // ja tem o item Flow.game_native.showMessage("Already has item","You already have this item."); callback(ShopResultStatus.Failed, item.id); return; } //else if(itemWithin.forFree } //Flow.game_native.startLoading(); if(item.coinPrice > Flow.header.coins) { // nao tem coins OfferCoinPackAndBuyItem(callback, item); } else { Debug.Log("tem coins, soma eh: "+item.coinPrice); // tem coins Flow.header.coins -= item.coinPrice; foreach(ShopItem iw in item.itemsWithin) { Debug.Log(iw.id); Debug.Log(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id)); Debug.Log(iw.type.ToString()); if(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM+iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM+iw.id,userStock); Debug.Log("tem item, eh consumivel"); } else if(!Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM+iw.id,1); Debug.Log("nao tem item, eh nao consumivel"); } else { Save.Set(PlayerPrefsKeys.ITEM+iw.id, iw.count); Debug.Log("nao tem item, eh consumivel"); } } if(item.type == ShopItemType.NonConsumable) Save.Set(PlayerPrefsKeys.ITEMSPACK+item.id,true); //Save.Set(PlayerPrefsKeys.COINS,Flow.header.coins); Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for(int i = 0 ; i < item.itemsWithin.Length ; i++) { form.AddField("items["+i+"][id]", item.itemsWithin[i].id); form.AddField("items["+i+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach (ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if (pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: " + pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if (mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if (coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: " + coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if (Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach (ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if (Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM + iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM + iw.id, userStock); } else if (!Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM + iw.id, 1); } else { Save.Set(PlayerPrefsKeys.ITEM + iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for (int i = 0; i < item.itemsWithin.Length; i++) { form.AddField("items[" + i + "][id]", item.itemsWithin[i].id); form.AddField("items[" + i + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach(ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if(pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: "+ pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if(mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if(coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: "+ coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if(Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach(ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM+iw.id); userStock += iw.count; Save.Set (PlayerPrefsKeys.ITEM+iw.id,userStock); } else if(!Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM+iw.id,1); } else { Save.Set(PlayerPrefsKeys.ITEM+iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for(int i = 0 ; i < item.itemsWithin.Length ; i++) { form.AddField("items["+i+"][id]", item.itemsWithin[i].id); form.AddField("items["+i+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }