Inheritance: PlayFabRequestCommon
Beispiel #1
0
		/// <summary>
		/// Retrieves the title-specific custom data for the character which can only be read by the client
		/// </summary>
		public static void GetCharacterReadOnlyData(GetCharacterDataRequest request, GetCharacterReadOnlyDataCallback 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)
			{
				GetCharacterDataResult result = null;
				PlayFabError error = null;
				ResultContainer<GetCharacterDataResult>.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/GetCharacterReadOnlyData", serializedJSON, "X-Authorization", AuthKey, callback);
		}
        /// <summary>
        /// Retrieves the title-specific custom data for the character which can only be read by the client
        /// </summary>
        public static void GetCharacterReadOnlyData(GetCharacterDataRequest request, ProcessApiCallback<GetCharacterDataResult> 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<GetCharacterDataResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/GetCharacterReadOnlyData", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
    //Gets a specific character data
    public static void GetQuestLog()
    {
        var request = new GetCharacterDataRequest()
        {
            CharacterId = PlayFabDataStore.characterId
        };
        PlayFabClientAPI.GetCharacterData(request, (result) =>
        {
            if (result.Data.ContainsKey("QuestLog"))
            {
                
                Debug.Log(result.Data["QuestLog"].Value);
                string[] customData = result.Data["QuestLog"].Value.Split('#');
                Debug.Log(customData.Length);

                foreach (var quest in customData)
                {
                    if (!PlayFabDataStore.playerQuestLog.Contains(quest))
                    {
                        Debug.Log(quest);
                        PlayFabDataStore.playerQuestLog.Add(quest);
                    }
                }
                //PlayFabDataStore.playerQuestLog.Add("Quest_Initial"); Testing
            } 
            

            QuestTracker.questTracker.LoadTrackerQuests();
            Debug.Log("Quest Log retrieved and set");

        }, (error) =>
        {
            Debug.Log("Quest Log Cannot Retrieved!");
            Debug.Log(error.ErrorMessage);
            Debug.Log(error.ErrorDetails);
        });
    }
    //Get custom data of the character and set them to their locals
    public static void GetCharacterStats()
    {
        var request = new GetCharacterDataRequest()
        {
            CharacterId = PlayFabDataStore.characterId
        };
        PlayFabClientAPI.GetCharacterData(request, (result) =>
        {    
            PlayFabDataStore.playerLevel = int.Parse(result.Data["Level"].Value);
            PlayFabDataStore.playerExperience = int.Parse(result.Data["Experience"].Value);
            PlayFabDataStore.statsBuilder["Vitality"] = int.Parse(result.Data["StatBuilderVitality"].Value);
            PlayFabDataStore.statsBuilder["Strength"] = int.Parse(result.Data["StatBuilderStrength"].Value);
            PlayFabDataStore.statsBuilder["Intellect"] = int.Parse(result.Data["StatBuilderIntellect"].Value);
            PlayFabDataStore.statsBuilder["Dexterity"] = int.Parse(result.Data["StatBuilderDexterity"].Value);
            PlayFabDataStore.statsBuilder["Spirit"] = int.Parse(result.Data["StatBuilderSpirit"].Value);
            PlayFabDataStore.statsBuilder["Critical Chance"] = int.Parse(result.Data["StatBuilderCriticalChance"].Value);
            PlayFabDataStore.statsBuilder["Nature Resistance"] = int.Parse(result.Data["StatBuilderNatureResistance"].Value);
            PlayFabDataStore.statsBuilder["Fire Resistance"] = int.Parse(result.Data["StatBuilderFireResistance"].Value);
            PlayFabDataStore.statsBuilder["Frost Resistance"] = int.Parse(result.Data["StatBuilderFrostResistance"].Value);
            PlayFabDataStore.statsBuilder["Holy Resistance"] = int.Parse(result.Data["StatBuilderHolyResistance"].Value);
            PlayFabDataStore.statsBuilder["Arcane Resistance"] = int.Parse(result.Data["StatBuilderArcaneResistance"].Value);
            Debug.Log("Data successfully retrieved!");
            Debug.Log("LEVEL " + PlayFabDataStore.playerLevel);

        }, (error) =>
        {
            Debug.Log("Character data request failed!");
            Debug.Log(error.ErrorMessage);
            Debug.Log(error.ErrorDetails);
        });
    }
Beispiel #5
0
		/// <summary>
		/// Retrieves the title-specific custom data for the character which can only be read by the client
		/// </summary>
        public static async Task<PlayFabResult<GetCharacterDataResult>> GetCharacterReadOnlyDataAsync(GetCharacterDataRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

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

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<GetCharacterDataResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			GetCharacterDataResult result = resultData.data;
			
			
            return new PlayFabResult<GetCharacterDataResult>
                {
                    Result = result
                };
        }
        /// <summary>
        /// Retrieves the title-specific custom data for the character which is readable and writable by the client
        /// </summary>
        public static void GetCharacterData(GetCharacterDataRequest request, GetCharacterDataCallback resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (_authKey == null) throw new Exception("Must be logged in to call this method");

            string serializedJson = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
            Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                ResultContainer<GetCharacterDataResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/GetCharacterData", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }