public void CalculateAndNotify(T pkm, PokeTradeDetail <T> detail, SeedCheckSettings settings, PokeTradeBot bot) { var ec = pkm.EncryptionConstant; var pid = pkm.PID; var IVs = pkm.IVs.Length == 0 ? GetBlankIVTemplate() : PKX.ReorderSpeedLast((int[])pkm.IVs.Clone()); var name = SpeciesName.GetSpeciesName(pkm.Species, 2); var ot = pkm.OT_Name; var abilityNo = pkm.AbilityNumber; var ability = pkm.Ability; var gender = pkm.GetSaneGender(); var nature = pkm.Nature; if (settings.ShowAllZ3Results) { var matches = Z3Search.GetAllSeeds(ec, pid, IVs, name, ot, gender, abilityNo, ability, nature); foreach (var match in matches) { var lump = new PokeTradeSummary("Calculated Seed:", match); detail.SendNotification(bot, lump); } } else { var match = Z3Search.GetFirstSeed(ec, pid, IVs, name, ot, gender, abilityNo, ability, nature); var lump = new PokeTradeSummary("Calculated Seed:", match); detail.SendNotification(bot, lump); } }
/// <summary> /// Loading a file and creates <see cref="ShowdownSet"/>s form them. /// </summary> /// <param name="path">Path to the file containing showdown data.</param> public void LoadShowdown(string path) { try { string[] sets = File.ReadAllText(path).Split(new string[] { "\n\n", "\r\n\r\n" }, StringSplitOptions.None); if (string.IsNullOrWhiteSpace(sets[0])) { throw new Exception("Showdown file was invalid! Aborting loading showdown sets"); } for (int i = 0; i < sets.Length; i++) { showdownSets.Add(new ShowdownSet(sets[i])); if (showdownSets[i].InvalidLines.Count() == 0) { Console.WriteLine("Loading showdown set for " + SpeciesName.GetSpeciesName(showdownSets[i].Species, 2)); } else { showdownSets.Clear(); throw new Exception("Showdown file was invalid! Aborting loading showdown sets"); } } Console.WriteLine("Showdown file was successfully loaded."); } catch (Exception ex) { ShowError(ex.Message); } }
/// <summary> /// Set a chosen <see cref="PKM"/> to a box. /// </summary> /// <param name="showdownSetIndex">Index of the showdown set. index of ignored sets a invalid</param> /// <param name="box">Box to set the <see cref="PKM"/>.</param> /// <param name="slot">Slot of the chosen box to set the <see cref="PKM"/>.</param> /// <remarks>You can get the <paramref name="showdownSetIndex"/> by calling getshowdownsets.</remarks> public void SetPkm(int showdownSetIndex, int box, int slot) { string paramName = string.Empty; if (showdownSets[showdownSetIndex] == null || !IsValid[showdownSetIndex]) { paramName = nameof(showdownSetIndex); } if (box < 0 || box > 31) { paramName = nameof(box); } if (slot < 0 || slot > 29) { paramName = nameof(slot); } try { if (paramName != string.Empty) { throw new Exception(paramName + " is invalid"); } PKM pkm = ENTITIES[showdownSetIndex]; BoxEdit boxEdit = new BoxEdit(SAV); boxEdit.LoadBox(box); boxEdit[slot] = pkm; Console.WriteLine(SpeciesName.GetSpeciesName(pkm.Species, 2) + " was set to box " + box + " slot " + slot); } catch (Exception ex) { ShowError(ex.Message); } }
private async Task <PokeTradeResult> ProcessGiveawayUploadAsync(PokeTradeDetail <PK8> detail, CancellationToken token) { int ctr = 0; var time = TimeSpan.FromSeconds(Hub.Config.Trade.MaxDumpTradeTime); var start = DateTime.Now; var pkprev = new PK8(); var poolEntry = detail.PoolEntry; while (ctr < 1 && DateTime.Now - start < time) { var pk = await ReadUntilPresent(LinkTradePartnerPokemonOffset, 3_000, 1_000, token).ConfigureAwait(false); if (pk == null || pk.Species < 1 || !pk.ChecksumValid || SearchUtil.HashByDetails(pk) == SearchUtil.HashByDetails(pkprev)) { continue; } // Save the new Pokémon for comparison next round. pkprev = pk; poolEntry.PK8 = pk; poolEntry.Pokemon = SpeciesName.GetSpeciesName(pk.Species, 2); if (Hub.Config.Legality.VerifyLegality) { LogUtil.LogInfo($"Performing legality check on {poolEntry.Pokemon}", "PokeTradeBot.GiveawayUpload"); var la = new LegalityAnalysis(poolEntry.PK8); var verbose = la.Report(true); LogUtil.LogInfo($"Shown Pokémon is {(la.Valid ? "Valid" : "Invalid")}.", "PokeTradeBot.GiveawayUpload"); detail.SendNotification(this, pk, $"Pokémon sent is {(la.Valid ? "Valid" : "Invalid")}."); detail.SendNotification(this, pk, verbose); if (!la.Valid) { detail.SendNotification(this, pk, $"Show a different pokemon to continue or exit the trade to end."); continue; } } LogUtil.LogInfo("Creating new database entry", "PokeTradeBot.GiveawayUpload"); Hub.GiveawayPoolDatabase.NewEntry(poolEntry); if (Hub.Config.Discord.ReturnPK8s) { detail.SendNotification(this, pk, "Here's what you showed me!"); } ctr++; } LogUtil.LogInfo($"Ended Giveaway pool upload", "PokeTradeBot.GiveawayUpload"); await ExitSeedCheckTrade(Hub.Config, token).ConfigureAwait(false); if (ctr == 0) { return(PokeTradeResult.TrainerTooSlow); } detail.Notifier.SendNotification(this, detail, $"Finished uploading Pokémon to the Giveaway Pool."); detail.Notifier.TradeFinished(this, detail, detail.TradeData); // blank pk8 return(PokeTradeResult.Success); }
private void UpdatePKMList() { PKMList.Items.Clear(); foreach (SlotCache entry in cache) { var entity = entry.Entity; if (entity.Species != 0 && (entity.PID & 0xFFFF) == seed) { _ = PKMList.Items.Add($"{SpeciesName.GetSpeciesName(entity.Species, 2)}{(entity.IsNicknamed ? " (" + entity.Nickname + ")" : "")} {GetSlotInfo(entry)}"); } } }
private async Task CatchWildPokemon(PK8 pk, CancellationToken token) { var check = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false); if (encounterCount != 0 && encounterCount % catchCount == 0) { Log($"Ran out of Master Balls to catch {SpeciesName.GetSpeciesName(pk.Species, 2)}."); if (Hub.Config.StopConditions.InjectPokeBalls) { Log("Restoring original pouch data."); await Connection.WriteBytesAsync(pouchData, PokeBallOffset, Config.ConnectionType, token).ConfigureAwait(false); await Task.Delay(500, token).ConfigureAwait(false); } else { Log($"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again."); return; } } await SetLastUsedBall(Ball.Master, token).ConfigureAwait(false); await Click(B, 1_000, token).ConfigureAwait(false); await Click(X, 1_000, token).ConfigureAwait(false); await Click(A, 3_000, token).ConfigureAwait(false); // Throw ball await Click(B, 1_000, token).ConfigureAwait(false); await Click(B, 1_000, token).ConfigureAwait(false); // Just in case we didn't await Click(X, 1_000, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); // Attempt again to be sure while (!await IsOnOverworld(Hub.Config, token).ConfigureAwait(false) && check.Species != 0) { await Click(B, 0_400, token).ConfigureAwait(false); } if (await IsOnOverworld(Hub.Config, token).ConfigureAwait(false) && !await IsInBattle(token).ConfigureAwait(false)) { Log($"{Ping}Caught {SpeciesName.GetSpeciesName(pk.Species, 2)}! Resuming routine..."); await WalkInLine(token).ConfigureAwait(false); } }
private async Task CatchWildPokemon(PK8 pk, CancellationToken token) { var check = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false); if (encounterCount != 0 && encounterCount % catchCount == 0) { Log($"Ran out of Master Balls to catch {SpeciesName.GetSpeciesName(pk.Species, 2)}."); if (hub.Config.Encounter.InjectPokeBalls) { Log("Restoring original pouch data."); await Connection.WriteBytesAsync(pouchData, PokeBallOffset, token).ConfigureAwait(false); await Task.Delay(500, token).ConfigureAwait(false); } else { Log("Restart the game and the bot(s) or set \"Inject Poké Balls\" to True in the config."); return; } } await Click(B, 1_000, token).ConfigureAwait(false); await Click(X, 1_000, token).ConfigureAwait(false); await Click(A, 3_000, token).ConfigureAwait(false); //Throw ball await Click(B, 1_000, token).ConfigureAwait(false); await Click(B, 1_000, token).ConfigureAwait(false); //Just in case we didn't await Click(X, 1_000, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); //Attempt again to be sure while (!await IsOnOverworld(hub.Config, token).ConfigureAwait(false) && check.Species != 0) { await Click(B, 0_400, token).ConfigureAwait(false); } if (await IsOnOverworld(hub.Config, token).ConfigureAwait(false) && !await IsInBattle(token).ConfigureAwait(false)) { Log($"{Ping}Caught {SpeciesName.GetSpeciesName(pk.Species, 2)} in a Master Ball! Resuming routine..."); } }
public void ListPokemon() { var strings = GameInfo.GetStrings("ja"); foreach (var monster in savedata.PartyData) { Console.WriteLine(string.Join("\t", ((LanguageID)monster.Language).ToString(), monster.CurrentLevel.ToString(), SpeciesName.GetSpeciesName(monster.Species, 1), monster.Nickname.ToString(), monster.OT_Name)); var moves = ""; foreach (var move in monster.Moves) { moves += strings.movelist[move] + "\t"; } Console.WriteLine(moves); } }
public async Task EggRollAsync() { if (!Info.Hub.Config.Trade.EggRollChannels.Contains(Context.Channel.Id.ToString()) && !Info.Hub.Config.Trade.EggRollChannels.Equals("")) { await ReplyAsync($"You're typing the command in the wrong channel!").ConfigureAwait(false); return; } if (Info.Hub.Config.Trade.EggRollCooldown < 0) { Info.Hub.Config.Trade.EggRollCooldown = default; } var id = Context.User.Id.ToString(); var line = TradeExtensions.EggRollCooldown.FirstOrDefault(z => z.Contains(id)); System.DateTime.TryParse(line != null ? line.Split(',')[1] : string.Empty, out System.DateTime time); var timer = time.AddHours(Info.Hub.Config.Trade.EggRollCooldown); var timeRemaining = timer - System.DateTime.Now; if (System.DateTime.Now < timer) { await ReplyAsync($"{Context.User.Mention}, please try again in {timeRemaining.Hours:N0}h : {timeRemaining.Minutes:N0}m : {timeRemaining.Seconds:N0}s!").ConfigureAwait(false); return; } var code = Info.GetRandomTradeCode(); var rng = new System.Random(); int shinyRng = rng.Next(0, TradeExtensions.shinyOdds.Length); int abilityRng = rng.Next(0, TradeExtensions.abilityIndex.Length); var set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName((int)TradeExtensions.validEgg.GetValue(rng.Next(0, TradeExtensions.validEgg.Length)), 2)})"); var template = AutoLegalityWrapper.GetTemplate(set); var sav = AutoLegalityWrapper.GetTrainerInfo(8); var pkm = (PK8)sav.GetLegal(template, out _); if (TradeExtensions.regional.ToList().Contains(pkm.Species)) { int formRng = rng.Next(0, TradeExtensions.formIndex1.Length); int formRng2 = rng.Next(0, TradeExtensions.formIndex2.Length); if (pkm.Species != 52) { pkm.SetAltForm(TradeExtensions.formIndex1[formRng]); } else { pkm.SetAltForm(TradeExtensions.formIndex2[formRng2]); } if (pkm.AltForm != 0) { switch (pkm.Species) { case 27: pkm.RelearnMove3 = 10; break; case 37: pkm.RelearnMove4 = 39; break; case 52: pkm.RelearnMove2 = 252; pkm.RelearnMove3 = 45; break; case 83: pkm.RelearnMove1 = 64; pkm.RelearnMove4 = 28; break; case 222: pkm.RelearnMove1 = 33; break; case 263: pkm.RelearnMove2 = 43; pkm.RelearnMove3 = 0; pkm.RelearnMove4 = 0; break; } ; } } TradeExtensions.EggTrade(pkm); pkm.Nature = rng.Next(0, 24); pkm.StatNature = pkm.Nature; pkm.SetAbilityIndex(TradeExtensions.abilityIndex[abilityRng]); pkm.IVs = pkm.SetRandomIVs(3); BallApplicator.ApplyBallLegalRandom(pkm); switch (TradeExtensions.shinyOdds[shinyRng]) { case 3: CommonEdits.SetShiny(pkm, Shiny.Never); pkm.SetUnshiny(); break; case 5: CommonEdits.SetShiny(pkm, Shiny.AlwaysStar); break; case 6: CommonEdits.SetShiny(pkm, Shiny.AlwaysSquare); break; } ; var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality); if (invalid) { var imsg = $"Oops! I scrambled your egg! Don't tell Ramsay! Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } pkm.ResetPartyStats(); var sudo = Context.User.GetIsSudo(); await Context.AddToQueueAsync(code, Context.User.Username, sudo, pkm, PokeRoutineType.EggRoll, PokeTradeType.EggRoll).ConfigureAwait(false); }
private async Task DoSeededEncounter(CancellationToken token) { ScanMode type = Hub.Config.SWSH_OverworldScan.EncounteringType; SAV8 sav = await GetFakeTrainerSAV(token).ConfigureAwait(false); Species dexn = 0; uint offset = 0x00; if (type == ScanMode.G_Articuno) { dexn = (Species)144; offset = CrownTundraSnowslideSlopeSpawns; } else if (type == ScanMode.G_Zapdos) { dexn = (Species)145; offset = WildAreaMotostokeSpawns; } else if (type == ScanMode.G_Moltres) { dexn = (Species)146; offset = IsleOfArmorStationSpaws; } else if (type == ScanMode.IoA_Wailord) { dexn = (Species)321; offset = IsleOfArmorStationSpaws; } while (!token.IsCancellationRequested && offset != 0) { await FlyToRerollSeed(token).ConfigureAwait(false); var pkm = await ReadOwPokemon(dexn, offset, null, sav, token).ConfigureAwait(false); if (pkm != null && await LogPKMs(pkm, IsPKLegendary(pkm.Species), token).ConfigureAwait(false)) { await Click(X, 2_000, token).ConfigureAwait(false); await Click(R, 2_000, token).ConfigureAwait(false); await Click(A, 5_000, token).ConfigureAwait(false); await Click(X, 2_000, token).ConfigureAwait(false); Log($"The overworld encounter has been found. The progresses has been saved and the game is paused, you can now go and catch {SpeciesName.GetSpeciesName((int)dexn, 2)}"); return; } } }
public async Task LanRollAsync([Summary("User Requested IGN")][Remainder] string ign = "") { if (ign.Length > 12) { await ReplyAsync("IGN cannot exceed 12 characters.").ConfigureAwait(false); return; } var code = Info.GetRandomTradeCode(); int[] existantMon = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 50, 51, 52, 53, 54, 55, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 72, 73, 77, 78, 79, 80, 81, 82, 83, 90, 91, 92, 93, 94, 95, 98, 99, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 163, 164, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 182, 183, 184, 185, 186, 194, 195, 196, 197, 199, 202, 206, 208, 211, 212, 213, 214, 215, 220, 221, 222, 223, 224, 225, 226, 227, 230, 233, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 263, 264, 270, 271, 272, 273, 274, 275, 278, 279, 280, 281, 282, 290, 291, 292, 293, 294, 295, 298, 302, 303, 304, 305, 306, 309, 310, 315, 318, 319, 320, 321, 324, 328, 329, 330, 333, 334, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 355, 356, 359, 360, 361, 362, 363, 364, 365, 369, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 403, 404, 405, 406, 407, 415, 416, 420, 421, 422, 423, 425, 426, 427, 428, 434, 436, 437, 438, 439, 440, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 470, 471, 473, 474, 475, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 494, 506, 507, 508, 509, 510, 517, 518, 519, 520, 521, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 582, 583, 584, 587, 588, 589, 590, 591, 592, 593, 595, 596, 597, 598, 599, 600, 601, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 649, 659, 660, 661, 662, 663, 674, 675, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 736, 737, 738, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 776, 777, 778, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898 }; var rng = new System.Random(); var set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})"); while (!existantMon.ToList().Contains(set.Species)) { set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})"); } var template = AutoLegalityWrapper.GetTemplate(set); var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = (PK8)sav.GetLegal(template, out _);; LanRollTrade(pkm); pkm.ClearRecordFlags(); pkm.GetSuggestedRelearnMoves(); pkm.ResetPartyStats(); var sig = Context.User.GetFavor(); await Context.AddToQueueAsync(code, Context.User.Username, sig, pkm, PokeRoutineType.LanRoll, PokeTradeType.LanRoll, Context.User, ign).ConfigureAwait(false); }
private string GetSpeciesNameFromPKM(PKM pkm) => SpeciesName.GetSpeciesName(pkm.Species, SAV.Language);
private async Task Overworld(CancellationToken token, bool birds = false) { GameVersion version = await LGWhichGameVersion(token).ConfigureAwait(false); List <int[]> movementslist = ParseMovements(); bool firstrun = movementslist.Count > 0; Stopwatch stopwatch = new Stopwatch(); uint prev = 0; uint newspawn; uint catchcombo; uint speciescombo; int i = 0; bool freeze = false; bool searchforshiny = Hub.Config.LGPE_OverworldScan.OnlyShiny; bool found; if (movementslist.Count > 0) { Log($"{Environment.NewLine}----------------------------------------{Environment.NewLine}" + $"ATTENTION{Environment.NewLine}Any wild battles will broke the movement routine, resulting in the pg moving to unwanted areas!{Environment.NewLine}" + $"----------------------------------------{Environment.NewLine}" + $"ATTENTION{Environment.NewLine}Unexpected behaviour can occur if a Pokémon is detected while changing area. It is higlhy recommended to avoid that.{Environment.NewLine}" + $"-----------------------------------------{Environment.NewLine}"); } //Catch combo to increment spawn quality and shiny rate (Thanks to Lincoln-LM for the offsets) if ((int)Hub.Config.LGPE_OverworldScan.ChainSpecies > 0) { speciescombo = await LGReadSpeciesCombo(token).ConfigureAwait(false); if ((speciescombo != (uint)Hub.Config.LGPE_OverworldScan.ChainSpecies) && (Hub.Config.LGPE_OverworldScan.ChainSpecies != 0)) { Log($"Current catch combo being on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}, changing to {Hub.Config.LGPE_OverworldScan.ChainSpecies}."); await LGEditSpeciesCombo((uint)Hub.Config.LGPE_OverworldScan.ChainSpecies, token).ConfigureAwait(false); speciescombo = await LGReadSpeciesCombo(token).ConfigureAwait(false); Log($"Current catch combo being now on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}."); } } if (Hub.Config.LGPE_OverworldScan.ChainCount > 0) { catchcombo = await LGReadComboCount(token).ConfigureAwait(false); if (catchcombo < (uint)Hub.Config.LGPE_OverworldScan.ChainCount) { Log($"Current catch combo being {catchcombo}, incrementing to {Hub.Config.LGPE_OverworldScan.ChainCount}."); await LGEditComboCount((uint)Hub.Config.LGPE_OverworldScan.ChainCount, token).ConfigureAwait(false); catchcombo = await LGReadComboCount(token).ConfigureAwait(false); Log($"Current catch combo being now {catchcombo}."); } } //Main Loop while (!token.IsCancellationRequested) { if (searchforshiny) { await LGZaksabeast(token, version).ConfigureAwait(false); } //Main Loop while (!freeze && !token.IsCancellationRequested) { if (await LGCountMilliseconds(Hub.Config, token).ConfigureAwait(false) > 0 || !searchforshiny) { //Force the Fortune Teller Nature value, value is reset at the end of the day if (Hub.Config.LGPE_OverworldScan.SetFortuneTellerNature != Nature.Random && !await LGIsNatureTellerEnabled(token).ConfigureAwait(false)) { await LGEnableNatureTeller(token).ConfigureAwait(false); await LGEditWildNature(Hub.Config.LGPE_OverworldScan.SetFortuneTellerNature, token).ConfigureAwait(false); Log($"Fortune Teller enabled, Nature set to {await LGReadWildNature(token).ConfigureAwait(false)}."); } //PG Movements. The routine need to continue and check the overworld spawns, cannot be stuck at changing stick position. if (movementslist.Count > 0) { if (stopwatch.ElapsedMilliseconds >= movementslist.ElementAt(i)[2] || firstrun) { if (firstrun) { firstrun = false; } await ResetStick(token).ConfigureAwait(false); await SetStick(RIGHT, (short)(movementslist.ElementAt(i)[0]), (short)(movementslist.ElementAt(i)[1]), 0_001, token).ConfigureAwait(false); i++; if (i == movementslist.Count) { i = 0; } stopwatch.Restart(); } } //Check is inside an unwanted encounter if (await LGIsInCatchScreen(token).ConfigureAwait(false)) { await EscapeWildEncounter(token).ConfigureAwait(false); } //Check new spawns newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn, 2, token).ConfigureAwait(false), 0); if (newspawn != prev) { if (newspawn != 0) { encounterCount++; if (IsPKLegendary((int)newspawn)) { Counts.AddLGPELegendaryScans(); } else { Counts.AddLGPEOverworldScans(); } Log($"New spawn ({encounterCount}): {newspawn} {SpeciesName.GetSpeciesName((int)newspawn, 4)}"); } prev = newspawn; if (!searchforshiny && ((!birds && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) || (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0) || (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146)))) { await Click(X, 1_000, token).ConfigureAwait(false); await Click(HOME, 1_000, token).ConfigureAwait(false); if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> stop conditions met, restart the bot(s) to search again."); } else { Log("Stop conditions met, restart the bot(s) to search again."); } return; } } } else if (searchforshiny) { freeze = true; } } await LGUnfreeze(token, version).ConfigureAwait(false); freeze = false; newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn, 2, token).ConfigureAwait(false), 0); //Stop Conditions if (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146) && !token.IsCancellationRequested) { found = true; } else if ((!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies > 0 && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) || (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0)) { found = true; } else { found = false; } encounterCount++; if (IsPKLegendary((int)newspawn)) { Counts.AddLGPELegendaryScans(); } else { Counts.AddLGPEOverworldScans(); } if (!found && !token.IsCancellationRequested) { Log($"New spawn ({encounterCount}): {newspawn} Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)}"); } else if (found && !token.IsCancellationRequested) { await ResetStick(token).ConfigureAwait(false); if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> Shiny Target {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!"); } else { Log($"Shiny Target {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!"); } await Click(X, 1_000, token).ConfigureAwait(false); await Click(HOME, 1_000, token).ConfigureAwait(false); return; } } await ResetStick(token).ConfigureAwait(false); if (searchforshiny) { await LGUnfreeze(token, version).ConfigureAwait(false); } }
private async Task Overworld(CancellationToken token, bool birds = false) { GameVersion version = await LGWhichGameVersion(token).ConfigureAwait(false); List <int[]> movementslist = ParseMovements(); bool firstrun = movementslist.Count > 0; Stopwatch stopwatch = new Stopwatch(); uint prev = 0; uint newspawn; uint catchcombo; uint speciescombo; int i = 0; int j = 0; bool freeze = false; bool searchforshiny = Hub.Config.LGPE_OverworldScan.OnlyShiny; bool found = false; if (movementslist.Count > 0) { Log($"ATTENTION!{Environment.NewLine}Any wild encounter will broke the movement routine, resulting in the pg moving to unwanted places!{Environment.NewLine}" + $"----------------------------------------{Environment.NewLine}" + $"ATTENTION!\nUnexpected behaviour can occur if a shiny is detected while changing area. It his higlhy recommended to avoid that.{Environment.NewLine}" + $"-----------------------------------------{Environment.NewLine}"); } //Catch combo to increment spawn quality and shiny rate (Thanks to Lincoln-LM for the offsets) if ((int)Hub.Config.LGPE_OverworldScan.ChainSpecies > 0) { speciescombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); if ((speciescombo != (uint)Hub.Config.LGPE_OverworldScan.ChainSpecies) && (Hub.Config.LGPE_OverworldScan.ChainSpecies != 0)) { Log($"Current catch combo being on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}, changing to {Hub.Config.LGPE_OverworldScan.ChainSpecies}."); await SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainSpecies), await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false); speciescombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); Log($"Current catch combo being now on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}."); } } if (Hub.Config.LGPE_OverworldScan.ChainCount > 0) { catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); if (catchcombo < (uint)Hub.Config.LGPE_OverworldScan.ChainCount) { Log($"Current catch combo being {catchcombo}, incrementing to {Hub.Config.LGPE_OverworldScan.ChainCount}."); await SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainCount), await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false); catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); Log($"Current catch combo being now {catchcombo}."); } } while (!token.IsCancellationRequested) { if (searchforshiny) { await LGZaksabeast(token, version).ConfigureAwait(false); } while (freeze == false && !token.IsCancellationRequested && !found) { if (await LGCountMilliseconds(Hub.Config, token).ConfigureAwait(false) > 0 || !searchforshiny) { //The routine need to continue and check the overworld spawns, cannot be stuck at changing stick position. if (movementslist.Count > 0) { if (stopwatch.ElapsedMilliseconds >= movementslist.ElementAt(j)[2] || firstrun) { if (firstrun) { firstrun = false; } //Log($"Moved for {stopwatch.ElapsedMilliseconds}ms."); await ResetStick(token).ConfigureAwait(false); await SetStick(RIGHT, (short)(movementslist.ElementAt(j)[0]), (short)(movementslist.ElementAt(j)[1]), 0_001, token).ConfigureAwait(false); j++; if (j == movementslist.Count) { j = 0; } stopwatch.Restart(); } } //Check is inside an unwanted encounter if (await LGIsInCatchScreen(token).ConfigureAwait(false)) { await ResetStick(token).ConfigureAwait(false); Log($"Unwanted encounter detected!"); int y = 0; while (await LGIsInCatchScreen(token).ConfigureAwait(false) && !token.IsCancellationRequested) { y++; await Task.Delay(8_000, token).ConfigureAwait(false); if (y > 2) { await Click(B, 1_200, token).ConfigureAwait(false); } await Click(B, 1_200, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); await Task.Delay(6_500, token).ConfigureAwait(false); } Log($"Exited wild encounter."); } //Check new spawns newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0); if (newspawn != prev) { if (newspawn != 0) { i++; if (IsPKLegendary((int)newspawn)) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } Log($"New spawn ({i}): {newspawn} {SpeciesName.GetSpeciesName((int)newspawn, 4)}"); } prev = newspawn; if (!searchforshiny && ((!birds && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) || (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0) || (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146)))) { await Click(X, 1_000, token).ConfigureAwait(false); await Click(HOME, 1_000, token).ConfigureAwait(false); if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> stop conditions met, restart the bot(s) to search again."); } else { Log("Stop conditions met, restart the bot(s) to search again."); } return; } } } else if (searchforshiny) { freeze = true; } } if (searchforshiny && !token.IsCancellationRequested) { Log("A Shiny has been detected."); } //Unfreeze to restart the routine, or log the Shiny species. await LGUnfreeze(token, version).ConfigureAwait(false); newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0); //Stop Conditions logic if (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146) && !token.IsCancellationRequested) { found = true; } else if ((!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies > 0 && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) || (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0)) { found = true; } else { found = false; } if (!found && !token.IsCancellationRequested) { freeze = false; Log($"Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} is not the target, the routine will continue."); } else if (!token.IsCancellationRequested) { await ResetStick(token).ConfigureAwait(false); if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!"); } else { Log($"Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!"); } await Click(X, 1_000, token).ConfigureAwait(false); await Click(HOME, 1_000, token).ConfigureAwait(false); return; } } await ResetStick(token).ConfigureAwait(false); if (searchforshiny) { await LGUnfreeze(token, version).ConfigureAwait(false); } }
public async Task EggRaffleAsync() { if (!Info.Hub.Config.Trade.EggRaffle) { await ReplyAsync($"EggRaffle is currently disabled!").ConfigureAwait(false); return; } else if (!Info.Hub.Config.Trade.EggRaffleChannels.Contains(Context.Channel.Id.ToString()) && !Info.Hub.Config.Trade.EggRaffleChannels.Equals("")) { await ReplyAsync($"You're typing the command in the wrong channel!").ConfigureAwait(false); return; } if (Info.Hub.Config.Trade.EggRaffleCooldown < 0) { Info.Hub.Config.Trade.EggRaffleCooldown = default; } if (!System.IO.File.Exists("EggRngBlacklist.txt")) { System.IO.File.Create("EggRngBlacklist.txt").Close(); } System.IO.StreamReader reader = new System.IO.StreamReader("EggRngBlacklist.txt"); var content = reader.ReadToEnd(); reader.Close(); var id = $"{Context.Message.Author.Id}"; var parse = System.Text.RegularExpressions.Regex.Match(content, @"(" + id + @") - (\S*\ \S*\ \w*)", System.Text.RegularExpressions.RegexOptions.Multiline); if (content.Contains($"{Context.Message.Author.Id}")) { var timer = System.DateTime.Parse(parse.Groups[2].Value).AddHours(Info.Hub.Config.Trade.EggRaffleCooldown); var timeremaining = timer - System.DateTime.Now; if (System.DateTime.Now >= timer) { content = content.Replace(parse.Groups[0].Value, $"{id} - {System.DateTime.Now}").TrimEnd(); System.IO.StreamWriter writer = new System.IO.StreamWriter("EggRngBlacklist.txt"); writer.WriteLine(content); writer.Close(); } else { await ReplyAsync($"{Context.User.Mention}, please try again in {timeremaining.Hours:N0}h : {timeremaining.Minutes:N0}m : {timeremaining.Seconds:N0}s!").ConfigureAwait(false); return; } } else { System.IO.File.AppendAllText("EggRngBlacklist.txt", $"{Context.Message.Author.Id} - {System.DateTime.Now}{System.Environment.NewLine}"); } var code = Info.GetRandomTradeCode(); int[] validEgg = { 1, 4, 7, 10, 27, 37, 43, 50, 52, 54, 58, 60, 63, 66, 72, 77, 79, 81, 83, 90, 92, 95, 98, 102, 104, 108, 109, 111, 114, 115, 116, 118, 120, 122, 123, 127, 128, 129, 131, 133, 137, 163, 170, 172, 173, 174, 175, 177, 194, 206, 211, 213, 214, 215, 220, 222, 223, 225, 227, 236, 241, 246, 263, 270, 273, 278, 280, 290, 293, 298, 302, 303, 309, 318, 320, 324, 328, 337, 338, 339, 341, 343, 349, 355, 360, 361, 403, 406, 415, 420, 422, 425, 427, 434, 436, 438, 439, 440, 446, 447, 449, 451, 453, 458, 459, 479, 506, 509, 517, 519, 524, 527, 529, 532, 535, 538, 539, 543, 546, 548, 550, 551, 554, 556, 557, 559, 561, 562, 568, 570, 572, 574, 577, 582, 587, 588, 590, 592, 595, 597, 599, 605, 606, 607, 610, 613, 616, 618, 619, 621, 622, 624, 626, 627, 629, 631, 632, 633, 636, 659, 661, 674, 677, 679, 682, 684, 686, 688, 690, 692, 694, 701, 702, 704, 707, 708, 710, 712, 714, 722, 725, 728, 736, 742, 744, 746, 747, 749, 751, 753, 755, 757, 759, 761, 764, 765, 766, 767, 769, 771, 776, 777, 778, 780, 781, 782, 810, 813, 816, 819, 821, 824, 827, 829, 831, 833, 835, 837, 840, 843, 845, 846, 848, 850, 852, 854, 856, 859, 868, 870, 871, 872, 874, 875, 876, 877, 878, 884, 885 }; int[] regional = { 27, 37, 50, 52, 77, 79, 83, 122, 222, 263, 554, 562, 618 }; int[] shinyOdds = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6 }; int[] abilityIndex = { 0, 1, 2 }; int[] formIndex1 = { 0, 1 }; int[] formIndex2 = { 0, 1, 2 }; var rng = new System.Random(); int shinyRng = rng.Next(0, shinyOdds.Length); int abilityRng = rng.Next(0, abilityIndex.Length); var set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})"); while (!validEgg.ToList().Contains(set.Species)) { set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})"); } var template = AutoLegalityWrapper.GetTemplate(set); var sav = AutoLegalityWrapper.GetTrainerInfo(8); var pkm = (PK8)sav.GetLegal(template, out _); if (regional.ToList().Contains(pkm.Species)) { int formRng = rng.Next(0, formIndex1.Length); int formRng2 = rng.Next(0, formIndex2.Length); if (pkm.Species != 52) { pkm.SetAltForm(formIndex1[formRng]); } else { pkm.SetAltForm(formIndex2[formRng2]); } if (pkm.AltForm != 0) { if (pkm.Species == 27) { pkm.RelearnMove3 = 10; } else if (pkm.Species == 37) { pkm.RelearnMove4 = 39; } else if (pkm.Species == 52) { pkm.RelearnMove2 = 252; pkm.RelearnMove3 = 45; } else if (pkm.Species == 83) { pkm.RelearnMove1 = 64; pkm.RelearnMove4 = 28; } else if (pkm.Species == 222) { pkm.RelearnMove1 = 33; } else if (pkm.Species == 263) { pkm.RelearnMove2 = 43; pkm.RelearnMove3 = 0; pkm.RelearnMove4 = 0; } } } EggTrade(pkm); pkm.Nature = rng.Next(0, 24); pkm.StatNature = pkm.Nature; pkm.SetAbilityIndex(abilityIndex[abilityRng]); pkm.IVs = pkm.SetRandomIVs(3); BallApplicator.ApplyBallLegalRandom(pkm); if (shinyOdds[shinyRng] == 3) { CommonEdits.SetShiny(pkm, Shiny.Never); pkm.SetUnshiny(); } else if (shinyOdds[shinyRng] == 5) { CommonEdits.SetShiny(pkm, Shiny.AlwaysStar); } else { CommonEdits.SetShiny(pkm, Shiny.AlwaysSquare); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality); if (invalid) { var imsg = $"Oops! I scrambled your egg! Don't tell Ramsay! Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } pkm.ResetPartyStats(); var sudo = Context.User.GetIsSudo(); await AddTradeToQueueAsync(code, Context.User.Username, pkm, sudo).ConfigureAwait(false); }
/// <summary> /// Creates <see cref="PKM"/> from the showdownsets and checks compatibility with the savefile. /// </summary> /// <remarks>REMEMBER: Many moves was removed in the 8th gen, so some showdownsets will eventually be incompatible with your savefile.</remarks> public void CreatePkM() { if (SAV == null) { Console.WriteLine("No savefile loaded yet."); return; } if (showdownSets.Count == 0) { Console.WriteLine("No showdown set loaded."); return; } foreach (ShowdownSet set in showdownSets) { PKM pkm = SAV.BlankPKM; string speciesname = SpeciesName.GetSpeciesName(set.Species, 2); Console.WriteLine("Creating " + speciesname); if (Breeding.CanHatchAsEgg(set.Species)) { EncounterEgg egg = new EncounterEgg(set.Species, set.Form, set.Level, SAV.Generation, game); pkm = egg.ConvertToPKM(SAV); } else { pkm.Species = set.Species; pkm.Form = set.Form; pkm.SetGender(pkm.GetSaneGender()); IEncounterable[] encs = EncounterMovesetGenerator.GenerateEncounter(pkm, SAV.Generation).ToArray(); if (encs.Length == 0) { // use debut generation for Pokemon that available but not catchable in current generation e.g. Meltan encs = EncounterMovesetGenerator.GenerateEncounter(pkm, pkm.DebutGeneration).ToArray(); } foreach (IEncounterable enc in encs) { PKM pk = enc.ConvertToPKM(SAV); // not all Pokemon in database are legal in all games if (new LegalityAnalysis(pk, SAV.Personal).Valid) { pkm = PKMConverter.ConvertToType(pk, SAV.PKMType, out _); if ((pk.Generation != SAV.Generation || pk.GO || pk.GO_HOME || pk.LGPE) && pkm is IBattleVersion b) { b.BattleVersion = (int)game; } break; } } } pkm.Language = SAV.Language; pkm.ApplySetDetails(set); LegalityAnalysis la = new LegalityAnalysis(pkm, SAV.Personal); string report = la.Report(); if (report == "Legal!") { ENTITIES.Add(pkm); IsValid.Add(true); } else { // setting blank pkm if invalid for better indexing ENTITIES.Add(SAV.BlankPKM); IsValid.Add(false); Console.WriteLine("Warning: " + speciesname + " is invalid!"); Console.WriteLine(report); Console.WriteLine("Ignoring " + speciesname); } } }