Example #1
0
        /// <summary>
        /// スタミナを消費する。
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static async UniTask SubtractStaminaAsync(int amount)
        {
            // PlayFab 内部ではスタミナがユーザーごとのスタミナ最大値を超えていることがあるのでその分もここで考慮して減算する。
            var overMaxStaminaNum = StaminaRaw - UserDataManager.MaxStamina;

            if (overMaxStaminaNum > 0)
            {
                amount = overMaxStaminaNum + amount;
            }

            var request = new SubtractUserVirtualCurrencyRequest
            {
                VirtualCurrency = "ST",
                Amount          = amount
            };

            var response = await PlayFabClientAPI.SubtractUserVirtualCurrencyAsync(request);

            if (response.Error != null)
            {
                throw new PlayFabErrorException(response.Error);
            }

            StaminaRaw = response.Result.Balance;
        }
Example #2
0
    public void RemoveCredits(int amount)
    {
        var currencyRequest = new SubtractUserVirtualCurrencyRequest {
            VirtualCurrency = "CR", Amount = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(currencyRequest, OnSuccess, OnFailure);
    }
Example #3
0
    public void SubtractMoney()
    {
        var request = new SubtractUserVirtualCurrencyRequest()
        {
            VirtualCurrency = "GD", Amount = 50
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, (result) => print("돈 빼기 성공! 현재 돈 : " + result.Balance), (error) => print("돈 빼기 실패"));
    }
        /// <summary>
        /// Decrements the specified virtual currency by the stated amount
        /// </summary>
        public static void SubtractUserVirtualCurrency(SubtractUserVirtualCurrencyRequest 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/SubtractUserVirtualCurrency", request, AuthType.DevSecretKey, resultCallback, errorCallback, customData);
        }
    public void UseStamina(System.Action <ModifyUserVirtualCurrencyResult> returnCallback, int amount)
    {
        SubtractUserVirtualCurrencyRequest request = new SubtractUserVirtualCurrencyRequest()
        {
            VirtualCurrency = "ST", Amount = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, returnCallback, CommonFailure);
    }
    void SubstractVC(int amount)
    {
        var request = new SubtractUserVirtualCurrencyRequest()
        {
            VirtualCurrency = "CO",
            Amount          = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, SubSuccess, SubFailed);
    }
Example #7
0
    public void SubtractUserVirtualCurrency(string currency, int amount, System.Action <ModifyUserVirtualCurrencyResult> successCallback, System.Action <PlayFabError> failureCallback)
    {
        if (failureCallback == null)
        {
            failureCallback = Callback_Generic_Error;
        }
        var request = new SubtractUserVirtualCurrencyRequest {
            VirtualCurrency = currency, Amount = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, successCallback, failureCallback);
    }
Example #8
0
    public static Promise SubstractCurrency(CurrencyCode currencyCode, int amount)
    {
        var promise = new Promise();
        var request = new SubtractUserVirtualCurrencyRequest {
            VirtualCurrency = currencyCode.ToString(), Amount = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, (result) => {
            SuccessCallback(result);
            promise.Resolve();
        }, ErrorCallback);
        return(promise);
    }
Example #9
0
    public void spandMoney(int amount)
    {
        AllManager.AM.UM.buttonOff(1);
        var spandrequest = new SubtractUserVirtualCurrencyRequest()
        {
            VirtualCurrency = "MY", Amount = amount
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(spandrequest, (result) =>
        {
            AllManager.AM.UM.buttonOff(0);
            AllManager.AM.UM.setUserMoney();
        }, (error) => Debug.Log(error));
    }
Example #10
0
    private static void ConsumeCurrency(ECurrency _Currency, int _Amount)
    {
        SubtractUserVirtualCurrencyRequest request = new SubtractUserVirtualCurrencyRequest()
        {
            Amount          = _Amount,
            VirtualCurrency = _Currency.ToIdentifier()
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(request, OnTransactionResult,
                                                     (error) =>
        {
            Debug.Log("Got error substractin user currency :");
            Debug.Log(error.GenerateErrorReport());
        });
    }
Example #11
0
    private void RemoveCurrencyFromPlayer(int numberOfCoins)
    {
        makingPlayFabRequest = true;
        SubtractUserVirtualCurrencyRequest virtualCurrencyRequest = new SubtractUserVirtualCurrencyRequest()
        {
            VirtualCurrency = "GC",
            Amount          = numberOfCoins
        };

        PlayFabClientAPI.SubtractUserVirtualCurrency(virtualCurrencyRequest, (result) => {
            Debug.Log("Removing (" + numberOfCoins + ") coins from 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");
    }
    /// <summary>
    /// 仮想通貨を減らす
    /// </summary>
    /// <param name="VCcode">仮想通貨コード</param>
    /// <param name="value">減らす値</param>
    public void SubtractUserVirtualCurrency(string VCcode, int value)
    {
        // 通信待ちでなかったら通信開始
        if (!waitConnect.GetWait(gameObject.name))
        {
            // 通信待ちに設定する
            waitConnect.AddWait(gameObject.name);

            //AddUserVirtualCurrencyRequestのインスタンスを生成
            var subtractUserVirtualCurrencyRequest = new SubtractUserVirtualCurrencyRequest
            {
                Amount          = value,  //減らす金額
                VirtualCurrency = VCcode, //仮想通貨のコード
            };

            // 仮想通貨の減額
            Debug.Log($"仮想通貨の減額開始");
            PlayFabClientAPI.SubtractUserVirtualCurrency(subtractUserVirtualCurrencyRequest, OnSuccessSub, OnErrorSub);
        }
    }
Example #14
0
    /// <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);
        }
    }