diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 7ec8e4e35..31261f003 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -201,15 +201,16 @@ namespace ArchiSteamFarm { // Calculate our value of items to give List amountsToGive = new List(tradeOffer.ItemsToGive.Count); + Dictionary amountMapToGive = new Dictionary(amountMap); foreach (ulong key in tradeOffer.ItemsToGive.Select(item => item.ClassID)) { uint amount; - if (!amountMap.TryGetValue(key, out amount)) { + if (!amountMapToGive.TryGetValue(key, out amount)) { amountsToGive.Add(0); continue; } amountsToGive.Add(amount); - amountMap[key] = amount - 1; // We're giving one, so we have one less + amountMapToGive[key] = amount - 1; // We're giving one, so we have one less } // Sort it ascending @@ -217,21 +218,23 @@ namespace ArchiSteamFarm { // Calculate our value of items to receive List amountsToReceive = new List(tradeOffer.ItemsToReceive.Count); + Dictionary amountMapToReceive = new Dictionary(amountMap); foreach (ulong key in tradeOffer.ItemsToReceive.Select(item => item.ClassID)) { uint amount; - if (!amountMap.TryGetValue(key, out amount)) { + if (!amountMapToReceive.TryGetValue(key, out amount)) { amountsToReceive.Add(0); continue; } amountsToReceive.Add(amount); - amountMap[key] = amount + 1; // We're getting one, so we have one more + amountMapToReceive[key] = amount + 1; // We're getting one, so we have one more } // Sort it ascending amountsToReceive.Sort(); // Check actual difference + // We sum only values at proper indexes of giving, because user might be overpaying int difference = amountsToGive.Select((t, i) => (int) (t - amountsToReceive[i])).Sum(); // Trade is worth for us if the difference is greater than 0