ReadTime() public method

Reads a value, in local time comparable to NetTime.Now, written using WriteTime() Must have a connected sender
public ReadTime ( bool highPrecision ) : double
highPrecision bool
return double
Esempio n. 1
0
 // TODO: Merge opcodes for move direction, something like that: Move(LookDirection)
 void DataProcessing(NetIncomingMessage message, ref Client client)
 {
     switch (message.ReadByte())
     {
         case (byte)MessageType.ClientMessage.NeedMap:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Need map ! Let's give it to him :)");
             ReceiveNeedMap(client);
             break;
         case (byte)MessageType.ClientMessage.MapSelection:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Has selected a map to play ! :)");
             ReceiveMapSelection(client, message.ReadString());
             break;
         case (byte)MessageType.ClientMessage.Credentials:
             ReceiveCredentials(client, message.ReadString(), message.ReadString());
             break;
         case (byte)MessageType.ClientMessage.Ready:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Ready message !");
             ReceiveReady(client, message.ReadBoolean());
             break;
         case (byte)MessageType.ClientMessage.WantToStartGame:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] WantToStartGame message !");
             ReceiveWantToStartGame();
             break;
         case (byte)MessageType.ClientMessage.HasMap:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] HasMap message !");
             ReceiveHasMap(client);
             break;
         case (byte)MessageType.ClientMessage.MoveDown:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to move down !");
             ReceiveMovePlayer(client, LookDirection.Down);
             break;
         case (byte)MessageType.ClientMessage.MoveLeft:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to move left !");
             ReceiveMovePlayer(client, LookDirection.Left);
             break;
         case (byte)MessageType.ClientMessage.MoveRight:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to move right !");
             ReceiveMovePlayer(client, LookDirection.Right);
             break;
         case (byte)MessageType.ClientMessage.MoveUp:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to move up !");
             ReceiveMovePlayer(client, LookDirection.Up);
             break;
         case (byte)MessageType.ClientMessage.Standing:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to stay here !");
             ReceiveMovePlayer(client, LookDirection.Idle, message.ReadTime(client.ClientConnection, true));
             break;
         case (byte)MessageType.ClientMessage.PlaceBomb:
             Program.Log.Info("[RECEIVE][Client #" + client.ClientId + "] Want to place bomb !");
             ReceiveBombPlacing(client);
             break;
     }
 }
        private void ReadPlayerState(NetIncomingMessage msg, Player p)
        {
            bool alive = msg.ReadBoolean();
            if (alive)
            {
                float px = msg.ReadFloat();
                float py = msg.ReadFloat();
                bool moving = msg.ReadBoolean();
                Direction direction = (Direction)msg.ReadByte();
                float speed = msg.ReadFloat();

                // player state
                p.UpdateFromNetwork(px, py, moving, direction, speed);

                // powerups
                int powerupsCount = (int)Powerups.Count;
                for (int i = 0; i < powerupsCount; ++i)
                {
                    bool hasPower = msg.ReadBoolean();
                    if (hasPower)
                    {
                        int count = msg.ReadByte();
                        p.powerups.SetCount(i, count);
                    }
                    else
                    {
                        p.powerups.SetCount(i, 0);
                    }
                }

                // diseases
                int diseasesCount = DiseaseList.diseaseArray.Length;
                for (int i = 0; i < diseasesCount; ++i)
                {
                    bool infected = msg.ReadBoolean();
                    if (infected)
                    {
                        float remains = (float)(msg.ReadTime(false) - NetTime.Now);
                        p.diseases.TryInfect(i);
                        p.diseases.SetInfectedRemains(i, remains);
                    }
                    else
                    {
                        p.diseases.TryCure(i);
                    }
                }
            }
            else if (p.IsAlive)
            {
                Field.KillPlayer(p);
            }

            Bomb[] bombs = p.bombs.array;
            for (int i = 0; i < bombs.Length; ++i)
            {
                ReadBombState(msg, p, bombs[i]);
            }
        }
        private void ReadBombState(NetIncomingMessage msg, Player p, Bomb b)
        {
            bool active = msg.ReadBoolean();
            if (active)
            {
                float remains = (float)(msg.ReadTime(false) - NetTime.Now);
                float px = msg.ReadFloat();
                float py = msg.ReadFloat();
                Direction dir = (Direction)msg.ReadByte();
                float speed = msg.ReadFloat();
                bool jelly = msg.ReadBoolean();
                bool trigger = msg.ReadBoolean();

                if (!b.isActive)
                {
                    b.player = p;
                    b.Activate();
                    game.Field.SetBomb(b);
                }

                b.timeRemains = remains;
                b.SetPos(px, py);
                b.SetSpeed(speed);
                b.SetJelly(jelly);
                b.SetTrigger(trigger);
                // TODO: jelly & trigger
            }
            else if (b.isActive)
            {
                b.Deactivate();
                b.RemoveFromField();
            }
        }