Ejemplo n.º 1
0
        /// <summary>
        /// 指令对象转消息内容并发送
        /// </summary>
        /// <param name="cmd"></param>
        public void SendFspCmd(IFspCmdType cmd)
        {
            // 如果本地单机测试
            if (Client.Inst().isSingleTest)
            {
                PushCommand(cmd);
                return;
            }

            CmdFspEnum  type = cmd.GetCmdType();
            FspMsgFrame msg  = (FspMsgFrame)NetManager.Inst.GetMessage(eNetMessageID.FspMsgFrame);
            FspVKey     key  = new FspVKey();

            key.vkey     = (int)type;
            key.playerId = (uint)GetUid();
            switch (type)
            {
            case CmdFspEnum.eFspStopMove:
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspMove:
                CmdFspMove moveCmd = cmd as CmdFspMove;
                key.args    = new int[2];
                key.args[0] = (int)(moveCmd.m_dir.x * 100);
                key.args[1] = (int)(moveCmd.m_dir.y * 100);
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspAutoMove:
                CmdFspAutoMove amoveCmd = cmd as CmdFspAutoMove;
                key.args    = new int[2];
                key.args[0] = (int)(amoveCmd.m_pos.x * 100);
                key.args[1] = (int)(amoveCmd.m_pos.y * 100);
                Debug.Log("send :" + key.args[0] + "  " + key.args[1]);
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspSendSkill:
                CmdFspSendSkill skill = cmd as CmdFspSendSkill;
                key.args    = new int[7];
                key.args[0] = (int)skill.m_casterUid;
                key.args[1] = (int)skill.m_skillIndex;
                key.args[2] = (int)skill.m_targetId;

                key.args[3] = (int)(skill.m_dir.x * 100);
                key.args[4] = (int)(skill.m_dir.y * 100);

                key.args[5] = (int)(skill.m_endPos.x * 100);
                key.args[6] = (int)(skill.m_endPos.y * 100);

                msg.m_frameData.vkeys.Add(key);
                break;
            }
            FspNetRunTime.Inst.SendMessage(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 消息内容转指令对象
        /// </summary>
        private void HandleServerCmd(FspVKey cmd)
        {
            CmdFspEnum type = (CmdFspEnum)cmd.vkey;
            uint       uid  = cmd.playerId;

            if (uid == 0)
            {
                return;
            }
            CCreature   player   = CCreatureMgr.Get(uid);
            IFspCmdType logicCmd = null;

            switch (type)
            {
            case CmdFspEnum.eFspStopMove:
                //Debug.Log(uid + " 停止移动");
                logicCmd = new CmdFspStopMove();
                break;

            case CmdFspEnum.eFspMove:
                //Debug.Log(uid + " 客户端调用移动命令 " + cmd.args[0] + " " + cmd.args[1]);
                Vector2d v = new Vector2d(cmd.args[0] * 0.01f, cmd.args[1] * 0.01f);
                logicCmd = new CmdFspMove(ref v);
                break;

            case CmdFspEnum.eFspAutoMove:
                Vector2d v1 = new Vector2d(cmd.args[0] * 0.01f, cmd.args[1] * 0.01f);
                logicCmd = new CmdFspAutoMove(ref v1);
                break;

            case CmdFspEnum.eFspSendSkill:
                //Debug.Log(uid + " 客户端调用技能 " + cmd.args[0] + " " + cmd.args[1]);

                CmdFspSendSkill skill = new CmdFspSendSkill();
                skill.m_casterUid  = cmd.args[0];
                skill.m_skillIndex = cmd.args[1];
                skill.m_targetId   = cmd.args[2];
                Vector2d dir    = new Vector2d(cmd.args[3] * 0.01f, cmd.args[4] * 0.01f);
                Vector2d endPos = new Vector2d(cmd.args[5] * 0.01f, cmd.args[6] * 0.01f);
                skill.m_dir    = dir;
                skill.m_endPos = endPos;
                logicCmd       = skill;
                break;
            }
            player.PushCommand(logicCmd);
        }
Ejemplo n.º 3
0
        //直接发送移动消息
        private void PushMoveCommand(Vector2 dir)
        {
            if (dir == Vector2.zero)
            {
                return;
            }

            if (m_master != null)
            {
                Vector2d   _dir = dir.ToVector2d();
                CmdFspMove cmd  = new CmdFspMove(ref _dir);
                m_master.SendFspCmd(cmd);
                //Debug.Log("发送移动。。。。。。。。。。。。。。。。。。。。。");

                m_preMoveDir      = dir;
                m_isFirstJoyStick = false;
            }
        }
Ejemplo n.º 4
0
 public override void Enter(IFspCmdType cmd)
 {
     m_cmdFspMove = cmd as CmdFspMove;
 }