//开始战斗 public void MsgStartFight(Player player, ProtocolBase protocolBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("StartFight"); //条件判断 //玩家是否在房间里 if (player.tempData.status != PlayerTempData.Status.Room) { Console.WriteLine("MsgStartFight status error " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } //玩家是否为房主 if (!player.tempData.isOwner) { Console.WriteLine("MsgStartFigth owner error " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } //房间能否开启战斗 Room room = player.tempData.room; if (!room.IsCanStart()) { Console.WriteLine("MsgStartFight Can Start Error" + player.id); protocol.AddInt(-1); player.Send(protocol); return; } //开始战斗 protocol.AddInt(0); player.Send(protocol); room.StartFight(); }
/// <summary> /// 创建房间 /// </summary> /// <param name="player"></param> /// <param name="protocolBase"></param> public void MsgCreateRoom(Player player, ProtocolBase protocolBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("CreateRoom"); //条件检测,如果玩家的状态是在房间中或是战斗中,则不能创建房间,返回创建房间失败 if (player.tempData.status != PlayerTempData.Status.None) { Console.WriteLine("MsgCreateRoom Fail" + player.id); protocol.AddInt(-1); player.Send(protocol); return; } //创建房间并返回成功信息 RoomMgr.instance.CreateRoom(player); protocol.AddInt(0); player.Send(protocol); Console.WriteLine("MsgCreateRoom OK" + player.id); }
//更新信息 public void MsgUpdateInfo(Player player, ProtocolBase protocolBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protocolBase; string protoName = protocol.GetString(start, ref start); float x = protocol.GetFloat(start, ref start); float y = protocol.GetFloat(start, ref start); float z = protocol.GetFloat(start, ref start); int score = player.data.score; Scene.instance.UpdateInfo(player.id, x, y, z, score); //广播 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("UpdateInfo"); protocolRet.AddString(player.id); protocolRet.AddFloat(x); protocolRet.AddFloat(y); protocolRet.AddFloat(z); protocolRet.AddInt(score); ServNet.instance.Broadcast(protocolRet); }
//心跳 //协议参数:无 public void MsgHeartBeat(Conn conn, ProtocolBase protoBase) { conn.lastTickTime = Sys.GetTimeStamp(); //Console.WriteLine("[更新心跳时间 ]" + conn.GetAddress()); }
//获取玩家列表 public void MsgGetList(Player player, ProtocolBase protocolBase) { Scene.instance.SendPlayerList(player); }
//发送协议 public void Send(ProtocolBase protocol) { ServNet.instance.Send(this, protocol); }
/// <summary> /// 获取房间列表 /// </summary> /// <param name="player"></param> /// <param name="protocolBase"></param> public void MsgGetRoomList(Player player, ProtocolBase protocolBase) { player.Send(RoomMgr.instance.GetRoomList()); }