/// <summary> /// 経験値を増加する。 /// </summary> /// <param name="amount"></param> /// <returns></returns> public static async UniTask <bool> AddExpAsync(int amount, bool login = true) { var request = new AddUserVirtualCurrencyRequest { VirtualCurrency = "EP", Amount = amount, }; var response = await PlayFabClientAPI.AddUserVirtualCurrencyAsync(request); if (response.Error != null) { throw new PlayFabErrorException(response.Error); } Exp = response.Result.Balance; var isLevelUp = Exp >= UserDataManager.NextLevelInfo.Exp; if (isLevelUp) { await AddStaminaAsync(UserDataManager.NextLevelInfo.MaxStamina); } if (login) { await LoginManager.LoginAndUpdateLocalCacheAsync(); } return(isLevelUp); }
/// <summary> /// Send a request to playfab to increase the credit count for a player /// </summary> /// <param name="amount"></param> public void AddCredits(int amount) { var currencyRequest = new AddUserVirtualCurrencyRequest { VirtualCurrency = "CR", Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(currencyRequest, OnSuccess, OnFailure); }
public void AddPlayFabVirtualCurrecy(int i, string virtualCurrecy) { var request = new AddUserVirtualCurrencyRequest { Amount = i, VirtualCurrency = virtualCurrecy }; PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddVirtualCurrencySuccess, OnAddVirtualCurrencyFailure); }
/// <summary> /// Method called to give the player a certain amount of in-game currency. /// </summary> /// <param name="amount">Currency amount to give.</param> public void AddInGameCurrency(int amount) { AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest(); request.VirtualCurrency = GameConstants.inGameCurrencyID; request.Amount = amount; PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddedInGameCurrency, OnAddGameCurrencyError); }
/// <summary> /// Increments the specified virtual currency by the stated amount /// </summary> public static void AddUserVirtualCurrency(AddUserVirtualCurrencyRequest request, Action <ModifyUserVirtualCurrencyResult> resultCallback, Action <PlayFabError> errorCallback, object customData = null) { if (PlayFabSettings.DeveloperSecretKey == null) { throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method"); } PlayFabHttp.MakeApiCall("/Admin/AddUserVirtualCurrency", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData); }
void UpdateCoins() { AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest(); request.VirtualCurrency = "CO"; request.Amount = Coins - InitCoins; PlayFabClientAPI.AddUserVirtualCurrency(request, UpdateCoinsSuccess, UpdateCoinsFailed); }
public void AddSBCurrency(int amount) { var request = new AddUserVirtualCurrencyRequest { Amount = amount, VirtualCurrency = "SB" }; PlayFabClientAPI.AddUserVirtualCurrency(request, AddCurrencySuccess, AddCurrencyError); }
// ADS // public void ShowRewardedAd() // { // if(Advertisement.IsReady("rewardedVideo")) // { // var options = new ShowOptions // { // resultCallback = HandleShowResult // }; // Advertisement.Show("rewardedVideo", options); // } // } // private void HandleShowResult(ShowResult result) // { // switch (result) // { // case ShowResult.Finished: // //Ajouter des Coins // playFabMananger.LoadingMessage("Updating data..."); // playFabMananger.Player_Coin += 500; // txtCoins.text = playFabMananger.Player_Coin.ToString(); // AddCoins(); // //Update de VC sur Playfab // break; // case ShowResult.Skipped: // Debug.Log("..."); // break; // case ShowResult.Failed: // Debug.Log("..."); // break; // } // } void AddCoins() { var request = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "CO", Amount = 500 }; PlayFabClientAPI.AddUserVirtualCurrency(request, AddSuccess, AddFailed); }
public void AddMoney() { //request - 청구서 , VirtualCurrency = 통화의 단위(플레이펩에서 설정), Amount : 더하고 싶은 양 var request = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = 50 }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => print("돈 얻기 성공! 현재 돈 : " + result.Balance), (error) => print("돈 얻기 실패")); }
public void AddUserVirtualCurrency(string currency, int amount, System.Action <ModifyUserVirtualCurrencyResult> successCallback, System.Action <PlayFabError> failureCallback) { if (failureCallback == null) { failureCallback = Callback_Generic_Error; } var request = new AddUserVirtualCurrencyRequest { VirtualCurrency = currency, Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(request, successCallback, failureCallback); }
public static Promise AddCurrency(CurrencyCode currencyCode, int amount) { var promise = new Promise(); var request = new AddUserVirtualCurrencyRequest { VirtualCurrency = currencyCode.ToString(), Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { SuccessCallback(result); promise.Resolve(); }, ErrorCallback); return(promise); }
// 유저 돈 지급 public void giveMoney(int amout) { var moneyrequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "MY", Amount = amout }; PlayFabClientAPI.AddUserVirtualCurrency(moneyrequest, (resultmoney) => { User.money = resultmoney.Balance; AllManager.AM.UM.setUserMoney(); } , (errormoney) => Debug.Log("돈 지급 실패")); }
//添加金币 void AddUserCurrency(int resultWeight) { var playerCustomProperties = PhotonNetwork.player.customProperties; int currencyAmount = 20 + 200 * resultWeight + 10 * (int)playerCustomProperties["Score"] - 1 * (int)playerCustomProperties["Death"]; Dictionary <string, string> skillData = PlayFabSimpleJson.DeserializeObject <Dictionary <string, string> >(GameInfo.titleData["ExpAndMoneySkill"]); currencyAmount = (int)((float)currencyAmount * (1.0f + float.Parse(skillData["Level" + PlayFabUserData.expAndMoneySkillLV.ToString()]) / 100)); GMInstance.UIController.showCurrencyReward(currencyAmount); AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = currencyAmount }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { }, (error) => { }); }
/// <summary> /// スタミナを回復する。 /// </summary> /// <param name="amount"></param> /// <returns></returns> public static async UniTask AddStaminaAsync(int amount) { var request = new AddUserVirtualCurrencyRequest { VirtualCurrency = "ST", Amount = amount, }; var response = await PlayFabClientAPI.AddUserVirtualCurrencyAsync(request); if (response.Error != null) { throw new PlayFabErrorException(response.Error); } StaminaRaw = response.Result.Balance; }
private void GiveCurrencyToPlayer(int numberOfCoins) { makingPlayFabRequest = true; AddUserVirtualCurrencyRequest virtualCurrencyRequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = numberOfCoins }; PlayFabClientAPI.AddUserVirtualCurrency(virtualCurrencyRequest, (result) => { Debug.Log("Adding (" + numberOfCoins + ") coins to Player " + result.PlayFabId + " has left them with: " + result.Balance); makingPlayFabRequest = false; }, (error) => { Debug.Log("Error Updating Virtual Currency: " + error.ErrorMessage); makingPlayFabRequest = false; }); }
public void saveMoney(int money, bool isSub = false) { Debug.Log("saveMoeny callled"); if (!isSub) { var moneyrequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = money }; PlayFabClientAPI.AddUserVirtualCurrency(moneyrequest, (resultmoney) => { MoneyManager.instance.setMoneyText(resultmoney.Balance); }, (errormoney) => Error("ERROR-A-2")); } else { loadPopUpflag = true; var moneycheckrequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = 0 }; PlayFabClientAPI.AddUserVirtualCurrency(moneycheckrequest, (resultmoney) => { //// 구매 할수 있는지 체크 //if (resultmoney.Balance - money < 0) //{ // Debug.Log("니 돈없음 ㅅㄱ 팝업창 띄워 주세요."); // return; //} // 돈 사용 var moneylessrequest = new SubtractUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = money }; PlayFabClientAPI.SubtractUserVirtualCurrency(moneylessrequest, (resultmoney1) => { Debug.Log(money + "원 사용 완료 (1/2)"); loadPopUpflag = false; MoneyManager.instance.setMoneyText(resultmoney1.Balance); Debug.Log(money + "원 사용 완료 (2/2)"); }, (errormoney1) => Error("ERROR-A-1")); }, (errormoney) => Error("ERROR-A-1")); } Debug.Log("saveMoeny done"); }
private void GetCurrencyOfPlayer() { makingPlayFabRequest = true; AddUserVirtualCurrencyRequest virtualCurrencyRequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = 0 }; PlayFabClientAPI.AddUserVirtualCurrency(virtualCurrencyRequest, (result) => { Debug.Log("It looks like player (" + result.PlayFabId + ") currently has the following Virtual Currency: " + result.Balance); this.virtualCurrency = result.Balance; makingPlayFabRequest = false; }, (error) => { Debug.Log("Error Retrieving Virtual Currency: " + error.ErrorMessage); makingPlayFabRequest = false; }); }
public async Task <string> AddUserVirtualCurrency(string playFabId, int Amount) { var reqAddUserVirtualCurrency = new AddUserVirtualCurrencyRequest { PlayFabId = playFabId, Amount = Amount, VirtualCurrency = configuration.Currency }; var result = await PlayFabAdminAPI.AddUserVirtualCurrencyAsync(reqAddUserVirtualCurrency); if (result.Error != null) { throw new Exception(result.Error.ErrorMessage); } return(await UpdateBudget()); }
/// <summary> /// 仮想通貨を追加 /// </summary> public void AddUserVirtualCurrency(string VCcode, int value) { // 通信待ちでなかったら通信開始 if (!waitConnect.GetWait(gameObject.name)) { // 通信待ちに設定する waitConnect.AddWait(gameObject.name); //AddUserVirtualCurrencyRequestのインスタンスを生成 var addUserVirtualCurrencyRequest = new AddUserVirtualCurrencyRequest { Amount = value, //追加する金額 VirtualCurrency = VCcode, //仮想通貨のコード }; //仮想通貨の追加 Debug.Log($"仮想通貨の追加開始"); PlayFabClientAPI.AddUserVirtualCurrency(addUserVirtualCurrencyRequest, OnSuccessAdd, OnErrorAdd); } }
/* 学生作业:实现成就奖励领取按钮的响应函数GetReward以及相关PlayFab请求成功或者失败的回调函数 * GetReward函数的两个参数解释:name表示成就奖励名称,value表示成就奖励的金币数。 * 作业提示: * 首先,启用processingWindow窗口,提示正在处理玩家领取成就奖励的请求; * 其次,使用UpdateUserDataRequest函数,更新玩家的自定义属性Player Data,包括玩家已领取相关成就奖励的数据; * UpdateUserDataRequest函数调用成功后,使用GetUserDataRequest函数,重新获取玩家的自定义属性,保存在PlayFabUserData类的userData中; * 接着,使用AddUserVirtualCurrencyRequest函数,增加玩家的金币数量(该请求需要包含两个参数:VirtualCurrency表示增加的虚拟货币种类,Amount表示增加的虚拟货币数量); * AddUserVirtualCurrencyRequest函数调用成功后,更新玩家金币数量的显示 * 最后,若两个请求都调用成功,禁用processingWindow窗口,并更新成就奖励条目的显示。 */ //领取成就奖励 //GetReward函数的两个参数解释:name表示成就奖励名称,value表示成就奖励的金币数。 void GetReward(string name, int value) { //启用processingWindow窗口,提示正在处理玩家领取成就奖励的请求; processingWindow.SetActive(true); requestNum = 2; //使用UpdateUserDataRequest函数,更新玩家的自定义属性Player Data,包括玩家已领取相关成就奖励的数据; UpdateUserDataRequest updateUserDataRequest = new UpdateUserDataRequest(); updateUserDataRequest.Data = new Dictionary <string, string>(); updateUserDataRequest.Data.Add(name, "true"); PlayFabClientAPI.UpdateUserData(updateUserDataRequest, OnUpdateUserRewardData, OnPlayFabError); //使用AddUserVirtualCurrencyRequest函数,增加玩家的金币数量(该请求需要包含两个参数:VirtualCurrency表示增加的虚拟货币种类,Amount表示增加的虚拟货币数量); AddUserVirtualCurrencyRequest addUserVirtualCurrencyRequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = value }; //AddUserVirtualCurrencyRequest函数调用成功后,更新玩家金币数量的显示 PlayFabClientAPI.AddUserVirtualCurrency(addUserVirtualCurrencyRequest, OnAddUserVirtualCurrencyResult, OnPlayFabError); }
/// <summary> /// Syncing player prefs data for highscore if playing offline. /// Syncing player prefs data for currency value if purchase with diamonds was made offline. /// </summary> public static void SyncCurrencyWhenOnline() { Debug.Log(PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToAddForSync)); Debug.Log(PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToSubstractForSync)); AddUserVirtualCurrencyRequest addCurrencyRequest = new AddUserVirtualCurrencyRequest() { Amount = PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToAddForSync), VirtualCurrency = "DM" }; if (PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToAddForSync) != 0) { PlayFabClientAPI.AddUserVirtualCurrency(addCurrencyRequest, result => { PlayerPrefs.SetInt(PlayerPrefsStrings.currencyValueToAddForSync, 0); PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 0); }, error => { FindObjectOfType <ShowErrorMessageController>().SetErrorMessage("Syncing offline data failed: " + error.GenerateErrorReport()); PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 1); }); } else { if (PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToSubstractForSync) == 0) { PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 0); } } //TBD: This was made because when clicking an upgrade, substract currency is updated as playerpref, if game is closed without pressing back, when coming online again currency could go to minus //With this check players can exploit the upgrades without paying for currency //You could create a new playerpref holding the values before starting the upgrades as (old currency value) and one for upgrades process started = 1 //When pressing back the upgrade process started playerpref should be 0 and the old values should be updated with the new upgraded ones //If upgrade process started playerpref = 1 don't do the currency substraction // eventuall make a difference between the currency substracted from upgrades and other currencies if (PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToSubstractForSync) != 0) { SubtractUserVirtualCurrencyRequest substractCurrencyRequest = new SubtractUserVirtualCurrencyRequest() { Amount = PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToSubstractForSync), VirtualCurrency = "DM" }; if (PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToSubstractForSync) != 0) { PlayFabClientAPI.SubtractUserVirtualCurrency(substractCurrencyRequest, result => { PlayerPrefs.SetInt(PlayerPrefsStrings.currencyValueToSubstractForSync, 0); PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 0); }, error => { if (error.GenerateErrorReport().Contains("destination host")) { FindObjectOfType <ShowErrorMessageController>().SetErrorMessage("NETWORK CONNECTION FAILED! PLEASE MAKE SURE YOU HAVE AN ACTIVE INTERNET CONNECTION!"); } else { FindObjectOfType <ShowErrorMessageController>().SetErrorMessage("SyncCurrencyWhenOnline: " + error.GenerateErrorReport()); } PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 1); }); } else { if (PlayerPrefs.GetInt(PlayerPrefsStrings.currencyValueToAddForSync) == 0) { PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 0); } } } else { PlayerPrefs.SetInt(PlayerPrefsStrings.currencyValueToSubstractForSync, 0); PlayerPrefs.SetInt(PlayerPrefsStrings.currencyNeedsSync, 0); } }
IEnumerator Load() { int i = 0; string star = null; int cut = 0; #region 서버에 저장된 데이터를 꺼내옴 var request = new GetUserDataRequest() { PlayFabId = User.FabId }; PlayFabClientAPI.GetUserData(request, (result) => { loadData = new string[result.Data.Count, 4]; #region 저 도감, 재화, 세포 데이터 로드 if (result.Data.Count > 0) // 유저 데이터가 있으면 로드 없으면 새로만들기 { foreach (var item in result.Data) { // 값이 비었으면 불러오지 않음 if (item.Value.Value != null) { // 도감 데이터 로드 if (item.Key == "book") { string[] book = item.Value.Value.Split('|'); for (int h = 0; h < book.Length; h++) { if (book[h] == "o") { CellData.CellDataArray[h, 5] = book[h]; } } continue; } // 유저 자금 if (item.Key == "usermoney") { string[] init = item.Value.Value.Split('|'); if (init[0] == "true") { var moneyrequest1 = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "MY", Amount = 0 }; PlayFabClientAPI.AddUserVirtualCurrency(moneyrequest1, (resultmoney1) => { User.money = resultmoney1.Balance; AllManager.AM.UM.setUserMoney(); }, (errormoney1) => Debug.Log("돈 로드 실패")); } continue; } // 유저 캐릭터 정보 if (item.Key == "userchar") { string[] init = item.Value.Value.Split('|'); if (init[0] == "true") { AllManager.AM.UM.setUserCharMini(int.Parse(init[1])); AllManager.AM.UM.onPlayerCharInfoUI(int.Parse(init[1])); } continue; } // 유저 정보 if (item.Key == "userInfo") { string[] init = item.Value.Value.Split('|'); AllManager.AM.GM.setUserInfo(init[0], init[1]); continue; } // 세포 가격 if (item.Key == "cellCount") { SystemDB.CurrentCellValue = int.Parse(item.Value.Value); AllManager.AM.UM.setCellPayText(item.Value.Value); continue; } // 좌표와 몇성인지 분해 star = item.Key.Substring(2, 1); cut = item.Value.Value.IndexOf("|"); // 이름 분해 textEnd = item.Key.IndexOf("|"); cellName = item.Key.Substring(0, textEnd); loadData[i, 0] = cellName; loadData[i, 1] = item.Value.Value.Substring(0, cut); loadData[i, 2] = item.Value.Value.Substring(cut + 1); loadData[i, 3] = star; i++; } } // 불러온 데이터 새로고침 PoolingManager.PM.LoadCell(loadData); } else if (result.Data.Count == 0) // 완전 초기 실행 { // 유저 돈 지급 var moneyrequest = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "MY", Amount = 1000 }; PlayFabClientAPI.AddUserVirtualCurrency(moneyrequest, (resultmoney) => { User.money = resultmoney.Balance; AllManager.AM.UM.setUserMoney(); }, (errormoney) => Debug.Log("돈 지급 실패")); var usermoneysave = new UpdateUserDataRequest() { Data = new Dictionary <string, string>() { { "usermoney", "true|" } } }; PlayFabClientAPI.UpdateUserData(usermoneysave, (result3) => { }, (error2) => Debug.Log("데이터 저장실패")); // 캐릭터 생성 AllManager.AM.UM.startSeletingChar(); } #endregion #region 저 인벤토리 로드 getInventory(); #endregion }, (error) => Debug.Log("세포 데이터 로드 실패")); #endregion yield return(new WaitForSeconds(0.2f)); }