public LedyResponse <T> GetLedyTrade(T pk, Species speciesMatch = NoMatchSpecies) { if (speciesMatch != NoMatchSpecies && pk.Species != (int)speciesMatch) { return(GetRandomResponse()); } // All the files should be loaded in as lowercase, regular-width text with no white spaces. var nick = StringsUtil.Sanitize(pk.Nickname); if (UserRequests.TryGetValue(nick, out var match)) { return(new LedyResponse <T>(match.RequestInfo, LedyResponseType.MatchRequest)); } if (Distribution.TryGetValue(nick, out match)) { return(new LedyResponse <T>(match.RequestInfo, LedyResponseType.MatchPool)); } return(GetRandomResponse()); }
public bool LoadFolder(string path) { Clear(); Files.Clear(); if (!Directory.Exists(path)) { return(false); } var loadedAny = false; var files = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories); var matchFiles = LoadUtil.GetFilesOfSize(files, ExpectedSize); int surpriseBlocked = 0; foreach (var file in matchFiles) { var data = File.ReadAllBytes(file); var pkm = PKMConverter.GetPKMfromBytes(data); if (!(pkm is T dest)) { continue; } if (dest.Species == 0 || !(dest is PK8 pk8)) { LogUtil.LogInfo("SKIPPED: Provided pk8 is not valid: " + dest.FileName, nameof(PokemonPool <T>)); continue; } if (!dest.CanBeTraded()) { LogUtil.LogInfo("SKIPPED: Provided pk8 cannot be traded: " + dest.FileName, nameof(PokemonPool <T>)); continue; } var la = new LegalityAnalysis(pk8); if (!la.Valid && Settings.Legality.VerifyLegality) { var reason = la.Report(); LogUtil.LogInfo($"SKIPPED: Provided pk8 is not legal: {dest.FileName} -- {reason}", nameof(PokemonPool <T>)); continue; } if (DisallowSurpriseTrade(pk8)) { LogUtil.LogInfo("Provided pk8 was loaded but can't be Surprise Traded: " + dest.FileName, nameof(PokemonPool <T>)); surpriseBlocked++; } if (Settings.Legality.ResetHOMETracker) { pk8.Tracker = 0; } var fn = Path.GetFileNameWithoutExtension(file); fn = StringsUtil.Sanitize(fn); // Since file names can be sanitized to the same string, only add one of them. if (!Files.ContainsKey(fn)) { Add(dest); Files.Add(fn, new LedyRequest <T>(dest, fn)); } else { LogUtil.LogInfo("Provided pk8 was not added due to duplicate name: " + dest.FileName, nameof(PokemonPool <T>)); } loadedAny = true; } if (surpriseBlocked == Count) { LogUtil.LogInfo("Surprise trading will fail; failed to load any compatible files.", nameof(PokemonPool <T>)); } return(loadedAny); }