예제 #1
0
 /// <summary>
 /// 解析关键帧数据,执行命令
 /// </summary>
 /// <param name="data"></param>
 public void ProcessKeyFrameData(List <KeyFrame> data)
 {
     for (int i = 0; i < data.Count; i++)
     {
         KeyFrame kf = data[i];
         //shot优先级最高
         if (kf.ShotPower > 0)
         {
             //执行Shot
             continue;
         }
         if (kf.PassPower > 0)
         {
             //执行Shot
             continue;
         }
         if (kf.StolenPower > 0)
         {
             continue;
         }
         if (kf.isMoved > 0)
         {
             //移动
             for (int j = 0; j < GlobalClient.GameManager.LogicManager.entities.Count; ++j)
             {
                 if (GlobalClient.GameManager.LogicManager.entities[j].mCharData.clientID == kf.ClientID)
                 {
                     //(GlobalClient.GameManager.viewMap.LogicMap.gameObjList[i] as Player).DoSkill(int.Parse(param));
                     string msg = string.Format("isMoved{0}, shotPower{1}, passPower{2}, stolenPower{3}, angle{4}", kf.isMoved, kf.ShotPower, kf.PassPower, kf.StolenPower, kf.OtherParam);
                     //Debug.LogWarning(msg);
                     MoveCommand cmd = new MoveCommand(kf.PlayerEntityID, float.Parse(kf.OtherParam));
                     GlobalClient.CommandManager.AddCommand(cmd);
                 }
             }
             continue;
         }
     }
 }
예제 #2
0
        public void OnMessage(MessageBuffer msg)
        {
            int cproto = msg.ReadInt();

            //Debug.Log(cproto);
            switch (cproto)
            {
            case cProto.CONNECT:
            {
                int id = msg.ReadInt();
                clientID = id;
                Debug.Log("玩家客户端id = " + id);
                //服务器已连接
                ServerOnConnectArg arg = new ServerOnConnectArg();
                arg.ClientID = id;
                m_context.FireEvent(this, EventType.EVT_SERVER_ON_CONNECT, arg);
            }
            break;

            case cProto.READY:
                break;

            //位置同步
            case cProto.SYNC_POS:
                int    clientId = msg.ReadInt();
                int    entityId = msg.ReadInt();
                string pos      = msg.ReadString();
                GameManager.instance.ViewManager.SyncPos(clientId, pos, entityId);
                //Debug.Log(string.Format("玩家 {0} ,pos = {1}", cRoleId ,pos));
                break;

            //同步关键帧k
            case cProto.TO_TEAM_SELECT:
            {
                int             playerID       = msg.ReadInt();
                string          playerName     = msg.ReadString();
                string          playerIconPath = msg.ReadString();
                GamePlayer      playerInfo     = new GamePlayer(playerID, playerName, playerIconPath);
                ToSelectTeamArg arg            = new ToSelectTeamArg();
                arg.playerInfo = playerInfo;
                m_context.FireEvent(this, EventType.EVT_TO_TEAM_SELECT, arg);
                break;
            }

            case cProto.SYNC_KEY:
                //读取服务器帧数
                int servFrameCount = msg.ReadInt();
                //Debug.LogWarning(string.Format("服务器关键帧={0}", servFrameCount));
                GlobalClient.KeyFrameManager.serverKeyFrameNo = servFrameCount;
                //当服务器帧数>=当前客户端帧数的时候,客户端本地帧才更新
                if (servFrameCount >= GlobalClient.KeyFrameManager.curKeyFrameNo)
                {
                    //解析出所有用户的KeyDataList
                    string keyStr = msg.ReadString();
                    //分号分离各个用户的KeyDataList;
                    string[] keyData = keyStr.Split(';');
                    for (int i = 0; i < keyData.Length; ++i)
                    {
                        if (keyData[i] == "")
                        {
                            continue;
                        }
                        KeyFrame kf = new KeyFrame(keyData[i]);
                        //插入关键帧管理器中
                        GlobalClient.KeyFrameManager.AddKeyData(servFrameCount, kf);
                    }
                }
                break;

            case cProto.START:
                //读取玩家列表
                string players = msg.ReadString();
                //创建所有玩家
                GameManager.instance.ViewManager.CreateAllPlayer(players);
                //初始化服务器关键帧为1
                GlobalClient.KeyFrameManager.serverKeyFrameNo = 0;
                //每50毫秒向服务器发送位置信息
                //TimerHeap.AddTimer(0, 50, SycMePos);
                //每100毫秒向服务器关键帧数据
                // TimerHeap.AddTimer(0, 100, SycKey);
                break;
            }
        }