Esempio n. 1
0
        /// <summary>
        /// Initializes the inventory for the specified steamId and appId.
        /// </summary>
        /// <param name="steamId">steamId64 of the inventory to request.</param>
        /// <param name="appId">App ID of the inventory to request.</param>
        private void InitializeInventory(uint appId)
        {
            dynamic inventoryJson = RequestInventory(appId);

            if (inventoryJson.success == null)
            {
                throw new InventoryException("Inventory request was not successful. 'success' field was null.");
            }
            if (inventoryJson.success != true && inventoryJson.Error != null)
            {
                throw new InventoryException(
                          "Inventory request was not successful. 'success' field was false. Error Message: " +
                          inventoryJson.Error.ToString());
            }
            if (inventoryJson.success != true)
            {
                throw new InventoryException(
                          "Inventory request was not successsful. 'success' field was false. Likely cause: No items in inventory.");
            }

            dynamic rgInventory = null;

            if (inventoryJson.rgInventory.Count != 0)
            {
                rgInventory = inventoryJson.rgInventory;
            }

            Dictionary <string, RgDescription> deserializedDescriptions = new Dictionary <string, RgDescription>();

            if (inventoryJson.rgDescriptions.Count != 0)
            {
                dynamic rgDescriptions = inventoryJson.rgDescriptions;
                deserializedDescriptions =
                    JsonConvert.DeserializeObject <Dictionary <string, RgDescription> >(rgDescriptions.ToString());
            }

            foreach (RgDescription rgDescription in deserializedDescriptions.Values)
            {
                try
                {
                    var description = new Item {
                        Description = rgDescription
                    };

                    if (!Items.ContainsKey(rgDescription.ClassId))
                    {
                        Items.Add(rgDescription.ClassId, description);
                    }
                }
                catch (NullReferenceException)
                {
                    //I can't remember why, but it prevents bad things from happening.
                }
            }

            //later implement RgInventory like I did with RgDescription
            if (rgInventory == null)
            {
                return;
            }
            foreach (dynamic obj in rgInventory)
            {
                dynamic item = JsonConvert.DeserializeObject <dynamic>(obj.Value.ToString());

                var inventoryItem = new RgInventoryItem
                {
                    Amount     = item.amount,
                    ClassId    = item.classid,
                    Id         = item.id,
                    InstanceId = item.instanceid,
                    Pos        = item.pos
                };
                Items[inventoryItem.ClassId].Items.Add(inventoryItem);
            }
        }
Esempio n. 2
0
 //predicate
 private static bool BeingUsed(RgInventoryItem rgInventoryItem)
 {
     return(rgInventoryItem.InUse);
 }