/// <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 = inventoryJson.rgInventory; dynamic rgDescriptions = inventoryJson.rgDescriptions; Dictionary <string, RgDescription> 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 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); } }
//predicate private static bool BeingUsed(RgInventoryItem rgInventoryItem) { return rgInventoryItem.InUse; }
/// <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 = inventoryJson.rgInventory; dynamic rgDescriptions = inventoryJson.rgDescriptions; Dictionary<string, RgDescription> 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 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); } }
//predicate private static bool BeingUsed(RgInventoryItem rgInventoryItem) { return(rgInventoryItem.InUse); }