コード例 #1
0
ファイル: ChuanQiUtils.cs プロジェクト: neyma2379294/MuOrigin
        /// <summary>
        /// 走动到新的位置
        /// </summary>
        /// <param name="nX"></param>
        /// <param name="nY"></param>
        /// <param name="nDir"></param>
        /// <returns></returns>
        protected static Boolean RunXY1(IObject obj, int nX, int nY, Dircetions nDir, String pathStr)
        {
            //旧传奇代码这儿是开关门【同时处理障碍物】的判断
            if (!CanMove(obj, nX, nY))
            {
                return(false);
            }

            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];

            //对象在格子间移动
            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                NotifyOthersMyMoving1(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir);

                obj.CurrentGrid = new Point(nX, nY);
                obj.CurrentDir  = nDir;

                //进行九宫格通知
                Notify9Grid(obj);
                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: ChuanQiUtils.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 跑到XY坐标,计算时已经验证可移动,这儿不需要再次进行可否移动的判断
        /// </summary>
        /// <param name="nX"></param>
        /// <param name="nY"></param>
        /// <param name="nDir"></param>
        /// <returns></returns>
        protected static Boolean RunXY(IObject obj, int nX, int nY, Dircetions nDir, String pathStr, IObject target)
        {
            //旧传奇代码这儿是开关门【同时处理障碍物】的判断
            //if (!CanMove(obj, nX, nY))
            //{
            //    return false;
            //}
            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;



            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];

            //对象在格子间移动
            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                NotifyOthersMyMoving(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir, ((target is GameClient) ? (target as GameClient).ClientData.RoleID : 0));

                obj.CurrentGrid = new Point(nX, nY);
                obj.CurrentDir  = nDir;

                //进行九宫格通知
                Notify9Grid(obj);
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: ChuanQiUtils.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 走动到新的位置
        /// </summary>
        /// <param name="nX"></param>
        /// <param name="nY"></param>
        /// <param name="nDir"></param>
        /// <returns></returns>
        protected static Boolean WalkXY(IObject obj, int nX, int nY, Dircetions nDir, String pathStr)
        {
            //旧传奇代码这儿是开关门【同时处理障碍物】的判断
            if (!CanMove(obj, nX, nY))
            {
                // SysConOut.WriteLine(String.Format("****************不能移动有障碍物***************ID = {0}***********", (obj is Monster ? (obj as Monster).RoleID : ((obj as GameClient).ClientData.RoleID))));
                return(false);
            }

            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];

            //对象在格子间移动
            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                NotifyOthersMyMoving(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir);

                obj.CurrentGrid = new Point(nX, nY);
                obj.CurrentDir  = nDir;

                //进行九宫格通知
                Notify9Grid(obj);
                return(true);
            }

            return(false);
        }
コード例 #4
0
        protected static bool RunXY1(IObject obj, int nX, int nY, Dircetions nDir, string pathStr)
        {
            bool result;

            if (!ChuanQiUtils.CanMove(obj, nX, nY))
            {
                result = false;
            }
            else
            {
                Point   grid    = obj.CurrentGrid;
                int     nCurrX  = (int)grid.X;
                int     nCurrY  = (int)grid.Y;
                MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];
                if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
                {
                    ChuanQiUtils.NotifyOthersMyMoving1(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir);
                    obj.CurrentGrid = new Point((double)nX, (double)nY);
                    obj.CurrentDir  = nDir;
                    ChuanQiUtils.Notify9Grid(obj, false);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: ChuanQiUtils.cs プロジェクト: neyma2379294/MuOrigin
        /// <summary>
        /// 传送对象到目标位置,相当于瞬移
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="nX"></param>
        /// <param name="nY"></param>
        /// <param name="nDir"></param>
        /// <param name="?"></param>
        /// <param name="pathStr"></param>
        /// <returns></returns>
        public static Boolean TransportTo(IObject obj, int nX, int nY, Dircetions nDir, int oldMapCode, String pathStr = "")
        {
            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            if (oldMapCode > 0 && oldMapCode != obj.CurrentMapCode)
            {
                MapGrid oldMapGrid = GameManager.MapGridMgr.DictGrids[oldMapCode];
                if (oldMapGrid != null)
                {
                    oldMapGrid.RemoveObject(obj);

                    //这儿还需要通知旧九宫格对象自己的离开
                }

                //强行设置 -1
                nCurrX = -1;
                nCurrY = -1;
            }

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];

            //对象在格子间移动
            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                //对于传送移动,根本不需要移动通知,只需要九宫格通知
                //NotifyOthersMyMoving(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir);

                obj.CurrentGrid = new Point(nX, nY);
                obj.CurrentDir  = nDir;

                //进行九宫格通知 --->不管在哪个地图,一旦coordinate 坐标 和 grid坐标保持一致,九宫格不会触发
                //此时,需要提前更改coordinate
                Notify9Grid(obj, true);
                return(true);
            }

            return(false);
        }
コード例 #6
0
        public static bool TransportTo(IObject obj, int nX, int nY, Dircetions nDir, int oldMapCode, string pathStr = "")
        {
            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            if (oldMapCode > 0 && oldMapCode != obj.CurrentMapCode)
            {
                MapGrid oldMapGrid = GameManager.MapGridMgr.DictGrids[oldMapCode];
                if (oldMapGrid != null)
                {
                    oldMapGrid.RemoveObject(obj);
                }
                nCurrX = -1;
                nCurrY = -1;
            }
            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];
            bool    result;

            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                obj.CurrentGrid = new Point((double)nX, (double)nY);
                obj.CurrentDir  = nDir;
                if (obj is Monster && (obj as Monster).MonsterType == 1001)
                {
                    GameManager.MonsterMgr.ChangePosition(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, obj as Monster, (int)obj.CurrentPos.X, (int)obj.CurrentPos.Y, (int)nDir, 159, 0);
                }
                ChuanQiUtils.Notify9Grid(obj, true);
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
コード例 #7
0
        private bool StepMove(double toMoveDist, GameClient client)
        {
            StoryBoard4Client sb = StoryBoard4Client.FindStoryBoard(this._RoleID);
            bool result;

            if (null == sb)
            {
                result = false;
            }
            else
            {
                lock (this.mutex)
                {
                    this._PathIndex = Math.Min(this._PathIndex, this._Path.Count - 1);
                    if (!this.DetectNextGrid())
                    {
                        result = true;
                    }
                    else
                    {
                        double targetX          = this._Path[this._PathIndex].X * (double)this._CellSizeX + (double)this._CellSizeX / 2.0;
                        double targetY          = this._Path[this._PathIndex].Y * (double)this._CellSizeY + (double)this._CellSizeY / 2.0;
                        int    direction        = (int)StoryBoard4Client.GetDirectionByTan(targetX, targetY, (double)this._LastTargetX, (double)this._LastTargetY);
                        double dx               = targetX - (double)this._LastTargetX;
                        double dy               = targetY - (double)this._LastTargetY;
                        double thisGridStepDist = Math.Sqrt(dx * dx + dy * dy);
                        bool   needWalking      = false;
                        if (this._Path.Count <= 1)
                        {
                            needWalking = true;
                        }
                        if (null != client)
                        {
                            GameMap gameMap = GameManager.MapMgr.DictMaps[client.ClientData.MapCode];
                            if (gameMap.InSafeRegionList(this._Path[this._PathIndex]))
                            {
                                needWalking = true;
                            }
                        }
                        int action = needWalking ? 1 : 2;
                        if (needWalking)
                        {
                            toMoveDist *= 0.8;
                        }
                        double thisToMoveDist = (thisGridStepDist < toMoveDist) ? thisGridStepDist : toMoveDist;
                        double angle          = Math.Atan2(dy, dx);
                        double speedX         = thisToMoveDist * Math.Cos(angle);
                        double speedY         = thisToMoveDist * Math.Sin(angle);
                        this._CurrentX += speedX;
                        this._CurrentY += speedY;
                        if (null != client)
                        {
                            client.ClientData.CurrentAction = action;
                            if (direction != client.ClientData.RoleDirection)
                            {
                                client.ClientData.RoleDirection = direction;
                            }
                        }
                        if (thisGridStepDist >= toMoveDist)
                        {
                            if (null != client)
                            {
                                GameMap gameMap  = GameManager.MapMgr.DictMaps[client.ClientData.MapCode];
                                int     oldGridX = client.ClientData.PosX / gameMap.MapGridWidth;
                                int     oldGridY = client.ClientData.PosY / gameMap.MapGridHeight;
                                client.ClientData.PosX = (int)this._CurrentX;
                                client.ClientData.PosY = (int)this._CurrentY;
                                int newGridX = client.ClientData.PosX / gameMap.MapGridWidth;
                                int newGridY = client.ClientData.PosY / gameMap.MapGridHeight;
                                if (oldGridX != newGridX || oldGridY != newGridY)
                                {
                                    MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[client.ClientData.MapCode];
                                    mapGrid.MoveObjectEx(oldGridX, oldGridY, newGridX, newGridY, client);
                                }
                            }
                            this._LastTargetX = (int)this._CurrentX;
                            this._LastTargetY = (int)this._CurrentY;
                        }
                        else
                        {
                            this._PathIndex++;
                            if (this._PathIndex >= this._Path.Count)
                            {
                                if (null != client)
                                {
                                    client.ClientData.PosX = (int)targetX;
                                    client.ClientData.PosY = (int)targetY;
                                }
                                return(true);
                            }
                            this._LastTargetX = (int)targetX;
                            this._LastTargetY = (int)targetY;
                            toMoveDist       -= thisGridStepDist;
                            this.StepMove(toMoveDist, client);
                        }
                        result = false;
                    }
                }
            }
            return(result);
        }
コード例 #8
0
        private bool StepMove(long elapsedTicks)
        {
            //防止外部结束后,这里还在递归处理
            StoryBoard4Client sb = FindStoryBoard(_RoleID);

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

            lock (mutex)
            {
                //已到最后一个目的地,则停下
                _PathIndex = Math.Min(_PathIndex, _Path.Count - 1);

                //探测下一个格子
                if (!DetectNextGrid())
                {
                    return(true);
                }

                double targetX   = _Path[_PathIndex].X * _CellSizeX + _CellSizeX / 2.0; //根据节点列号求得屏幕坐标
                double targetY   = _Path[_PathIndex].Y * _CellSizeY + _CellSizeY / 2.0; //根据节点行号求得屏幕坐标
                int    direction = (int)(GetDirectionByTan(targetX, targetY, _LastTargetX, _LastTargetY));

                double dx = targetX - _LastTargetX;
                double dy = targetY - _LastTargetY;
                double thisGridStepDist = Math.Sqrt(dx * dx + dy * dy);
                //trace("_PathIndex=" + _PathIndex + ", " + "thisGridStepDist=" + thisGridStepDist);

                bool needWalking = false;// _LastNeedWalking;
                //if (_PathIndex > _ActionIndex)
                //{
                //    int currentGridX = (int)(_LastTargetX / _CellSizeX);
                //    int currentGridY = (int)(_LastTargetY / _CellSizeY);
                //    needWalking = NeedWalking(currentGridX, currentGridY);
                //    _LastNeedWalking = needWalking;
                //}

                if (_Path.Count <= 1)
                {
                    needWalking = true;
                }

                int action = needWalking ? (int)GActions.Walk : (int)GActions.Run;

                long thisGridNeedTicks = GetNeedTicks(needWalking, direction);
                long thisToNeedTicks   = Math.Min(thisGridNeedTicks - _LastUsedTicks, elapsedTicks);
                _LastUsedTicks += thisToNeedTicks;

                //trace(thisToNeedTicks);

                double movePercent  = (double)(thisToNeedTicks) / (double)(thisGridNeedTicks);
                var    realMoveDist = thisGridStepDist * movePercent;
                //trace("_PathIndex=" + _PathIndex + ", " + "movePercent=" + movePercent + ", realMoveDist=" + realMoveDist);

                var angle  = Math.Atan2(dy, dx);
                var speedX = realMoveDist * Math.Cos(angle);
                var speedY = realMoveDist * Math.Sin(angle);

                //trace("_PathIndex=" + _PathIndex + ", " + "speedX=" + speedX + ", speedY=" + speedY);

                _CurrentX = _CurrentX + speedX;
                _CurrentY = _CurrentY + speedY;

                if (thisToNeedTicks >= elapsedTicks)
                {
                    //trace("_PathIndex=" + _PathIndex + ", " + "old_cx=" + _MovingObj.cx + ", old_cy=" + _MovingObj.cy);

                    GameClient client = GameManager.ClientMgr.FindClient(_RoleID);
                    if (null != client)
                    {
                        client.ClientData.CurrentAction = action;

                        //求当前格子到目标格子的方向
                        if ((int)targetX != (int)_CurrentX || (int)targetY != (int)_CurrentY)
                        {
                            if (direction != client.ClientData.RoleDirection)
                            {
                                client.ClientData.RoleDirection = direction;
                            }
                            //Debug.WriteLine("_MovingObj.Direction=" + _MovingObj.Direction + ", targetX=" + targetX + ", targetY=" + targetY + ", _MovingObj.cx=" +  _MovingObj.cx + ",  _MovingObj.cy=" + _MovingObj.cy);
                        }

                        GameMap gameMap  = GameManager.MapMgr.DictMaps[client.ClientData.MapCode];
                        int     oldGridX = client.ClientData.PosX / gameMap.MapGridWidth;
                        int     oldGridY = client.ClientData.PosY / gameMap.MapGridHeight;

                        client.ClientData.PosX = (int)_CurrentX;
                        client.ClientData.PosY = (int)_CurrentY;
                        //_MovingObj.Z = int(_MovingObj.Y); //此处应该非常消耗CPU
                        //trace("_PathIndex=" + _PathIndex + ", " + "now_cx=" + _MovingObj.cx + ", now_cy=" + _MovingObj.cy);
                        //System.Diagnostics.Debug.WriteLine(string.Format("StepMove, toX={0}, toY={1}", client.ClientData.PosX, client.ClientData.PosY));

                        int newGridX = client.ClientData.PosX / gameMap.MapGridWidth;
                        int newGridY = client.ClientData.PosY / gameMap.MapGridHeight;

                        if (oldGridX != newGridX || oldGridY != newGridY)
                        {
                            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[client.ClientData.MapCode];
                            mapGrid.MoveObjectEx(oldGridX, oldGridY, newGridX, newGridY, client);

                            /// 玩家进行了移动
                            //Global.GameClientMoveGrid(client);
                        }
                    }
                }
                else //到达当前目的地
                {
                    //trace("_PathIndex=" + _PathIndex + ", " + "targetX=" + targetX + ", targetY=" + targetY + ", cx=" + _MovingObj.cx + ", cy=" + _MovingObj.cy );
                    //trace("_PathIndex=" + _PathIndex + ", " + "_LastUsedTicks=" + _LastUsedTicks + ", " + "_LastLostNumberX=" + _LastLostNumberX + ", _LastLostNumberY=" + _LastLostNumberY + ", _TotalMovePercent=" + _TotalMovePercent);
                    //trace("_LastTargetX=" + _LastTargetX + ", " + "_LastTargetY=" + _LastTargetY + ", TargetX=" + targetX + ", " + "targetY=" + targetY + ", cx=" + _MovingObj.cx + ", cy=" + _MovingObj.cy );
                    //trace(_TotalTicksSlot);
                    _PathIndex++;

                    //已到最后一个目的地,则停下
                    if (_PathIndex >= _Path.Count)
                    {
                        GameClient client = GameManager.ClientMgr.FindClient(_RoleID);
                        if (null != client)
                        {
                            client.ClientData.PosX = (int)targetX;
                            client.ClientData.PosY = (int)targetY;
                        }
                        return(true);
                    }

                    _LastTargetX   = (int)targetX;
                    _LastTargetY   = (int)targetY;
                    _LastUsedTicks = 0;
                    //_TotalTicksSlot = "";

                    elapsedTicks = elapsedTicks - thisToNeedTicks; //减去此次移动的距离
                    StepMove(elapsedTicks);
                }

                return(false);
            }
        }