/// <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); }
/// <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); }
// 正式的游戏逻辑帧 private void ExecuteFrame(int frameId, FspFrame frameMsg) { if (frameMsg != null && frameMsg.vkeys != null) { for (int i = 0; i < frameMsg.vkeys.Count; i++) { FspVKey cmd = frameMsg.vkeys[i]; // 根据keyid做不同逻辑处理 HandleServerCmd(cmd); } } CFrameTimeMgr.Inst.FixedUpdate(); CCreatureMgr.ExecuteFrame(frameId); CSkillMgr.ExecuteFrame(frameId); CBuffMgr.ExecuteFrame(frameId); CBuffTriggerMgr.ExecuteFrame(frameId); }
private void HandleClientCmd(Player player, FspVKey cmd) { cmd.playerId = (uint)player.id; m_lockedFrame.vkeys.Add(cmd); Console.WriteLine("添加帧消息中"); }