示例#1
0
        protected virtual void BuildTransmission(ref ByteBuffer.ByteBuffer buffer)
        {
            buffer.WriteInteger(Entity_ID);
            buffer.WriteFloat(_position.x);
            buffer.WriteFloat(_position.y);
            buffer.WriteFloat(_position.z);
            buffer.WriteFloat(_r);
            buffer.WriteFloat(_vx);
            buffer.WriteFloat(_vy);
            buffer.WriteFloat(_vz);
            buffer.WriteInteger(current_HP);
            bool b3    = false;
            bool b4    = false;
            bool b5    = false;
            bool b6    = false;
            bool b7    = false;
            byte bools = BitwiseRefinement.BoolsToByte
                         (
                AnimState.Attacking,
                AnimState.Attacked,
                AnimState.Dead,
                b3,
                b4,
                b5,
                b6,
                b7
                         );

            buffer.WriteByte(bools);
            switch (type)
            {
            case EntityType.Player:
                buffer.WriteFloat(AnimState.Forward);
                buffer.WriteFloat(AnimState.Turn);
                buffer.WriteByte((byte)((AnimState.Crouch) ? 1 : 0));
                buffer.WriteByte((byte)((AnimState.OnGround) ? 1 : 0));
                buffer.WriteFloat(AnimState.Jump);
                buffer.WriteFloat(AnimState.JumpLeg);
                buffer.WriteByte((byte)((AnimState.Cast) ? 1 : 0));
                break;

            case EntityType.NPC:
                break;

            default:
                break;
            }
            buffer.WriteInteger((int)_TargetType);
            buffer.WriteInteger(_TargetID);
            buffer.WriteByte(inCombat ? (byte)1 : (byte)0);
        }
示例#2
0
        private static void Update(ConnectionType type, int index, byte[] data)
        {
            ByteBuffer.ByteBuffer buffer = new ByteBuffer.ByteBuffer();
            if (data.Length == 105)
            {
                buffer.WriteBytes(data);
                ReadHeader(ref buffer);
                // Connectivity Statistics
                Client client = Network.instance.Clients[index];
                client.TCP_Throughput = buffer.ReadFloat();
                client.TCP_SetLatency(buffer.ReadFloat());
                client.TCP_PacketsReceived = buffer.ReadInteger();
                client.UDP_Throughput      = buffer.ReadFloat();
                client.UDP_SetLatency(buffer.ReadFloat());
                client.UDP_PacketsReceived = buffer.ReadInteger();

                // ID
                int Character_ID = buffer.ReadInteger();
                // Position
                float X = buffer.ReadFloat();
                float Y = buffer.ReadFloat();
                float Z = buffer.ReadFloat();
                float R = buffer.ReadFloat();
                // Velocity
                float vx = buffer.ReadFloat();
                float vy = buffer.ReadFloat();
                float vz = buffer.ReadFloat();
                // Camera Position
                float cX = buffer.ReadFloat();
                float cY = buffer.ReadFloat();
                float cZ = buffer.ReadFloat();
                float cR = buffer.ReadFloat();
                // Animation State
                float Forward   = buffer.ReadFloat();
                float Turn      = buffer.ReadFloat();
                float Jump      = buffer.ReadFloat();
                float JumpLeg   = buffer.ReadFloat();
                byte  bools     = buffer.ReadByte();
                bool  Crouch    = false;
                bool  OnGround  = false;
                bool  Attacking = false;
                bool  Dead      = false;
                bool  Attacked  = false;
                bool  Cast      = false;
                bool  b6        = false; // Unused
                bool  b7        = false; // Unused
                BitwiseRefinement.ByteToBools(bools, out Crouch, out OnGround, out Attacking, out Dead, out Attacked, out Cast, out b6, out b7);
                // Target
                EntityType TargetType = (EntityType)buffer.ReadInteger();
                int        TargetID   = buffer.ReadInteger();

                if (World.instance.players.ContainsKey(Character_ID))
                {
                    Player player = World.instance.players[Character_ID];
                    // Position
                    player.position.x = X;
                    player.position.y = Y;
                    player.position.z = Z;
                    player.r          = R;
                    // Velocity
                    player.vx = vx;
                    player.vy = vy;
                    player.vz = vz;
                    // Camera Position and Rotation
                    player.Camera_Pos_X      = cX;
                    player.Camera_Pos_Y      = cY;
                    player.Camera_Pos_Z      = cZ;
                    player.Camera_Rotation_Y = cR;
                    // Animations
                    player.AnimState.Forward   = Forward;
                    player.AnimState.Turn      = Turn;
                    player.AnimState.Jump      = Jump;
                    player.AnimState.JumpLeg   = JumpLeg;
                    player.AnimState.Crouch    = Crouch;
                    player.AnimState.OnGround  = OnGround;
                    player.AnimState.Attacking = Attacking;
                    player.AnimState.Dead      = Dead;
                    player.AnimState.Attacked  = Attacked;
                    player.AnimState.Cast      = Cast;
                    // Target
                    player.TargetType = TargetType;
                    player.TargetID   = TargetID;
                    SendData.UpdatePlayerData(player);
                }
            }
        }