示例#1
0
        public static List <Mobile> ApplyFilter(Filter filter)
        {
            List <Mobile>           result           = new List <Mobile>();
            List <Assistant.Mobile> assistantMobiles = new List <Assistant.Mobile>(World.Mobiles.Values.ToList());

            if (filter.Enabled)
            {
                if (filter.Serials.Count > 0)
                {
                    assistantMobiles = assistantMobiles.Where((m) => filter.Serials.Contains((int)m.Serial.Value)).ToList();
                }
                else
                {
                    if (filter.Name != String.Empty)
                    {
                        Regex rgx = new Regex(filter.Name, RegexOptions.IgnoreCase);
                        List <Assistant.Mobile> list = assistantMobiles.Where(i => rgx.IsMatch(i.Name)).ToList();
                        assistantMobiles = list;
                    }

                    if (filter.Bodies.Count > 0)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => filter.Bodies.Contains(m.Body)).ToList();
                    }

                    if (filter.Hues.Count > 0)
                    {
                        assistantMobiles = assistantMobiles.Where((i) => filter.Hues.Contains(i.Hue)).ToList();
                    }

                    if (filter.RangeMin != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) =>
                                                                  Utility.Distance(World.Player.Position.X, World.Player.Position.Y, m.Position.X, m.Position.Y) >= filter.RangeMin
                                                                  ).ToList();
                    }

                    if (filter.RangeMax != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) =>
                                                                  Utility.Distance(World.Player.Position.X, World.Player.Position.Y, m.Position.X, m.Position.Y) <= filter.RangeMax
                                                                  ).ToList();
                    }

                    if (filter.Warmode != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.Warmode == Convert.ToBoolean(filter.Warmode)).ToList();
                    }

                    if (filter.Poisoned != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.Poisoned == Convert.ToBoolean(filter.Poisoned)).ToList();
                    }

                    if (filter.Blessed != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.Blessed == Convert.ToBoolean(filter.Blessed)).ToList();
                    }

                    if (filter.IsHuman != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.IsHuman == Convert.ToBoolean(filter.IsHuman)).ToList();
                    }

                    if (filter.IsGhost != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.IsGhost == Convert.ToBoolean(filter.IsGhost)).ToList();
                    }

                    if (filter.Female != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.Female == Convert.ToBoolean(filter.Female)).ToList();
                    }

                    if (filter.Friend != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => RazorEnhanced.Friend.IsFriend(m.Serial) == Convert.ToBoolean(filter.Friend)).ToList();
                    }

                    if (filter.Paralized != -1)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => m.Paralized == Convert.ToBoolean(filter.Paralized)).ToList();
                    }

                    if (filter.Notorieties.Count > 0)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => filter.Notorieties.Contains(m.Notoriety)).ToList();
                    }

                    if (filter.CheckIgnoreObject)
                    {
                        assistantMobiles = assistantMobiles.Where((m) => Misc.CheckIgnoreObject(m.Serial) != true).ToList();
                    }

                    // Esclude Self dalla ricerca
                    assistantMobiles = assistantMobiles.Where((m) => m.Serial != World.Player.Serial).ToList();
                }
                // check line of site last because its expensive
                if (filter.CheckLineOfSite)
                {
                    assistantMobiles = CheckLineOfSite(assistantMobiles);
                }
            }

            foreach (Assistant.Mobile assistantMobile in assistantMobiles)
            {
                RazorEnhanced.Mobile enhancedMobile = new RazorEnhanced.Mobile(assistantMobile);
                result.Add(enhancedMobile);
            }

            return(result);
        }