Esempio n. 1
0
        /// <summary>
        /// Ticks the physics entity, doing nothing at all.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.LoadedChunks.ContainsKey(cpos))
            {
                TheRegion.LoadChunk(cpos);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Ticks the physics entity.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.TryFindChunk(cpos, out Chunk _)) // TODO: is this really needed every tick?
            {
                TheRegion.LoadChunk(cpos);
            }
            if (!GenBlockShadow)// TODO: and world config allows trackables
            {
                if (TheRegion.GetEntitiesInRadius(GetPosition(), 1.5f, EntityType.SMASHER_PRIMTIVE).Count == 0)
                {
                    // TODO: 5 * 60 -> world config
                    TheRegion.SpawnEntity(new SmasherPrimitiveEntity(TheRegion, Math.Min((float)GetScaleEstimate(), 2f), TheRegion.TheWorld.GlobalTickTime + (5 * 60))
                    {
                        Position = GetPosition()
                    });
                }
            }
            // TODO: More genericish
            if (TheRegion.Generator is SphereGeneratorCore)
            {
                Location pos   = new Location(Body.Position);
                double   scale = TheRegion.TheWorld.GeneratorScale;
                Location gravDir;
                if (pos.LengthSquared() > scale * scale)
                {
                    gravDir = new Location(scale / pos.X, scale / pos.Y, scale / pos.Z);
                }
                else
                {
                    gravDir = pos / scale;
                }
                SetGravity(gravDir * (-TheRegion.GravityStrength));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ticks the physics entity.
        /// </summary>
        public override void Tick()
        {
            if (!TheRegion.IsVisible(GetPosition()))
            {
                if (Body.ActivityInformation.IsActive)
                {
                    wasActive = true;
                    // TODO: Is this needed?
                    if (Body.ActivityInformation.SimulationIsland != null)
                    {
                        Body.ActivityInformation.SimulationIsland.IsActive = false;
                    }
                }
            }
            else if (wasActive)
            {
                wasActive = false;
                Body.ActivityInformation.Activate();
            }
            Vector3i cpos = TheRegion.ChunkLocFor(GetPosition());

            if (CanSave && !TheRegion.LoadedChunks.ContainsKey(cpos)) // TODO: is this really needed every tick?
            {
                TheRegion.LoadChunk(cpos);
            }
            // TODO: More genericish
            if (TheRegion.Generator is SphereGeneratorCore)
            {
                Location pos   = new Location(Body.Position);
                double   scale = TheRegion.TheWorld.GeneratorScale;
                Location gravDir;
                if (pos.LengthSquared() > scale * scale)
                {
                    gravDir = new Location(scale / pos.X, scale / pos.Y, scale / pos.Z);
                }
                else
                {
                    gravDir = pos / scale;
                }
                SetGravity(gravDir * (-TheRegion.GravityStrength));
            }
        }
Esempio n. 4
0
        public override void Tick()
        {
            if (TheRegion.IsVisible(GetPosition()))
            {
                bool sme = false;
                SetVelocity(GetVelocity() * 0.99f + Gravity * TheRegion.Delta);
                if (GetVelocity().LengthSquared() > 0)
                {
                    CollisionResult cr  = TheRegion.Collision.CuboidLineTrace(Scale, GetPosition(), GetPosition() + GetVelocity() * TheRegion.Delta, FilterHandle);
                    Location        vel = GetVelocity();
                    if (cr.Hit && Collide != null)
                    {
                        Collide(this, new CollisionEventArgs(cr));
                    }
                    if (!IsSpawned || Removed)
                    {
                        return;
                    }
                    if (vel == GetVelocity())
                    {
                        SetVelocity((cr.Position - GetPosition()) / TheRegion.Delta);
                    }
                    SetPosition(cr.Position);
                    // TODO: Timer
                    if (network)
                    {
                        sme = true;
                    }
                    netdeltat = 2;
                }
                else
                {
                    netdeltat += TheRegion.Delta;
                    if (netdeltat > 2.0)
                    {
                        netdeltat -= 2.0;
                        sme        = true;
                    }
                }
                Location pos = GetPosition();
                PrimitiveEntityUpdatePacketOut primupd = sme ? new PrimitiveEntityUpdatePacketOut(this) : null;
                foreach (PlayerEntity player in TheRegion.Players)
                {
                    bool shouldseec = player.ShouldSeePosition(pos);
                    bool shouldseel = player.ShouldSeePositionPreviously(lPos);
                    if (shouldseec && !shouldseel)
                    {
                        player.Network.SendPacket(GetSpawnPacket());
                    }
                    if (shouldseel && !shouldseec)
                    {
                        player.Network.SendPacket(new DespawnEntityPacketOut(EID));
                    }
                    if (sme && shouldseec)
                    {
                        player.Network.SendPacket(primupd);
                    }
                }
            }
            lPos = GetPosition();
            Vector3i cpos = TheRegion.ChunkLocFor(lPos);

            if (CanSave && !TheRegion.TryFindChunk(cpos, out Chunk _))
            {
                TheRegion.LoadChunk(cpos);
            }
        }