Esempio n. 1
0
 public void Clear()
 {
     if (-1 != this._RoleID)
     {
         StoryBoard4Client.RemoveStoryBoard(this._RoleID);
     }
 }
Esempio n. 2
0
        //驱动所有的故事板
        public static void runStoryBoards()
        {
            long currentTicks = getMyTimer();

            //Debug.WriteLine("runStoryBoards elapsedTicks=" + (currentTicks - LastRunStoryTicks) + ", stage.frameRate=" + stage.frameRate + ", DateTimeTicks=" + (DateTime.Now.toString("yyyy-MM-dd HH:mm:ss")));
            LastRunStoryTicks = currentTicks;

            List <StoryBoard4Client> list = new List <StoryBoard4Client>();

            lock (StoryBoardDict)
            {
                foreach (var sb in StoryBoardDict.Values)
                {
                    list.Add(sb);
                }
            }

            for (int i = 0; i < list.Count; i++)
            {
                StoryBoard4Client sb = list[i];
                if (null != sb)
                {
                    sb.Run(currentTicks);
                }
            }
        }
Esempio n. 3
0
        public static StoryBoard4Client FindStoryBoard(int roleID)
        {
            StoryBoard4Client storyBd = null;

            lock (StoryBoard4Client.StoryBoardDict)
            {
                StoryBoard4Client.StoryBoardDict.TryGetValue(roleID, out storyBd);
            }
            return(storyBd);
        }
Esempio n. 4
0
        public static void StopStoryBoard(int roleID, int stopIndex)
        {
            StoryBoard4Client storyBd = null;

            lock (StoryBoard4Client.StoryBoardDict)
            {
                if (!StoryBoard4Client.StoryBoardDict.TryGetValue(roleID, out storyBd))
                {
                    return;
                }
            }
            if (null != storyBd)
            {
                storyBd.StopOnNextGrid(stopIndex);
            }
        }
Esempio n. 5
0
        public static void RemoveStoryBoard(int roleID)
        {
            StoryBoard4Client storyBd = null;

            lock (StoryBoard4Client.StoryBoardDict)
            {
                if (StoryBoard4Client.StoryBoardDict.TryGetValue(roleID, out storyBd))
                {
                    StoryBoard4Client.StoryBoardDict.Remove(roleID);
                    if (null != storyBd)
                    {
                        storyBd.Completed = null;
                    }
                }
            }
        }
Esempio n. 6
0
        public static StoryBoard4Client StopStoryBoard(int roleID, long clientTicks)
        {
            StoryBoard4Client storyBd = null;

            lock (StoryBoard4Client.StoryBoardDict)
            {
                if (!StoryBoard4Client.StoryBoardDict.TryGetValue(roleID, out storyBd))
                {
                    return(null);
                }
                StoryBoard4Client.StoryBoardDict.Remove(roleID);
            }
            if (null != storyBd)
            {
                storyBd.Run(clientTicks);
            }
            return(storyBd);
        }
Esempio n. 7
0
        //获取当前故事版的路径索引
        public static int GetStoryBoardPathIndex(int roleID)
        {
            StoryBoard4Client storyBd = null;

            lock (StoryBoardDict)
            {
                if (!StoryBoardDict.TryGetValue(roleID, out storyBd))
                {
                    return(0);
                }
            }

            if (null != storyBd)
            {
                return(storyBd.GetStoryBoardPathIndex());
            }

            return(0);
        }
Esempio n. 8
0
        public static void ClearStoryBoard()
        {
            List <StoryBoard4Client> list = new List <StoryBoard4Client>();

            lock (StoryBoard4Client.StoryBoardDict)
            {
                foreach (StoryBoard4Client sb in StoryBoard4Client.StoryBoardDict.Values)
                {
                    list.Add(sb);
                }
                StoryBoard4Client.StoryBoardDict.Clear();
            }
            for (int i = 0; i < list.Count; i++)
            {
                StoryBoard4Client sb = list[i];
                if (null != sb)
                {
                    sb.Completed = null;
                    sb.Clear();
                }
            }
        }
Esempio n. 9
0
        public bool Start(GameClient client, List <Point> path, int cellSizeX, int cellSizeY, long elapsedTicks)
        {
            bool result;

            lock (this.mutex)
            {
                if (this._Started)
                {
                    result = false;
                }
                else
                {
                    this._CellSizeX      = cellSizeX;
                    this._CellSizeY      = cellSizeY;
                    this._PathIndex      = 0;
                    this._LastRunTicks   = StoryBoard4Client.getMyTimer() - elapsedTicks;
                    this._LastTargetX    = client.ClientData.PosX;
                    this._LastTargetY    = client.ClientData.PosY;
                    this._CurrentX       = (double)client.ClientData.PosX;
                    this._CurrentY       = (double)client.ClientData.PosY;
                    this._Path           = path;
                    this._CompletedState = false;
                    this._Started        = true;
                    this._Stopped        = false;
                    this._LastStopIndex  = -1;
                    this._FirstPoint     = new Point(this._Path[0].X * (double)this._CellSizeX + (double)(this._CellSizeX / 2), this._Path[0].Y * (double)this._CellSizeY + (double)(this._CellSizeY / 2));
                    if (this._Path.Count <= 0)
                    {
                        this._LastPoint = this._FirstPoint;
                    }
                    else
                    {
                        this._LastPoint = new Point(this._Path[this._Path.Count - 1].X * (double)this._CellSizeX + (double)(this._CellSizeX / 2), this._Path[this._Path.Count - 1].Y * (double)this._CellSizeY + (double)(this._CellSizeY / 2));
                    }
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 10
0
        public static void runStoryBoards()
        {
            long currentTicks = StoryBoard4Client.getMyTimer();

            StoryBoard4Client.LastRunStoryTicks = currentTicks;
            List <StoryBoard4Client> list = new List <StoryBoard4Client>();

            lock (StoryBoard4Client.StoryBoardDict)
            {
                foreach (StoryBoard4Client sb in StoryBoard4Client.StoryBoardDict.Values)
                {
                    list.Add(sb);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                StoryBoard4Client sb = list[i];
                if (null != sb)
                {
                    sb.Run(currentTicks);
                }
            }
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
            }
        }