public void TurnOnJetpack(bool newState, bool fromLoad = false, bool updateSync = true, bool fromInit = false)
        {
            bool originalNewState = newState;

            newState = newState && MySession.Static.Settings.EnableJetpack;
            newState = newState && Character.Definition.Jetpack != null;
            newState = newState && (!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL || MySession.Static.IsAdminModeEnabled);

            bool valueChanged = TurnedOn != newState;

            TurnedOn                 = newState;
            ThrustComp.Enabled       = newState;
            ThrustComp.ControlThrust = Vector3.Zero;
            ThrustComp.MarkDirty();
            ThrustComp.UpdateBeforeSimulation();
            if (!ThrustComp.Enabled)
            {
                ThrustComp.SetRequiredFuelInput(ref FuelDefinition.Id, 0f, null);
            }

            ThrustComp.ResourceSink(Character).Update();

            if (!Character.ControllerInfo.IsLocallyControlled() && !fromInit && !Sync.IsServer && !MyFakes.CHARACTER_SERVER_SYNC)
            {
                return;
            }

            MyCharacterMovementEnum currentMovementState = Character.GetCurrentMovementState();

            if (currentMovementState == MyCharacterMovementEnum.Sitting)
            {
                return;
            }

            Character.StopFalling();

            bool noHydrogen    = false;
            bool canUseJetpack = newState;

            if (!IsPowered && canUseJetpack && (MySession.Static.IsAdminModeEnabled == false || MySession.Static.LocalCharacter != Character))
            {
                canUseJetpack = false;
                noHydrogen    = true;
            }

            if (canUseJetpack)
            {
                Character.IsUsing = null;
            }

            if (MySession.Static.ControlledEntity == Character && valueChanged && !fromLoad)
            {
                m_jetpackToggleNotification.Text = (noHydrogen) ? MySpaceTexts.NotificationJetpackOffNoHydrogen
                                                                                                         : (canUseJetpack || (originalNewState)) ? MySpaceTexts.NotificationJetpackOn
                                                                                                                                                  : MySpaceTexts.NotificationJetpackOff;
                MyHud.Notifications.Add(m_jetpackToggleNotification);

                if (canUseJetpack)
                {
                    MyAnalyticsHelper.ReportActivityStart(Character, "jetpack", "character", string.Empty, string.Empty);
                }
                else
                {
                    MyAnalyticsHelper.ReportActivityEnd(Character, "jetpack");
                }

                //unable sound + turn off jetpack
                if (noHydrogen)
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                    TurnedOn                 = false;
                    ThrustComp.Enabled       = false;
                    ThrustComp.ControlThrust = Vector3.Zero;
                    ThrustComp.MarkDirty();
                    ThrustComp.UpdateBeforeSimulation();
                    ThrustComp.SetRequiredFuelInput(ref FuelDefinition.Id, 0f, null);
                    ThrustComp.ResourceSink(Character).Update();
                }
            }

            var characterProxy = Character.Physics.CharacterProxy;

            if (characterProxy != null)
            {
                characterProxy.Forward = Character.WorldMatrix.Forward;
                characterProxy.Up      = Character.WorldMatrix.Up;
                characterProxy.EnableFlyingState(Running);

                if (currentMovementState != MyCharacterMovementEnum.Died)
                {
                    if (!Running && (characterProxy.GetState() == HkCharacterStateType.HK_CHARACTER_IN_AIR || (int)characterProxy.GetState() == MyCharacter.HK_CHARACTER_FLYING))
                    {
                        Character.StartFalling();
                    }
                    //If we are in any state but not standing and new state is to be flying, dont change to standing. Else is probably ok?
                    else if (currentMovementState != MyCharacterMovementEnum.Standing && !newState)
                    {
                        Character.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f);
                        Character.SetCurrentMovementState(MyCharacterMovementEnum.Standing);
                        currentMovementState = Character.GetCurrentMovementState();
                    }
                }

                if (Running && currentMovementState != MyCharacterMovementEnum.Died)
                {
                    Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.0f);
                    Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying);
                    Character.SetLocalHeadAnimation(0, 0, 0.3f);

                    // If the character is running when enabling the jetpack, these will keep making him fly in the same direction always if not zeroed
                    characterProxy.PosX = 0;
                    characterProxy.PosY = 0;
                }

                // When disabling the jetpack normally during the game in zero-G, disable jetpack autoenable
                if (!fromLoad && !newState && characterProxy.Gravity.LengthSquared() <= 0.1f)
                {
                    CurrentAutoEnableDelay = -1;
                }
            }
        }
 public override void UpdateBeforeSimulation()
 {
     ThrustComp.UpdateBeforeSimulation();
 }
 public override void OnBeforeRemovedFromContainer()
 {
     Character.SuitRechargeDistributor.RemoveSink(ThrustComp.ResourceSink(Character), true, Entity.MarkedForClose);
     base.OnBeforeRemovedFromContainer();
 }
        public virtual void Init(MyObjectBuilder_Character characterBuilder)
        {
            if (characterBuilder == null)
            {
                return;
            }

            m_inertiaDampenersNotification = new MyHudNotification();
            m_jetpackToggleNotification    = new MyHudNotification();

            CurrentAutoEnableDelay = characterBuilder.AutoenableJetpackDelay;

            if (ThrustComp != null)
            {
                Character.Components.Remove <MyJetpackThrustComponent>();
            }

            var thrustProperties = Character.Definition.Jetpack.ThrustProperties;

            FuelConverterDefinition = null;;
            FuelConverterDefinition = !MyFakes.ENABLE_HYDROGEN_FUEL ? new MyFuelConverterInfo {
                Efficiency = 1.0f
            } : Character.Definition.Jetpack.ThrustProperties.FuelConverter;

            MyDefinitionId fuelId = new MyDefinitionId();

            if (!FuelConverterDefinition.FuelId.IsNull())
            {
                fuelId = thrustProperties.FuelConverter.FuelId;
            }

            MyGasProperties fuelDef = null;

            if (MyFakes.ENABLE_HYDROGEN_FUEL)
            {
                MyDefinitionManager.Static.TryGetDefinition(fuelId, out fuelDef);
            }

            FuelDefinition = fuelDef ?? new MyGasProperties // Use electricity by default
            {
                Id            = MyResourceDistributorComponent.ElectricityId,
                EnergyDensity = 1f,
            };

            ForceMagnitude              = thrustProperties.ForceMagnitude;
            MinPowerConsumption         = thrustProperties.MinPowerConsumption;
            MaxPowerConsumption         = thrustProperties.MaxPowerConsumption;
            MinPlanetaryInfluence       = thrustProperties.MinPlanetaryInfluence;
            MaxPlanetaryInfluence       = thrustProperties.MaxPlanetaryInfluence;
            EffectivenessAtMinInfluence = thrustProperties.EffectivenessAtMinInfluence;
            EffectivenessAtMaxInfluence = thrustProperties.EffectivenessAtMaxInfluence;
            NeedsAtmosphereForInfluence = thrustProperties.NeedsAtmosphereForInfluence;
            ConsumptionFactorPerG       = thrustProperties.ConsumptionFactorPerG;

            MyEntityThrustComponent thrustComp = new MyJetpackThrustComponent();

            thrustComp.Init();
            Character.Components.Add(thrustComp);


            ThrustComp.DampenersEnabled = characterBuilder.DampenersEnabled;

            foreach (Vector3I direction in Base6Directions.IntDirections)
            {
                ThrustComp.Register(Character, direction);                      // Preferably there should be a jetpack entity (equipment) that could hold the thrusts instead of the character
            }
            thrustComp.ResourceSink(Character).TemporaryConnectedEntity = Character;
            Character.SuitRechargeDistributor.AddSink(thrustComp.ResourceSink(Character));
            TurnOnJetpack(characterBuilder.JetpackEnabled, true, true, true);
        }
 public void UpdateThrustFromNetwork()
 {
     ThrustComp.UpdateBeforeSimulation(true, true);
     ClearMovement();
 }
 public override void UpdateBeforeSimulation()
 {
     ThrustComp.UpdateBeforeSimulation(false, Sync.IsServer || Character == MySession.Static.LocalCharacter);
 }