Exemple #1
0
        public async Task <List <ItemInstance> > GetUserInventoryUsingAdminAPI(string playFabId)
        {
            PlayFabResult <GetUserInventoryResult> result;
            var reqGetInventory = new GetUserInventoryRequest
            {
                PlayFabId = playFabId,
            };

            try
            {
                result = await PlayFabAdminAPI.GetUserInventoryAsync(reqGetInventory);
            }
            catch
            {
                // This is a retry, since we've seen a random issue that fails to return the user inventory
                // and succeeds on the following request
                result = await PlayFabAdminAPI.GetUserInventoryAsync(reqGetInventory);
            }

            return(result?.Result?.Inventory ?? new List <ItemInstance>());
        }
Exemple #2
0
        public async Task <UserInventoryResponse> GetUserInventory(string playfabId)
        {
            var reqGetInventory = new GetUserInventoryRequest
            {
                PlayFabId = playfabId
            };

            var result = await PlayFabAdminAPI.GetUserInventoryAsync(reqGetInventory);

            if (result.Error != null)
            {
                throw new Exception(result.Error.ErrorMessage);
            }

            var budget    = result?.Result?.VirtualCurrency?.ContainsKey(configuration.Currency) == true ? result.Result.VirtualCurrency[configuration.Currency] : 0;
            var inventory = await CompleteWithDataStore(result.Result.Inventory.ToList <dynamic>());

            return(new UserInventoryResponse
            {
                Inventory = inventory,
                Budget = budget
            });
        }