Example #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;

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

                double distance = Utility.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);
        }
Example #2
0
        public bool GetElementByCliloc(int cliloc, out GumpElement gumpElement)
        {
            gumpElement = null;

            if (GumpElements == null)
            {
                return(false);
            }

            GumpElement element = GumpElements.FirstOrDefault(m => m.Cliloc == cliloc);

            if (element != null)
            {
                gumpElement = element;
            }

            return(gumpElement != null);
        }
Example #3
0
        public bool GetElementByXY(int x, int y, out GumpElement gumpElement)
        {
            gumpElement = null;

            if (GumpElements == null)
            {
                return(false);
            }

            GumpElement element = GumpElements.FirstOrDefault(m => m.X == x && m.Y == y);

            if (element != null)
            {
                gumpElement = element;
            }

            return(gumpElement != null);
        }
Example #4
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 = Utility.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);
        }