Esempio n. 1
0
        /// <summary>
        /// Get nearest GumpElement from source.
        /// </summary>
        /// <returns>True on success.</returns>
        public bool GetNearestElement(GumpElement source, out GumpElement element)
        {
            GumpElement nearest = null;
            double      closest = 0, distance;

            foreach (GumpElement ge in myGumpElements)
            {
                if (ge == source)
                {
                    continue;
                }
                distance = UOMath.Distance(source.X, source.Y, ge.X, ge.Y);
                if (nearest == null)
                {
                    closest = distance;
                    nearest = ge;
                }
                else
                {
                    if (distance < closest)
                    {
                        closest = distance;
                        nearest = ge;
                    }
                }
            }
            element = nearest;
            return(nearest != null);
        }
Esempio n. 2
0
        public void RemoveByDistance(int maxDistance, int x, int y)
        {
            bool changed = false;

            Mobile[] mobileArray = this.GetMobiles();
            for (int i = 0; i < mobileArray.Length; i++)
            {
                double d = UOMath.Distance(x, y, mobileArray[i].X, mobileArray[i].Y);
                if (d > maxDistance)
                {
                    myMobileList.Remove(mobileArray[i].Serial);
                    myLinkedItemCollection.RemoveByOwner(mobileArray[i].Serial);

                    /*foreach (int serial in mobileArray[i].GetAllLayers())
                     * {
                     *  if (serial != 0) myLinkedItemCollection.Remove(serial);
                     * }*/
                    changed = true;
                }
            }
            if (changed)
            {
                this.OnCollectionChanged();
            }
        }
Esempio n. 3
0
        public override void RemoveByDistance(int maxDistance, int x, int y)
        {
            bool changed = false;

            Mobile[] mobiles = SelectEntities(m =>
            {
                double d = UOMath.Distance(x, y, m.X, m.Y);
                return(d > maxDistance);
            });

            if (mobiles == null)
            {
                return;
            }

            foreach (Mobile m in mobiles)
            {
                Remove(m.Serial);
                _linkedItemCollection.RemoveByOwner(m.Serial);
                changed = true;
            }

            if (changed)
            {
                OnCollectionChanged(false, mobiles);
            }
        }
Esempio n. 4
0
 internal void RemoveByDistance(int maxDistance, int x, int y)
 {
     Item[] items = this.GetItems();
     for (int i = 0; i < items.Length; i++)
     {
         if (items[i] != null && items[i].Owner == 0 && UOMath.Distance(x, y, items[i].X, items[i].Y) > maxDistance)
         {
             this.Remove(items[i].Serial);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Get nearest GumpElement to source, but only if it's ElementType is contained in the include list.
        /// </summary>
        /// <param name="source">Source GumpElement</param>
        /// <param name="includeTypes">Array of ElementTypes which specifies valid GumpElements to search.</param>
        /// <param name="element">GumpElement (out).</param>
        /// <returns>True on success.</returns>
        public bool GetNearestElement(GumpElement source, ElementType[] includeTypes, out GumpElement element)
        {
            GumpElement nearest = null;
            double      closest = 0, distance;

            if (source.ParentPage != null)
            {
                return(source.ParentPage.GetNearestElement(source, includeTypes, out element));
            }
            bool found;

            foreach (GumpElement ge in this.GumpElements)
            {
                if (ge == source)
                {
                    continue;
                }
                found = false;
                foreach (ElementType et in includeTypes)
                {
                    if (ge.Type == et)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    continue;
                }
                distance = UOMath.Distance(source.X, source.Y, ge.X, ge.Y);
                if (nearest == null)
                {
                    closest = distance;
                    nearest = ge;
                }
                else
                {
                    if (distance < closest)
                    {
                        closest = distance;
                        nearest = ge;
                    }
                }
            }
            element = nearest;
            return(nearest != null);
        }
        public static void ShowNames(string showType)
        {
            const int MAX_DISTANCE = 32;
            const int corpseType   = 0x2006;

            ShowNamesType enumValue = Utility.GetEnumValueByName <ShowNamesType>(showType);

            switch (enumValue)
            {
            case ShowNamesType.Mobiles:

                Mobile[] mobiles = Engine.Mobiles.SelectEntities(m =>
                                                                 m.Distance < MAX_DISTANCE);

                if (mobiles == null)
                {
                    return;
                }

                foreach (Mobile mobile in mobiles)
                {
                    Engine.SendPacketToServer(new LookRequest(mobile.Serial));
                }

                break;

            case ShowNamesType.Corpses:

                Item[] corpses = Engine.Items.SelectEntities(i =>
                                                             UOMath.Distance(i.X, i.Y, Engine.Player.X, Engine.Player.Y) < MAX_DISTANCE &&
                                                             i.ID == corpseType);

                if (corpses == null)
                {
                    return;
                }

                foreach (Item corpse in corpses)
                {
                    Engine.SendPacketToServer(new LookRequest(corpse.Serial));
                }

                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Get nearest GumpElement to source, but only if it's ElementType is contained in the include list.
        /// </summary>
        /// <param name="source">Source element.</param>
        /// <param name="includeTypes">Array of ElementTypes which specifies valid GumpElements to search.</param>
        /// <param name="element">GumpElement (out).</param>
        /// <returns>True on success.</returns>
        public bool GetNearestElement(GumpElement source, ElementType[] includeTypes, out GumpElement element)
        {
            GumpElement nearest = null;
            double      closest = 0;

            foreach (GumpElement ge in GumpElements)
            {
                if (ge == source)
                {
                    continue;
                }

                bool found = includeTypes.Any(et => ge.Type == et);

                if (!found)
                {
                    continue;
                }

                double distance = UOMath.Distance(source.X, source.Y, ge.X, ge.Y);

                if (nearest == null)
                {
                    closest = distance;
                    nearest = ge;
                }
                else
                {
                    if (!(distance < closest))
                    {
                        continue;
                    }

                    closest = distance;
                    nearest = ge;
                }
            }

            element = nearest;
            return(nearest != null);
        }