public void Shoot(Vector3 position, Vector3 target) { Packet.Builder requestBuilder = GetRequestHeader(PacketType.FLOODING, Endpoint.SHOOT, 1); Debug.DrawRay(position, 10 * target, Color.red, 5); if (Physics.Raycast(position, target, out RaycastHit hit)) { requestBuilder.AddByte((byte)hit.collider.gameObject.GetComponent <Enemy>().GetID()); } else { requestBuilder.AddByte((byte)255); } Packet request = requestBuilder.Build(); packets.Add(sequence - 1, request); output.Write(request); }
/** * Devuelve la representación en forma de paquete de bytes de esta snapshot. */ public Packet ToPacket() { Packet.Builder builder = new Packet.Builder(13 + 72 * players) .AddPacketType(PacketType.SNAPSHOT) .AddInteger(sequence) .AddFloat(timestamp) .AddInteger(players); for (int k = 0; k < players; ++k) { builder.AddInteger(ids[k]) .AddInteger(acks[k]) .AddInteger(lifes[k]) .AddVector(positions[k]) .AddQuaternion(rotations[k]) .AddFloat(gFuses[k]) .AddVector(gPositions[k]) .AddQuaternion(gRotations[k]); } // Otros datos... return(builder.Build()); }
/** * Mueve un jugador en alguna dirección. No maneja el 'straferunning'. Se * encarga de aplicar predicción, en caso de que esté habilitada. */ public void Move(List <Direction> directions) { BitBuffer bb = new BitBuffer(); float Δt = Time.deltaTime; if (config.usePrediction) { predictor.PredictMove(directions, Δt); predictor.SaveState(sequence); } bb.PutFloat(Δt, 0, 1, 0.0001f); bb.PutInt(directions.Count, 0, 10); Packet.Builder builder = GetRequestHeader(PacketType.FLOODING, Endpoint.MOVE, 8 + directions.Count); foreach (Direction direction in directions) { bb.PutDirection(direction); } builder.AddBitBuffer(bb); Packet request = builder.Build(); packets.Add(sequence - 1, request); output.Write(request); }
public void Put(byte[] buff, int size) { byte[] test = new byte[size]; //Array.Copy( buff, 0, test, 0, size ); //System.Console.WriteLine( "Read Buffer : {0}", BitConverter.ToString( test ) ); //System.Console.WriteLine(); for (int i = 0; i < size; i++) { if (buff[i] == Const.PK_STX) { // packet start mBuffer = new ByteUtil(); IsEscape = false; } else if (buff[i] == Const.PK_ETX) { // end of packet Packet.Builder builder = new Packet.Builder(); int cmd = mBuffer.GetByteToInt(); string cmdstr = Enum.GetName(typeof(Cmd), cmd); int result_size = cmdstr != null && cmdstr.EndsWith("RESPONSE") ? 1 : 0; int result = result_size > 0 ? mBuffer.GetByteToInt() : -1; int length = mBuffer.GetUShort(); byte[] data = mBuffer.GetBytes(); //System.Console.WriteLine( "length : {0}, data : {1}", length, data.Length ); builder.cmd(cmd) .result(result) .data(data); //System.Console.WriteLine( "Read Packet : {0}", BitConverter.ToString( data ) ); //System.Console.WriteLine(); mBuffer.Clear(); mBuffer = null; PacketCreated(this, new PacketEventArgs(builder.Build())); IsEscape = false; } else if (buff[i] == Const.PK_DLE) { if (i < size - 1) { mBuffer.Put((byte)(buff[++i] ^ 0x20)); } else { IsEscape = true; } } else if (IsEscape) { mBuffer.Put((byte)(buff[i] ^ 0x20)); IsEscape = false; } else { mBuffer.Put(buff[i]); } } }