/// <summary> /// 玩家获得有害状态,转发 /// </summary> public void MsgPlayerGetBuff(Player player, BaseProtocol baseProtocol) { //消息结构: (string)PlayerName + (int)BuffType +(float)buffTime int startIndex = 0; BytesProtocol get = baseProtocol as BytesProtocol; Room room = player.playerStatus.room; get.GetString(startIndex, ref startIndex); string PlayerName = get.GetString(startIndex, ref startIndex); int bufftype = get.GetInt(startIndex, ref startIndex); float bufftime = get.GetFloat(startIndex, ref startIndex); if (room.playerDict.ContainsKey(PlayerName)) { room.playerDict[PlayerName].playerStatus.buffType = bufftype; room.playerDict[PlayerName].playerStatus.buffTime = bufftime; } BytesProtocol p = new BytesProtocol(); p.SpliceString("PlayerGetBuff"); p.SpliceString(PlayerName); p.SpliceInt(bufftype); p.SpliceFloat(bufftime); foreach (Player pr in room.playerDict.Values) { p.SpliceString(pr.name); } player.Send(p); }
/// <summary> /// 玩家特殊魔法,带终点 /// </summary> public void MsgPlayerMagicEndpoint(Player player, BaseProtocol baseProtocol) { //玩家特殊魔法,终点生成 //消息结构: (string)PlayerMagic + (string)playerName + (int)magicItemID + (float)endposX+(float)endposY+(float)endposZ if (player.playerStatus.status != PlayerStatus.Status.Gaming) { return; } Room room = player.playerStatus.room; int startIndex = 0; BytesProtocol p = baseProtocol as BytesProtocol; p.GetString(startIndex, ref startIndex); string playerName = p.GetString(startIndex, ref startIndex); int magicItemID = p.GetInt(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); //转发魔法消息 BytesProtocol p_broadcast = new BytesProtocol(); p_broadcast.SpliceString("PlayerMagicEndpoint"); p_broadcast.SpliceString(player.name); p_broadcast.SpliceInt(magicItemID); p_broadcast.SpliceFloat(posX); p_broadcast.SpliceFloat(posY); p_broadcast.SpliceFloat(posZ); room.Broadcast(p_broadcast); }
/// <summary> /// 拾取物品 /// </summary> public void MsgPickItem(Player player, BaseProtocol baseProtocol) { //拾取物品 //消息结构: (string)PickItem + (int)GroundItemID int startIndex = 0; BytesProtocol get = baseProtocol as BytesProtocol; get.GetString(startIndex, ref startIndex); int GroundItemID = get.GetInt(startIndex, ref startIndex); BytesProtocol p = new BytesProtocol(); p.SpliceString("PickItem"); p.SpliceInt(GroundItemID); player.playerStatus.room.Broadcast(p); }
/// <summary> /// 房间门打开转发 /// </summary> /// <param name="player"></param> /// <param name="baseProtocol"></param> public void MsgDoorOpen(Player player, BaseProtocol baseProtocol) { //开门 //消息结构: (string)DoorOpen + (int)DoorID Room room = player.playerStatus.room; int startIndex = 0; BytesProtocol p = baseProtocol as BytesProtocol; p.GetString(startIndex, ref startIndex); int DoorID = p.GetInt(startIndex, ref startIndex); BytesProtocol doorProtocol = new BytesProtocol(); doorProtocol.SpliceString("DoorOpen"); doorProtocol.SpliceInt(DoorID); room.Broadcast(doorProtocol); }
/// <summary> /// 玩家扔物品 /// </summary> public void MsgDropItem(Player player, BaseProtocol baseProtocol) { //拾取物品 //消息结构: (string)PickItem + (int)GroundItemID int startIndex = 0; BytesProtocol p = baseProtocol as BytesProtocol; p.GetString(startIndex, ref startIndex); int GroundItemID = p.GetInt(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); //转发魔法消息 BytesProtocol p_broadcast = new BytesProtocol(); p_broadcast.SpliceString("DropItem"); p_broadcast.SpliceInt(GroundItemID); p_broadcast.SpliceFloat(posX); p_broadcast.SpliceFloat(posY); p_broadcast.SpliceFloat(posZ); player.playerStatus.room.Broadcast(p); }
public void MsgJoinRoom(Player player, BaseProtocol baseProtocol) { int startIndex = 0; BytesProtocol Protocol = baseProtocol as BytesProtocol; string methodName = Protocol.GetString(startIndex, ref startIndex); int RoomIndex = Protocol.GetInt(startIndex, ref startIndex); Console.WriteLine("[客户端 " + player.name + " ]" + "请求加入房间(MsgJoinRoom):index:" + RoomIndex); Protocol = new BytesProtocol(); Protocol.SpliceString("JoinRoom"); if (RoomIndex < 0 || RoomIndex >= RoomManager.instance.RoomList.Count) { Console.WriteLine("[客户端 " + player.name + " ]" + "请求加入房间(MsgJoinRoom):index:" + RoomIndex + " 超出列表范围"); Protocol.SpliceInt(-1); player.Send(Protocol); return; } Room room = RoomManager.instance.RoomList[RoomIndex]; if (room.status != Room.Status.Preparing) { Console.WriteLine("[客户端 " + player.name + " ]" + "请求加入房间(MsgJoinRoom):index:" + RoomIndex + " 房间正在游玩"); Protocol.SpliceInt(-1); player.Send(Protocol); return; } if (room.AddPlayer(player)) { room.Broadcast(room.GetRoomInfo()); Protocol.SpliceInt(0); player.Send(Protocol); } else { Console.WriteLine("[客户端 " + player.name + " ]" + "请求加入房间(MsgJoinRoom):index:" + RoomIndex + " 房间人数已满"); Protocol.SpliceInt(-1); player.Send(Protocol); } }