예제 #1
0
        public bool UpdatePhysicalMovement()
        {
            if (!this.Running)
            {
                return(false);
            }
            MyPhysicsBody    physics        = base.Character.Physics;
            MyCharacterProxy characterProxy = physics.CharacterProxy;

            if ((characterProxy != null) && (characterProxy.LinearVelocity.Length() < 0.001f))
            {
                characterProxy.LinearVelocity = Vector3.Zero;
            }
            float       num       = 1f;
            HkRigidBody rigidBody = physics.RigidBody;

            if (rigidBody != null)
            {
                rigidBody.Gravity = Vector3.Zero;
                if (MySession.Static.SurvivalMode || MyFakes.ENABLE_PLANETS_JETPACK_LIMIT_IN_CREATIVE)
                {
                    Vector3 vector2 = (Vector3)(num * MyGravityProviderSystem.CalculateNaturalGravityInPoint(base.Character.PositionComp.WorldAABB.Center));
                    if (vector2 != Vector3.Zero)
                    {
                        rigidBody.Gravity = vector2 * MyPerGameSettings.CharacterGravityMultiplier;
                    }
                }
                return(true);
            }
            if (characterProxy == null)
            {
                return(false);
            }
            characterProxy.Gravity = Vector3.Zero;
            if (MySession.Static.SurvivalMode || MyFakes.ENABLE_PLANETS_JETPACK_LIMIT_IN_CREATIVE)
            {
                Vector3 vector3 = (Vector3)(num * MyGravityProviderSystem.CalculateNaturalGravityInPoint(base.Character.PositionComp.WorldAABB.Center));
                if (vector3 != Vector3.Zero)
                {
                    characterProxy.Gravity = vector3 * MyPerGameSettings.CharacterGravityMultiplier;
                }
            }
            return(true);
        }
예제 #2
0
        public void TurnOnJetpack(bool newState, bool fromInit = false, bool fromLoad = false)
        {
            int num1;
            int num2;
            MyEntityController controller = base.Character.ControllerInfo.Controller;

            newState = newState && MySession.Static.Settings.EnableJetpack;
            newState = newState && (base.Character.Definition.Jetpack != null);
            if (!newState)
            {
                num1 = 0;
            }
            else if ((!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL) || (controller == null))
            {
                num1 = 1;
            }
            else
            {
                num1 = (int)MySession.Static.CreativeToolsEnabled(controller.Player.Id.SteamId);
            }
            newState = (bool)num2;
            bool flag = this.TurnedOn != newState;

            this.TurnedOn                 = newState;
            this.ThrustComp.Enabled       = newState;
            this.ThrustComp.ControlThrust = Vector3.Zero;
            this.ThrustComp.MarkDirty(false);
            this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity);
            if (!this.ThrustComp.Enabled)
            {
                this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null);
            }
            this.ThrustComp.ResourceSink(base.Character).Update();
            if ((base.Character.ControllerInfo.IsLocallyControlled() || fromInit) || Sync.IsServer)
            {
                MyCharacterMovementEnum currentMovementState = base.Character.GetCurrentMovementState();
                if (currentMovementState != MyCharacterMovementEnum.Sitting)
                {
                    if (this.TurnedOn)
                    {
                        base.Character.StopFalling();
                    }
                    bool flag2 = false;
                    bool flag3 = newState;
                    if ((!this.IsPowered & flag3) && (((base.Character.ControllerInfo.Controller != null) && !MySession.Static.CreativeToolsEnabled(base.Character.ControllerInfo.Controller.Player.Id.SteamId)) || (!ReferenceEquals(MySession.Static.LocalCharacter, base.Character) && !Sync.IsServer)))
                    {
                        flag3 = false;
                        flag2 = true;
                    }
                    if (flag3)
                    {
                        if (base.Character.IsOnLadder)
                        {
                            base.Character.GetOffLadder();
                        }
                        base.Character.IsUsing = null;
                    }
                    if (flag && !base.Character.IsDead)
                    {
                        base.Character.UpdateCharacterPhysics(false);
                    }
                    if ((ReferenceEquals(MySession.Static.ControlledEntity, base.Character) & flag) && !fromLoad)
                    {
                        if (flag3)
                        {
                            MyAnalyticsHelper.ReportActivityStart(base.Character, "jetpack", "character", string.Empty, string.Empty, true);
                        }
                        else
                        {
                            MyAnalyticsHelper.ReportActivityEnd(base.Character, "jetpack");
                        }
                        if (flag2)
                        {
                            MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                            this.TurnedOn                 = false;
                            this.ThrustComp.Enabled       = false;
                            this.ThrustComp.ControlThrust = Vector3.Zero;
                            this.ThrustComp.MarkDirty(false);
                            this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity);
                            this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null);
                            this.ThrustComp.ResourceSink(base.Character).Update();
                        }
                    }
                    MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy;
                    if (characterProxy == null)
                    {
                        if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died))
                        {
                            base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false);
                            base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f);
                        }
                    }
                    else
                    {
                        MatrixD worldMatrix = base.Character.WorldMatrix;
                        characterProxy.SetForwardAndUp((Vector3)worldMatrix.Forward, (Vector3)worldMatrix.Up);
                        characterProxy.EnableFlyingState(this.Running);
                        if ((currentMovementState != MyCharacterMovementEnum.Died) && !base.Character.IsOnLadder)
                        {
                            if (!this.Running && ((characterProxy.GetState() == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (characterProxy.GetState() == ((HkCharacterStateType)5))))
                            {
                                base.Character.StartFalling();
                            }
                            else if ((currentMovementState != MyCharacterMovementEnum.Standing) && !newState)
                            {
                                base.Character.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false);
                                base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Standing);
                                currentMovementState = base.Character.GetCurrentMovementState();
                            }
                        }
                        if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died))
                        {
                            base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false);
                            base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying);
                            base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f);
                            characterProxy.PosX = 0f;
                            characterProxy.PosY = 0f;
                        }
                        if ((!fromLoad && !newState) && (base.Character.Physics.Gravity.LengthSquared() <= 0.1f))
                        {
                            this.CurrentAutoEnableDelay = -1f;
                        }
                    }
                }
            }
        }
예제 #3
0
        public unsafe void MoveAndRotate(ref Vector3 moveIndicator, ref Vector2 rotationIndicator, float roll, bool canRotate)
        {
            MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy;

            this.ThrustComp.ControlThrust = Vector3.Zero;
            base.Character.SwitchAnimation(MyCharacterMovementEnum.Flying, true);
            base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying);
            MyCharacterMovementFlags movementFlags = base.Character.MovementFlags;
            MyCharacterMovementFlags flags2        = base.Character.MovementFlags;

            this.IsFlying = !(moveIndicator.LengthSquared() == 0f);
            HkCharacterStateType type = (characterProxy != null) ? characterProxy.GetState() : HkCharacterStateType.HK_CHARACTER_ON_GROUND;

            if ((type == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (type == ((HkCharacterStateType)5)))
            {
                base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false);
                base.Character.CanJump = true;
            }
            MatrixD worldMatrix = base.Character.WorldMatrix;

            if (canRotate)
            {
                MatrixD identity = MatrixD.Identity;
                MatrixD xd3      = MatrixD.Identity;
                MatrixD xd4      = MatrixD.Identity;
                if (Math.Abs(rotationIndicator.X) > float.Epsilon)
                {
                    if (base.Character.Definition.VerticalPositionFlyingOnly)
                    {
                        base.Character.SetHeadLocalXAngle(base.Character.HeadLocalXAngle - (rotationIndicator.X * base.Character.RotationSpeed));
                    }
                    else
                    {
                        identity = MatrixD.CreateFromAxisAngle(worldMatrix.Right, (double)((-rotationIndicator.X * base.Character.RotationSpeed) * 0.02f));
                    }
                }
                if (Math.Abs(rotationIndicator.Y) > float.Epsilon)
                {
                    xd3 = MatrixD.CreateFromAxisAngle(worldMatrix.Up, (double)((-rotationIndicator.Y * base.Character.RotationSpeed) * 0.02f));
                }
                if (!base.Character.Definition.VerticalPositionFlyingOnly && (Math.Abs(roll) > float.Epsilon))
                {
                    xd4 = MatrixD.CreateFromAxisAngle(worldMatrix.Forward, (double)(roll * 0.02f));
                }
                float    y      = base.Character.ModelCollision.BoundingBoxSizeHalf.Y;
                MatrixD  xd7    = worldMatrix.GetOrientation() * ((identity * xd3) * xd4);
                MatrixD *xdPtr1 = (MatrixD *)ref xd7;
                xdPtr1.Translation         = (base.Character.Physics.GetWorldMatrix().Translation + (worldMatrix.Up * y)) - (xd7.Up * y);
                base.Character.WorldMatrix = xd7;
                base.Character.ClearShapeContactPoints();
            }
            Vector3 position = moveIndicator;

            if (base.Character.Definition.VerticalPositionFlyingOnly)
            {
                float  num2 = Math.Sign(base.Character.HeadLocalXAngle);
                double x    = Math.Abs(MathHelper.ToRadians(base.Character.HeadLocalXAngle));
                double y    = 1.95;
                double num5 = Math.Pow(x, y) * (x / Math.Pow((double)MathHelper.ToRadians((float)89f), y));
                position = (Vector3)Vector3D.Transform(position, MatrixD.CreateFromAxisAngle(Vector3D.Right, num2 * num5));
            }
            if (!Vector3.IsZero(position))
            {
                position.Normalize();
            }
            MyJetpackThrustComponent thrustComp = this.ThrustComp;

            thrustComp.ControlThrust += position * this.ForceMagnitude;
        }