Skip to content

Commit 50b5c7b

Browse files
committed
Correct STM algorithm when overpaying with cards from the same game
us: X X Y them: Y Y Z trade: Y -> X + Z New: toGive: 1 toReceive: 2 + 0 -> 0 + 2 diff: 1 - 0 = 1 1 > 0 ? True Old: toGive: 1 toReceive: 2 1 > 2 ? False
1 parent b60448e commit 50b5c7b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

ArchiSteamFarm/Trading.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,34 +165,47 @@ private async Task<bool> ShouldAcceptTrade(Steam.TradeOffer tradeOffer) {
165165
}
166166

167167
// Calculate our value of items to give
168-
uint itemsToGiveDupesValue = 0;
168+
List<uint> amountsToGive = new List<uint>(tradeOffer.ItemsToGive.Count);
169169
foreach (Steam.Item item in tradeOffer.ItemsToGive) {
170170
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(item.ClassID, item.InstanceID);
171171

172172
uint amount;
173173
if (!amountMap.TryGetValue(key, out amount)) {
174+
amountsToGive.Add(0);
174175
continue;
175176
}
176177

177-
itemsToGiveDupesValue += amount;
178+
amountsToGive.Add(amount);
178179
}
179180

181+
// Sort it ascending
182+
amountsToGive.Sort();
183+
180184
// Calculate our value of items to receive
181-
uint itemsToReceiveDupesValue = 0;
185+
List<uint> amountsToReceive = new List<uint>(tradeOffer.ItemsToReceive.Count);
182186
foreach (Steam.Item item in tradeOffer.ItemsToReceive) {
183187
Tuple<ulong, ulong> key = new Tuple<ulong, ulong>(item.ClassID, item.InstanceID);
184188

185189
uint amount;
186190
if (!amountMap.TryGetValue(key, out amount)) {
191+
amountsToReceive.Add(0);
187192
continue;
188193
}
189194

190-
itemsToReceiveDupesValue += amount;
195+
amountsToReceive.Add(amount);
196+
}
197+
198+
// Sort it ascending
199+
amountsToReceive.Sort();
200+
201+
// Check actual difference
202+
int difference = 0;
203+
for (int i = 0; i < amountsToGive.Count; i++) {
204+
difference += (int) (amountsToGive[i] - amountsToReceive[i]);
191205
}
192206

193-
// Trade is worth for us if we're in total trading more of our dupes for less of our dupes (or at least same amount)
194-
// Which means that itemsToGiveDupesValue should be greater than itemsToReceiveDupesValue
195-
return itemsToGiveDupesValue > itemsToReceiveDupesValue;
207+
// Trade is worth for us if the difference is greater than 0
208+
return difference > 0;
196209
}
197210
}
198211
}

0 commit comments

Comments
 (0)