private static ModifyResult SetPKMProperty(PKM PKM, PKMInfo info, StringInstruction cmd) { if (cmd.PropertyValue.StartsWith(CONST_BYTES)) { return(SetByteArrayProperty(PKM, cmd) ? ModifyResult.Modified : ModifyResult.Error); } if (cmd.PropertyValue == CONST_SUGGEST) { return(SetSuggestedPKMProperty(PKM, cmd, info) ? ModifyResult.Modified : ModifyResult.Error); } SetProperty(PKM, cmd); return(ModifyResult.Modified); }
private static bool SetSuggestedPKMProperty(PKM PKM, StringInstruction cmd, PKMInfo info) { switch (cmd.PropertyName) { case nameof(PKM.HyperTrainFlags): PKM.HyperTrainFlags = GetSuggestedHyperTrainingStatus(PKM); return(true); case nameof(PKM.RelearnMoves): PKM.RelearnMoves = info.SuggestedRelearn; return(true); case nameof(PKM.Met_Location): var encounter = info.SuggestedEncounter; if (encounter == null) { return(false); } int level = encounter.Level; int location = encounter.Location; int minlvl = Legal.GetLowestLevel(PKM, encounter.LevelMin); PKM.Met_Level = level; PKM.Met_Location = location; PKM.CurrentLevel = Math.Max(minlvl, level); return(true); case nameof(PKM.Moves): var moves = info.SuggestedMoves; Util.Shuffle(moves); Array.Resize(ref moves, 4); PKM.Moves = moves; return(true); default: return(false); } }
private static void setRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { bool IV3 = Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species); int[] IVs = new int[6]; do { for (int i = 0; i < 6; i++) { IVs[i] = (int)(Util.rnd32() & MaxIV); } } while (IV3 && IVs.Where(i => i == MaxIV).Count() < 3); ReflectUtil.SetValue(PKM, cmd.PropertyName, IVs); } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV); } }
private static bool IsPKMFiltered(Type pkm, StringInstruction cmd, PKMInfo info, out ModifyResult result) { result = ModifyResult.Error; if (cmd.PropertyName == PROP_LEGAL) { if (!bool.TryParse(cmd.PropertyValue, out bool legal)) { return(true); } if (legal == info.Legal == cmd.Evaluator) { return(false); } result = ModifyResult.Filtered; return(true); } if (!pkm.HasPropertyAll(cmd.PropertyName) || pkm.IsValueEqual(info.pkm, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator) { result = ModifyResult.Filtered; return(true); } return(false); }
// View Updates private IEnumerable <PKM> SearchDatabase() { // Populate Search Query Result IEnumerable <PKM> res = RawDB; // Filter for Selected Source if (!Menu_SearchBoxes.Checked) { res = res.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal)); } if (!Menu_SearchDatabase.Checked) { res = res.Where(pk => !pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal)); #if LOADALL res = res.Where(pk => !pk.Identifier.StartsWith(EXTERNAL_SAV, StringComparison.Ordinal)); #endif } int format = MAXFORMAT + 1 - CB_Format.SelectedIndex; switch (CB_FormatComparator.SelectedIndex) { case 0: /* Do nothing */ break; case 1: res = res.Where(pk => pk.Format >= format); break; case 2: res = res.Where(pk => pk.Format == format); break; case 3: res = res.Where(pk => pk.Format <= format); break; } if (CB_FormatComparator.SelectedIndex != 0) { if (format <= 2) // 1-2 { res = res.Where(pk => pk.Format <= 2); } if (format >= 3 && format <= 6) // 3-6 { res = res.Where(pk => pk.Format >= 3); } } switch (CB_Generation.SelectedIndex) { case 0: /* Do nothing */ break; case 1: res = res.Where(pk => pk.Gen7); break; case 2: res = res.Where(pk => pk.Gen6); break; case 3: res = res.Where(pk => pk.Gen5); break; case 4: res = res.Where(pk => pk.Gen4); break; case 5: res = res.Where(pk => pk.Gen3); break; } // Primary Searchables int species = WinFormsUtil.GetIndex(CB_Species); int ability = WinFormsUtil.GetIndex(CB_Ability); int nature = WinFormsUtil.GetIndex(CB_Nature); int item = WinFormsUtil.GetIndex(CB_HeldItem); if (species != -1) { res = res.Where(pk => pk.Species == species); } if (ability != -1) { res = res.Where(pk => pk.Ability == ability); } if (nature != -1) { res = res.Where(pk => pk.Nature == nature); } if (item != -1) { res = res.Where(pk => pk.HeldItem == item); } // Secondary Searchables int move1 = WinFormsUtil.GetIndex(CB_Move1); int move2 = WinFormsUtil.GetIndex(CB_Move2); int move3 = WinFormsUtil.GetIndex(CB_Move3); int move4 = WinFormsUtil.GetIndex(CB_Move4); var moves = new[] { move1, move2, move3, move4 }.Where(z => z > 0).ToList(); int count = moves.Count; if (count > 0) { res = res.Where(pk => pk.Moves.Intersect(moves).Count() == count); } int vers = WinFormsUtil.GetIndex(CB_GameOrigin); if (vers != -1) { res = res.Where(pk => pk.Version == vers); } int hptype = WinFormsUtil.GetIndex(CB_HPType); if (hptype != -1) { res = res.Where(pk => pk.HPType == hptype); } if (CHK_Shiny.CheckState == CheckState.Checked) { res = res.Where(pk => pk.IsShiny); } if (CHK_Shiny.CheckState == CheckState.Unchecked) { res = res.Where(pk => !pk.IsShiny); } if (CHK_IsEgg.CheckState == CheckState.Checked) { res = res.Where(pk => pk.IsEgg); } if (CHK_IsEgg.CheckState == CheckState.Unchecked) { res = res.Where(pk => !pk.IsEgg); } if (CHK_IsEgg.CheckState == CheckState.Checked && int.TryParse(MT_ESV.Text, out int esv)) { res = res.Where(pk => pk.PSV == esv); } // Tertiary Searchables res = FilterByLVL(res, CB_Level.SelectedIndex, TB_Level.Text); res = FilterByIVs(res, CB_IV.SelectedIndex); res = FilterByEVs(res, CB_EVTrain.SelectedIndex); slotSelected = -1; // reset the slot last viewed if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked) { res = res.Where(pk => new LegalityAnalysis(pk).Valid); } if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked) { res = res.Where(pk => !new LegalityAnalysis(pk).Valid); } if (RTB_Instructions.Lines.Any(line => line.Length > 0)) { var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray(); BatchEditing.ScreenStrings(filters); res = res.Where(pkm => BatchEditing.IsFiltered(filters, pkm)); // Compare across all filters } if (Menu_SearchClones.Checked) { res = res.GroupBy(Hash).Where(group => group.Count() > 1).SelectMany(z => z); } return(res); }
// View Updates private void B_Search_Click(object sender, EventArgs e) { // Populate Search Query Result IEnumerable <MysteryGift> res = RawDB; int format = MAXFORMAT + 1 - CB_Format.SelectedIndex; switch (CB_FormatComparator.SelectedIndex) { case 0: /* Do nothing */ break; case 1: res = res.Where(mg => mg.Format >= format); break; case 2: res = res.Where(mg => mg.Format == format); break; case 3: res = res.Where(mg => mg.Format <= format); break; } // Primary Searchables int species = WinFormsUtil.GetIndex(CB_Species); int item = WinFormsUtil.GetIndex(CB_HeldItem); if (species != -1) { res = res.Where(pk => pk.Species == species); } if (item != -1) { res = res.Where(pk => pk.HeldItem == item); } // Secondary Searchables int move1 = WinFormsUtil.GetIndex(CB_Move1); int move2 = WinFormsUtil.GetIndex(CB_Move2); int move3 = WinFormsUtil.GetIndex(CB_Move3); int move4 = WinFormsUtil.GetIndex(CB_Move4); if (move1 != -1) { res = res.Where(mg => mg.HasMove(move1)); } if (move2 != -1) { res = res.Where(mg => mg.HasMove(move2)); } if (move3 != -1) { res = res.Where(mg => mg.HasMove(move3)); } if (move4 != -1) { res = res.Where(mg => mg.HasMove(move4)); } if (CHK_Shiny.CheckState == CheckState.Checked) { res = res.Where(pk => pk.IsShiny); } if (CHK_Shiny.CheckState == CheckState.Unchecked) { res = res.Where(pk => !pk.IsShiny); } if (CHK_IsEgg.CheckState == CheckState.Checked) { res = res.Where(pk => pk.IsEgg); } if (CHK_IsEgg.CheckState == CheckState.Unchecked) { res = res.Where(pk => !pk.IsEgg); } slotSelected = -1; // reset the slot last viewed if (RTB_Instructions.Lines.Any(line => line.Length > 0)) { var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray(); BatchEditing.ScreenStrings(filters); res = res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters } var results = res.ToArray(); if (results.Length == 0) { WinFormsUtil.Alert(MsgDBSearchNone); } SetResults(new List <MysteryGift>(results)); // updates Count Label as well. System.Media.SystemSounds.Asterisk.Play(); }
private void runBackgroundWorker() { var Filters = StringInstruction.getFilters(RTB_Instructions.Lines).ToArray(); if (Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))) { WinFormsUtil.Error("Empty Filter Value detected."); return; } var Instructions = StringInstruction.getInstructions(RTB_Instructions.Lines).ToArray(); var emptyVal = Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue)).ToArray(); if (emptyVal.Any()) { string props = string.Join(", ", emptyVal.Select(z => z.PropertyName)); if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props, "Continue?")) { return; } } if (!Instructions.Any()) { WinFormsUtil.Error("No instructions defined."); return; } string destPath = ""; if (RB_Path.Checked) { WinFormsUtil.Alert("Please select the folder where the files will be saved to.", "This can be the same folder as the source of PKM files."); var fbd = new FolderBrowserDialog(); var dr = fbd.ShowDialog(); if (dr != DialogResult.OK) { return; } destPath = fbd.SelectedPath; } FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false; b = new BackgroundWorker { WorkerReportsProgress = true }; screenStrings(Filters); screenStrings(Instructions); b.DoWork += (sender, e) => { len = err = ctr = 0; if (RB_SAV.Checked) { var data = Main.SAV.BoxData; setupProgressBar(data.Length); processSAV(data, Filters, Instructions); Main.SAV.BoxData = data; } else { var files = Directory.GetFiles(TB_Folder.Text, "*", SearchOption.AllDirectories); setupProgressBar(files.Length); processFolder(files, Filters, Instructions, destPath); } }; b.ProgressChanged += (sender, e) => { setProgressBar(e.ProgressPercentage); }; b.RunWorkerCompleted += (sender, e) => { string result = $"Modified {ctr}/{len} files."; if (err > 0) { result += Environment.NewLine + $"{err} files ignored due to an internal error."; } WinFormsUtil.Alert(result); FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true; setupProgressBar(0); }; b.RunWorkerAsync(); }
public bool IsFiltered(object pk, StringInstruction value) => FilterPKM(pk, value);
private static void setRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { bool IV3 = Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species); int[] IVs = new int[6]; do { for (int i = 0; i < 6; i++) IVs[i] = (int)(Util.rnd32() & MaxIV); } while (IV3 && IVs.Where(i => i == MaxIV).Count() < 3); ReflectUtil.SetValue(PKM, cmd.PropertyName, IVs); } else ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV); }
public bool IsFiltered(BatchInfo info, StringInstruction value) => FilterBulk(info, value);