diff --git a/ArchiSteamFarm.Tests/Trading.cs b/ArchiSteamFarm.Tests/Trading.cs index 882fb4bc9..90af28457 100644 --- a/ArchiSteamFarm.Tests/Trading.cs +++ b/ArchiSteamFarm.Tests/Trading.cs @@ -367,6 +367,6 @@ namespace ArchiSteamFarm.Tests { } [NotNull] - private static Steam.Asset CreateItem(ulong classID, ulong instanceID = 0, uint amount = 1, bool marketable = true, uint realAppID = Steam.Asset.SteamAppID, Steam.Asset.EType type = Steam.Asset.EType.TradingCard, Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Common) => new Steam.Asset(Steam.Asset.SteamAppID, Steam.Asset.SteamCommunityContextID, classID, instanceID, amount, marketable, realAppID, type, rarity); + private static Steam.Asset CreateItem(ulong classID, ulong instanceID = 0, uint amount = 1, bool marketable = true, bool tradable = true, uint realAppID = Steam.Asset.SteamAppID, Steam.Asset.EType type = Steam.Asset.EType.TradingCard, Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Common) => new Steam.Asset(Steam.Asset.SteamAppID, Steam.Asset.SteamCommunityContextID, classID, instanceID, amount, marketable, tradable, realAppID, type, rarity); } } diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index e8fd4c159..77291e772 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -1464,7 +1464,7 @@ namespace ArchiSteamFarm { return null; } - Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> descriptions = new Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)>(); + Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description> descriptions = new Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description>(); foreach (KeyValue description in response["descriptions"].Children) { uint appID = description["appid"].AsUnsignedInteger(); @@ -1491,11 +1491,13 @@ namespace ArchiSteamFarm { continue; } - bool marketable = description["marketable"].AsBoolean(); - - Steam.Asset.EType type = Steam.Asset.EType.Unknown; - Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Unknown; - uint realAppID = 0; + Steam.InventoryResponse.Description parsedDescription = new Steam.InventoryResponse.Description { + AppID = appID, + ClassID = classID, + InstanceID = instanceID, + Marketable = description["marketable"].AsBoolean(), + Tradable = true // We're parsing active trade offers, we can assume as much + }; List tags = description["tags"].Children; @@ -1521,9 +1523,11 @@ namespace ArchiSteamFarm { parsedTags.Add(new Steam.InventoryResponse.Description.Tag(identifier, value)); } + + parsedDescription.Tags = parsedTags.ToImmutableHashSet(); } - descriptions[key] = (marketable, realAppID, type, rarity); + descriptions[key] = parsedDescription; } HashSet result = new HashSet(); @@ -2437,7 +2441,7 @@ namespace ArchiSteamFarm { return uri.AbsolutePath.StartsWith("/login", StringComparison.Ordinal) || uri.Host.Equals("lostauth"); } - private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> descriptions, IReadOnlyCollection input, ICollection output) { + private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description> descriptions, IReadOnlyCollection input, ICollection output) { if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) { ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output)); @@ -2482,18 +2486,20 @@ namespace ArchiSteamFarm { } bool marketable = true; + bool tradable = true; uint realAppID = 0; Steam.Asset.EType type = Steam.Asset.EType.Unknown; Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Unknown; - if (descriptions.TryGetValue(key, out (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) description)) { + if (descriptions.TryGetValue(key, out Steam.InventoryResponse.Description description)) { marketable = description.Marketable; + tradable = description.Tradable; realAppID = description.RealAppID; type = description.Type; rarity = description.Rarity; } - Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, instanceID, amount, marketable, realAppID, type, rarity); + Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, instanceID, amount, marketable, tradable, realAppID, type, rarity); output.Add(steamAsset); } diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 2b5bfe5d3..e553bedc4 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -198,7 +198,7 @@ namespace ArchiSteamFarm.Json { #pragma warning restore IDE0051 // Constructed from trades being received or plugins - public Asset(uint appID, ulong contextID, ulong classID, ulong instanceID, uint amount, bool marketable = true, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) { + public Asset(uint appID, ulong contextID, ulong classID, ulong instanceID, uint amount, bool marketable = true, bool tradable = true, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) { if ((appID == 0) || (contextID == 0) || (classID == 0) || (amount == 0)) { throw new ArgumentNullException(nameof(appID) + " || " + nameof(contextID) + " || " + nameof(classID) + " || " + nameof(amount)); } @@ -209,6 +209,7 @@ namespace ArchiSteamFarm.Json { InstanceID = instanceID; Amount = amount; Marketable = marketable; + Tradable = tradable; RealAppID = realAppID; Type = type; Rarity = rarity; @@ -485,12 +486,6 @@ namespace ArchiSteamFarm.Json { internal readonly ImmutableDictionary AdditionalProperties; #pragma warning restore 649 - [JsonProperty(PropertyName = "appid", Required = Required.Always)] - internal readonly uint AppID; - - [JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)] - internal readonly ImmutableHashSet Tags; - internal Asset.ERarity Rarity { get { foreach (Tag tag in Tags) { @@ -606,10 +601,17 @@ namespace ArchiSteamFarm.Json { } } - internal ulong ClassID { get; private set; } - internal ulong InstanceID { get; private set; } - internal bool Marketable { get; private set; } - internal bool Tradable { get; private set; } + [JsonProperty(PropertyName = "appid", Required = Required.Always)] + internal uint AppID { get; set; } + + internal ulong ClassID { get; set; } + internal ulong InstanceID { get; set; } + internal bool Marketable { get; set; } + + [JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)] + internal ImmutableHashSet Tags { get; set; } + + internal bool Tradable { get; set; } #pragma warning disable IDE0051 [JsonProperty(PropertyName = "classid", Required = Required.Always)] @@ -666,7 +668,7 @@ namespace ArchiSteamFarm.Json { #pragma warning restore IDE0051 [JsonConstructor] - private Description() { } + internal Description() { } internal sealed class Tag { [JsonProperty(PropertyName = "category", Required = Required.Always)]