Skip fair bots with huge inventories when active matching

This commit is contained in:
JustArchi
2020-06-21 00:06:17 +02:00
parent 2e5828779f
commit e5eea110f1

View File

@@ -34,6 +34,7 @@ using Newtonsoft.Json;
namespace ArchiSteamFarm {
internal sealed class Statistics : IAsyncDisposable {
private const ushort MaxItemsForFairBots = 30000; // Determines which fair bots we'll skip when matching due to excessive number of inventory requests they need to make, which are likely to fail in the process or cause excessive delays
private const byte MaxMatchedBotsHard = 40; // Determines how many bots we can attempt to match in total, where match attempt is equal to analyzing bot's inventory
private const byte MaxMatchedBotsSoft = MaxMatchedBotsHard / 2; // Determines how many consecutive empty matches we need to get before we decide to skip bots from the same category
private const byte MaxMatchingRounds = 10; // Determines maximum amount of matching rounds we're going to consider before leaving the rest of work for the next batch
@@ -400,7 +401,7 @@ namespace ArchiSteamFarm {
HashSet<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> skippedSetsThisRound = new HashSet<(uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)>();
foreach (ListedUser listedUser in listedUsers.Where(listedUser => (listedUser.SteamID != Bot.SteamID) && acceptedMatchableTypes.Any(listedUser.MatchableTypes.Contains) && (!triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet<ulong> GivenAssetIDs, ISet<ulong> ReceivedAssetIDs) attempt) || (attempt.Tries < byte.MaxValue)) && !Bot.IsBlacklistedFromTrades(listedUser.SteamID)).OrderBy(listedUser => triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet<ulong> GivenAssetIDs, ISet<ulong> ReceivedAssetIDs) attempt) ? attempt.Tries : 0).ThenByDescending(listedUser => listedUser.MatchEverything).ThenByDescending(listedUser => listedUser.Score)) {
foreach (ListedUser listedUser in listedUsers.Where(listedUser => (listedUser.SteamID != Bot.SteamID) && (listedUser.MatchEverything || (listedUser.ItemsCount < MaxItemsForFairBots)) && acceptedMatchableTypes.Any(listedUser.MatchableTypes.Contains) && (!triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet<ulong> GivenAssetIDs, ISet<ulong> ReceivedAssetIDs) attempt) || (attempt.Tries < byte.MaxValue)) && !Bot.IsBlacklistedFromTrades(listedUser.SteamID)).OrderBy(listedUser => triedSteamIDs.TryGetValue(listedUser.SteamID, out (byte Tries, ISet<ulong> GivenAssetIDs, ISet<ulong> ReceivedAssetIDs) attempt) ? attempt.Tries : 0).ThenByDescending(listedUser => listedUser.MatchEverything).ThenByDescending(listedUser => listedUser.Score)) {
if (listedUser.MatchEverything && skipAnyBots) {
continue;
}
@@ -696,6 +697,11 @@ namespace ArchiSteamFarm {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
private sealed class ListedUser {
#pragma warning disable 649
[JsonProperty(PropertyName = "items_count", Required = Required.Always)]
internal readonly ushort ItemsCount;
#pragma warning restore 649
internal readonly HashSet<Steam.Asset.EType> MatchableTypes = new HashSet<Steam.Asset.EType>();
#pragma warning disable 649
@@ -715,11 +721,6 @@ namespace ArchiSteamFarm {
private readonly ushort GamesCount;
#pragma warning restore 649
#pragma warning disable 649
[JsonProperty(PropertyName = "items_count", Required = Required.Always)]
private readonly ushort ItemsCount;
#pragma warning restore 649
internal bool MatchEverything { get; private set; }
#pragma warning disable IDE0051