Example #1
0
        public override void OnTick()
        {
            TimeToLive--;

            if (TimeToLive <= 0)
            {
                DespawnEntity(null);
                return;
            }

            var players = Level.GetOnlinePlayers;

            foreach (var player in players)
            {
                if (KnownPosition.DistanceTo(player.KnownPosition) <= 1.8)
                {
                    player.Inventory.AddItem(Item.ItemId, Item.MetaData);

                    DespawnEntity(player);
                    break;
                }
                new EntityTeleport(player.Wrapper)
                {
                    UniqueServerId = EntityId,
                    Coordinates    = KnownPosition.ToVector3(),
                    Yaw            = (byte)KnownPosition.Yaw,
                    Pitch          = (byte)KnownPosition.Pitch,
                    OnGround       = true
                }.Write();
            }
        }
        public override void OnTick(Entity[] entities)
        {
            TimeToLive--;
            PickupDelay--;

            if (TimeToLive <= 0)
            {
                DespawnEntity();
                return;
            }

            if (PickupDelay > 0)
            {
                return;
            }

            var players = Level.GetSpawnedPlayers();

            foreach (SkyPlayer player in players)
            {
                if (!player.IsGameSpectator && KnownPosition.DistanceTo(player.KnownPosition) <= 2)
                {
                    GameState.AddPlayerGunParts((MurderLevel)Level, player);

                    GameState.GunParts.Remove(SpawnLocation);

                    DespawnEntity();
                    break;
                }
            }
        }
Example #3
0
        public override void OnTick()
        {
            base.OnTick();

            TimeToLive--;
            PickupDelay--;

            if (TimeToLive <= 0)
            {
                DespawnEntity();
                return;
            }

            // Motion



            if (PickupDelay > 0)
            {
                return;
            }

            var players = Level.GetSpawnedPlayers();

            foreach (var player in players)
            {
                if (KnownPosition.DistanceTo(player.KnownPosition) <= 2)
                {
                    if (player.GameMode == GameMode.Survival)
                    {
                        //Add the items to the inventory if posible
                        if (player.Inventory.SetFirstEmptySlot((short)Item.Id, (byte)Count, Item.Metadata))
                        {
                            //BUG: If this is sent, the client crashes for some unknown reason.
                            var takeItemEntity = McpeTakeItemEntity.CreateObject();
                            takeItemEntity.entityId = EntityId;
                            takeItemEntity.target   = player.EntityId;

                            Level.RelayBroadcast(takeItemEntity);
                            DespawnEntity();
                            break;
                        }
                    }
                }
            }
        }
Example #4
0
        public override void OnTick()
        {
            base.OnTick();

            TimeToLive--;
            PickupDelay--;

            if (TimeToLive <= 0)
            {
                DespawnEntity();
                return;
            }

            if (PickupDelay > 0)
            {
                return;
            }

            var players = Level.GetSpawnedPlayers();

            foreach (var player in players)
            {
                if (KnownPosition.DistanceTo(player.KnownPosition) <= 1)
                {
                    //BUG: If this is sent, the client crashes for some unknown reason.
                    Level.RelayBroadcast(new McpeTakeItemEntity()
                    {
                        //entityId = player.EntityId,
                        //target = EntityId
                        entityId = EntityId,
                        target   = player.EntityId
                    });
                    player.Inventory.SetFirstEmptySlot((short)Item.Id, (byte)Count, Item.Metadata);                     //Add the items to the inventory

                    DespawnEntity();
                    break;
                }
            }
        }
Example #5
0
        public override void OnTick()
        {
            if (Velocity == Vector3.Zero)
            {
                // Object was resting and now someone removed the block on which it was resting
                // or someone places a block over it.
                if (IsMobInGround(KnownPosition))
                {
                    Velocity += new Vector3(0, (float)Gravity, 0);
                }
                else
                {
                    bool onGround = IsMobOnGround(KnownPosition);
                    if (!onGround)
                    {
                        Velocity -= new Vector3(0, (float)Gravity, 0);
                    }
                }
            }

            if (Velocity.Length() > 0.01)
            {
                bool onGroundBefore = IsMobOnGround(KnownPosition);

                if (IsMobInGround(KnownPosition))
                {
                    Velocity        += new Vector3(0, (float)Gravity, 0);
                    KnownPosition.X += Velocity.X;
                    KnownPosition.Y += Velocity.Y;
                    KnownPosition.Z += Velocity.Z;
                    BroadcastMove();
                    BroadcastMotion();
                    return;
                }

                Vector3 adjustedVelocity = GetAdjustedLengthFromCollision(Velocity);

                KnownPosition.X += adjustedVelocity.X;
                KnownPosition.Y += adjustedVelocity.Y;
                KnownPosition.Z += adjustedVelocity.Z;

                BroadcastMove();
                BroadcastMotion();

                bool adjustAngle = adjustedVelocity != Velocity;
                if (adjustAngle)
                {
                    CheckBlockAhead();
                }

                bool onGround = IsMobOnGround(KnownPosition);

                if (!onGroundBefore && onGround)
                {
                    float ff = 0.6f * 0.98f;
                    Velocity *= new Vector3(ff, 0, ff);
                }
                else
                {
                    Velocity *= (float)(1.0 - Drag);

                    if (!onGround)
                    {
                        Velocity -= new Vector3(0, (float)Gravity, 0);
                    }
                    else
                    {
                        float ff = 0.6f * 0.98f;
                        Velocity *= new Vector3(ff, 0, ff);
                    }
                }
            }
            else if (Velocity != Vector3.Zero)
            {
                KnownPosition.X += (float)Velocity.X;
                KnownPosition.Y += (float)Velocity.Y;
                KnownPosition.Z += (float)Velocity.Z;

                Velocity        = Vector3.Zero;
                LastUpdatedTime = DateTime.UtcNow;
                NoAi            = true;
                BroadcastMove(true);
                BroadcastMotion(true);
            }

            TimeToLive--;
            PickupDelay--;

            if (TimeToLive <= 0)
            {
                DespawnEntity();
                return;
            }

            // Motion


            if (PickupDelay > 0)
            {
                return;
            }

            var players = Level.GetSpawnedPlayers();

            foreach (var player in players)
            {
                if (player.GameMode != GameMode.Spectator && KnownPosition.DistanceTo(player.KnownPosition) <= 2)
                {
                    {
                        var takeItemEntity = McpeTakeItemEntity.CreateObject();
                        takeItemEntity.runtimeEntityId = EntityId;
                        takeItemEntity.target          = player.EntityId;
                        Level.RelayBroadcast(player, takeItemEntity);
                    }
                    {
                        var takeItemEntity = McpeTakeItemEntity.CreateObject();
                        takeItemEntity.runtimeEntityId = EntityId;
                        takeItemEntity.target          = EntityManager.EntityIdSelf;
                        player.SendPackage(takeItemEntity);
                    }

                    DespawnEntity();
                    break;
                }
            }
        }