Ejemplo n.º 1
0
        public static Point3D GetWorldTop(this IPoint3D p, Map map)
        {
            if (map == null || map == Map.Internal)
            {
                return(p.ToPoint3D());
            }

            Point3D point;

            if (p is Item)
            {
                point = p.Clone3D(0, 0, ((Item)p).ItemData.Height);
            }
            else if (p is Mobile)
            {
                point = p.Clone3D(0, 0, 20);
            }
            else if (p is Entity)
            {
                point = p.Clone3D(0, 0, 5);
            }
            else
            {
                point = p.ToPoint3D();
            }

            int z, a, t;

            GetAverageZ(point, map, out z, out a, out t);

            point.Z = t;

            return(point);
        }
Ejemplo n.º 2
0
        public static Point3D GetRandomPoint3D(
            this IPoint3D start,
            int minRange,
            int maxRange,
            Map map,
            bool checkLOS,
            bool checkSpawn)
        {
            if ((map == null || map == Map.Internal) && start is IEntity)
            {
                map = ((IEntity)start).Map;
            }

            double  a, r;
            int     x, y;
            Point3D s, p;

            var c = 30;

            do
            {
                a = Utility.RandomDouble() * Math.PI * 2;
                r = minRange + (Math.Sqrt(Utility.RandomDouble()) * (maxRange - minRange));

                x = (int)(r * Math.Cos(a));
                y = (int)(r * Math.Sin(a));

                s = start.Clone3D(0, 0, 16);
                p = start.Clone3D(x, y);

                if (map != null)
                {
                    p = p.GetSurfaceTop(map);
                }

                if (map == null || ((!checkLOS || map.LineOfSight(s, p)) && (!checkSpawn || map.CanSpawnMobile(p))))
                {
                    break;
                }
            }while (--c >= 0);

            if (c >= 0)
            {
                return(p);
            }

            if (map != null)
            {
                return(start.GetSurfaceTop(map));
            }

            return(start.ToPoint3D());
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets a collection of all objects of the given Type 'T' that are within 'range' of 'center' on the given 'map'.
        /// </summary>
        public static List <T> GetEntitiesInRange <T>(this IPoint3D center, Map map, int range) where T : IEntity
        {
            if (center == null || map == null || map == Map.Internal)
            {
                return(new List <T>());
            }

            range = Math.Abs(range);

            var ipe  = map.GetObjectsInRange(center.ToPoint3D(), range);
            var list = ipe.OfType <T>().ToList();

            ipe.Free();

            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Gets an ISpawner collection representing all ISpawners that are within 'range' of 'center' on the given 'map'.
        /// </summary>
        public static List <ISpawner> GetSpawnersInRange(this IPoint3D center, Map map, int range)
        {
            if (center == null || map == null || map == Map.Internal)
            {
                return(new List <ISpawner>());
            }

            range = Math.Abs(range);

            var ipe  = map.GetObjectsInRange(center.ToPoint3D(), range);
            var list = ipe.OfType <ISpawner>().ToList();

            ipe.Free();

            return(list);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Gets a collection of all objects of the given Type 'T' that are within 'range' of 'center' on the given 'map'.
        /// </summary>
        public static IEnumerable <T> FindEntitiesInRange <T>(this IPoint3D center, Map map, int range) where T : IEntity
        {
            if (center == null || map == null || map == Map.Internal)
            {
                yield break;
            }

            range = Math.Abs(range);

            var ipe = map.GetObjectsInRange(center.ToPoint3D(), range);

            foreach (var s in ipe.OfType <T>())
            {
                yield return(s);
            }

            ipe.Free();
        }
Ejemplo n.º 6
0
        public static Point3D GetSurfaceTop(this IPoint3D p, Map map, bool items = true)
        {
            if (map == null || map == Map.Internal)
            {
                return(p.ToPoint3D());
            }

            Point3D point = Point3D.Zero;

            if (p is Item)
            {
                point = p.Clone3D(0, 0, ((Item)p).ItemData.Height);
            }
            else if (p is Mobile)
            {
                point = p.Clone3D(0, 0, 20);
            }

            /*else
             * {
             *      point = p.Clone3D(0, 0, 5);
             * }*/

            object o = map.GetTopSurface(point);

            if (o != null && o != p)
            {
                if (o is LandTile)
                {
                    point.Z = ((LandTile)o).Z + ((LandTile)o).Height + 1;
                }
                else if (o is StaticTile)
                {
                    point.Z = ((StaticTile)o).Z + ((StaticTile)o).Height + 1;
                }
                else if (o is Item && items)
                {
                    point = ((Item)o).GetSurfaceTop();
                }
            }

            return(point);
        }