private bool IsCatchRateValid(PK1 pk1) { var catch_rate = pk1.Catch_Rate; if (Species == (int)Core.Species.Pikachu) { if (catch_rate == 190) // Red Blue Pikachu is not a static encounter { return(false); } if (catch_rate == 163 && Level == 5) // Light Ball (Yellow) starter { return(true); } } if (Version == GameVersion.Stadium) { // Amnesia Psyduck has different catch rates depending on language if (Species == (int)Core.Species.Psyduck) { return(catch_rate == (pk1.Japanese ? 167 : 168)); } return(catch_rate == 167 || catch_rate == 168); } // Encounters can have different Catch Rates (RBG vs Y) var table = Version == GameVersion.Y ? PersonalTable.Y : PersonalTable.RB; var rate = table[Species].CatchRate; return(catch_rate == rate); }
private static int GetSuggestedPKMCatchRate(PK1 pk1) { var la = new LegalityAnalysis(pk1); if (la.Valid) { return(pk1.Catch_Rate); } if (la.Info.Generation == 2) { return(0); } var enc = la.EncounterOriginal; switch (enc) { case EncounterTradeCatchRate c: return((int)c.Catch_Rate); case EncounterStatic s when s.Version == GameVersion.Stadium && s.Species == 054: return(pk1.Japanese ? 167 : 168); // Amnesia Psyduck has different catch rates depending on language case IVersion v when v.Version.Contains(GameVersion.YW): return(PersonalTable.Y[enc.Species].CatchRate); default: return(PersonalTable.RB[enc.Species].CatchRate); } }
public override PKM Clone() { var clone = new PK1((byte[])Data.Clone(), Japanese); OT_Trash.CopyTo(clone.OT_Trash); Nickname_Trash.CopyTo(clone.Nickname_Trash); return(clone); }
protected override PKM GetPKM(byte[] data) { int len = StringLength; var nick = data.AsSpan(PokeCrypto.SIZE_1STORED, len); var ot = data.AsSpan(PokeCrypto.SIZE_1STORED + len, len); data = data.Slice(0, PokeCrypto.SIZE_1STORED); var pk1 = new PK1(data, Japanese); nick.CopyTo(pk1.RawNickname); ot.CopyTo(pk1.RawOT); return(pk1); }
protected override PKM GetPKM(byte[] data) { const int len = StringLength; var nick = data.AsSpan(0x21, len); var ot = data.AsSpan(0x21 + len, len); data = data.Slice(0, 0x21); var pk1 = new PK1(data, true); nick.CopyTo(pk1.RawNickname); ot.CopyTo(pk1.RawOT); return(pk1); }
private static string GetGBPKM(GBPKM gb) { string form = gb.Form > 0 ? $"-{gb.Form:00}" : string.Empty; string star = gb.IsShiny ? " ★" : string.Empty; var raw = gb switch { PK1 pk1 => new PokeList1(pk1).Write(), PK2 pk2 => new PokeList2(pk2).Write(), _ => gb.Data, }; var checksum = Checksums.CRC16_CCITT(raw); return($"{gb.Species:000}{form}{star} - {gb.Nickname} - {checksum:X4}"); }
public override SlotGroup GetTeam(int team) { if ((uint)team >= TeamCount) { throw new ArgumentOutOfRangeException(nameof(team)); } var name = GetTeamName(team); var members = new PK1[6]; var ofs = GetTeamOffset(team); for (int i = 0; i < 6; i++) { var rel = ofs + ListHeaderSize + (i * SIZE_STORED); members[i] = (PK1)GetStoredSlot(Data, rel); } return(new SlotGroup(name, members)); }
public static int GetSuggestedCatchRate(PK1 pk1, SaveFile sav, LegalityAnalysis la) { if (la.Valid) { return(pk1.Catch_Rate); } if (la.Info.Generation == 2) { return(0); } var v = la.EncounterMatch; switch (v) { case EncounterTrade1 c: return(c.GetInitialCatchRate()); case EncounterStatic1E { Version: GameVersion.Stadium, Species : (int)Species.Psyduck } : return(pk1.Japanese ? 167 : 168); // Amnesia Psyduck has different catch rates depending on language
public static int GetSuggestedCatchRate(PK1 pk1, SaveFile sav, LegalityAnalysis la) { if (la.Valid) { return(pk1.Catch_Rate); } if (la.Info.Generation == 2) { return(0); } var v = la.EncounterOriginal; switch (v) { case EncounterTrade1 c: return(c.GetInitialCatchRate()); case EncounterStatic s when s.Version == GameVersion.Stadium && s.Species == (int)Species.Psyduck: return(pk1.Japanese ? 167 : 168); // Amnesia Psyduck has different catch rates depending on language default: { if (sav.Version.Contains(v.Version) || v.Version.Contains(sav.Version)) { return(sav.Personal[v.Species].CatchRate); } if (!GameVersion.RB.Contains(v.Version)) { return(PersonalTable.Y[v.Species].CatchRate); } return(PersonalTable.RB[v.Species].CatchRate); } } }
public void LoadPK1(PK1 pk) => NUD_CatchRate.Value = (pk1 = pk).Catch_Rate;
public static int GetSuggestedCatchRate(PK1 pk1, SaveFile sav) { var la = new LegalityAnalysis(pk1); return(GetSuggestedCatchRate(pk1, sav, la)); }
private PKM preparePK1() { PK1 pk1 = pkm as PK1; if (pk1 == null) { return(null); } pk1.Species = WinFormsUtil.getIndex(CB_Species); pk1.TID = Util.ToInt32(TB_TID.Text); pk1.EXP = Util.ToUInt32(TB_EXP.Text); pk1.EV_HP = Util.ToInt32(TB_HPEV.Text); pk1.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk1.EV_DEF = Util.ToInt32(TB_DEFEV.Text); pk1.EV_SPE = Util.ToInt32(TB_SPEEV.Text); pk1.EV_SPC = Util.ToInt32(TB_SPAEV.Text); if (CHK_Nicknamed.Checked) { pk1.Nickname = TB_Nickname.Text; } else { pk1.setNotNicknamed(); } pk1.Move1 = WinFormsUtil.getIndex(CB_Move1); pk1.Move2 = WinFormsUtil.getIndex(CB_Move2); pk1.Move3 = WinFormsUtil.getIndex(CB_Move3); pk1.Move4 = WinFormsUtil.getIndex(CB_Move4); pk1.Move1_PP = WinFormsUtil.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; pk1.Move2_PP = WinFormsUtil.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; pk1.Move3_PP = WinFormsUtil.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; pk1.Move4_PP = WinFormsUtil.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; pk1.Move1_PPUps = WinFormsUtil.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; pk1.Move2_PPUps = WinFormsUtil.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; pk1.Move3_PPUps = WinFormsUtil.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; pk1.Move4_PPUps = WinFormsUtil.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; pk1.IV_HP = Util.ToInt32(TB_HPIV.Text); pk1.IV_ATK = Util.ToInt32(TB_ATKIV.Text); pk1.IV_DEF = Util.ToInt32(TB_DEFIV.Text); pk1.IV_SPE = Util.ToInt32(TB_SPEIV.Text); pk1.IV_SPA = Util.ToInt32(TB_SPAIV.Text); pk1.OT_Name = TB_OT.Text; // Toss in Party Stats Array.Resize(ref pk1.Data, pk1.SIZE_PARTY); pk1.Stat_Level = Util.ToInt32(TB_Level.Text); pk1.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); pk1.Stat_HPMax = Util.ToInt32(Stat_HP.Text); pk1.Stat_ATK = Util.ToInt32(Stat_ATK.Text); pk1.Stat_DEF = Util.ToInt32(Stat_DEF.Text); pk1.Stat_SPE = Util.ToInt32(Stat_SPE.Text); pk1.Stat_SPA = Util.ToInt32(Stat_SPA.Text); pk1.Stat_SPD = Util.ToInt32(Stat_SPD.Text); if (HaX) { pk1.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); } // Fix Moves if a slot is empty pk1.FixMoves(); pk1.RefreshChecksum(); return(pk1); }
private void populateFieldsPK1() { PK1 pk1 = pkm as PK1; if (pk1 == null) { return; } // Do first pk1.Stat_Level = PKX.getLevel(pk1.Species, pk1.EXP); if (pk1.Stat_Level == 100 && !HaX) { pk1.EXP = PKX.getEXP(pk1.Stat_Level, pk1.Species); } CB_Species.SelectedValue = pk1.Species; TB_Level.Text = pk1.Stat_Level.ToString(); TB_EXP.Text = pk1.EXP.ToString(); // Load rest TB_TID.Text = pk1.TID.ToString("00000"); CHK_Nicknamed.Checked = pk1.IsNicknamed; TB_Nickname.Text = pk1.Nickname; TB_OT.Text = pk1.OT_Name; GB_OT.BackgroundImage = null; // Reset Label and ComboBox visibility, as well as non-data checked status. Label_PKRS.Visible = false; Label_PKRSdays.Visible = false; TB_HPIV.Text = pk1.IV_HP.ToString(); TB_ATKIV.Text = pk1.IV_ATK.ToString(); TB_DEFIV.Text = pk1.IV_DEF.ToString(); TB_SPEIV.Text = pk1.IV_SPE.ToString(); TB_SPAIV.Text = pk1.IV_SPA.ToString(); TB_HPEV.Text = pk1.EV_HP.ToString(); TB_ATKEV.Text = pk1.EV_ATK.ToString(); TB_DEFEV.Text = pk1.EV_DEF.ToString(); TB_SPEEV.Text = pk1.EV_SPE.ToString(); TB_SPAEV.Text = pk1.EV_SPA.ToString(); CB_Move1.SelectedValue = pk1.Move1; CB_Move2.SelectedValue = pk1.Move2; CB_Move3.SelectedValue = pk1.Move3; CB_Move4.SelectedValue = pk1.Move4; CB_PPu1.SelectedIndex = pk1.Move1_PPUps; CB_PPu2.SelectedIndex = pk1.Move2_PPUps; CB_PPu3.SelectedIndex = pk1.Move3_PPUps; CB_PPu4.SelectedIndex = pk1.Move4_PPUps; TB_PP1.Text = pk1.Move1_PP.ToString(); TB_PP2.Text = pk1.Move2_PP.ToString(); TB_PP3.Text = pk1.Move3_PP.ToString(); TB_PP4.Text = pk1.Move4_PP.ToString(); CB_Language.SelectedIndex = pk1.Japanese ? 0 : 1; updateStats(); TB_EXP.Text = pk1.EXP.ToString(); }
public void AddToBoxesButtonClick(Object sender, EventArgs events) { var sav = SaveFileEditor.SAV; // current save int generation = sav.Generation; // the generation of the current save -- used to determine the PK save format List <PKM> pokemonList = new List <PKM>(); // list of all Pokemon that will be added to the sav string showdownData = this.input.Text; // user's input var pokemonArray = JsonConvert.DeserializeObject <List <RawPokemon> >(showdownData); //jsonify the data foreach (RawPokemon rawPokemon in pokemonArray) { PKM pokemon = new PK2(); //Determine save format switch (generation) { case 1: pokemon = new PK1(); break; case 2: pokemon = new PK2(); break; case 3: pokemon = new PK3(); break; case 4: pokemon = new PK4(); break; case 5: pokemon = new PK5(); break; case 6: pokemon = new PK6(); break; case 7: pokemon = new PK7(); break; case 8: pokemon = new PK8(); break; } // Set the species according to the Species enum int speciesAsNumber = 0; //Check if the Pokemon is Alolan or not; if it is, do some extra logic to set the proper form if (rawPokemon.Species.Contains("Alolan")) { string[] pokemon_name = rawPokemon.Species.Split('_'); speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), pokemon_name[1]); pokemon.SetForm(810); pokemon.Species = speciesAsNumber; } else { speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), rawPokemon.Species); pokemon.Species = speciesAsNumber; } // Check to see if the Pokemon has forms (i.e. Flabebe, Shellos, etc.), and if it does, randomly generate one if (rawPokemon.Species.Contains("Burmy")) { int form = random.Next(0, burmyForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Shellos")) { int form = random.Next(0, shellosForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Scatterbug")) { int form = random.Next(0, scatterbugForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Flabébé")) { int form = random.Next(0, flabebeForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Oricorio")) { int form = random.Next(0, oricorioForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Minior")) { int form = random.Next(0, miniorForms.Length - 1); pokemon.SetForm(form); } GameVersion game = (GameVersion)sav.Game; EncounterEgg encounterEgg = new EncounterEgg(speciesAsNumber, pokemon.Form, 1, sav.Generation, game); PKM pokemonAsEgg = encounterEgg.ConvertToPKM(sav); pokemonAsEgg.IsEgg = true; pokemon.IsNicknamed = true; pokemon.Nickname = "Egg"; // Set the ability string ability = rawPokemon.Ability.Replace(" ", ""); int abilityAsNumber = (int)(Ability)Enum.Parse(typeof(Ability), ability); pokemonAsEgg.SetAbility(abilityAsNumber); //Set gender switch (rawPokemon.Gender) { case "M": pokemonAsEgg.SetGender(0); break; case "F": pokemonAsEgg.SetGender(1); break; case "N": pokemonAsEgg.SetGender(2); break; } // Set Nature via the Nature enum int natureAsNumber = (int)(Nature)Enum.Parse(typeof(Nature), rawPokemon.Nature); pokemonAsEgg.Nature = natureAsNumber; // Set the IVs pokemonAsEgg.IV_HP = rawPokemon.HP; pokemonAsEgg.IV_ATK = rawPokemon.Atk; pokemonAsEgg.IV_DEF = rawPokemon.Def; pokemonAsEgg.IV_SPA = rawPokemon.SpA; pokemonAsEgg.IV_SPD = rawPokemon.SpD; pokemonAsEgg.IV_SPE = rawPokemon.Spe; // Set moves and make sure they have the proper PP string move = ""; if (string.IsNullOrEmpty(rawPokemon.MoveOne) == false) { move = rawPokemon.MoveOne.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move1 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove1 = pokemonAsEgg.Move1; } if (string.IsNullOrEmpty(rawPokemon.MoveTwo) == false) { move = rawPokemon.MoveTwo.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move2 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove2 = pokemonAsEgg.Move2; } if (string.IsNullOrEmpty(rawPokemon.MoveThree) == false) { move = rawPokemon.MoveThree.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move3 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove3 = pokemonAsEgg.Move3; } if (string.IsNullOrEmpty(rawPokemon.MoveFour) == false) { move = rawPokemon.MoveFour.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move4 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove4 = pokemonAsEgg.Move4; } pokemonAsEgg.SetMaximumPPCurrent(); //Finally, if the Pokemon is supposed to be shiny, make it so if (rawPokemon.IsShiny == "true") { CommonEdits.SetShiny(pokemonAsEgg); } else { CommonEdits.SetUnshiny(pokemonAsEgg); } pokemonAsEgg.Met_Location = 0; if (generation == 7 || generation == 6 || generation == 5) { pokemonAsEgg.Egg_Location = Locations.Daycare5; } else { pokemonAsEgg.Egg_Location = Locations.Daycare4; } pokemonAsEgg.IsNicknamed = true; pokemonAsEgg.Nickname = SpeciesName.GetSpeciesNameGeneration(0, sav.Language, generation); //Hatch counter is for some reason called "CurrentFriendship". Don't ask me why, I don't know. pokemonAsEgg.CurrentFriendship = 1; pokemonList.Add(pokemonAsEgg); } // Import Pokemon, reload the boxes so they can be seen, show a message and close the window sav.ImportPKMs(pokemonList); SaveFileEditor.ReloadSlots(); MessageBox.Show("Done!"); this.input.Clear(); this.form.Close(); }