public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } var template = AutoLegalityWrapper.GetTemplate(set); var pkm = sav.GetLegal(template, out var result); if (SysCordInstance.Self.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg") { TradeExtensions.EggTrade((PK8)pkm); } if (SysCordInstance.Self.Hub.Config.Trade.DittoTrade && set.Species == 132) { TradeExtensions.DittoTrade(pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var reason = result == "Timeout" ? "That set took too long to generate." : "I wasn't able to create something from that."; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! {reason} Here's my best attempt for that {spec}!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } var pkm = sav.GetLegal(set, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[set.Species]; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } try { var template = AutoLegalityWrapper.GetTemplate(set); var pkm = sav.GetLegal(template, out var result); if (pkm is PK8 && pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <PK8> .EggTrade(pkm); } else if (pkm is PB8 && pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <PB8> .EggTrade(pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; if (!la.Valid) { var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set."; var imsg = $"Oops! {reason}"; if (result == "Failed") { imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}"; } await channel.SendMessageAsync(imsg).ConfigureAwait(false); return; } var msg = $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); } catch (Exception ex) { LogUtil.LogSafe(ex, nameof(AutoLegalityExtensionsDiscord)); var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```"; await channel.SendMessageAsync(msg).ConfigureAwait(false); } }