public void SetFormString(int index) { FormIndex = index; if (index <= 0) { Form = string.Empty; return; } var Forms = PKX.GetFormList(Species, Strings.Types, Strings.forms, genderForms, Format); Form = FormIndex >= Forms.Length ? string.Empty : Forms[index]; }
private void LoadLines(IEnumerable <string> lines) { lines = lines.Select(z => z.Replace("'", "’").Replace("–", "-").Trim()); // Sanitize apostrophes & dashes lines = lines.Where(z => z.Length > 2); ParseLines(lines); // Showdown Quirks Form = ConvertFormFromShowdown(Form, Species, Ability); // Set Form string[] formStrings = PKX.GetFormList(Species, Strings.Types, Strings.forms, genderForms); FormIndex = string.IsNullOrWhiteSpace(Form) ? 0 : Math.Max(0, Array.FindIndex(formStrings, z => z.Contains(Form))); }
public void ApplyToPKM(PKM pkm) { if (Species < 0) { return; } pkm.Species = Species; if (Nickname != null && Nickname.Length <= pkm.NickLength) { pkm.Nickname = Nickname; } else { pkm.Nickname = PKX.GetSpeciesName(pkm.Species, pkm.Language); } int gender = PKX.GetGenderFromString(Gender); pkm.Gender = Math.Max(0, gender); var list = PKX.GetFormList(pkm.Species, types, forms, genders); int formnum = Array.IndexOf(list, Form); pkm.AltForm = Math.Max(0, formnum); var abils = pkm.PersonalInfo.Abilities; int index = Array.IndexOf(abils, Ability); pkm.RefreshAbility(Math.Max(0, Math.Min(2, index))); if (Shiny && !pkm.IsShiny) { pkm.SetShinyPID(); } else if (!Shiny && pkm.IsShiny) { pkm.PID = Util.Rand32(); } pkm.CurrentLevel = Level; pkm.HeldItem = Math.Max(0, HeldItem); pkm.CurrentFriendship = Friendship; pkm.Nature = Nature; pkm.EVs = EVs; pkm.IVs = IVs; pkm.Moves = Moves; }
private void LoadLines(IEnumerable <string> lines) { lines = lines.Select(z => z.Replace('\'', '’').Replace('–', '-').Trim()); // Sanitize apostrophes & dashes lines = lines.Where(z => z.Length > 2); ParseLines(lines); // Showdown Quirks Form = ConvertFormFromShowdown(Form, Species, Ability); // Set Form if (Form.Length == 0) { FormIndex = 0; return; } string[] formStrings = PKX.GetFormList(Species, Strings.Types, Strings.forms, genderForms); FormIndex = Math.Max(0, Array.FindIndex(formStrings, z => z.Contains(Form))); }
public static string GetShowdownText(PKM pkm) { if (pkm.Species == 0) { return(""); } string[] Forms = PKX.GetFormList(pkm.Species, types, forms, new[] { "", "F", "" }, pkm.Format); ShowdownSet Set = new ShowdownSet { Nickname = pkm.Nickname, Species = pkm.Species, HeldItem = pkm.HeldItem, Ability = pkm.Ability, EVs = pkm.EVs, IVs = pkm.IVs, Moves = pkm.Moves, Nature = pkm.Nature, Gender = new[] { "M", "F", "" }[pkm.Gender < 2 ? pkm.Gender: 2], Friendship = pkm.CurrentFriendship, Level = PKX.GetLevel(pkm.Species, pkm.EXP), Shiny = pkm.IsShiny, Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "", }; if (Set.Form == "F") { Set.Gender = ""; } else if (Set.Species == 676) { Set.Form = ""; // Furfrou } else if (Set.Species == 666 && Set.Form == "Poké Ball") { Set.Form = "Pokeball"; // Vivillon } return(Set.Text); }
// Parsing Utility public ShowdownSet(string input = null) { if (input == null) { return; } string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Replace("'", "’").Trim(); // Sanitize apostrophes } lines = lines.Where(line => line.Length > 2).ToArray(); if (lines.Length < 3) { return; } // Seek for start of set int start = Array.FindIndex(lines, line => line.Contains(" @ ")); if (start != -1) // Has Item -- skip to start. { lines = lines.Skip(start).Take(lines.Length - start).ToArray(); } else // Has no Item -- try parsing the first line anyway. { ParseFirstLine(lines[0]); if (Species < -1) { return; // Abort if no text is found } lines = lines.Skip(1).Take(lines.Length - 1).ToArray(); } int movectr = 0; // Detect relevant data foreach (string line in lines) { if (line.StartsWith("-")) { string moveString = ParseLineMove(line); int move = Array.IndexOf(moves, moveString); if (move < 0) { InvalidLines.Add($"Unknown Move: {moveString}"); } else { Moves[movectr++] = move; } if (movectr == 4) { break; // End of moves } continue; } string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); if (brokenline.Length == 1) { brokenline = new[] { brokenline[0], string.Empty } } ; switch (brokenline[0]) { case "Trait": case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1].Trim()); break; } case "Level": { if (int.TryParse(brokenline[1].Trim(), out int val)) { Level = val; } else { InvalidLines.Add(line); } break; } case "Shiny": { Shiny = brokenline[1].Trim() == "Yes"; break; } case "Happiness": { if (int.TryParse(brokenline[1].Trim(), out int val)) { Friendship = val; } else { InvalidLines.Add(line); } break; } case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; } case "Language": { Language = Array.IndexOf(languages, brokenline[1].Trim()); break; } case "EV": case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; } case "IV": case "IVs": { ParseLineIVs(brokenline[1].Trim()); break; } case "Type": { brokenline = new[] { line }; goto default; } // Type: Null edge case default: { // Either Nature or Gender ItemSpecies if (brokenline[0].Contains(" @ ")) { string[] pieces = line.Split(new[] { " @ " }, StringSplitOptions.None); string itemstr = pieces.Last().Trim(); int item = Array.IndexOf(items, itemstr); if (item < 0) { InvalidLines.Add($"Unknown Item: {itemstr}"); } else { HeldItem = item; } ParseFirstLine(pieces[0]); } else if (brokenline[0].Contains("Nature")) { string naturestr = line.Split(' ')[0].Trim(); int nature = Array.IndexOf(natures, naturestr); if (nature < 0) { InvalidLines.Add($"Unknown Nature: {naturestr}"); } else { Nature = nature; } } else // Fallback { string speciesstr = line.Split('(')[0].Trim(); int spec = Array.IndexOf(species, speciesstr); if (spec < 1) { InvalidLines.Add(speciesstr); } else { Species = spec; } } break; } } } IVs = IVsSpeedFirst; EVs = EVsSpeedFirst; // Showdown Quirks Form = ConvertFormFromShowdown(Form, Species, Ability); // Set Form string[] formStrings = PKX.GetFormList(Species, types, forms, genderForms); FormIndex = Math.Max(0, Array.FindIndex(formStrings, z => z.Contains(Form ?? ""))); }