Inheritance: PlayFabRequestCommon
 public void storeStats(Dictionary<string,int> stats)
 {
     PlayFab.ClientModels.UpdateUserStatisticsRequest request = new PlayFab.ClientModels.UpdateUserStatisticsRequest ();
     request.UserStatistics = stats;
     if (PlayFabData.AuthKey != null)
         PlayFabClientAPI.UpdateUserStatistics (request, StatsUpdated, OnPlayFabError);
 }
Ejemplo n.º 2
0
 public void storeStats(Dictionary <string, int> stats)
 {
     PlayFab.ClientModels.UpdateUserStatisticsRequest request = new PlayFab.ClientModels.UpdateUserStatisticsRequest();
     request.UserStatistics = stats;
     if (PlayFabData.AuthKey != null)
     {
         PlayFabClientAPI.UpdateUserStatistics(request, StatsUpdated, OnPlayFabError);
     }
 }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start () {
		Debug.Log ("GameManager->Start");

		plotFactory = GetComponent<PlotFactory>();
		enemyFactory = GetComponent<EnemyFactory>();

		canvasInit();

		state = State.NewGame;
		PlayFabSettings.TitleId = "E232";
		UpdateUserStatisticsRequest updateReq = new UpdateUserStatisticsRequest (); 
		updateReq.UserStatistics = new System.Collections.Generic.Dictionary<string, int> (); 
		updateReq.UserStatistics.Add("nightsSurvived", nightCounter); 
		Login ("E232", SystemInfo.deviceUniqueIdentifier);
	}
Ejemplo n.º 4
0
        private void GetUserStatsCallback1(GetUserStatisticsResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            if (!result.UserStatistics.TryGetValue(TEST_DATA_KEY, out _testInteger))
                _testInteger = 0; // Default if the data isn't present
            _testInteger = (_testInteger + 1) % 100; // This test is about the Expected value changing - but not testing more complicated issues like bounds

            var updateRequest = new UpdateUserStatisticsRequest
            {
                UserStatistics = new Dictionary<string, int>
                {
                    { TEST_DATA_KEY, _testInteger }
                }
            };
            PlayFabClientAPI.UpdateUserStatistics(updateRequest, PlayFabUUnitUtils.ApiCallbackWrapper<UpdateUserStatisticsResult>(testContext, UpdateUserStatsCallback), SharedErrorCallback, testContext);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Updates the values of the specified title-specific statistics for the user
		/// </summary>
		public static void UpdateUserStatistics(UpdateUserStatisticsRequest request, UpdateUserStatisticsCallback resultCallback, ErrorCallback errorCallback)
		{
			if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

			string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
			Action<string,string> callback = delegate(string responseStr, string errorStr)
			{
				UpdateUserStatisticsResult result = null;
				PlayFabError error = null;
				ResultContainer<UpdateUserStatisticsResult>.HandleResults(responseStr, errorStr, out result, out error);
				if(error != null && errorCallback != null)
				{
					errorCallback(error);
				}
				if(result != null)
				{
					
					if(resultCallback != null)
					{
						resultCallback(result);
					}
				}
			};
			PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/UpdateUserStatistics", serializedJSON, "X-Authorization", AuthKey, callback);
		}
Ejemplo n.º 6
0
        public void UserStatisticsApi()
        {
            int testStatExpected, testStatActual;

            var getRequest = new ClientModels.GetUserStatisticsRequest();
            var getStatTask1 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest);
            getStatTask1.Wait();
            UUnitAssert.Null(getStatTask1.Result.Error, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask1.Result.Result, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask1.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call");
            if (!getStatTask1.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatExpected))
                testStatExpected = TEST_STAT_BASE;
            testStatExpected = ((testStatExpected + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new ClientModels.UpdateUserStatisticsRequest();
            updateRequest.UserStatistics = new Dictionary<string, int>();
            updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected;
            var updateTask = PlayFabClientAPI.UpdateUserStatisticsAsync(updateRequest);
            updateTask.Wait(); // The update doesn't return anything, so can't test anything other than failure

            // Test update result - no data returned, so error or no error, based on Title settings
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Null(updateTask.Result.Result, "UpdateStatistics should have failed");
                UUnitAssert.NotNull(updateTask.Result.Error, "UpdateStatistics should have failed");
                return; // The rest of this tests changing settings - Which we verified we cannot do
            }
            else // if (CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Null(updateTask.Result.Error, "UpdateStatistics call failed");
                UUnitAssert.NotNull(updateTask.Result.Result, "UpdateStatistics call failed");
            }

            getRequest = new ClientModels.GetUserStatisticsRequest();
            var getStatTask2 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest);
            getStatTask2.Wait();
            UUnitAssert.Null(getStatTask2.Result.Error, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask2.Result.Result, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask2.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call");
            getStatTask2.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatActual);
            UUnitAssert.Equals(testStatExpected, testStatActual);
        }
        /// <summary>
        /// Updates the values of the specified title-specific statistics for the user. By default, clients are not permitted to update statistics. Developers may override this setting in the Game Manager > Settings > API Features.
        /// </summary>
        public static void UpdateUserStatistics(UpdateUserStatisticsRequest request, ProcessApiCallback<UpdateUserStatisticsResult> resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (_authKey == null) throw new Exception("Must be logged in to call this method");

            string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy);
            Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                ResultContainer<UpdateUserStatisticsResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/UpdateUserStatistics", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
Ejemplo n.º 8
0
	void GameOverBegin(State previousState) {
        GameObject.Find("musicSource").GetComponent<AudioSource>().clip = gameOverMusic;
        GameObject.Find("musicSource").GetComponent<AudioSource>().Play();

        //.. gameOverUI
        gameoverPanel.SetActive(true);
		StartCoroutine(GameOverAsync());
		Time.timeScale = 0;
		string debugOut = "GameOver\n\n";
		debugOut += "\nNights " + nightCounter;
		debugOut += "\nWaves " + waveCounter;
		debugOut += "\n\nBodies Aquired " + totalBodiesAquired;
		debugOut += "\nBodies Lost " + totalBodiesLost;
		debugOut += "\nGravestones Lost " + totalGravestonesLost;
		Debug.Log(debugOut);
		gravestonesLostLabel.text = "" + totalGravestonesLost;
		bodiesLostLabel.text = "" + totalBodiesLost;
		bodiesAquiredLabel.text = "" + totalBodiesAquired;
		wavesLabel.text = "" + waveCounter;
		nightsLabel.text = "" + nightCounter;
		PlayFabSettings.TitleId = "E232";
		if(!userStatistics.ContainsKey("userStatistics") || nightCounter > userStatistics["nightsSurvived"])
		{
		UpdateUserStatisticsRequest updateReq = new UpdateUserStatisticsRequest (); 
		updateReq.UserStatistics = new System.Collections.Generic.Dictionary<string, int> (); 
		updateReq.UserStatistics.Add("nightsSurvived", nightCounter); 
		PlayFabClientAPI.UpdateUserStatistics (updateReq, OnUpdateSuccess, onPlayFabError); 
		}
	}
Ejemplo n.º 9
0
        public void UserStatisticsApi()
        {
            int testStatExpected, testStatActual;

            var getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            UUnitAssert.Equals("User Stats Received", lastReceivedMessage);
            testStatExpected = ((testStatReturn + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new UpdateUserStatisticsRequest();
            updateRequest.UserStatistics = new Dictionary<string, int>();
            updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected;
            PlayFabClientAPI.UpdateUserStatistics(updateRequest, UpdateUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            // Test update result - no data returned, so error or no error, based on Title settings
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Equals("error message from PlayFab", lastReceivedMessage);
                return; // The rest of this tests changing settings - Which we verified we cannot do
            }
            else // if (CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Equals("User Stats Updated", lastReceivedMessage);
            }

            getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            UUnitAssert.Equals("User Stats Received", lastReceivedMessage);
            testStatActual = testStatReturn;
            UUnitAssert.Equals(testStatExpected, testStatActual);
        }
Ejemplo n.º 10
0
		/// <summary>
		/// Updates the values of the specified title-specific statistics for the user
		/// </summary>
        public static async Task<PlayFabResult<UpdateUserStatisticsResult>> UpdateUserStatisticsAsync(UpdateUserStatisticsRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

            object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/UpdateUserStatistics", request, "X-Authorization", AuthKey);
            if(httpResult is PlayFabError)
            {
                PlayFabError error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                    PlayFabSettings.GlobalErrorHandler(error);
                return new PlayFabResult<UpdateUserStatisticsResult>
                {
                    Error = error,
                };
            }
            string resultRawJson = (string)httpResult;

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<UpdateUserStatisticsResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			UpdateUserStatisticsResult result = resultData.data;
			
			
            return new PlayFabResult<UpdateUserStatisticsResult>
                {
                    Result = result
                };
        }
        public void UserStatisticsApi()
        {
            int testStatExpected, testStatActual;

            var getStatTask1 = Client.GetUserStatisticsAsync();
            try
            {
                getStatTask1.Wait();
            }
            catch (Exception ex)
            {
                UUnitAssert.True(false, ex.Message);
            }

            UUnitAssert.NotNull(getStatTask1.Result, "UserStatistics should have been retrieved from Api call");

            if (!getStatTask1.Result.TryGetValue(TEST_STAT_NAME, out testStatExpected))
                testStatExpected = TEST_STAT_BASE;
            testStatExpected = ((testStatExpected + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new ClientModels.UpdateUserStatisticsRequest();
            updateRequest.UserStatistics = new Dictionary<string, int>();
            updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected;
            var updateTask = Client.UpdateUserStatisticsAsync(updateRequest);
            bool failed = false;
            string failedMessage = "UpdateStatistics should have failed";
            try
            {
                updateTask.Wait(); // The update doesn't return anything, so can't test anything other than failure
            }
            catch (Exception ex)
            {
                failed = true;
                failedMessage = ex.Message;
            }

            // Test update result - no data returned, so error or no error, based on Title settings
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.True(failed, failedMessage);
            }
            else
            {
                UUnitAssert.False(failed, failedMessage);
            }

            var getStatTask2 = Client.GetUserStatisticsAsync();
            try
            {
                getStatTask2.Wait();
            }
            catch (Exception ex)
            {
                UUnitAssert.True(false, ex.Message);
            }
            UUnitAssert.NotNull(getStatTask2.Result, "UserStatistics should have been retrieved from Api call");
            getStatTask2.Result.TryGetValue(TEST_STAT_NAME, out testStatActual);
            UUnitAssert.Equals(testStatExpected, testStatActual);
        }
    /// <summary>
    /// Reports user's wins statistics.
    /// </summary>
    /// <param name="amount"></param>
    public void ReportWins(int amount)
    {
        UpdateUserStatisticsRequest request = new UpdateUserStatisticsRequest();
        request.UserStatistics = new Dictionary<string, int>();
        request.UserStatistics.Add(GameConstants.winsStatsKey, amount);

        PlayFabClientAPI.UpdateUserStatistics(request, OnUpdateStatsCompleted, OnUpdateStatsError);
    }
	public void UpdatePlayerXP(int xp) {
		UpdateUserStatisticsRequest updateReq = new UpdateUserStatisticsRequest ();
		updateReq.UserStatistics = new System.Collections.Generic.Dictionary<string, int> ();
		updateReq.UserStatistics.Add("XP", xp);
		PlayFabClientAPI.UpdateUserStatistics (updateReq, OnUpdatePlayerXPSuccess, OnPlayFabError);
	}
	//set user data
	public void SetUserStats (Dictionary<string,int> lstUserData)
	{
		UpdateUserStatisticsRequest request = new UpdateUserStatisticsRequest () {
			UserStatistics = lstUserData
		};
		//PlayFabClientAPI.UpdatePlayerStatistics
		PlayFabClientAPI.UpdateUserStatistics (request, (result) => {
			Debug.Log ("Successfully updated user statistics");
		}, (error) => {
			Debug.Log ("Got error setting user statistics");
			Debug.Log (error.ErrorDetails);
		});
	}