diff --git a/ArchiSteamFarm.Tests/Trading.cs b/ArchiSteamFarm.Tests/Trading.cs index f437d2be8..bcb2467dd 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, uint amount = 1, ulong instanceID = 0, ulong assetID = 0, 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, amount, instanceID, assetID, marketable, tradable, realAppID, type, rarity); + private static Steam.Asset CreateItem(ulong classID, uint amount = 1, 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, amount, realAppID: realAppID, type: type, rarity: rarity); } } diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index e3facfe5d..98e07cc51 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -226,6 +226,7 @@ namespace ArchiSteamFarm { asset.Marketable = description.Marketable; asset.Tradable = description.Tradable; + asset.Tags = description.Tags; asset.RealAppID = description.RealAppID; asset.Type = description.Type; asset.Rarity = description.Rarity; @@ -1502,7 +1503,7 @@ namespace ArchiSteamFarm { List tags = description["tags"].Children; if (tags.Count > 0) { - HashSet parsedTags = new HashSet(); + HashSet parsedTags = new HashSet(); foreach (KeyValue tag in tags) { string identifier = tag["category"].AsString(); @@ -1521,7 +1522,7 @@ namespace ArchiSteamFarm { return null; } - parsedTags.Add(new Steam.InventoryResponse.Description.Tag(identifier, value)); + parsedTags.Add(new Steam.Asset.Tag(identifier, value)); } parsedDescription.Tags = parsedTags.ToImmutableHashSet(); @@ -2489,6 +2490,7 @@ namespace ArchiSteamFarm { bool marketable = true; bool tradable = true; + ImmutableHashSet tags = null; uint realAppID = 0; Steam.Asset.EType type = Steam.Asset.EType.Unknown; Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Unknown; @@ -2496,12 +2498,13 @@ namespace ArchiSteamFarm { if (descriptions.TryGetValue(key, out Steam.InventoryResponse.Description description)) { marketable = description.Marketable; tradable = description.Tradable; + tags = description.Tags; realAppID = description.RealAppID; type = description.Type; rarity = description.Rarity; } - Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, amount, instanceID, assetID, marketable, tradable, realAppID, type, rarity); + Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, amount, instanceID, assetID, marketable, tradable, tags, realAppID, type, rarity); output.Add(steamAsset); } diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 9edd070eb..680113852 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -71,6 +71,9 @@ namespace ArchiSteamFarm.Json { [PublicAPI] public uint RealAppID { get; internal set; } + [PublicAPI] + public ImmutableHashSet Tags { get; internal set; } = ImmutableHashSet.Empty; + [PublicAPI] public bool Tradable { get; internal set; } @@ -198,7 +201,7 @@ namespace ArchiSteamFarm.Json { #pragma warning restore IDE0051 // Constructed from trades being received or plugins - public Asset(uint appID, ulong contextID, ulong classID, uint amount, ulong instanceID = 0, ulong assetID = 0, bool marketable = true, bool tradable = true, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) { + public Asset(uint appID, ulong contextID, ulong classID, uint amount, ulong instanceID = 0, ulong assetID = 0, bool marketable = true, bool tradable = true, ImmutableHashSet tags = null, 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)); } @@ -214,6 +217,10 @@ namespace ArchiSteamFarm.Json { RealAppID = realAppID; Type = type; Rarity = rarity; + + if ((tags != null) && (tags.Count > 0)) { + Tags = tags; + } } [JsonConstructor] @@ -222,6 +229,28 @@ namespace ArchiSteamFarm.Json { [JetBrains.Annotations.NotNull] internal Asset CreateShallowCopy() => (Asset) MemberwiseClone(); + public sealed class Tag { + [JsonProperty(PropertyName = "category", Required = Required.Always)] + [PublicAPI] + public readonly string Identifier; + + [JsonProperty(PropertyName = "internal_name", Required = Required.Always)] + [PublicAPI] + public readonly string Value; + + internal Tag([JetBrains.Annotations.NotNull] string identifier, [JetBrains.Annotations.NotNull] string value) { + if (string.IsNullOrEmpty(identifier) || string.IsNullOrEmpty(value)) { + throw new ArgumentNullException(nameof(identifier) + " || " + nameof(value)); + } + + Identifier = identifier; + Value = value; + } + + [JsonConstructor] + private Tag() { } + } + public enum ERarity : byte { Unknown, Common, @@ -489,7 +518,7 @@ namespace ArchiSteamFarm.Json { internal Asset.ERarity Rarity { get { - foreach (Tag tag in Tags) { + foreach (Asset.Tag tag in Tags) { switch (tag.Identifier) { case "droprate": switch (tag.Value) { @@ -515,7 +544,7 @@ namespace ArchiSteamFarm.Json { internal uint RealAppID { get { - foreach (Tag tag in Tags) { + foreach (Asset.Tag tag in Tags) { switch (tag.Identifier) { case "Game": if ((tag.Value.Length <= 4) || !tag.Value.StartsWith("app_", StringComparison.Ordinal)) { @@ -544,7 +573,7 @@ namespace ArchiSteamFarm.Json { get { Asset.EType type = Asset.EType.Unknown; - foreach (Tag tag in Tags) { + foreach (Asset.Tag tag in Tags) { switch (tag.Identifier) { case "cardborder": switch (tag.Value) { @@ -610,7 +639,7 @@ namespace ArchiSteamFarm.Json { internal bool Marketable { get; set; } [JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)] - internal ImmutableHashSet Tags { get; set; } = ImmutableHashSet.Empty; + internal ImmutableHashSet Tags { get; set; } = ImmutableHashSet.Empty; internal bool Tradable { get; set; } @@ -670,26 +699,6 @@ namespace ArchiSteamFarm.Json { [JsonConstructor] internal Description() { } - - internal sealed class Tag { - [JsonProperty(PropertyName = "category", Required = Required.Always)] - internal readonly string Identifier; - - [JsonProperty(PropertyName = "internal_name", Required = Required.Always)] - internal readonly string Value; - - internal Tag([JetBrains.Annotations.NotNull] string identifier, [JetBrains.Annotations.NotNull] string value) { - if (string.IsNullOrEmpty(identifier) || string.IsNullOrEmpty(value)) { - throw new ArgumentNullException(nameof(identifier) + " || " + nameof(value)); - } - - Identifier = identifier; - Value = value; - } - - [JsonConstructor] - private Tag() { } - } } }