public void MsgHit(Player player, ProtocolBase protoBase) { //解析协议 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); string enemyName = protocol.GetString(start, ref start); float damage = protocol.GetFloat(start, ref start); //作弊校验 //long lastShootTime = (long)player.tempData.lastShootTime; //if(Sys.GetTimeStamp()-lastShootTime<1) //{ // Console.WriteLine("MsgHit开炮作弊 " + player.id); // return; //} //player.tempData.lastShootTime = Sys.GetTimeStamp(); //获取房间 if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; //扣除生命值 if (!room.playerList.ContainsKey(enemyName)) { Console.WriteLine("MsgHit not contains enemy" + enemyName); return; } Player enemy = room.playerList[enemyName]; if (enemy == null) { return; } if (enemy.tempData.hp <= 0) { return; } enemy.tempData.hp -= damage; Console.WriteLine("MsgHit " + enemyName + " hp" + enemy.tempData.hp); //广播 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Hit"); protocolRet.AddString(player.id); protocolRet.AddString(enemy.id); protocolRet.AddFloat(damage); room.Broadcast(protocolRet); //胜负判断 room.UpdateWin(); }
public void MsgShooting(Player player, ProtocolBase protoBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); float posX = protocol.GetFloat(start, ref start); float posY = protocol.GetFloat(start, ref start); float posZ = protocol.GetFloat(start, ref start); float rotX = protocol.GetFloat(start, ref start); float rotY = protocol.GetFloat(start, ref start); float rotZ = protocol.GetFloat(start, ref start); //获取房间 if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; //广播 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Shooting"); protocolRet.AddString(player.id); protocolRet.AddFloat(posX); protocolRet.AddFloat(posY); protocolRet.AddFloat(posZ); protocolRet.AddFloat(rotX); protocolRet.AddFloat(rotY); protocolRet.AddFloat(rotZ); room.Broadcast(protocolRet); }
//同步坦克单元 public void MsgUpdateUnitInfo(Player player, ProtocolBase protoBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); float posX = protocol.GetFloat(start, ref start); float posY = protocol.GetFloat(start, ref start); float posZ = protocol.GetFloat(start, ref start); float rotX = protocol.GetFloat(start, ref start); float rotY = protocol.GetFloat(start, ref start); float rotZ = protocol.GetFloat(start, ref start); float gunRot = protocol.GetFloat(start, ref start); float gunRoll = protocol.GetFloat(start, ref start); //获取房间 if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; //作弊校验 略 player.tempData.posX = posX; player.tempData.posY = posY; player.tempData.posZ = posZ; player.tempData.lastUpdateTime = Sys.GetTimeStamp(); //广播 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("UpdateUnitInfo"); protocolRet.AddString(player.id); protocolRet.AddFloat(posX); protocolRet.AddFloat(posY); protocolRet.AddFloat(posZ); protocolRet.AddFloat(rotX); protocolRet.AddFloat(rotY); protocolRet.AddFloat(rotZ); protocolRet.AddFloat(gunRot); protocolRet.AddFloat(gunRoll); room.Broadcast(protocolRet); }
//更新信息 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); }