Пример #1
0
        private void characterEntity_MovementStateChanged(IMyCharacter currentcharacter, MyCharacterMovementEnum oldState, MyCharacterMovementEnum newState)
        {
            if (skipNextActivation > 0)
            {
                skipNextActivation--;
            }
            if (oldState == MyCharacterMovementEnum.Sitting)
            {
            }
            if (newState == MyCharacterMovementEnum.Died)
            {
                characterEntity.MovementStateChanged -= characterEntity_MovementStateChanged;
                handlerAdded       = false;
                skipNextActivation = 0;
            }

            if ((oldState == MyCharacterMovementEnum.Flying) || (newState == MyCharacterMovementEnum.Flying))
            {
                MyEntityComponentContainer  playercontainer = characterEntity.Components;
                MyCharacterJetpackComponent JetpackComp     = playercontainer.Get <MyCharacterJetpackComponent>();
                if (JetpackComp != null)
                {
                    if ((oldState == MyCharacterMovementEnum.Flying) && (newState == MyCharacterMovementEnum.Sitting))
                    {
                        skipNextActivation = activationskippingdelay;
                    }
                    else
                    {
                        if (!MyAPIGateway.Input.IsNewGameControlPressed(MyControlsSpace.THRUSTS))
                        {
                            if (JetpackComp.TurnedOn)
                            {
                                if (skipNextActivation > 0)
                                {
                                    skipNextActivation = 0;
                                }
                                else
                                {
                                    JetpackComp.TurnOnJetpack(false); //turn the jetpack off
                                }
                            }
                        }
                    }
                }
            }
            //  if ((newState != MyCharacterMovementEnum.Sitting) || (oldState != MyCharacterMovementEnum.Sitting)) skipNextActivation = false;
        }
Пример #2
0
        private void characterEntity_OnMovementStateChanged(MyCharacterMovementEnum oldState, MyCharacterMovementEnum newState)
        {
            if (oldState == MyCharacterMovementEnum.Sitting)
            {
            }

            if ((oldState == MyCharacterMovementEnum.Flying) || (newState == MyCharacterMovementEnum.Flying))
            {
                MyEntityComponentContainer  playercontainer = characterEntity.Components;
                MyCharacterJetpackComponent JetpackComp     = playercontainer.Get <MyCharacterJetpackComponent>();
                if (JetpackComp != null)
                {
                    if ((oldState == MyCharacterMovementEnum.Flying) && (newState == MyCharacterMovementEnum.Sitting))
                    {
                        skipNextActivation = true;
                    }
                    else
                    {
                        if (!MyAPIGateway.Input.IsNewGameControlPressed(MyControlsSpace.THRUSTS))
                        {
                            if (JetpackComp.TurnedOn)
                            {
                                if (skipNextActivation)
                                {
                                    skipNextActivation = false;
                                }
                                else
                                {
                                    JetpackComp.TurnOnJetpack(false); //turn the jetpack off
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        protected virtual void Controller_ControlledEntityChanged(IMyControllableEntity oldEntity, IMyControllableEntity newEntity)
        {
            if ((oldEntity == null) && (newEntity is MyCharacter))
            {
                this.EraseRespawn();
            }
            this.m_navigation.ChangeEntity(newEntity);
            this.m_navigation.AimWithMovement();
            MyCharacter character = newEntity as MyCharacter;

            if (character != null)
            {
                IMyControllableEntity       controlledEntity = this.m_player.Controller.ControlledEntity;
                MyCharacterJetpackComponent jetpackComp      = character.JetpackComp;
                if (jetpackComp != null)
                {
                    jetpackComp.TurnOnJetpack(false, false, false);
                }
            }
            if (this.HasLogic)
            {
                this.m_botLogic.OnControlledEntityChanged(newEntity);
            }
        }
Пример #4
0
        private void DrawJetpackThrusts(bool updateCalled)
        {
            MyCharacter skinnedEntity = base.m_skinnedEntity as MyCharacter;

            if ((skinnedEntity != null) && (skinnedEntity.GetCurrentMovementState() != MyCharacterMovementEnum.Died))
            {
                MyCharacterJetpackComponent jetpackComp = skinnedEntity.JetpackComp;
                if ((jetpackComp != null) && jetpackComp.CanDrawThrusts)
                {
                    MyEntityThrustComponent component2 = base.Container.Get <MyEntityThrustComponent>();
                    if (component2 != null)
                    {
                        MatrixD worldToLocal = MatrixD.Invert(base.Container.Entity.PositionComp.WorldMatrix);
                        foreach (MyJetpackThrust thrust in this.m_jetpackThrusts)
                        {
                            Vector3D zero = Vector3D.Zero;
                            if ((!jetpackComp.TurnedOn || !jetpackComp.IsPowered) || ((skinnedEntity.IsInFirstPersonView && ReferenceEquals(skinnedEntity, MySession.Static.LocalCharacter)) && !MyAnsel.IsAnselSessionRunning))
                            {
                                if (updateCalled || (skinnedEntity.IsUsing != null))
                                {
                                    thrust.ThrustRadius = 0f;
                                }
                            }
                            else
                            {
                                MatrixD  matrix   = thrust.ThrustMatrix * base.Container.Entity.PositionComp.WorldMatrix;
                                Vector3D vectord2 = Vector3D.TransformNormal(thrust.Forward, matrix);
                                zero = matrix.Translation + (vectord2 * thrust.Offset);
                                float num = 0.05f;
                                if (updateCalled)
                                {
                                    thrust.ThrustRadius = MyUtils.GetRandomFloat(0.9f, 1.1f) * num;
                                }
                                float   num2    = MathHelper.Clamp((float)(Vector3.Dot((Vector3)vectord2, (Vector3)(-Vector3.Transform(component2.FinalThrust, base.Entity.WorldMatrix.GetOrientation()) / ((double)skinnedEntity.BaseMass))) * 0.09f), (float)0.1f, (float)1f);
                                Vector4 color   = Vector4.Zero;
                                Vector4 vector2 = Vector4.Zero;
                                if ((num2 > 0f) && (thrust.ThrustRadius > 0f))
                                {
                                    float num4 = (1f - ((float)Math.Pow((double)(1f - (1f - Math.Abs(Vector3.Dot((Vector3)MyUtils.Normalize(MySector.MainCamera.Position - zero), (Vector3)vectord2)))), 30.0))) * 0.5f;
                                    if (updateCalled)
                                    {
                                        thrust.ThrustLength    = ((num2 * 12f) * MyUtils.GetRandomFloat(1.6f, 2f)) * num;
                                        thrust.ThrustThickness = MyUtils.GetRandomFloat(thrust.ThrustRadius * 1.9f, thrust.ThrustRadius);
                                    }
                                    color = thrust.Light.Color.ToVector4() * new Vector4(1f, 1f, 1f, 0.4f);
                                    MyTransparentGeometry.AddLineBillboard(thrust.ThrustLengthMaterial, color, zero + (vectord2 * JETPACK_THRUST_OFFSET), base.GetRenderObjectID(), ref worldToLocal, (Vector3)vectord2, thrust.ThrustLength * JETPACK_THRUST_LENGTH, thrust.ThrustThickness * JETPACK_THRUST_THICKNESS, MyBillboard.BlendTypeEnum.Standard, -1, num4 * (JETPACK_THRUST_INTENSITY_BASE + (num2 * JETPACK_THRUST_INTENSITY)), null);
                                }
                                if (thrust.ThrustRadius > 0f)
                                {
                                    vector2 = thrust.Light.Color.ToVector4() * new Vector4(1f, 1f, 1f, 0.4f);
                                    MyTransparentGeometry.AddPointBillboard(thrust.ThrustPointMaterial, vector2, zero, base.GetRenderObjectID(), ref worldToLocal, thrust.ThrustRadius * JETPACK_THRUST_THICKNESS, 0f, -1, MyBillboard.BlendTypeEnum.Standard, JETPACK_THRUST_INTENSITY_BASE + (num2 * JETPACK_THRUST_INTENSITY), null);
                                }
                            }
                            if (thrust.Light != null)
                            {
                                if (thrust.ThrustRadius <= 0f)
                                {
                                    thrust.Light.GlareOn = false;
                                    thrust.Light.LightOn = false;
                                    thrust.Light.UpdateLight();
                                }
                                else
                                {
                                    thrust.Light.LightOn        = true;
                                    thrust.Light.Intensity      = JETPACK_LIGHT_INTENSITY_BASE + (thrust.ThrustLength * JETPACK_LIGHT_INTENSITY_LENGTH);
                                    thrust.Light.Range          = (thrust.ThrustRadius * JETPACK_LIGHT_RANGE_RADIUS) + (thrust.ThrustLength * JETPACK_LIGHT_RANGE_LENGTH);
                                    thrust.Light.Position       = Vector3D.Transform(zero, base.Container.Entity.PositionComp.WorldMatrixNormalizedInv);
                                    thrust.Light.ParentID       = this.m_cullRenderId;
                                    thrust.Light.GlareOn        = true;
                                    thrust.Light.GlareIntensity = (JETPACK_GLARE_INTENSITY_BASE + (thrust.ThrustLength * JETPACK_GLARE_INTENSITY_LENGTH)) * this.m_flareJetpack.Intensity;
                                    thrust.Light.GlareType      = MyGlareTypeEnum.Normal;
                                    thrust.Light.GlareSize      = (this.m_flareJetpack.Size * ((thrust.ThrustRadius * JETPACK_GLARE_SIZE_RADIUS) + (thrust.ThrustLength * JETPACK_GLARE_SIZE_LENGTH))) * thrust.ThrustGlareSize;
                                    thrust.Light.SubGlares      = this.m_flareJetpack.SubGlares;
                                    thrust.Light.GlareQuerySize = 0.1f;
                                    thrust.Light.UpdateLight();
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 internal static bool AccelNotDueToJetpack(MyCharacterJetpackComponent jetpack)
 {
     return(jetpack != null && jetpack.Running && jetpack.FinalThrust.LengthSquared() > 0);
 }
Пример #6
0
 public override void UpdateAfterSimulation()
 {
     try
     {
         tick++;
         if (MyAPIGateway.Session == null)
         {
             return;
         }
         if (!init) //reinit just to be save
         {
             Init();
         }
         if (isDedicatedHost)
         {
             return;        //there is no jetpack or even a player on the dedicated host itself
         }
         if (tick % 3 == 0) //better performance if the code is executed less - only do it every 3 ticks will work until you play below 4 FPS
         {
             if ((skipNextActivation > 0) && (skipNextActivation < activationskippingdelay))
             {
                 skipNextActivation--;
             }
             var camera = MyAPIGateway.Session.CameraController;
             if (camera == null)
             {
                 return;
             }
             if (characterEntity != null && (characterEntity.MarkedForClose || characterEntity.Closed))
             {
                 characterEntity = null; //remove the stored character
             }
             if (camera is IMyCharacter)
             {
                 if (camera as IMyCharacter != characterEntity)
                 {
                     if (characterEntity != null)
                     {
                         characterEntity.MovementStateChanged -= characterEntity_MovementStateChanged;
                     }
                     handlerAdded = false;
                 }
                 characterEntity = ((IMyCharacter)camera);
                 MyEntityComponentContainer  playercontainer = ((IMyCharacter)camera).Components;
                 MyCharacterJetpackComponent JetpackComp     = playercontainer.Get <MyCharacterJetpackComponent>();
                 if (JetpackComp != null)
                 {
                     if (JetpackComp.CurrentAutoEnableDelay > 0)  //The coundown is running so deactivate it
                     {
                         JetpackComp.CurrentAutoEnableDelay = -1; //now it is deactivated again
                     }
                 }
             }
         }
         if (!handlerAdded) //only once
         {
             var camera = MyAPIGateway.Session.CameraController;
             if (camera == null)
             {
                 return;
             }
             if (camera is IMyCharacter)
             {
                 characterEntity = ((IMyCharacter)camera);                                     //store the character Entity
                 characterEntity.MovementStateChanged += characterEntity_MovementStateChanged; //add the handler
                 handlerAdded       = true;
                 skipNextActivation = activationskippingdelay;
             }
         }
     }
     catch (Exception e)
     {
         //Lazy lazy... still no logging...
     }
 }
Пример #7
0
        private void MoveCharacter()
        {
            MyCharacter entity = this.m_entity as MyCharacter;

            if (entity != null)
            {
                if (this.m_speed != 0f)
                {
                    MyCharacterJetpackComponent jetpackComp = entity.JetpackComp;
                    if (((jetpackComp != null) && !jetpackComp.TurnedOn) && this.m_path.Flying)
                    {
                        jetpackComp.TurnOnJetpack(true, false, false);
                    }
                    else if (((jetpackComp != null) && jetpackComp.TurnedOn) && !this.m_path.Flying)
                    {
                        jetpackComp.TurnOnJetpack(false, false, false);
                    }
                    Vector3 vector  = Vector3.TransformNormal(this.m_forwardVector, entity.PositionComp.WorldMatrixNormalizedInv);
                    Vector3 vector2 = this.m_aiming.RotationHint * this.m_rotationSpeedModifier;
                    if (this.m_path.Flying)
                    {
                        if (vector.Y > 0f)
                        {
                            entity.Up();
                        }
                        else
                        {
                            entity.Down();
                        }
                    }
                    entity.MoveAndRotate(vector * this.m_speed, new Vector2(vector2.Y * 30f, vector2.X * 30f), 0f);
                }
                else if (this.m_speed == 0f)
                {
                    if (!this.HasRotation(0.0316f))
                    {
                        if (this.m_wasStopped)
                        {
                            entity.MoveAndRotate(Vector3.Zero, Vector2.Zero, 0f);
                            this.m_wasStopped = true;
                        }
                    }
                    else
                    {
                        int num1;
                        if (entity.WantsWalk || entity.IsCrouching)
                        {
                            num1 = 1;
                        }
                        else
                        {
                            num1 = 2;
                        }
                        float   num     = num1;
                        Vector3 vector3 = this.m_aiming.RotationHint * this.m_rotationSpeedModifier;
                        entity.MoveAndRotate(Vector3.Zero, new Vector2((vector3.Y * 20f) * num, (vector3.X * 25f) * num), 0f);
                        this.m_wasStopped = false;
                    }
                }
            }
            Vector3D targetLocation = new Vector3D();

            this.m_stuckDetection.Update(this.m_worldMatrix.Translation, this.m_aiming.RotationHint, targetLocation);
        }