/// <summary> /// Search spells and save to [Results] /// </summary> public void Search() { AutoSearch.Enabled = false; var filter = GetFilter(); Results = Cache.Search(filter); int cls = SpellParser.ParseClass(SearchClass.Text) - 1; // optionally add back refs if (filter.AddBackRefs) { Cache.AddBackRefs(Results); } else { Results.RemoveAll(x => x.Levels[cls] == 0); //removes references to spells with level 0 which are effects of other spells. } // remove excluded ranks (this should be done after back refs are added) if (filter.Ranks == "Unranked") { Results.RemoveAll(x => x.Rank != 0); } if (filter.Ranks == "Rank 1") { Results.RemoveAll(x => x.Rank != 1); } if (filter.Ranks == "Rank 2") { Results.RemoveAll(x => x.Rank != 2); } if (filter.Ranks == "Rank 3") { Results.RemoveAll(x => x.Rank != 3); } if (filter.Ranks == "Unranked + Rank 1") { Results.RemoveAll(x => x.Rank != 0 && x.Rank != 1); } if (filter.Ranks == "Unranked + Rank 2") { Results.RemoveAll(x => x.Rank != 0 && x.Rank != 2); } if (filter.Ranks == "Unranked + Rank 3") { Results.RemoveAll(x => x.Rank != 0 && x.Rank != 3); } // hide anything that isn't in the results yet. additional spells will only be shown when a link is clicked VisibleResults = new HashSet <int>(Results.Select(x => x.ID)); // if we are filtering by class then auto hide all spells that aren't castable by that class //int i = SpellParser.ParseClass(filter.Class) - 1; //VisibleResults = new HashSet<int>(i >= 0 ? Results.Where(x => x.Levels[i] != 0).Select(x => x.ID) : Results.Select(x => x.ID)); // always add forward refs so that links can be clicked Cache.AddForwardRefs(Results); Cache.Sort(Results, filter); }
private void SearchClass_TextChanged(object sender, EventArgs e) { // cancel if spells haven't been loaded yet if (Cache == null) { return; } // only show level filter when a class is selected int cls = SpellParser.ParseClass(SearchClass.Text) - 1; SearchLevel.Enabled = (cls >= 0); SearchText_TextChanged(sender, e); }
/// <summary> /// Search the spell list for matching spells. /// </summary> static List <Spell> Search(string field, string value) { IEnumerable <Spell> results = null; var q = cache.SpellList; if (field == "all") { results = q; } //results = list.Where(x => (int)x.TargetRestrict > 0).OrderBy(x => x.TargetRestrict); // search by effect type if (field == "type" || field == "spa") { results = q.Where(x => x.HasEffect(value, 0)); } // search by id if (field == "id") { results = q.Where(x => x.ID.ToString() == value); } // search by group if (field == "group") { results = q.Where(x => x.GroupID.ToString() == value); } // search by name if (field == "name") { results = q.Where(x => x.Name.IndexOf(value, StringComparison.InvariantCultureIgnoreCase) >= 0).OrderBy(x => x.Name); } // search by class if (field == "class") { int i = SpellParser.ParseClass(value) - 1; if (i < 0) { throw new Exception("Unknown class: " + value); } results = q.Where(x => x.ExtLevels[i] > 0 && x.ExtLevels[i] < 255).OrderBy(x => x.Levels[i]).ThenBy(x => x.ID); } // search by target if (field == "target") { results = q.Where(x => x.Target.ToString().Equals(value, StringComparison.InvariantCultureIgnoreCase)); } // debugging: search the unknown field if (field == "unknown") { results = q.Where(x => x.Unknown > 0).OrderBy(x => x.Unknown); } return(results.ToList()); }