public void Update(float dt)
 {
     if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0))
     {
         m_updateIndex++;
         foreach (Point3 key in m_particleSystemsByCell.Keys)
         {
             PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(key.X, key.Z);
             if ((precipitationShaftInfo.Intensity > 0f && key.Y >= precipitationShaftInfo.YLimit - 1) || m_updateIndex % 5 == 0)
             {
                 m_toReduce.Add(key);
             }
         }
         foreach (Point3 item in m_toReduce)
         {
             ResizeCampfire(item.X, item.Y, item.Z, -1, playSound: true);
         }
         m_toReduce.Clear();
     }
     if (Time.PeriodicEvent(0.5, 0.0))
     {
         float num = float.MaxValue;
         foreach (Point3 key2 in m_particleSystemsByCell.Keys)
         {
             float x = m_subsystemAmbientSounds.SubsystemAudio.CalculateListenerDistanceSquared(new Vector3(key2.X, key2.Y, key2.Z));
             num = MathUtils.Min(num, x);
         }
         m_fireSoundVolume = m_subsystemAmbientSounds.SubsystemAudio.CalculateVolume(MathUtils.Sqrt(num), 2f);
     }
     m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume);
 }
 public static void Update()
 {
     m_averageFrameTime.AddSample(Program.LastFrameTime);
     m_averageCpuFrameTime.AddSample(Program.LastCpuFrameTime);
     if (Time.PeriodicEvent(1.0, 0.0))
     {
         m_totalMemoryUsed    = GC.GetTotalMemory(forceFullCollection: false);
         m_totalGpuMemoryUsed = Display.GetGpuMemoryUsage();
     }
     m_stateMachine.Update();
 }
        public static void Draw()
        {
            Vector2  scale    = new Vector2(MathUtils.Round(MathUtils.Clamp(ScreensManager.RootWidget.GlobalScale, 1f, 4f)));
            Viewport viewport = Display.Viewport;

            if (SettingsManager.DisplayFpsCounter)
            {
                if (Time.PeriodicEvent(1.0, 0.0))
                {
                    m_statsString = $"CPUMEM {(float)TotalMemoryUsed / 1024f / 1024f:0}MB, GPUMEM {(float)TotalGpuMemoryUsed / 1024f / 1024f:0}MB, CPU {AverageCpuFrameTime / AverageFrameTime * 100f:0}%, FPS {1f / AverageFrameTime:0.0}";
                }
                m_primitivesRenderer.FontBatch(BitmapFont.DebugFont, 0, null, null, null, SamplerState.PointClamp).QueueText(m_statsString, new Vector2(viewport.Width, 0f), 0f, Color.White, TextAnchor.Right, scale, Vector2.Zero);
            }
            if (SettingsManager.DisplayFpsRibbon)
            {
                float num  = ((float)viewport.Width / scale.X > 480f) ? (scale.X * 2f) : scale.X;
                float num2 = (float)viewport.Height / -0.1f;
                float num3 = viewport.Height - 1;
                float s    = 0.5f;
                int   num4 = MathUtils.Max((int)((float)viewport.Width / num), 1);
                if (m_frameData == null || m_frameData.Length != num4)
                {
                    m_frameData      = new FrameData[num4];
                    m_frameDataIndex = 0;
                }
                m_frameData[m_frameDataIndex] = new FrameData
                {
                    CpuTime   = Program.LastCpuFrameTime,
                    TotalTime = Program.LastFrameTime
                };
                m_frameDataIndex = (m_frameDataIndex + 1) % m_frameData.Length;
                FlatBatch2D flatBatch2D = m_primitivesRenderer.FlatBatch();
                Color       color       = Color.Orange * s;
                Color       color2      = Color.Red * s;
                for (int num5 = m_frameData.Length - 1; num5 >= 0; num5--)
                {
                    int       num6      = (num5 - m_frameData.Length + 1 + m_frameDataIndex + m_frameData.Length) % m_frameData.Length;
                    FrameData frameData = m_frameData[num6];
                    float     x         = (float)num5 * num;
                    float     x2        = (float)(num5 + 1) * num;
                    flatBatch2D.QueueQuad(new Vector2(x, num3), new Vector2(x2, num3 + frameData.CpuTime * num2), 0f, color);
                    flatBatch2D.QueueQuad(new Vector2(x, num3 + frameData.CpuTime * num2), new Vector2(x2, num3 + frameData.TotalTime * num2), 0f, color2);
                }
                flatBatch2D.QueueLine(new Vector2(0f, num3 + 0.0166666675f * num2), new Vector2(viewport.Width, num3 + 0.0166666675f * num2), 0f, Color.Green);
            }
            else
            {
                m_frameData = null;
            }
            m_primitivesRenderer.Flush();
        }
Beispiel #4
0
 public static void Update()
 {
     if (Time.PeriodicEvent(1.0, 0.0))
     {
         TimeSpan t   = TimeSpan.FromHours(SettingsManager.MotdUpdatePeriodHours);
         DateTime now = DateTime.Now;
         if (now >= SettingsManager.MotdLastUpdateTime + t)
         {
             SettingsManager.MotdLastUpdateTime = now;
             Log.Information("Downloading MOTD");
             AnalyticsManager.LogEvent("[MotdManager] Downloading MOTD", new AnalyticsParameter("Time", DateTime.Now.ToString("HH:mm:ss.fff")));
             string url = GetMotdUrl();
             WebManager.Get(url, null, null, null, delegate(byte[] result)
             {
                 try
                 {
                     string motdLastDownloadedData = UnpackMotd(result);
                     MessageOfTheDay = null;
                     SettingsManager.MotdLastDownloadedData = motdLastDownloadedData;
                     Log.Information("Downloaded MOTD");
                     AnalyticsManager.LogEvent("[MotdManager] Downloaded MOTD", new AnalyticsParameter("Time", DateTime.Now.ToString("HH:mm:ss.fff")), new AnalyticsParameter("Url", url));
                     SettingsManager.MotdUseBackupUrl = false;
                 }
                 catch (Exception ex)
                 {
                     Log.Error("Failed processing MOTD string. Reason: " + ex.Message);
                     SettingsManager.MotdUseBackupUrl = !SettingsManager.MotdUseBackupUrl;
                 }
             }, delegate(Exception error)
             {
                 Log.Error("Failed downloading MOTD. Reason: {0}", error.Message);
                 SettingsManager.MotdUseBackupUrl = !SettingsManager.MotdUseBackupUrl;
             });
         }
     }
     if (MessageOfTheDay == null && !string.IsNullOrEmpty(SettingsManager.MotdLastDownloadedData))
     {
         MessageOfTheDay = ParseMotd(SettingsManager.MotdLastDownloadedData);
         if (MessageOfTheDay == null)
         {
             SettingsManager.MotdLastDownloadedData = string.Empty;
         }
     }
 }
Beispiel #5
0
        public void Update(float dt)
        {
            ComponentPlayer componentPlayer = (m_subsystemPlayers.ComponentPlayers.Count > 0) ? m_subsystemPlayers.ComponentPlayers[0] : null;

            if (componentPlayer == null)
            {
                return;
            }
            if (m_newYearCelebrationTimeRemaining <= 0f && Time.PeriodicEvent(5.0, 0.0) && m_subsystemSky.SkyLightIntensity == 0f && !componentPlayer.ComponentSleep.IsSleeping)
            {
                DateTime now = DateTime.Now;
                if (now.Year > SettingsManager.NewYearCelebrationLastYear && now.Month == 1 && now.Day == 1 && now.Hour == 0 && now.Minute < 59)
                {
                    SettingsManager.NewYearCelebrationLastYear = now.Year;
                    m_newYearCelebrationTimeRemaining          = 180f;
                    componentPlayer.ComponentGui.DisplayLargeMessage("Happy New Year!", "--- Enjoy the fireworks ---", 15f, 3f);
                }
            }
            if (!(m_newYearCelebrationTimeRemaining > 0f))
            {
                return;
            }
            m_newYearCelebrationTimeRemaining -= dt;
            float num = (m_newYearCelebrationTimeRemaining > 10f) ? MathUtils.Lerp(1f, 7f, 0.5f * MathUtils.Sin(0.25f * m_newYearCelebrationTimeRemaining) + 0.5f) : 20f;

            if (m_random.Float(0f, 1f) < num * dt)
            {
                Vector2 vector  = m_random.Vector2(35f, 50f);
                Vector3 vector2 = componentPlayer.ComponentBody.Position + new Vector3(vector.X, 0f, vector.Y);
                TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(new Vector3(vector2.X, 120f, vector2.Z), new Vector3(vector2.X, 40f, vector2.Z), useInteractionBoxes: false, skipAirBlocks: true, null);
                if (terrainRaycastResult.HasValue)
                {
                    int data = 0;
                    data = FireworksBlock.SetShape(data, (FireworksBlock.Shape)m_random.Int(0, 7));
                    data = FireworksBlock.SetColor(data, m_random.Int(0, 7));
                    data = FireworksBlock.SetAltitude(data, m_random.Int(0, 1));
                    data = FireworksBlock.SetFlickering(data, m_random.Float(0f, 1f) < 0.25f);
                    int     value    = Terrain.MakeBlockValue(215, 0, data);
                    Vector3 position = new Vector3(terrainRaycastResult.Value.CellFace.Point.X, terrainRaycastResult.Value.CellFace.Point.Y + 1, terrainRaycastResult.Value.CellFace.Point.Z);
                    m_subsystemProjectiles.FireProjectile(value, position, new Vector3(m_random.Float(-3f, 3f), 45f, m_random.Float(-3f, 3f)), Vector3.Zero, null);
                }
            }
        }
Beispiel #6
0
        public new void HandleInput()
        {
            WidgetInput    input          = m_componentPlayer.View.Input;
            PlayerInput    playerInput    = m_componentPlayer.ComponentInput.PlayerInput;
            ComponentRider componentRider = m_componentPlayer.ComponentRider;

            if (m_componentPlayer.View.ActiveCamera.IsEntityControlEnabled)
            {
                if (!m_keyboardHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_keyboardHelpMessageShown = true;
                    DisplaySmallMessage(Utils.Get("按 H 键查看键盘控制帮助\n(或看帮助)"), true, true);
                }
                else if (!m_gamepadHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_gamepadHelpMessageShown = true;
                    DisplaySmallMessage(Utils.Get("按 START/PAUSE 键查看手柄控制帮助\n(或看帮助)"), true, true);
                }
            }
            if (playerInput.KeyboardHelp)
            {
                if (m_keyboardHelpDialog == null)
                {
                    m_keyboardHelpDialog = new KeyboardHelpDialog();
                }
                if (m_keyboardHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_keyboardHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, m_keyboardHelpDialog);
                }
            }
            if (playerInput.GamepadHelp)
            {
                if (m_gamepadHelpDialog == null)
                {
                    m_gamepadHelpDialog = new GamepadHelpDialog();
                }
                if (m_gamepadHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_gamepadHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, m_gamepadHelpDialog);
                }
            }
            if (m_helpButtonWidget.IsClicked)
            {
                ScreensManager.SwitchScreen("Help");
            }
            IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;

            if (playerInput.ToggleInventory || m_inventoryButtonWidget.IsClicked)
            {
                if (componentRider.Mount != null && ModalPanelWidget == null)
                {
                    Widget widget = OpenEntity(inventory, m_componentPlayer.ComponentRider.Mount.Entity);
                    if (widget != null)
                    {
                        ModalPanelWidget = widget;
                        AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                        return;
                    }
                }
                ModalPanelWidget = IsInventoryVisible()
                                        ? null
                                        : inventory is ComponentCreativeInventory
                                        ? new CreativeInventoryWidget(m_componentPlayer.Entity)
                                        : (Widget) new FullInventoryWidget(inventory, m_componentPlayer.Entity.FindComponent <ComponentCraftingTable>(true));
            }
            if (playerInput.ToggleClothing || m_clothingButtonWidget.IsClicked)
            {
                ModalPanelWidget = IsClothingVisible() ? null : new ClothingWidget(m_componentPlayer);
            }
            if (m_sneakButtonWidget.IsClicked || playerInput.ToggleSneak)
            {
                bool isSneaking = m_componentPlayer.ComponentBody.IsSneaking;
                m_componentPlayer.ComponentBody.IsSneaking = !isSneaking;
                if (m_componentPlayer.ComponentBody.IsSneaking != isSneaking)
                {
                    DisplaySmallMessage(Utils.Get(m_componentPlayer.ComponentBody.IsSneaking ? "潜行模式:开" : "潜行模式:关"), false, false);
                }
            }
            if (componentRider != null && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount))
            {
                bool flag = componentRider.Mount != null;
                if (flag)
                {
                    componentRider.StartDismounting();
                }
                else
                {
                    ComponentMount componentMount = FindNearestMount(componentRider);
                    if (componentMount != null)
                    {
                        componentRider.StartMounting(componentMount);
                    }
                }
                if (componentRider.Mount != null != flag)
                {
                    DisplaySmallMessage(Utils.Get(componentRider.Mount != null ? "上马" : "下马"), false, false);
                }
            }
            if ((m_editItemButton.IsClicked || playerInput.EditItem) && m_nearbyEditableCell.HasValue)
            {
                int cellValue = m_subsystemTerrain.Terrain.GetCellValue(m_nearbyEditableCell.Value.X, m_nearbyEditableCell.Value.Y, m_nearbyEditableCell.Value.Z);
                int contents  = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(m_nearbyEditableCell.Value.X, m_nearbyEditableCell.Value.Y, m_nearbyEditableCell.Value.Z, cellValue, m_componentPlayer); i++)
                {
                }
            }
            else if ((m_editItemButton.IsClicked || playerInput.EditItem) && IsActiveSlotEditable())
            {
                if (inventory != null)
                {
                    int activeSlotIndex = inventory.ActiveSlotIndex;
                    int num             = Terrain.ExtractContents(inventory.GetSlotValue(activeSlotIndex));
                    if (BlocksManager.Blocks[num].IsEditable)
                    {
                        SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                        for (int j = 0; j < blockBehaviors2.Length && !blockBehaviors2[j].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer); j++)
                        {
                        }
                    }
                }
            }
            bool isCreative = m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative;

            if (isCreative && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly) && componentRider.Mount == null)
            {
                bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
                m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
                if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled)
                {
                    if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled)
                    {
                        m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                        DisplaySmallMessage(Utils.Get("飞行模式:开"), false, false);
                    }
                    else
                    {
                        DisplaySmallMessage(Utils.Get("飞行模式:关"), false, false);
                    }
                }
            }
            if (m_cameraButtonWidget.IsClicked || playerInput.SwitchCameraMode)
            {
                View view = m_componentPlayer.View;
                if (view.ActiveCamera.GetType() == typeof(FppCamera))
                {
                    view.ActiveCamera = view.FindCamera <TppCamera>(true);
                    DisplaySmallMessage(Utils.Get("第三人称视角"), false, false);
                }
                else if (view.ActiveCamera.GetType() == typeof(TppCamera))
                {
                    view.ActiveCamera = view.FindCamera <OrbitCamera>(true);
                    DisplaySmallMessage(Utils.Get("滑轨视角"), false, false);
                }
                else if (view.ActiveCamera.GetType() == typeof(OrbitCamera))
                {
                    view.ActiveCamera = isCreative ? (Camera) new DebugCamera(view) : view.FindCamera <FixedCamera>(true);
                    DisplaySmallMessage(Utils.Get(isCreative ? "调试视角" : "固定视角"), false, false);
                }
                else if (isCreative && view.ActiveCamera.GetType() == typeof(FixedCamera))
                {
                    view.ActiveCamera = new FlyCamera(view);
                    DisplaySmallMessage(Utils.Get("飞行视角"), false, false);
                }
                else if (view.ActiveCamera.GetType() == typeof(DebugCamera))
                {
                    view.ActiveCamera = view.FindCamera <FixedCamera>(true);
                    DisplaySmallMessage(Utils.Get("固定视角"), false, false);
                }
                else if (view.ActiveCamera.GetType() == typeof(FlyCamera))
                {
                    view.ActiveCamera = new RandomJumpCamera(view);
                    DisplaySmallMessage(Utils.Get("随机跳跃视角"), false, false);
                }
                else if (view.ActiveCamera.GetType() == typeof(RandomJumpCamera))
                {
                    view.ActiveCamera = new StraightFlightCamera(view);
                    DisplaySmallMessage(Utils.Get("垂直飞行视角"), false, false);
                }
                else
                {
                    view.ActiveCamera = view.FindCamera <FppCamera>(true);
                    DisplaySmallMessage(Utils.Get("第一人称视角"), false, false);
                }
            }
            if (m_photoButtonWidget.IsClicked || playerInput.TakeScreenshot)
            {
                ScreenCaptureManager.CapturePhoto();
                Time.QueueFrameCountDelayedExecution(Time.FrameIndex + 1, delegate
                {
                    DisplaySmallMessage(Utils.Get("照片已保存到图片相册"), false, false);
                });
            }
            if (isCreative && (m_lightningButtonWidget.IsClicked || playerInput.Lighting))
            {
                Project.FindSubsystem <SubsystemWeather>(true).ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation).Forward);
            }
            if (isCreative && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay))
            {
                float num2  = MathUtils.Remainder(0.25f, 1f);
                float num3  = MathUtils.Remainder(0.5f, 1f);
                float num4  = MathUtils.Remainder(0.75f, 1f);
                float num5  = MathUtils.Remainder(1f, 1f);
                float num6  = MathUtils.Remainder(num2 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num7  = MathUtils.Remainder(num3 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num8  = MathUtils.Remainder(num4 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num9  = MathUtils.Remainder(num5 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num10 = MathUtils.Min(num6, num7, num8, num9);
                if (num6 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num6;
                    DisplaySmallMessage(Utils.Get("黎明"), false, false);
                }
                else if (num7 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num7;
                    DisplaySmallMessage(Utils.Get("中午"), false, false);
                }
                else if (num8 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num8;
                    DisplaySmallMessage(Utils.Get("黄昏"), false, false);
                }
                else if (num9 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num9;
                    DisplaySmallMessage(Utils.Get("午夜"), false, false);
                }
            }
            if (ModalPanelWidget != null)
            {
                if (input.Cancel || input.Back || m_backButtonWidget.IsClicked)
                {
                    ModalPanelWidget = null;
                }
            }
            else if (input.Back || m_backButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(m_componentPlayer.View.GameWidget, new GameMenuDialog(m_componentPlayer));
            }
            return;
        }
        public void NormalMovement(float dt)
        {
            m_componentCreature.ComponentBody.IsGravityEnabled    = true;
            m_componentCreature.ComponentBody.IsGroundDragEnabled = true;
            m_componentCreature.ComponentBody.IsWaterDragEnabled  = true;
            Vector3 velocity = m_componentCreature.ComponentBody.Velocity;
            Vector3 right    = m_componentCreature.ComponentBody.Matrix.Right;
            Vector3 vector   = Vector3.Transform(m_componentCreature.ComponentBody.Matrix.Forward, Quaternion.CreateFromAxisAngle(right, LookAngles.Y));

            if (WalkSpeed > 0f && WalkOrder.HasValue)
            {
                if (IsCreativeFlyEnabled)
                {
                    Vector3 v = new Vector3(WalkOrder.Value.X, 0f, WalkOrder.Value.Y);
                    if (FlyOrder.HasValue)
                    {
                        v += FlyOrder.Value;
                    }
                    Vector3 v2  = (!SettingsManager.HorizontalCreativeFlight || m_componentPlayer == null || m_componentPlayer.ComponentInput.IsControlledByTouch) ? Vector3.Normalize(vector + 0.1f * Vector3.UnitY) : Vector3.Normalize(vector * new Vector3(1f, 0f, 1f));
                    Vector3 v3  = CreativeFlySpeed * (right * v.X + Vector3.UnitY * v.Y + v2 * v.Z);
                    float   num = (v == Vector3.Zero) ? 5f : 3f;
                    velocity += MathUtils.Saturate(num * dt) * (v3 - velocity);
                    m_componentCreature.ComponentBody.IsGravityEnabled    = false;
                    m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                    m_flying = true;
                }
                else
                {
                    Vector2 value = WalkOrder.Value;
                    if (m_walkSpeedWhenTurning > 0f && MathUtils.Abs(TurnOrder.X) > 0.02f)
                    {
                        value.Y = MathUtils.Max(value.Y, MathUtils.Lerp(0f, m_walkSpeedWhenTurning, MathUtils.Saturate(2f * MathUtils.Abs(TurnOrder.X))));
                    }
                    float num2 = WalkSpeed;
                    if (m_componentCreature.ComponentBody.ImmersionFactor > 0.2f)
                    {
                        num2 *= 0.66f;
                    }
                    if (value.Y < 0f)
                    {
                        num2 *= 0.6f;
                    }
                    if (m_componentLevel != null)
                    {
                        num2 *= m_componentLevel.SpeedFactor;
                    }
                    if (m_componentMount != null)
                    {
                        ComponentRider rider = m_componentMount.Rider;
                        if (rider != null)
                        {
                            ComponentClothing componentClothing = rider.Entity.FindComponent <ComponentClothing>();
                            if (componentClothing != null)
                            {
                                num2 *= componentClothing.SteedMovementSpeedFactor;
                            }
                        }
                    }
                    Vector3 v4      = value.X * Vector3.Normalize(new Vector3(right.X, 0f, right.Z)) + value.Y * Vector3.Normalize(new Vector3(vector.X, 0f, vector.Z));
                    Vector3 vector2 = num2 * v4 + m_componentCreature.ComponentBody.StandingOnVelocity;
                    float   num4;
                    if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
                    {
                        float num3 = MathUtils.Max(BlocksManager.Blocks[Terrain.ExtractContents(m_componentCreature.ComponentBody.StandingOnValue.Value)].FrictionFactor, m_minFrictionFactor);
                        num4 = MathUtils.Saturate(dt * 6f * AccelerationFactor * num3);
                        if (num3 < 0.25f)
                        {
                            SlipSpeed = num2 * value.Length();
                        }
                        m_walking = true;
                    }
                    else
                    {
                        num4 = MathUtils.Saturate(dt * 6f * AccelerationFactor * InAirWalkFactor);
                        if (m_componentCreature.ComponentBody.ImmersionFactor > 0f)
                        {
                            m_swimming = true;
                        }
                        else
                        {
                            m_falling = true;
                        }
                    }
                    velocity.X += num4 * (vector2.X - velocity.X);
                    velocity.Z += num4 * (vector2.Z - velocity.Z);
                    Vector3 vector3 = value.X * right + value.Y * vector;
                    if (m_componentLevel != null)
                    {
                        vector3 *= m_componentLevel.SpeedFactor;
                    }
                    velocity.Y += 10f * AccelerationFactor * vector3.Y * m_componentCreature.ComponentBody.ImmersionFactor * dt;
                    m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                    if (m_componentPlayer != null && Time.PeriodicEvent(10.0, 0.0) && (m_shoesWarningTime == 0.0 || Time.FrameStartTime - m_shoesWarningTime > 300.0) && m_componentCreature.ComponentBody.StandingOnValue.HasValue && m_componentCreature.ComponentBody.ImmersionFactor < 0.1f)
                    {
                        bool flag   = false;
                        int  value2 = m_componentPlayer.ComponentClothing.GetClothes(ClothingSlot.Feet).LastOrDefault();
                        if (Terrain.ExtractContents(value2) == 203)
                        {
                            flag = (ClothingBlock.GetClothingData(Terrain.ExtractData(value2)).MovementSpeedFactor > 1f);
                        }
                        if (!flag && vector2.LengthSquared() / velocity.LengthSquared() > 0.99f && WalkOrder.Value.LengthSquared() > 0.99f)
                        {
                            m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(GetType().Name, 1), Color.White, blinking: true, playNotificationSound: true);
                            m_shoesWarningTime = Time.FrameStartTime;
                        }
                    }
                }
            }
            if (FlySpeed > 0f && FlyOrder.HasValue)
            {
                Vector3 value3 = FlyOrder.Value;
                Vector3 v5     = FlySpeed * value3;
                velocity += MathUtils.Saturate(2f * AccelerationFactor * dt) * (v5 - velocity);
                m_componentCreature.ComponentBody.IsGravityEnabled = false;
                m_flying = true;
            }
            if (SwimSpeed > 0f && SwimOrder.HasValue && m_componentCreature.ComponentBody.ImmersionFactor > 0.5f)
            {
                Vector3 value4 = SwimOrder.Value;
                Vector3 v6     = SwimSpeed * value4;
                float   num5   = 2f;
                if (value4.LengthSquared() >= 0.99f)
                {
                    v6   *= MathUtils.Lerp(1f, 2f, m_swimBurstRemaining);
                    num5 *= MathUtils.Lerp(1f, 4f, m_swimBurstRemaining);
                    m_swimBurstRemaining -= dt;
                }
                velocity += MathUtils.Saturate(num5 * AccelerationFactor * dt) * (v6 - velocity);
                m_componentCreature.ComponentBody.IsGravityEnabled    = (MathUtils.Abs(value4.Y) <= 0.07f);
                m_componentCreature.ComponentBody.IsWaterDragEnabled  = false;
                m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                m_swimming = true;
            }
            if (JumpOrder > 0f && (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.ImmersionFactor > 0.5f) && !m_componentCreature.ComponentBody.IsSneaking)
            {
                float num6 = JumpSpeed;
                if (m_componentLevel != null)
                {
                    num6 *= 0.25f * (m_componentLevel.SpeedFactor - 1f) + 1f;
                }
                velocity.Y = MathUtils.Min(velocity.Y + MathUtils.Saturate(JumpOrder) * num6, num6);
                m_jumping  = true;
                m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
                m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 10f);
            }
            if (MathUtils.Abs(m_componentCreature.ComponentBody.CollisionVelocityChange.Y) > 3f)
            {
                m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
                m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 10f);
            }
            m_componentCreature.ComponentBody.Velocity = velocity;
        }
        public void Update(float dt)
        {
            if (m_subsystemGameInfo.TotalElapsedGameTime > m_precipitationEndTime)
            {
                if (m_precipitationEndTime == 0.0)
                {
                    if (m_subsystemGameInfo.WorldSettings.StartingPositionMode == StartingPositionMode.Hard)
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(2f, 3f));
                        m_lightningIntensity     = m_random.Float(0.5f, 1f);
                    }
                    else
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(3f, 6f));
                        m_lightningIntensity     = m_random.Float(0.33f, 0.66f);
                    }
                }
                else
                {
                    m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(5f, 45f));
                    m_lightningIntensity     = ((m_random.Float(0f, 1f) < 0.5f) ? m_random.Float(0.33f, 1f) : 0f);
                }
                m_precipitationEndTime = m_precipitationStartTime + (double)(60f * m_random.Float(3f, 6f));
            }
            float num = (float)MathUtils.Max(0.0, MathUtils.Min(m_subsystemGameInfo.TotalElapsedGameTime - m_precipitationStartTime, m_precipitationEndTime - m_subsystemGameInfo.TotalElapsedGameTime));

            GlobalPrecipitationIntensity = (m_subsystemGameInfo.WorldSettings.AreWeatherEffectsEnabled ? MathUtils.Saturate(num * 0.04f) : 0f);
            if (GlobalPrecipitationIntensity == 1f && SubsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                TerrainChunk[] allocatedChunks = SubsystemTerrain.Terrain.AllocatedChunks;
                for (int i = 0; i < allocatedChunks.Length; i++)
                {
                    TerrainChunk terrainChunk = allocatedChunks[m_random.Int(0, allocatedChunks.Length - 1)];
                    if (terrainChunk.State < TerrainChunkState.InvalidVertices1 || !m_random.Bool(m_lightningIntensity * 0.0002f))
                    {
                        continue;
                    }
                    int     num2   = terrainChunk.Origin.X + m_random.Int(0, 15);
                    int     num3   = terrainChunk.Origin.Y + m_random.Int(0, 15);
                    Vector3?vector = null;
                    for (int j = num2 - 8; j < num2 + 8; j++)
                    {
                        for (int k = num3 - 8; k < num3 + 8; k++)
                        {
                            int topHeight = SubsystemTerrain.Terrain.GetTopHeight(j, k);
                            if (!vector.HasValue || (float)topHeight > vector.Value.Y)
                            {
                                vector = new Vector3(j, topHeight, k);
                            }
                        }
                    }
                    if (vector.HasValue)
                    {
                        SubsystemSky.MakeLightningStrike(vector.Value);
                        return;
                    }
                }
            }
            if (Time.PeriodicEvent(0.5, 0.0))
            {
                float num4 = 0f;
                if (GlobalPrecipitationIntensity > 0f)
                {
                    float num5 = 0f;
                    foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions)
                    {
                        int     num6    = Terrain.ToCell(listenerPosition.X) - 5;
                        int     num7    = Terrain.ToCell(listenerPosition.Z) - 5;
                        int     num8    = Terrain.ToCell(listenerPosition.X) + 5;
                        int     num9    = Terrain.ToCell(listenerPosition.Z) + 5;
                        Vector3 vector2 = default(Vector3);
                        for (int l = num6; l <= num8; l++)
                        {
                            for (int m = num7; m <= num9; m++)
                            {
                                PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(l, m);
                                if (precipitationShaftInfo.Type == PrecipitationType.Rain && precipitationShaftInfo.Intensity > 0f)
                                {
                                    vector2.X = (float)l + 0.5f;
                                    vector2.Y = MathUtils.Max(precipitationShaftInfo.YLimit, listenerPosition.Y);
                                    vector2.Z = (float)m + 0.5f;
                                    float num10    = vector2.X - listenerPosition.X;
                                    float num11    = 8f * (vector2.Y - listenerPosition.Y);
                                    float num12    = vector2.Z - listenerPosition.Z;
                                    float distance = MathUtils.Sqrt(num10 * num10 + num11 * num11 + num12 * num12);
                                    num5 += m_subsystemAudio.CalculateVolume(distance, 1.5f) * precipitationShaftInfo.Intensity;
                                }
                            }
                        }
                    }
                    num4 = MathUtils.Max(num4, num5);
                }
                m_targetRainSoundVolume = MathUtils.Saturate(1.5f * num4 / m_rainVolumeFactor);
            }
            m_rainSound.Volume = MathUtils.Saturate(MathUtils.Lerp(m_rainSound.Volume, SettingsManager.SoundsVolume * m_targetRainSoundVolume, 5f * dt));
            if (m_rainSound.Volume > AudioManager.MinAudibleVolume)
            {
                m_rainSound.Play();
            }
            else
            {
                m_rainSound.Pause();
            }
        }
        public void Update(float dt)
        {
            CollisionVelocityChange = Vector3.Zero;
            Velocity      += m_totalImpulse;
            m_totalImpulse = Vector3.Zero;
            if (m_parentBody != null || m_velocity.LengthSquared() > 9.99999944E-11f || m_directMove != Vector3.Zero)
            {
                m_stoppedTime = 0f;
            }
            else
            {
                m_stoppedTime += dt;
                if (m_stoppedTime > 0.5f && !Time.PeriodicEvent(0.25, 0.0))
                {
                    return;
                }
            }
            Vector3      position    = base.Position;
            TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(position.X), Terrain.ToCell(position.Z));

            if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4)
            {
                Velocity = Vector3.Zero;
                return;
            }
            m_bodiesCollisionBoxes.Clear();
            FindBodiesCollisionBoxes(position, m_bodiesCollisionBoxes);
            m_movingBlocksCollisionBoxes.Clear();
            FindMovingBlocksCollisionBoxes(position, m_movingBlocksCollisionBoxes);
            if (!MoveToFreeSpace())
            {
                ComponentHealth componentHealth = base.Entity.FindComponent <ComponentHealth>();
                if (componentHealth != null)
                {
                    componentHealth.Injure(1f, null, ignoreInvulnerability: true, "Crushed");
                }
                else
                {
                    base.Project.RemoveEntity(base.Entity, disposeEntity: true);
                }
                return;
            }
            if (IsGravityEnabled)
            {
                m_velocity.Y -= 10f * dt;
                if (ImmersionFactor > 0f)
                {
                    float num = ImmersionFactor * (1f + 0.03f * MathUtils.Sin((float)MathUtils.Remainder(2.0 * m_subsystemTime.GameTime, 6.2831854820251465)));
                    m_velocity.Y += 10f * (1f / Density * num) * dt;
                }
            }
            float num2 = MathUtils.Saturate(AirDrag.X * dt);
            float num3 = MathUtils.Saturate(AirDrag.Y * dt);

            m_velocity.X *= 1f - num2;
            m_velocity.Y *= 1f - num3;
            m_velocity.Z *= 1f - num2;
            if (IsWaterDragEnabled && ImmersionFactor > 0f && ImmersionFluidBlock != null)
            {
                Vector2?vector  = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(position.X), Terrain.ToCell(position.Y), Terrain.ToCell(position.Z));
                Vector3 vector2 = vector.HasValue ? new Vector3(vector.Value.X, 0f, vector.Value.Y) : Vector3.Zero;
                float   num4    = 1f;
                if (ImmersionFluidBlock.FrictionFactor != 1f)
                {
                    num4 = ((SimplexNoise.Noise((float)MathUtils.Remainder(6.0 * Time.FrameStartTime + (double)(GetHashCode() % 1000), 1000.0)) > 0.5f) ? ImmersionFluidBlock.FrictionFactor : 1f);
                }
                float f  = MathUtils.Saturate(WaterDrag.X * num4 * ImmersionFactor * dt);
                float f2 = MathUtils.Saturate(WaterDrag.Y * num4 * dt);
                m_velocity.X = MathUtils.Lerp(m_velocity.X, vector2.X, f);
                m_velocity.Y = MathUtils.Lerp(m_velocity.Y, vector2.Y, f2);
                m_velocity.Z = MathUtils.Lerp(m_velocity.Z, vector2.Z, f);
                if (m_parentBody == null && vector.HasValue && !StandingOnValue.HasValue)
                {
                    if (WaterTurnSpeed > 0f)
                    {
                        float   s       = MathUtils.Saturate(MathUtils.Lerp(1f, 0f, m_velocity.Length()));
                        Vector2 vector3 = Vector2.Normalize(vector.Value) * s;
                        base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, WaterTurnSpeed * (-1f * vector3.X + 0.71f * vector3.Y) * dt);
                    }
                    if (WaterSwayAngle > 0f)
                    {
                        base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, WaterSwayAngle * (float)MathUtils.Sin((double)(200f / Mass) * m_subsystemTime.GameTime));
                    }
                }
            }
            if (m_parentBody != null)
            {
                Vector3 v = Vector3.Transform(ParentBodyPositionOffset, m_parentBody.Rotation) + m_parentBody.Position - position;
                m_velocity    = ((dt > 0f) ? (v / dt) : Vector3.Zero);
                base.Rotation = ParentBodyRotationOffset * m_parentBody.Rotation;
            }
            StandingOnValue    = null;
            StandingOnBody     = null;
            StandingOnVelocity = Vector3.Zero;
            Vector3 velocity = m_velocity;
            float   num5     = m_velocity.Length();

            if (num5 > 0f)
            {
                float x    = 0.45f * MathUtils.Min(BoxSize.X, BoxSize.Y, BoxSize.Z) / num5;
                float num6 = dt;
                while (num6 > 0f)
                {
                    float num7 = MathUtils.Min(num6, x);
                    MoveWithCollision(num7, m_velocity * num7 + m_directMove);
                    m_directMove = Vector3.Zero;
                    num6        -= num7;
                }
            }
            CollisionVelocityChange = m_velocity - velocity;
            if (IsGroundDragEnabled && StandingOnValue.HasValue)
            {
                m_velocity = Vector3.Lerp(m_velocity, StandingOnVelocity, 6f * dt);
            }
            if (!StandingOnValue.HasValue)
            {
                IsSneaking = false;
            }
            UpdateImmersionData();
            if (ImmersionFluidBlock is WaterBlock && ImmersionDepth > 0.3f && !m_fluidEffectsPlayed)
            {
                m_fluidEffectsPlayed = true;
                m_subsystemAudio.PlayRandomSound("Audio/WaterFallIn", m_random.Float(0.75f, 1f), m_random.Float(-0.3f, 0f), position, 4f, autoDelay: true);
                m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f));
            }
            else if (ImmersionFluidBlock is MagmaBlock && ImmersionDepth > 0f && !m_fluidEffectsPlayed)
            {
                m_fluidEffectsPlayed = true;
                m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, position, 4f, autoDelay: true);
                m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f));
            }
            else if (ImmersionFluidBlock == null)
            {
                m_fluidEffectsPlayed = false;
            }
        }
Beispiel #10
0
        public PlayerData(Project project)
        {
            m_project            = project;
            SubsystemPlayers     = project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
            SubsystemGameWidgets = project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true);
            m_subsystemTerrain   = project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemGameInfo  = project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemSky       = project.FindSubsystem <SubsystemSky>(throwOnError: true);
            m_playerClass        = PlayerClass.Male;
            Level          = 1f;
            FirstSpawnTime = -1.0;
            LastSpawnTime  = -1.0;
            RandomizeCharacterSkin();
            ResetName();
            InputDevice = WidgetInputDevice.None;
            m_stateMachine.AddState("FirstUpdate", null, delegate
            {
                if (ComponentPlayer != null)
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 4), Name, MathUtils.Floor(Level)), null, 0f, resetProgress: true);
                    m_stateMachine.TransitionTo("WaitForTerrain");
                }
                else
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
            }, null);
            m_stateMachine.AddState("PrepareSpawn", delegate
            {
                if (SpawnPosition == Vector3.Zero)
                {
                    if (SubsystemPlayers.GlobalSpawnPosition == Vector3.Zero)
                    {
                        PlayerData playerData = SubsystemPlayers.PlayersData.FirstOrDefault((PlayerData pd) => pd.SpawnPosition != Vector3.Zero);
                        if (playerData != null)
                        {
                            if (playerData.ComponentPlayer != null)
                            {
                                SpawnPosition = playerData.ComponentPlayer.ComponentBody.Position;
                                m_spawnMode   = SpawnMode.InitialNoIntro;
                            }
                            else
                            {
                                SpawnPosition = playerData.SpawnPosition;
                                m_spawnMode   = SpawnMode.InitialNoIntro;
                            }
                        }
                        else
                        {
                            SpawnPosition = m_subsystemTerrain.TerrainContentsGenerator.FindCoarseSpawnPosition();
                            m_spawnMode   = SpawnMode.InitialIntro;
                        }
                        SubsystemPlayers.GlobalSpawnPosition = SpawnPosition;
                    }
                    else
                    {
                        SpawnPosition = SubsystemPlayers.GlobalSpawnPosition;
                        m_spawnMode   = SpawnMode.InitialNoIntro;
                    }
                }
                else
                {
                    m_spawnMode = SpawnMode.Respawn;
                }
                if (m_spawnMode == SpawnMode.Respawn)
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 2), Name, MathUtils.Floor(Level)), LanguageControl.Get(fName, 3), 0f, resetProgress: true);
                }
                else
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 4), Name, MathUtils.Floor(Level)), null, 0f, resetProgress: true);
                }
                m_subsystemTerrain.TerrainUpdater.SetUpdateLocation(PlayerIndex, SpawnPosition.XZ, 0f, 64f);
                m_terrainWaitStartTime = Time.FrameStartTime;
            }, delegate
            {
                if (Time.PeriodicEvent(0.1, 0.0))
                {
                    float updateProgress2 = m_subsystemTerrain.TerrainUpdater.GetUpdateProgress(PlayerIndex, 0f, 64f);
                    UpdateSpawnDialog(null, null, 0.5f * updateProgress2, resetProgress: false);
                    if (!(updateProgress2 < 1f) || !(Time.FrameStartTime - m_terrainWaitStartTime < 15.0))
                    {
                        switch (m_spawnMode)
                        {
                        case SpawnMode.InitialIntro:
                            SpawnPosition = FindIntroSpawnPosition(SpawnPosition.XZ);
                            break;

                        case SpawnMode.InitialNoIntro:
                            SpawnPosition = FindNoIntroSpawnPosition(SpawnPosition, respawn: false);
                            break;

                        case SpawnMode.Respawn:
                            SpawnPosition = FindNoIntroSpawnPosition(SpawnPosition, respawn: true);
                            break;

                        default:
                            throw new InvalidOperationException(LanguageControl.Get(fName, 5));
                        }
                        m_stateMachine.TransitionTo("WaitForTerrain");
                    }
                }
            }, null);
            m_stateMachine.AddState("WaitForTerrain", delegate
            {
                m_terrainWaitStartTime = Time.FrameStartTime;
                Vector2 center         = (ComponentPlayer != null) ? ComponentPlayer.ComponentBody.Position.XZ : SpawnPosition.XZ;
                m_subsystemTerrain.TerrainUpdater.SetUpdateLocation(PlayerIndex, center, MathUtils.Min(m_subsystemSky.VisibilityRange, 64f), 0f);
            }, delegate
            {
                if (Time.PeriodicEvent(0.1, 0.0))
                {
                    float updateProgress = m_subsystemTerrain.TerrainUpdater.GetUpdateProgress(PlayerIndex, MathUtils.Min(m_subsystemSky.VisibilityRange, 64f), 0f);
                    UpdateSpawnDialog(null, null, 0.5f + 0.5f * updateProgress, resetProgress: false);
                    if ((updateProgress >= 1f && Time.FrameStartTime - m_terrainWaitStartTime > 2.0) || Time.FrameStartTime - m_terrainWaitStartTime >= 15.0)
                    {
                        if (ComponentPlayer == null)
                        {
                            SpawnPlayer(SpawnPosition, m_spawnMode);
                        }
                        m_stateMachine.TransitionTo("Playing");
                    }
                }
            }, null);
            m_stateMachine.AddState("Playing", delegate
            {
                HideSpawnDialog();
            }, delegate
            {
                if (ComponentPlayer == null)
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
                else if (m_playerDeathTime.HasValue)
                {
                    m_stateMachine.TransitionTo("PlayerDead");
                }
                else if (ComponentPlayer.ComponentHealth.Health <= 0f)
                {
                    m_playerDeathTime = Time.RealTime;
                }
            }, null);
            m_stateMachine.AddState("PlayerDead", delegate
            {
                GameWidget.ActiveCamera = GameWidget.FindCamera <DeathCamera>();
                if (ComponentPlayer != null)
                {
                    string text = ComponentPlayer.ComponentHealth.CauseOfDeath;
                    if (string.IsNullOrEmpty(text))
                    {
                        text = LanguageControl.Get(fName, 12);
                    }
                    string arg = string.Format(LanguageControl.Get(fName, 13), text);
                    if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Cruel)
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 7), arg, LanguageControl.Get("GameMode", m_subsystemGameInfo.WorldSettings.GameMode.ToString())), 30f, 1.5f);
                    }
                    else if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Adventure && !m_subsystemGameInfo.WorldSettings.IsAdventureRespawnAllowed)
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 8), arg), 30f, 1.5f);
                    }
                    else
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 9), arg), 30f, 1.5f);
                    }
                }
                Level = MathUtils.Max(MathUtils.Floor(Level / 2f), 1f);
            }, delegate
            {
                if (ComponentPlayer == null)
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
                else if (Time.RealTime - m_playerDeathTime.Value > 1.5 && !DialogsManager.HasDialogs(ComponentPlayer.GuiWidget) && ComponentPlayer.GameWidget.Input.Any)
                {
                    if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Cruel)
                    {
                        DialogsManager.ShowDialog(ComponentPlayer.GuiWidget, new GameMenuDialog(ComponentPlayer));
                    }
                    else if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Adventure && !m_subsystemGameInfo.WorldSettings.IsAdventureRespawnAllowed)
                    {
                        ScreensManager.SwitchScreen("GameLoading", GameManager.WorldInfo, "AdventureRestart");
                    }
                    else
                    {
                        m_project.RemoveEntity(ComponentPlayer.Entity, disposeEntity: true);
                    }
                }
            }, null);
            m_stateMachine.TransitionTo("FirstUpdate");
        }
Beispiel #11
0
        public void DrawIceOverlay(Camera camera, float factor)
        {
            Vector2 viewportSize = camera.ViewportSize;
            float   s            = camera.Eye.HasValue ? 1.3f : 1f;
            float   num          = camera.Eye.HasValue ? MathUtils.Pow(factor, 0.4f) : factor;
            Vector2 v            = camera.Eye.HasValue ? viewportSize : new Vector2(1f);
            float   num2         = v.Length();
            Point2  point        = new Point2((int)MathUtils.Round(12f * viewportSize.X / viewportSize.Y), (int)MathUtils.Round(12f));

            if (m_iceVertices == null || m_cellsCount != point)
            {
                m_cellsCount = point;
                m_random.Seed(0);
                m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)];
                for (int i = 0; i <= point.X; i++)
                {
                    for (int j = 0; j <= point.Y; j++)
                    {
                        float num3 = i;
                        float num4 = j;
                        if (i != 0 && i != point.X)
                        {
                            num3 += m_random.Float(-0.4f, 0.4f);
                        }
                        if (j != 0 && j != point.Y)
                        {
                            num4 += m_random.Float(-0.4f, 0.4f);
                        }
                        float x = num3 / (float)point.X;
                        float y = num4 / (float)point.Y;
                        m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y);
                    }
                }
            }
            Vector3 vector  = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s;
            Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s;
            Vector3 v2      = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2);

            if (!m_light.HasValue || Time.PeriodicEvent(0.05000000074505806, 0.0))
            {
                m_light = (LightingManager.CalculateSmoothLight(m_subsystemTerrain, camera.ViewPosition) ?? m_light ?? 1f);
            }
            Color color = Color.MultiplyColorOnly(Color.White, m_light.Value);

            m_random.Seed(0);
            Texture2D       texture         = ContentManager.Get <Texture2D>("Textures/IceOverlay");
            TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.PointWrap);
            Vector2         v3      = new Vector2(viewportSize.X / viewportSize.Y, 1f);
            Vector2         vector3 = new Vector2(point.X - 1, point.Y - 1);

            for (int k = 0; k < point.X; k++)
            {
                for (int l = 0; l < point.Y; l++)
                {
                    float num5 = (new Vector2((float)(2 * k) / vector3.X - 1f, (float)(2 * l) / vector3.Y - 1f) * v).Length() / num2;
                    if (1f - num5 + m_random.Float(0f, 0.05f) < num)
                    {
                        Vector2 v4        = m_iceVertices[k + l * (point.X + 1)];
                        Vector2 v5        = m_iceVertices[k + 1 + l * (point.X + 1)];
                        Vector2 v6        = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)];
                        Vector2 v7        = m_iceVertices[k + (l + 1) * (point.X + 1)];
                        Vector3 vector4   = v2 + v4.X * vector + v4.Y * vector2;
                        Vector3 p         = v2 + v5.X * vector + v5.Y * vector2;
                        Vector3 vector5   = v2 + v6.X * vector + v6.Y * vector2;
                        Vector3 p2        = v2 + v7.X * vector + v7.Y * vector2;
                        Vector2 vector6   = v4 * v3;
                        Vector2 texCoord  = v5 * v3;
                        Vector2 vector7   = v6 * v3;
                        Vector2 texCoord2 = v7 * v3;
                        texturedBatch3D.QueueTriangle(vector4, p, vector5, vector6, texCoord, vector7, color);
                        texturedBatch3D.QueueTriangle(vector5, p2, vector4, vector7, texCoord2, vector6, color);
                    }
                }
            }
            texturedBatch3D.Flush(camera.ProjectionMatrix);
        }
Beispiel #12
0
 public void Update(float dt)
 {
     if (!base.IsAddedToProject)
     {
         return;
     }
     if (IsOnFire)
     {
         m_fireDuration = MathUtils.Max(m_fireDuration - dt, 0f);
         if (m_onFireParticleSystem == null)
         {
             m_onFireParticleSystem = new OnFireParticleSystem();
             m_subsystemParticles.AddParticleSystem(m_onFireParticleSystem);
         }
         BoundingBox boundingBox = ComponentBody.BoundingBox;
         m_onFireParticleSystem.Position = 0.5f * (boundingBox.Min + boundingBox.Max);
         m_onFireParticleSystem.Radius   = 0.5f * MathUtils.Min(boundingBox.Max.X - boundingBox.Min.X, boundingBox.Max.Z - boundingBox.Min.Z);
         if (ComponentBody.ImmersionFactor > 0.5f && ComponentBody.ImmersionFluidBlock is WaterBlock)
         {
             Extinguish();
             m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, m_onFireParticleSystem.Position, 4f, autoDelay: true);
         }
         if (Time.PeriodicEvent(0.5, 0.0))
         {
             float distance = m_subsystemAudio.CalculateListenerDistance(ComponentBody.Position);
             m_soundVolume = m_subsystemAudio.CalculateVolume(distance, 2f, 5f);
         }
         m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_soundVolume);
     }
     else
     {
         if (m_onFireParticleSystem != null)
         {
             m_onFireParticleSystem.IsStopped = true;
             m_onFireParticleSystem           = null;
         }
         m_soundVolume = 0f;
     }
     if (!(m_subsystemTime.GameTime > m_nextCheckTime))
     {
         return;
     }
     m_nextCheckTime = m_subsystemTime.GameTime + (double)m_random.Float(0.9f, 1.1f);
     TouchesFire     = CheckIfBodyTouchesFire();
     if (TouchesFire)
     {
         m_fireTouchCount++;
         if (m_fireTouchCount >= 5)
         {
             SetOnFire(null, m_random.Float(12f, 15f));
         }
     }
     else
     {
         m_fireTouchCount = 0;
     }
     if (ComponentBody.ImmersionFactor > 0.2f && ComponentBody.ImmersionFluidBlock is MagmaBlock)
     {
         SetOnFire(null, m_random.Float(12f, 15f));
     }
 }
Beispiel #13
0
        public void Update(float dt)
        {
            PlayerInput playerInput = ComponentInput.PlayerInput;

            if (ComponentInput.IsControlledByTouch && m_aim.HasValue)
            {
                playerInput.Look = Vector2.Zero;
            }
            if (ComponentMiner.Inventory != null)
            {
                ComponentMiner.Inventory.ActiveSlotIndex += playerInput.ScrollInventory;
                if (playerInput.SelectInventorySlot.HasValue)
                {
                    ComponentMiner.Inventory.ActiveSlotIndex = MathUtils.Clamp(playerInput.SelectInventorySlot.Value, 0, 9);
                }
            }
            ComponentSteedBehavior componentSteedBehavior = null;
            ComponentBoat          componentBoat          = null;
            ComponentMount         mount = ComponentRider.Mount;

            if (mount != null)
            {
                componentSteedBehavior = mount.Entity.FindComponent <ComponentSteedBehavior>();
                componentBoat          = mount.Entity.FindComponent <ComponentBoat>();
            }
            if (componentSteedBehavior != null)
            {
                if (playerInput.Move.Z > 0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = 1;
                    m_speedOrderBlocked = true;
                }
                else if (playerInput.Move.Z < -0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = -1;
                    m_speedOrderBlocked = true;
                }
                else if (MathUtils.Abs(playerInput.Move.Z) <= 0.25f)
                {
                    m_speedOrderBlocked = false;
                }
                componentSteedBehavior.TurnOrder   = playerInput.Move.X;
                componentSteedBehavior.JumpOrder   = (playerInput.Jump ? 1 : 0);
                base.ComponentLocomotion.LookOrder = new Vector2(playerInput.Look.X, 0f);
            }
            else if (componentBoat != null)
            {
                componentBoat.TurnOrder                   = playerInput.Move.X;
                componentBoat.MoveOrder                   = playerInput.Move.Z;
                base.ComponentLocomotion.LookOrder        = new Vector2(playerInput.Look.X, 0f);
                base.ComponentCreatureModel.RowLeftOrder  = (playerInput.Move.X <-0.2f || playerInput.Move.Z> 0.2f);
                base.ComponentCreatureModel.RowRightOrder = (playerInput.Move.X > 0.2f || playerInput.Move.Z > 0.2f);
            }
            else
            {
                base.ComponentLocomotion.WalkOrder = (base.ComponentBody.IsSneaking ? (0.66f * new Vector2(playerInput.SneakMove.X, playerInput.SneakMove.Z)) : new Vector2(playerInput.Move.X, playerInput.Move.Z));
                base.ComponentLocomotion.FlyOrder  = new Vector3(0f, playerInput.Move.Y, 0f);
                base.ComponentLocomotion.TurnOrder = playerInput.Look * new Vector2(1f, 0f);
                base.ComponentLocomotion.JumpOrder = MathUtils.Max(playerInput.Jump ? 1 : 0, base.ComponentLocomotion.JumpOrder);
            }
            base.ComponentLocomotion.LookOrder  += playerInput.Look * (SettingsManager.FlipVerticalAxis ? new Vector2(0f, -1f) : new Vector2(0f, 1f));
            base.ComponentLocomotion.VrLookOrder = playerInput.VrLook;
            base.ComponentLocomotion.VrMoveOrder = playerInput.VrMove;
            int   num   = Terrain.ExtractContents(ComponentMiner.ActiveBlockValue);
            Block block = BlocksManager.Blocks[num];
            bool  flag  = false;

            if (playerInput.Interact.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                if (!ComponentMiner.Use(playerInput.Interact.Value))
                {
                    TerrainRaycastResult?terrainRaycastResult = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Interact.Value, RaycastMode.Interaction);
                    if (terrainRaycastResult.HasValue)
                    {
                        if (!ComponentMiner.Interact(terrainRaycastResult.Value))
                        {
                            if (ComponentMiner.Place(terrainRaycastResult.Value))
                            {
                                m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                                flag           = true;
                                m_isAimBlocked = true;
                            }
                        }
                        else
                        {
                            m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                            flag           = true;
                            m_isAimBlocked = true;
                        }
                    }
                }
                else
                {
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                    flag           = true;
                    m_isAimBlocked = true;
                }
            }
            float num2 = (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) ? 0.1f : 1.4f;

            if (playerInput.Aim.HasValue && block.IsAimable && m_subsystemTime.GameTime - m_lastActionTime > (double)num2)
            {
                if (!m_isAimBlocked)
                {
                    Ray3    value  = playerInput.Aim.Value;
                    Vector3 vector = GameWidget.ActiveCamera.WorldToScreen(value.Position + value.Direction, Matrix.Identity);
                    Point2  size   = Window.Size;
                    if (ComponentInput.IsControlledByVr || (vector.X >= (float)size.X * 0.02f && vector.X < (float)size.X * 0.98f && vector.Y >= (float)size.Y * 0.02f && vector.Y < (float)size.Y * 0.98f))
                    {
                        m_aim = value;
                        if (ComponentMiner.Aim(value, AimState.InProgress))
                        {
                            ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                            m_aim          = null;
                            m_isAimBlocked = true;
                        }
                        else if (!m_aimHintIssued && Time.PeriodicEvent(1.0, 0.0))
                        {
                            Time.QueueTimeDelayedExecution(Time.RealTime + 3.0, delegate
                            {
                                if (!m_aimHintIssued && m_aim.HasValue && !base.ComponentBody.IsSneaking)
                                {
                                    m_aimHintIssued = true;
                                    ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                                }
                            });
                        }
                    }
                    else if (m_aim.HasValue)
                    {
                        ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                        m_aim          = null;
                        m_isAimBlocked = true;
                    }
                }
            }
            else
            {
                m_isAimBlocked = false;
                if (m_aim.HasValue)
                {
                    ComponentMiner.Aim(m_aim.Value, AimState.Completed);
                    m_aim            = null;
                    m_lastActionTime = m_subsystemTime.GameTime;
                }
            }
            flag |= m_aim.HasValue;
            if (playerInput.Hit.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                BodyRaycastResult?bodyRaycastResult = ComponentMiner.Raycast <BodyRaycastResult>(playerInput.Hit.Value, RaycastMode.Interaction);
                if (bodyRaycastResult.HasValue)
                {
                    flag           = true;
                    m_isDigBlocked = true;
                    if (Vector3.Distance(bodyRaycastResult.Value.HitPoint(), base.ComponentCreatureModel.EyePosition) <= 2f)
                    {
                        ComponentMiner.Hit(bodyRaycastResult.Value.ComponentBody, bodyRaycastResult.Value.HitPoint(), playerInput.Hit.Value.Direction);
                    }
                }
            }
            if (playerInput.Dig.HasValue && !flag && !m_isDigBlocked && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                TerrainRaycastResult?terrainRaycastResult2 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Dig.Value, RaycastMode.Digging);
                if (terrainRaycastResult2.HasValue && ComponentMiner.Dig(terrainRaycastResult2.Value))
                {
                    m_lastActionTime = m_subsystemTime.GameTime;
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                }
            }
            if (!playerInput.Dig.HasValue)
            {
                m_isDigBlocked = false;
            }
            if (playerInput.Drop && ComponentMiner.Inventory != null)
            {
                IInventory inventory = ComponentMiner.Inventory;
                int        slotValue = inventory.GetSlotValue(inventory.ActiveSlotIndex);
                int        num3      = inventory.RemoveSlotItems(count: inventory.GetSlotCount(inventory.ActiveSlotIndex), slotIndex: inventory.ActiveSlotIndex);
                if (slotValue != 0 && num3 != 0)
                {
                    Vector3 position = base.ComponentBody.Position + new Vector3(0f, base.ComponentBody.BoxSize.Y * 0.66f, 0f) + 0.25f * base.ComponentBody.Matrix.Forward;
                    Vector3 value2   = 8f * Matrix.CreateFromQuaternion(base.ComponentCreatureModel.EyeRotation).Forward;
                    m_subsystemPickables.AddPickable(slotValue, num3, position, value2, null);
                }
            }
            if (!playerInput.PickBlockType.HasValue || flag)
            {
                return;
            }
            ComponentCreativeInventory componentCreativeInventory = ComponentMiner.Inventory as ComponentCreativeInventory;

            if (componentCreativeInventory == null)
            {
                return;
            }
            TerrainRaycastResult?terrainRaycastResult3 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.PickBlockType.Value, RaycastMode.Digging, raycastTerrain: true, raycastBodies: false, raycastMovingBlocks: false);

            if (!terrainRaycastResult3.HasValue)
            {
                return;
            }
            int value3 = terrainRaycastResult3.Value.Value;

            value3 = Terrain.ReplaceLight(value3, 0);
            int               num4           = Terrain.ExtractContents(value3);
            Block             block2         = BlocksManager.Blocks[num4];
            int               num5           = 0;
            IEnumerable <int> creativeValues = block2.GetCreativeValues();

            if (block2.GetCreativeValues().Contains(value3))
            {
                num5 = value3;
            }
            if (num5 == 0 && !block2.IsNonDuplicable)
            {
                List <BlockDropValue> list = new List <BlockDropValue>();
                block2.GetDropValues(m_subsystemTerrain, value3, 0, int.MaxValue, list, out bool _);
                if (list.Count > 0 && list[0].Count > 0)
                {
                    num5 = list[0].Value;
                }
            }
            if (num5 == 0)
            {
                num5 = creativeValues.FirstOrDefault();
            }
            if (num5 == 0)
            {
                return;
            }
            int num6 = -1;

            for (int i = 0; i < 10; i++)
            {
                if (componentCreativeInventory.GetSlotCapacity(i, num5) > 0 && componentCreativeInventory.GetSlotCount(i) > 0 && componentCreativeInventory.GetSlotValue(i) == num5)
                {
                    num6 = i;
                    break;
                }
            }
            if (num6 < 0)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (componentCreativeInventory.GetSlotCapacity(j, num5) > 0 && (componentCreativeInventory.GetSlotCount(j) == 0 || componentCreativeInventory.GetSlotValue(j) == 0))
                    {
                        num6 = j;
                        break;
                    }
                }
            }
            if (num6 < 0)
            {
                num6 = componentCreativeInventory.ActiveSlotIndex;
            }
            componentCreativeInventory.RemoveSlotItems(num6, int.MaxValue);
            componentCreativeInventory.AddSlotItems(num6, num5, 1);
            componentCreativeInventory.ActiveSlotIndex = num6;
            ComponentGui.DisplaySmallMessage(block2.GetDisplayName(m_subsystemTerrain, value3), Color.White, blinking: false, playNotificationSound: false);
            m_subsystemAudio.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f, 0f);
        }
Beispiel #14
0
        public void HandleInput()
        {
            WidgetInput    input          = m_componentPlayer.GameWidget.Input;
            PlayerInput    playerInput    = m_componentPlayer.ComponentInput.PlayerInput;
            ComponentRider componentRider = m_componentPlayer.ComponentRider;

            if (m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled)
            {
                if (!m_keyboardHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_keyboardHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (!m_gamepadHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_gamepadHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                }
            }
            if (playerInput.KeyboardHelp)
            {
                if (m_keyboardHelpDialog == null)
                {
                    m_keyboardHelpDialog = new KeyboardHelpDialog();
                }
                if (m_keyboardHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_keyboardHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_keyboardHelpDialog);
                }
            }
            if (playerInput.GamepadHelp)
            {
                if (m_gamepadHelpDialog == null)
                {
                    m_gamepadHelpDialog = new GamepadHelpDialog();
                }
                if (m_gamepadHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_gamepadHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_gamepadHelpDialog);
                }
            }
            if (m_helpButtonWidget.IsClicked)
            {
                ScreensManager.SwitchScreen("Help");
            }
            if (playerInput.ToggleInventory || m_inventoryButtonWidget.IsClicked)
            {
                if (IsInventoryVisible())
                {
                    ModalPanelWidget = null;
                }
                else if (m_componentPlayer.ComponentMiner.Inventory is ComponentCreativeInventory)
                {
                    ModalPanelWidget = new CreativeInventoryWidget(m_componentPlayer.Entity);
                }
                else
                {
                    ModalPanelWidget = new FullInventoryWidget(m_componentPlayer.ComponentMiner.Inventory, m_componentPlayer.Entity.FindComponent <ComponentCraftingTable>(throwOnError: true));
                }
            }
            if (playerInput.ToggleClothing || m_clothingButtonWidget.IsClicked)
            {
                if (IsClothingVisible())
                {
                    ModalPanelWidget = null;
                }
                else
                {
                    ModalPanelWidget = new ClothingWidget(m_componentPlayer);
                }
            }
            if (m_sneakButtonWidget.IsClicked || playerInput.ToggleSneak)
            {
                bool isSneaking = m_componentPlayer.ComponentBody.IsSneaking;
                m_componentPlayer.ComponentBody.IsSneaking = !isSneaking;
                if (m_componentPlayer.ComponentBody.IsSneaking != isSneaking)
                {
                    if (m_componentPlayer.ComponentBody.IsSneaking)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 4), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (componentRider != null && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount))
            {
                bool flag = componentRider.Mount != null;
                if (flag)
                {
                    componentRider.StartDismounting();
                }
                else
                {
                    ComponentMount componentMount = componentRider.FindNearestMount();
                    if (componentMount != null)
                    {
                        componentRider.StartMounting(componentMount);
                    }
                }
                if (componentRider.Mount != null != flag)
                {
                    if (componentRider.Mount != null)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 5), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 6), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if ((m_editItemButton.IsClicked || playerInput.EditItem) && m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue)
            {
                Point3 value     = m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.Value;
                int    cellValue = m_subsystemTerrain.Terrain.GetCellValue(value.X, value.Y, value.Z);
                int    contents  = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(value.X, value.Y, value.Z, cellValue, m_componentPlayer); i++)
                {
                }
            }
            else if ((m_editItemButton.IsClicked || playerInput.EditItem) && IsActiveSlotEditable())
            {
                IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
                if (inventory != null)
                {
                    int activeSlotIndex = inventory.ActiveSlotIndex;
                    int num             = Terrain.ExtractContents(inventory.GetSlotValue(activeSlotIndex));
                    if (BlocksManager.Blocks[num].IsEditable)
                    {
                        SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                        for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer); i++)
                        {
                        }
                    }
                }
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly) && componentRider.Mount == null)
            {
                bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
                m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
                if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled)
                {
                    if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled)
                    {
                        m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                        DisplaySmallMessage(LanguageControl.Get(fName, 7), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 8), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (!m_componentPlayer.ComponentInput.IsControlledByVr && (m_cameraButtonWidget.IsClicked || playerInput.SwitchCameraMode))
            {
                GameWidget gameWidget = m_componentPlayer.GameWidget;
                if (gameWidget.ActiveCamera.GetType() == typeof(FppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <TppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 9), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(TppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <OrbitCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 10), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(OrbitCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FixedCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 11), Color.White, blinking: false, playNotificationSound: false);
                }
                else
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 12), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (m_photoButtonWidget.IsClicked || playerInput.TakeScreenshot)
            {
                ScreenCaptureManager.CapturePhoto(delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 13), Color.White, blinking: false, playNotificationSound: false);
                }, delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 14), Color.White, blinking: false, playNotificationSound: false);
                });
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_lightningButtonWidget.IsClicked || playerInput.Lighting))
            {
                Matrix matrix = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
                base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true).ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, matrix.Forward);
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay))
            {
                float num2  = MathUtils.Remainder(0.25f, 1f);
                float num3  = MathUtils.Remainder(0.5f, 1f);
                float num4  = MathUtils.Remainder(0.75f, 1f);
                float num5  = MathUtils.Remainder(1f, 1f);
                float num6  = MathUtils.Remainder(num2 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num7  = MathUtils.Remainder(num3 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num8  = MathUtils.Remainder(num4 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num9  = MathUtils.Remainder(num5 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num10 = MathUtils.Min(num6, num7, num8, num9);
                if (num6 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num6;
                    DisplaySmallMessage(LanguageControl.Get(fName, 15), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num7 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num7;
                    DisplaySmallMessage(LanguageControl.Get(fName, 16), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num8 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num8;
                    DisplaySmallMessage(LanguageControl.Get(fName, 17), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num9 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num9;
                    DisplaySmallMessage(LanguageControl.Get(fName, 18), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (ModalPanelWidget != null)
            {
                if (input.Cancel || input.Back || m_backButtonWidget.IsClicked)
                {
                    ModalPanelWidget = null;
                }
            }
            else if (input.Back || m_backButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new GameMenuDialog(m_componentPlayer));
            }
        }