diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 4d5fd42e2..b34671502 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -70,8 +70,6 @@ namespace ArchiSteamFarm.Json { [PublicAPI] public EType Type { get; internal set; } - internal Asset CreateShallowCopy() => (Asset) MemberwiseClone(); - #pragma warning disable IDE0051 [JsonProperty(PropertyName = "amount", Required = Required.Always)] [NotNull] @@ -192,6 +190,9 @@ namespace ArchiSteamFarm.Json { [JsonConstructor] private Asset() { } + [NotNull] + internal Asset CreateShallowCopy() => (Asset) MemberwiseClone(); + public enum ERarity : byte { Unknown, Common, diff --git a/ArchiSteamFarm/Statistics.cs b/ArchiSteamFarm/Statistics.cs index 90c008c98..37e34235b 100644 --- a/ArchiSteamFarm/Statistics.cs +++ b/ArchiSteamFarm/Statistics.cs @@ -475,12 +475,12 @@ namespace ArchiSteamFarm { fairClassIDsToReceive.TryGetValue(theirItem, out uint fairReceivedAmount); fairClassIDsToGive[ourItem] = ++fairGivenAmount; fairClassIDsToReceive[theirItem] = ++fairReceivedAmount; - + // Filter their inventory for the sets we're trading or have traded with this user - HashSet fairFiltered = theirInventory.Where(item => (item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity) || skippedSetsThisTrade.Any(skippedSets => skippedSets.RealAppID == item.RealAppID && skippedSets.Type == item.Type && skippedSets.Rarity == item.Rarity)).Select(item => item.CreateShallowCopy()).ToHashSet(); + HashSet fairFiltered = theirInventory.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Any(skippedSets => (skippedSets.RealAppID == item.RealAppID) && (skippedSets.Type == item.Type) && (skippedSets.Rarity == item.Rarity))).Select(item => item.CreateShallowCopy()).ToHashSet(); // Copy list to HashSet - HashSet fairItemsToGive = Trading.GetTradableItemsFromInventory(ourInventory.Where(item => (item.RealAppID == set.RealAppID && item.Type == set.Type && item.Rarity == set.Rarity) || skippedSetsThisTrade.Any(skippedSets => skippedSets.RealAppID == item.RealAppID && skippedSets.Type == item.Type && skippedSets.Rarity == item.Rarity)).Select(item => item.CreateShallowCopy()).ToHashSet(), fairClassIDsToGive.ToDictionary(classID => classID.Key, classID => classID.Value)); + HashSet fairItemsToGive = Trading.GetTradableItemsFromInventory(ourInventory.Where(item => ((item.RealAppID == set.RealAppID) && (item.Type == set.Type) && (item.Rarity == set.Rarity)) || skippedSetsThisTrade.Any(skippedSets => (skippedSets.RealAppID == item.RealAppID) && (skippedSets.Type == item.Type) && (skippedSets.Rarity == item.Rarity))).Select(item => item.CreateShallowCopy()).ToHashSet(), fairClassIDsToGive.ToDictionary(classID => classID.Key, classID => classID.Value)); HashSet fairItemsToReceive = Trading.GetTradableItemsFromInventory(fairFiltered.Select(item => item.CreateShallowCopy()).ToHashSet(), fairClassIDsToReceive.ToDictionary(classID => classID.Key, classID => classID.Value)); // Actual check: diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index bc94c8d99..9d81f2451 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -239,28 +239,6 @@ namespace ArchiSteamFarm { return tradableState; } - internal static Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary> GetInventoryState(IReadOnlyCollection inventory) { - if ((inventory == null) || (inventory.Count == 0)) { - ASF.ArchiLogger.LogNullError(nameof(inventory)); - - return null; - } - - Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary> state = new Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary>(); - - foreach (Steam.Asset item in inventory) { - (uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) key = (item.RealAppID, item.Type, item.Rarity); - - if (state.TryGetValue(key, out Dictionary set)) { - set[item.ClassID] = set.TryGetValue(item.ClassID, out uint amount) ? amount + item.Amount : item.Amount; - } else { - state[key] = new Dictionary { { item.ClassID, item.Amount } }; - } - } - - return state; - } - internal static HashSet GetTradableItemsFromInventory(IReadOnlyCollection inventory, IDictionary classIDs) { if ((inventory == null) || (inventory.Count == 0) || (classIDs == null) || (classIDs.Count == 0)) { ASF.ArchiLogger.LogNullError(nameof(inventory) + " || " + nameof(classIDs)); @@ -399,6 +377,28 @@ namespace ArchiSteamFarm { return sets.ToDictionary(set => set.Key, set => set.Value.Values.OrderBy(amount => amount).ToList()); } + private static Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary> GetInventoryState(IReadOnlyCollection inventory) { + if ((inventory == null) || (inventory.Count == 0)) { + ASF.ArchiLogger.LogNullError(nameof(inventory)); + + return null; + } + + Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary> state = new Dictionary<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity), Dictionary>(); + + foreach (Steam.Asset item in inventory) { + (uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) key = (item.RealAppID, item.Type, item.Rarity); + + if (state.TryGetValue(key, out Dictionary set)) { + set[item.ClassID] = set.TryGetValue(item.ClassID, out uint amount) ? amount + item.Amount : item.Amount; + } else { + state[key] = new Dictionary { { item.ClassID, item.Amount } }; + } + } + + return state; + } + private async Task ParseActiveTrades() { HashSet tradeOffers = await Bot.ArchiWebHandler.GetActiveTradeOffers().ConfigureAwait(false);