@@ -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