Пример #1
0
        public void PlayRelevantSounds()
        {
            if (SoundTimeout > 0)
            {
                SoundTimeout -= TheRegion.Delta;
                return;
            }
            Location vel = GetVelocity();

            if (vel.LengthSquared() < 0.2)
            {
                return;
            }
            Material      mat   = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f));
            MaterialSound sound = mat.Sound();

            if (sound == MaterialSound.NONE)
            {
                return;
            }
            double velLen = vel.Length();

            new DefaultSoundPacketIn()
            {
                TheClient = TheClient
            }.PlayDefaultBlockSound(GetPosition(), sound, 1f, 0.14f * (float)velLen);
            TheClient.Particles.Steps(GetPosition(), mat, GetVelocity(), (float)velLen);
            SoundTimeout = (Utilities.UtilRandom.NextDouble() * 0.2 + 1.0) / velLen;
        }
Пример #2
0
        public void SetMoveSpeed(CharacterController cc, UserInputSet uis)
        {
            float speedmod = (float)new Vector2(uis.XMove, uis.YMove).Length() * 2;

            speedmod *= (1f + uis.SprintOrWalk * 0.5f);
            if (Click)
            {
                ItemStack  item = TheClient.GetItemForSlot(TheClient.QuickBarPos);
                bool       has  = item.SharedAttributes.ContainsKey("charge");
                BooleanTag bt   = has ? BooleanTag.TryFor(item.SharedAttributes["charge"]) : null;
                if (bt != null && bt.Internal && item.SharedAttributes.ContainsKey("cspeedm"))
                {
                    NumberTag nt = NumberTag.TryFor(item.SharedAttributes["cspeedm"]);
                    if (nt != null)
                    {
                        speedmod *= (float)nt.Internal;
                    }
                }
            }
            RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);
            BoundingBox    box;

            cc.Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out box);
            Location pos = new Location(cc.Body.Position) + new Location(0, 0, box.Min.Z);
            Material mat = TheRegion.GetBlockMaterial(pos + new Location(0, 0, -0.05f));

            speedmod         *= (float)mat.GetSpeedMod();
            cc.StandingSpeed  = CBStandSpeed * speedmod;
            cc.CrouchingSpeed = CBCrouchSpeed * speedmod;
            float frictionmod = 1f;

            frictionmod     *= (float)mat.GetFrictionMod();
            cc.SlidingForce  = CBSlideForce * frictionmod * Mass;
            cc.AirForce      = CBAirForce * frictionmod * Mass;
            cc.TractionForce = CBTractionForce * frictionmod * Mass;
            cc.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
        }
Пример #3
0
        public override void Tick()
        {
            if (TheRegion.Delta <= 0)
            {
                return;
            }
            if (!IsSpawned)
            {
                return;
            }
            PathUpdate -= TheRegion.Delta;
            if (PathUpdate <= 0)
            {
                UpdatePath();
            }
            if (Path != null)
            {
                PathMovement = true;
                Location spos = GetPosition();
                while (Path.Length > 0 && ((Path.Peek() - spos).LengthSquared() < PathFindCloseEnough || (Path.Peek() - spos + new Location(0, 0, -1.5)).LengthSquared() < PathFindCloseEnough))
                {
                    Path.Pop();
                }
                if (Path.Length <= 0)
                {
                    Path = null;
                }
                else
                {
                    Location targetdir = (Path.Peek() - spos).Normalize();
                    Location movegoal  = Utilities.RotateVector(targetdir, (270 + Direction.Yaw) * Utilities.PI180);
                    Vector2  movegoal2 = new Vector2((double)movegoal.X, (double)movegoal.Y);
                    if (movegoal2.LengthSquared() > 0)
                    {
                        movegoal2.Normalize();
                    }
                    XMove = movegoal2.X;
                    YMove = movegoal2.Y;
                    if (movegoal.Z > 0.4)
                    {
                        CBody.Jump();
                    }
                }
            }
            if (Path == null && PathMovement)
            {
                XMove        = 0;
                YMove        = 0;
                PathMovement = false;
            }
            while (Direction.Yaw < 0)
            {
                Direction.Yaw += 360;
            }
            while (Direction.Yaw > 360)
            {
                Direction.Yaw -= 360;
            }
            if (Direction.Pitch > 89.9f)
            {
                Direction.Pitch = 89.9f;
            }
            if (Direction.Pitch < -89.9f)
            {
                Direction.Pitch = -89.9f;
            }
            CBody.ViewDirection = Utilities.ForwardVector_Deg(Direction.Yaw, Direction.Pitch).ToBVector();
            if (Upward && !IsFlying && !pup && CBody.SupportFinder.HasSupport)
            {
                CBody.Jump();
                pup = true;
            }
            else if (!Upward)
            {
                pup = false;
            }
            double speedmod = new Vector2(XMove, YMove).Length() * 1.25;

            speedmod *= (1f + SprintOrWalk * 0.5f);
            if (ItemDoSpeedMod)
            {
                speedmod *= ItemSpeedMod;
            }
            Material mat = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f));

            speedmod            *= mat.GetSpeedMod();
            CBody.StandingSpeed  = CBStandSpeed * speedmod;
            CBody.CrouchingSpeed = CBCrouchSpeed * speedmod;
            double frictionmod = 1f;

            frictionmod        *= mat.GetFrictionMod();
            CBody.SlidingForce  = CBSlideForce * frictionmod * Mass;
            CBody.AirForce      = CBAirForce * frictionmod * Mass;
            CBody.TractionForce = CBTractionForce * frictionmod * Mass;
            CBody.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
            if (CurrentSeat == null)
            {
                Vector3 movement = new Vector3(XMove, YMove, 0);
                if (Upward && IsFlying)
                {
                    movement.Z = 1;
                }
                else if (Downward && IsFlying)
                {
                    movement.Z = -1;
                }
                if (movement.LengthSquared() > 0)
                {
                    movement.Normalize();
                }
                if (Downward)
                {
                    CBody.StanceManager.DesiredStance = Stance.Crouching;
                }
                else
                {
                    CBody.StanceManager.DesiredStance = DesiredStance;
                }
                CBody.HorizontalMotionConstraint.MovementDirection = new Vector2(movement.X, movement.Y);
                Location pos     = GetPosition();
                Location rad     = new Location(CBody.BodyRadius, CBody.BodyRadius, 0);
                double   halfeye = CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5) * 0.5;
                bool     uw1     = TheRegion.InWater(pos - rad, pos + rad + new Location(0, 0, halfeye));
                bool     uw2     = TheRegion.InWater(pos - rad + new Location(0, 0, halfeye), pos + rad + new Location(0, 0, halfeye * 2));
                if (uw1 || uw2)
                {
                    double mult = uw1 ? (uw2 ? 0.6 : 0.3) : 0.3;
                    SetForSwim(mult, Body.Space.ForceUpdater.Gravity * (1.0 - mult));
                }
                else
                {
                    SetForGround();
                }
                if (IsFlying)
                {
                    Location forw = Utilities.RotateVector(new Location(-movement.Y, movement.X, movement.Z), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
                    SetPosition(GetPosition() + forw * TheRegion.Delta * CBStandSpeed * 2 * speedmod);
                    CBody.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
                    Body.LinearVelocity = new Vector3(0, 0, 0);
                }
                else if (IsSwimlogic)
                {
                    Location forw = Utilities.RotateVector(new Location(movement.X, movement.Y, 0), Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
                    if (Upward)
                    {
                        forw.Z = 1;
                    }
                    else if (Downward)
                    {
                        forw.Z = -1;
                    }
                    SwimForce(forw.ToBVector());
                }
            }
            else
            {
                CurrentSeat.HandleInput(this);
            }
            base.Tick();
            RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);

            Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out BoundingBox box);
            MinZ = box.Min.Z;
        }