/// <summary>
        /// Method to save the Patrol Path using the Patrol ID and the Component
        /// </summary>
        /// <param name="pathID"></param>
        /// <param name="path"></param>
        /// <param name="component"></param>
        public static void SavePatrolPath(string pathID, PathPoint path, GameKeepComponent component)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');             // we must replace the ', found no other way yet
            GameServer.Database.DeleteObject(DOLDB <DBPath> .SelectObjects(DB.Column(nameof(DBPath.PathID)).IsEqualTo(pathID)));
            PathPoint root = MovementMgr.FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path = root;
            DBPath dbp = new DBPath(pathID, ePathType.Loop);

            GameServer.Database.AddObject(dbp);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed);
                int         x, y;
                SaveXY(component, dbpp.X, dbpp.Y, out x, out y);
                dbpp.X = x;
                dbpp.Y = y;
                dbpp.Z = dbpp.Z - component.Z;

                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            } while (path != null && path != root);
        }
        /// <summary>
        /// Method to retrieve the Patrol Path from the Patrol ID and Component
        ///
        /// We need this because we store this all using our offset system
        /// </summary>
        /// <param name="pathID">The path ID, which is the Patrol ID</param>
        /// <param name="component">The Component object</param>
        /// <returns>The Patrol path</returns>
        public static PathPoint LoadPatrolPath(string pathID, GameKeepComponent component)
        {
            SortedList sorted = new SortedList();

            pathID.Replace('\'', '/'); // we must replace the ', found no other way yet
            DBPath dbpath = GameServer.Database.SelectObjects <DBPath>("`PathID` = @PathID", new QueryParameter("@PathID", pathID)).FirstOrDefault();
            IList <DBPathPoint> pathpoints = null;
            ePathType           pathType   = ePathType.Once;

            if (dbpath != null)
            {
                pathType = (ePathType)dbpath.PathType;
            }

            if (pathpoints == null)
            {
                pathpoints = GameServer.Database.SelectObjects <DBPathPoint>("`PathID` = @PathID", new QueryParameter("@PathID", pathID));
            }

            foreach (DBPathPoint point in pathpoints)
            {
                sorted.Add(point.Step, point);
            }

            PathPoint prev  = null;
            PathPoint first = null;

            for (int i = 0; i < sorted.Count; i++)
            {
                DBPathPoint pp = (DBPathPoint)sorted.GetByIndex(i);
                PathPoint   p  = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType);

                int x, y;
                LoadXY(component, pp.X, pp.Y, out x, out y);
                p.X = x;
                p.Y = y;
                p.Z = component.AbstractKeep.Z + p.Z;

                p.WaitTime = pp.WaitTime;

                if (first == null)
                {
                    first = p;
                }

                p.Prev = prev;
                if (prev != null)
                {
                    prev.Next = p;
                }

                prev = p;
            }

            return(first);
        }
        /// <summary>
        /// Method to retrieve the Patrol Path from the Patrol ID and Component
        ///
        /// We need this because we store this all using our offset system
        /// </summary>
        /// <param name="pathID">The path ID, which is the Patrol ID</param>
        /// <param name="component">The Component object</param>
        /// <returns>The Patrol path</returns>
        public static PathPoint LoadPatrolPath(string pathID, GameKeepComponent component)
        {
            SortedList sorted = new SortedList();

            pathID.Replace('\'', '/');             // we must replace the ', found no other way yet
            var dbpath = DOLDB <DBPath> .SelectObject(DB.Column(nameof(DBPath.PathID)).IsEqualTo(pathID));

            IList <DBPathPoint> pathpoints = null;
            ePathType           pathType   = ePathType.Once;

            if (dbpath != null)
            {
                pathType = (ePathType)dbpath.PathType;
            }
            if (pathpoints == null)
            {
                pathpoints = DOLDB <DBPathPoint> .SelectObjects(DB.Column(nameof(DBPathPoint.PathID)).IsEqualTo(pathID));
            }

            foreach (DBPathPoint point in pathpoints)
            {
                sorted.Add(point.Step, point);
            }
            PathPoint prev  = null;
            PathPoint first = null;

            for (int i = 0; i < sorted.Count; i++)
            {
                DBPathPoint pp = (DBPathPoint)sorted.GetByIndex(i);
                PathPoint   p  = new PathPoint(pp.X, pp.Y, pp.Z, pp.MaxSpeed, pathType);

                int x, y;
                LoadXY(component, pp.X, pp.Y, out x, out y);
                p.X = x;
                p.Y = y;
                p.Z = component.Keep.Z + p.Z;

                p.WaitTime = pp.WaitTime;

                if (first == null)
                {
                    first = p;
                }
                p.Prev = prev;
                if (prev != null)
                {
                    prev.Next = p;
                }
                prev = p;
            }
            return(first);
        }
Exemple #4
0
        /// <summary>
        /// Saves the path into the database
        /// </summary>
        /// <param name="pathID">The path ID</param>
        /// <param name="path">The path waypoint</param>
        public static void SavePath(string pathID, PathPoint path)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');

            // First delete any path with this pathID from the database

            DBPath dbpath = GameServer.Database.SelectObject <DBPath>("PathID='" + GameServer.Database.Escape(pathID) + "'");

            if (dbpath != null)
            {
                GameServer.Database.DeleteObject(dbpath);
            }

            foreach (DBPathPoint pp in GameServer.Database.SelectObjects <DBPathPoint>("PathID='" + GameServer.Database.Escape(pathID) + "'"))
            {
                GameServer.Database.DeleteObject(pp);
            }

            // Now add this path and iterate through the PathPoint linked list to add all the path points

            PathPoint root = FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path   = root;
            dbpath = new DBPath(pathID, root.Type);
            GameServer.Database.AddObject(dbpath);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint(path.X, path.Y, path.Z, path.MaxSpeed);
                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            }           while (path != null && path != root);

            UpdatePathInCache(pathID);
        }
Exemple #5
0
        /// <summary>
        /// Saves the path into the database
        /// </summary>
        /// <param name="pathID">The path ID</param>
        /// <param name="path">The path waypoint</param>
        public static void SavePath(string pathID, PathPoint path)
        {
            if (path == null)
            {
                return;
            }

            pathID.Replace('\'', '/');

            // First delete any path with this pathID from the database

            var dbpath = DOLDB <DBPath> .SelectObject(DB.Column(nameof(DBPath.PathID)).IsEqualTo(pathID));

            if (dbpath != null)
            {
                GameServer.Database.DeleteObject(dbpath);
            }

            GameServer.Database.DeleteObject(DOLDB <DBPathPoint> .SelectObjects(DB.Column(nameof(DBPathPoint.PathID)).IsEqualTo(pathID)));

            // Now add this path and iterate through the PathPoint linked list to add all the path points

            PathPoint root = FindFirstPathPoint(path);

            //Set the current pathpoint to the rootpoint!
            path   = root;
            dbpath = new DBPath(pathID, root.Type);
            GameServer.Database.AddObject(dbpath);

            int i = 1;

            do
            {
                DBPathPoint dbpp = new DBPathPoint((int)path.Position.X, (int)path.Position.Y, (int)path.Position.Z, path.MaxSpeed);
                dbpp.Step     = i++;
                dbpp.PathID   = pathID;
                dbpp.WaitTime = path.WaitTime;
                GameServer.Database.AddObject(dbpp);
                path = path.Next;
            }           while (path != null && path != root);

            UpdatePathInCache(pathID);
        }