/// <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 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 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); }
/// <summary> /// 玩家一般魔法,起点位置,起点旋转度 /// </summary> /// <param name="player"></param> /// <param name="baseProtocol"></param> public void MsgPlayerMagic(Player player, BaseProtocol baseProtocol) { //玩家魔法 //消息结构: (string)PlayerMagic + (string)magicName + (float)posX + (float)posY +(float)posZ+ (float)rotX + (float)rotY + (float)rotZ //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 magicName = p.GetString(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); float rotX = p.GetFloat(startIndex, ref startIndex); float rotY = p.GetFloat(startIndex, ref startIndex); float rotZ = p.GetFloat(startIndex, ref startIndex); //转发魔法消息 BytesProtocol p_broadcast = new BytesProtocol(); p_broadcast.SpliceString("PlayerMagic"); p_broadcast.SpliceString(magicName); p_broadcast.SpliceFloat(posX); p_broadcast.SpliceFloat(posY); p_broadcast.SpliceFloat(posZ); p_broadcast.SpliceFloat(rotX); p_broadcast.SpliceFloat(rotY); p_broadcast.SpliceFloat(rotZ); room.Broadcast(p_broadcast); }
/// <summary> /// 击中玩家 /// </summary> public void MsgPlayerHitSomeone(Player player, BaseProtocol baseProtocol) { //击中玩家协议 //消息结构:(string)PlayerHitSomeone + (string)PlayerName + (float)Damage //玩家不在游戏状态,当没事发生 Room room = player.playerStatus.room; int startIndex = 0; BytesProtocol p = baseProtocol as BytesProtocol; p.GetString(startIndex, ref startIndex); string HitplayerName = p.GetString(startIndex, ref startIndex); float Damage = p.GetFloat(startIndex, ref startIndex); if (room.playerDict.ContainsKey(HitplayerName)) { lock (room.playerDict) { //扣血操作 room.playerDict[HitplayerName].playerStatus.HP -= Damage; //死亡后自动离开房间 if (room.playerDict[HitplayerName].playerStatus.HP <= 0) { //玩家死亡协议 //消息结构:(string)PlayerKilled + (string)Killer + (string)KilledPlayer BytesProtocol deadProtool = new BytesProtocol(); deadProtool.SpliceString("PlayerKilled"); deadProtool.SpliceString(player.name); deadProtool.SpliceString(HitplayerName); room.Broadcast(deadProtool); RoomManager.instance.LeaveRoom(room.playerDict[HitplayerName]); } } } else { //玩家不在房间中,返回 return; } room.PlayerSuccess(); }
/// <summary> /// 更新玩家信息 /// </summary> public void MsgUpdatePlayerInfo(Player player, BaseProtocol baseProtocol) { //if (player.playerStatus.status != PlayerStatus.Status.Gaming) //{ // return; //} BytesProtocol p = baseProtocol as BytesProtocol; int startIndex = 0; p.GetString(startIndex, ref startIndex); float posX = p.GetFloat(startIndex, ref startIndex); float posY = p.GetFloat(startIndex, ref startIndex); float posZ = p.GetFloat(startIndex, ref startIndex); float rotX = p.GetFloat(startIndex, ref startIndex); float rotY = p.GetFloat(startIndex, ref startIndex); float rotZ = p.GetFloat(startIndex, ref startIndex); string CurrentAction = p.GetString(startIndex, ref startIndex); player.playerStatus.posX = posX; player.playerStatus.posY = posY; player.playerStatus.posZ = posZ; player.playerStatus.CurrentAction = CurrentAction; player.playerStatus.LastUpdateTime = Utility.GetTimeStamp(); BytesProtocol protocolReturn = new BytesProtocol(); protocolReturn.SpliceString("UpdatePlayerInfo"); protocolReturn.SpliceString(player.name); protocolReturn.SpliceFloat(player.playerStatus.HP); protocolReturn.SpliceFloat(posX); protocolReturn.SpliceFloat(posY); protocolReturn.SpliceFloat(posZ); protocolReturn.SpliceFloat(rotX); protocolReturn.SpliceFloat(rotY); protocolReturn.SpliceFloat(rotZ); protocolReturn.SpliceString(CurrentAction); player.playerStatus.room.Broadcast(protocolReturn); }