Пример #1
0
        /// <summary>
        /// For debugging of flight-path and rotation.
        /// </summary>
        private void BroadcastMoveAndMotion()
        {
            if (new Random().Next(5) == 0)
            {
                McpeSetEntityMotion motions = McpeSetEntityMotion.CreateObject();
                motions.runtimeEntityId = EntityId;
                motions.velocity        = Velocity;
                //new Task(() => Level.RelayBroadcast(motions)).Start();
                Level.RelayBroadcast(motions);
            }

            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();

            moveEntity.runtimeEntityId = EntityId;
            moveEntity.position        = KnownPosition;
            Level.RelayBroadcast(moveEntity);

            if (Shooter != null && IsCritical)
            {
                var p = Shooter as Player;

                if (p != null)
                {
                    var particle = new CriticalParticle(Level);
                    particle.Position = KnownPosition.ToVector3();
                    particle.Spawn(new[] { p });
                }
            }
        }
Пример #2
0
 public void BroadcastMove(bool forceMove = false)
 {
     if (NoAi || forceMove)
     {
         McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();
         moveEntity.runtimeEntityId = EntityId;
         moveEntity.position        = KnownPosition;
         moveEntity.Encode();
         Level.RelayBroadcast(moveEntity);
     }
 }
Пример #3
0
 public void BroadcastMove(bool forceMove = false)
 {
     if (NoAi || forceMove)
     {
         McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();
         moveEntity.runtimeEntityId = EntityId;
         moveEntity.position        = (PlayerLocation)KnownPosition.Clone();
         moveEntity.onGround        = IsOnGround;
         moveEntity.Encode();
         Level.RelayBroadcast(moveEntity);
     }
 }
Пример #4
0
        public override void HandleMcpeMoveEntity(McpeMoveEntity message)
        {
            if (message.runtimeEntityId != Client.EntityId)
            {
                BaseClient.WorldReceiver.UpdateEntityPosition(message.runtimeEntityId,
                                                              new PlayerLocation(message.position.X, message.position.Y - Player.EyeLevel, message.position.Z,
                                                                                 message.position.HeadYaw, message.position.Yaw, message.position.Pitch));
                return;
            }

            // BaseClient.WorldReceiver.UpdateEntityPosition(message.runtimeEntityId, new PlayerLocation(message.position), true, true, true);
            UnhandledPackage(message);
        }
Пример #5
0
        public Packet HandleIncoming(McpeMovePlayer packet, Player player)
        {
            if (_playerEntities.ContainsKey(player))
            {
                var entity = _playerEntities[player];
                entity.KnownPosition = player.KnownPosition;
                var message = McpeMoveEntity.CreateObject();
                message.runtimeEntityId = entity.EntityId;
                message.position        = entity.KnownPosition;
                player.Level.RelayBroadcast(message);
            }

            return(packet);            // Process
        }
Пример #6
0
        public Package HandleIncoming(McpeMovePlayer packet, Player player)
        {
            if (_playerEntities.ContainsKey(player))
            {
                var entity = _playerEntities[player];
                entity.KnownPosition = player.KnownPosition;
                var message = McpeMoveEntity.CreateObject();
                message.entities = new EntityLocations();
                message.entities.Add(entity.EntityId, entity.KnownPosition);
                player.Level.RelayBroadcast(message);
            }

            return(packet);            // Process
        }
Пример #7
0
        public Package HandleIncoming(McpeMovePlayer packet, Player player)
        {
            if (_playerEntities.ContainsKey(player))
            {
                var entity = _playerEntities[player];
                entity.KnownPosition = player.KnownPosition;
                var message = new McpeMoveEntity();
                message.entities = new EntityLocations();
                message.entities.Add(entity.EntityId, entity.KnownPosition);
                player.Level.RelayBroadcast(message);
            }

            return packet; // Process
        }
Пример #8
0
        /// <summary>
        /// For debugging of flight-path and rotation.
        /// </summary>
        private void BroadcastMoveAndMotion()
        {
            McpeSetEntityMotion motions = McpeSetEntityMotion.CreateObject();

            motions.entityId = EntityId;
            motions.velocity = Velocity;
            new Task(() => Level.RelayBroadcast(motions)).Start();

            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();

            moveEntity.entityId = EntityId;
            moveEntity.position = KnownPosition;
            new Task(() => Level.RelayBroadcast(moveEntity)).Start();
        }
Пример #9
0
        /// <summary>
        /// For debugging of flight-path and rotation.
        /// </summary>
        private void BroadcastMoveAndMotion()
        {
            McpeSetEntityMotion motions = McpeSetEntityMotion.CreateObject();

            motions.entities = new EntityMotions {
                { EntityId, Velocity }
            };
            new Task(() => Level.RelayBroadcast(motions)).Start();

            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();

            moveEntity.entities = new EntityLocations {
                { EntityId, KnownPosition }
            };
            new Task(() => Level.RelayBroadcast(moveEntity)).Start();
        }
Пример #10
0
        public override void OnTick()
        {
            base.OnTick();

            if (Velocity.Distance > 0)
            {
                PlayerLocation oldPosition    = (PlayerLocation)KnownPosition.Clone();
                var            onGroundBefore = IsOnGround(KnownPosition);

                KnownPosition.X += (float)Velocity.X;
                KnownPosition.Y += (float)Velocity.Y;
                KnownPosition.Z += (float)Velocity.Z;

                var onGround = IsOnGround(KnownPosition);
                if (!onGroundBefore && onGround)
                {
                    KnownPosition.Y = (float)Math.Floor(oldPosition.Y);
                    Velocity        = Vector3.Zero;
                }
                else
                {
                    Velocity *= (1.0 - Drag);
                    Velocity -= new Vector3(0, Gravity, 0);
                }
            }

            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();

            moveEntity.entities = new EntityLocations {
                { EntityId, KnownPosition }
            };
            Level.RelayBroadcast(moveEntity);

            McpeSetEntityMotion motions = McpeSetEntityMotion.CreateObject();

            motions.entities = new EntityMotions {
                { EntityId, Velocity }
            };
            Level.RelayBroadcast(motions);
        }
Пример #11
0
        protected override void BroadCastMovement(Player[] players, Player[] updatedPlayers)
        {
            if (updatedPlayers.Length == 0)
            {
                return;
            }

            var moveEntity = McpeMoveEntity.CreateObject(players.Count());

            moveEntity.entities = new EntityLocations();

            //var rotateHead = McpeRotateHead.CreateObject(players.Count());
            //rotateHead.entities = new EntityHeadRotations();

            foreach (var player in updatedPlayers)
            {
                Entity entity;
                if (!_playerEntities.TryGetValue(player, out entity))
                {
                    continue;
                }

                entity.KnownPosition = (PlayerLocation)player.KnownPosition.Clone();
                if (entity.EntityTypeId == 10)
                {
                    //BUG: Duck has it's value reversed
                    entity.KnownPosition.Pitch = -player.KnownPosition.Pitch;
                }
                moveEntity.entities.Add(entity.EntityId, entity.KnownPosition);
                //rotateHead.entities.Add(entity.EntityId, entity.KnownPosition);
            }

            moveEntity.Encode();
            //rotateHead.Encode();

            new Task(() => RelayBroadcast(moveEntity)).Start();
            //new Task(() => RelayBroadcast(rotateHead)).Start();
        }
Пример #12
0
        protected virtual void BroadCastMovement(Player[] players, Entity[] entities)
        {
            DateTime now = DateTime.UtcNow;

            if (players.Length == 0)
            {
                return;
            }

            if (players.Length <= 1 && entities.Length == 0)
            {
                return;
            }

            if (now - _lastBroadcast < TimeSpan.FromMilliseconds(50))
            {
                return;
            }

            DateTime tickTime = _lastSendTime;

            _lastSendTime = DateTime.UtcNow;

            using (MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream())
            {
                int playerMoveCount = 0;
                int entiyMoveCount  = 0;

                foreach (var player in players)
                {
                    if (now - player.LastUpdatedTime <= now - tickTime)
                    {
                        PlayerLocation knownPosition = player.KnownPosition;

                        McpeMovePlayer move = McpeMovePlayer.CreateObject();
                        move.entityId = player.EntityId;
                        move.x        = knownPosition.X;
                        move.y        = knownPosition.Y + 1.62f;
                        move.z        = knownPosition.Z;
                        move.yaw      = knownPosition.Yaw;
                        move.pitch    = knownPosition.Pitch;
                        move.headYaw  = knownPosition.HeadYaw;
                        move.mode     = 0;
                        byte[] bytes = move.Encode();
                        BatchUtils.WriteLength(stream, bytes.Length);
                        stream.Write(bytes, 0, bytes.Length);
                        move.PutPool();
                        playerMoveCount++;
                    }
                }

                foreach (var entity in entities)
                {
                    if (now - entity.LastUpdatedTime <= now - tickTime)
                    {
                        {
                            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();
                            moveEntity.entityId    = entity.EntityId;
                            moveEntity.position    = (PlayerLocation)entity.KnownPosition.Clone();
                            moveEntity.position.Y += entity.PositionOffset;
                            byte[] bytes = moveEntity.Encode();
                            BatchUtils.WriteLength(stream, bytes.Length);
                            stream.Write(bytes, 0, bytes.Length);
                            moveEntity.PutPool();
                        }
                        {
                            McpeSetEntityMotion entityMotion = McpeSetEntityMotion.CreateObject();
                            entityMotion.entityId = entity.EntityId;
                            entityMotion.velocity = entity.Velocity;
                            byte[] bytes = entityMotion.Encode();
                            BatchUtils.WriteLength(stream, bytes.Length);
                            stream.Write(bytes, 0, bytes.Length);
                            entityMotion.PutPool();
                        }
                        entiyMoveCount++;
                    }
                }

                if (playerMoveCount == 0 && entiyMoveCount == 0)
                {
                    return;
                }

                if (players.Length == 1 && entiyMoveCount == 0)
                {
                    return;
                }

                McpeBatch batch = BatchUtils.CreateBatchPacket(stream.GetBuffer(), 0, (int)stream.Length, CompressionLevel.Optimal, false);
                batch.AddReferences(players.Length - 1);
                batch.Encode();
                //batch.ValidUntil = now + TimeSpan.FromMilliseconds(50);
                foreach (var player in players)
                {
                    MiNetServer.FastThreadPool.QueueUserWorkItem(() => player.SendPackage(batch));
                }
                _lastBroadcast = DateTime.UtcNow;
            }
        }
Пример #13
0
        protected virtual void BroadCastMovement(Player[] players, Entity[] entities)
        {
            if (players.Length == 0)
            {
                return;
            }

            DateTime tickTime = _lastSendTime;

            _lastSendTime = DateTime.UtcNow;
            DateTime now = DateTime.UtcNow;

            MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream();

            int            count = 0;
            McpeMovePlayer move  = McpeMovePlayer.CreateObject();

            foreach (var player in players)
            {
                if (((now - player.LastUpdatedTime) <= now - tickTime))
                {
                    PlayerLocation knownPosition = player.KnownPosition;

                    move.entityId = player.EntityId;
                    move.x        = knownPosition.X;
                    move.y        = knownPosition.Y + 1.62f;
                    move.z        = knownPosition.Z;
                    move.yaw      = knownPosition.Yaw;
                    move.pitch    = knownPosition.Pitch;
                    move.headYaw  = knownPosition.HeadYaw;
                    move.mode     = 0;
                    byte[] bytes = move.Encode();
                    stream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4);
                    stream.Write(bytes, 0, bytes.Length);
                    move.Reset();
                    count++;
                }
            }
            move.PutPool();

            McpeMoveEntity moveEntity = McpeMoveEntity.CreateObject();

            moveEntity.entities = new EntityLocations();

            McpeSetEntityMotion entityMotion = McpeSetEntityMotion.CreateObject();

            entityMotion.entities = new EntityMotions();

            foreach (var entity in entities)
            {
                if (((now - entity.LastUpdatedTime) <= now - tickTime))
                {
                    moveEntity.entities.Add(entity.EntityId, entity.KnownPosition);
                    entityMotion.entities.Add(entity.EntityId, entity.Velocity);
                    count++;
                }
            }

            if (moveEntity.entities.Count > 0)
            {
                byte[] bytes = moveEntity.Encode();
                stream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4);
                stream.Write(bytes, 0, bytes.Length);
            }
            moveEntity.PutPool();

            if (moveEntity.entities.Count > 0)
            {
                byte[] bytes = entityMotion.Encode();
                stream.Write(BitConverter.GetBytes(Endian.SwapInt32(bytes.Length)), 0, 4);
                stream.Write(bytes, 0, bytes.Length);
            }
            entityMotion.PutPool();

            if (count == 0)
            {
                return;
            }

            McpeBatch batch = McpeBatch.CreateObject(players.Length);

            byte[] buffer = Player.CompressBytes(stream.ToArray(), CompressionLevel.Optimal);
            batch.payloadSize = buffer.Length;
            batch.payload     = buffer;
            batch.Encode(true);

            foreach (var player in players)
            {
                Task sendTask = new Task(obj => ((Player)obj).SendMoveList(batch, now), player);
                sendTask.Start();
            }
        }
Пример #14
0
 public virtual void HandleMcpeMoveEntity(McpeMoveEntity message)
 {
 }
 public abstract void HandleMcpeMoveEntity(McpeMoveEntity message);
Пример #16
0
 public override void HandleMcpeMoveEntity(McpeMoveEntity message)
 {
 }