Exemplo n.º 1
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     WorldSettings   = new WorldSettings();
     WorldSettings.Load(valuesDictionary);
     DirectoryName        = valuesDictionary.GetValue <string>("WorldDirectoryName");
     TotalElapsedGameTime = valuesDictionary.GetValue <double>("TotalElapsedGameTime");
     WorldSeed            = valuesDictionary.GetValue <int>("WorldSeed");
 }
Exemplo n.º 2
0
 public override void Enter(object[] parameters)
 {
     if (ScreensManager.PreviousScreen.GetType() != typeof(WorldOptionsScreen))
     {
         m_directoryName = (string)parameters[0];
         m_worldSettings = (WorldSettings)parameters[1];
         m_originalWorldSettingsData.Clear();
         m_worldSettings.Save(m_originalWorldSettingsData, liveModifiableParametersOnly: true);
     }
 }
Exemplo n.º 3
0
 public override void Enter(object[] parameters)
 {
     if (ScreensManager.PreviousScreen.GetType() != typeof(WorldOptionsScreen))
     {
         m_worldSettings = new WorldSettings
         {
             Name = WorldsManager.NewWorldNames[m_random.Int(0, WorldsManager.NewWorldNames.Count - 1)],
             OriginalSerializationVersion = VersionsManager.SerializationVersion
         };
     }
 }
Exemplo n.º 4
0
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            base.OnNeighborBlockChanged(x, y, z, neighborX, neighborY, neighborZ);
            WorldSettings worldSettings = m_subsystemGameInfo.WorldSettings;

            if (worldSettings.EnvironmentBehaviorMode == EnvironmentBehaviorMode.Living && y > 0 && y > worldSettings.TerrainLevel + worldSettings.SeaLevelOffset && (neighborX != x || neighborY != y || neighborZ != z))
            {
                Terrain terrain = SubsystemTerrain.Terrain;
                if (BlocksManager.Blocks[terrain.GetCellContents(x, y - 1, z)].IsFluidBlocker || BlocksManager.Blocks[terrain.GetCellContents(x, y - 1, z)].IsFluidBlocker)
                {
                    return;
                }
                int i = y;
                while (i < 128 && Terrain.ExtractContents(terrain.GetCellValue(x, i, z)) == 18)
                {
                    i++;
                }
                SubsystemTerrain.DestroyCell(0, x, i - 1, z, 0, false, false);
            }
        }
        public TerrainContentsGeneratorFlat(SubsystemTerrain subsystemTerrain)
        {
            m_subsystemTerrain = subsystemTerrain;
            SubsystemGameInfo subsystemGameInfo = subsystemTerrain.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);

            m_worldSettings             = subsystemGameInfo.WorldSettings;
            m_oceanCorner               = ((string.CompareOrdinal(subsystemGameInfo.WorldSettings.OriginalSerializationVersion, "2.1") < 0) ? (m_oceanCorner = new Vector2(2001f, 2001f)) : (m_oceanCorner = new Vector2(-199f, -199f)));
            m_islandSize                = ((m_worldSettings.TerrainGenerationMode == TerrainGenerationMode.FlatIsland) ? new Vector2?(m_worldSettings.IslandSize) : null);
            m_shoreRoughnessAmplitude.X = MathUtils.Pow(m_worldSettings.ShoreRoughness, 2f) * (m_islandSize.HasValue ? MathUtils.Min(4f * m_islandSize.Value.X, 400f) : 400f);
            m_shoreRoughnessAmplitude.Y = MathUtils.Pow(m_worldSettings.ShoreRoughness, 2f) * (m_islandSize.HasValue ? MathUtils.Min(4f * m_islandSize.Value.Y, 400f) : 400f);
            m_shoreRoughnessFrequency   = MathUtils.Lerp(0.5f, 1f, m_worldSettings.ShoreRoughness) * new Vector2(1f) / m_shoreRoughnessAmplitude;
            m_shoreRoughnessOctaves.X   = (int)MathUtils.Clamp(MathUtils.Log(1f / m_shoreRoughnessFrequency.X) / MathUtils.Log(2f) - 1f, 1f, 7f);
            m_shoreRoughnessOctaves.Y   = (int)MathUtils.Clamp(MathUtils.Log(1f / m_shoreRoughnessFrequency.Y) / MathUtils.Log(2f) - 1f, 1f, 7f);
            Random random = new Random(subsystemGameInfo.WorldSeed);

            m_shoreRoughnessOffset[0] = random.Float(-2000f, 2000f);
            m_shoreRoughnessOffset[1] = random.Float(-2000f, 2000f);
            m_shoreRoughnessOffset[2] = random.Float(-2000f, 2000f);
            m_shoreRoughnessOffset[3] = random.Float(-2000f, 2000f);
        }
Exemplo n.º 6
0
        public static void ChangeWorld(string directoryName, WorldSettings worldSettings)
        {
            string path = Storage.CombinePaths(directoryName, "Project.xml");

            if (!Storage.FileExists(path))
            {
                return;
            }
            XElement xElement = null;

            using (Stream stream = Storage.OpenFile(path, OpenFileMode.Read))
            {
                xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true);
            }
            XElement         gameInfoNode     = GetGameInfoNode(xElement);
            ValuesDictionary valuesDictionary = new ValuesDictionary();

            valuesDictionary.ApplyOverrides(gameInfoNode);
            GameMode value = valuesDictionary.GetValue <GameMode>("GameMode");

            worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: true);
            gameInfoNode.RemoveNodes();
            valuesDictionary.Save(gameInfoNode);
            using (Stream stream2 = Storage.OpenFile(path, OpenFileMode.Create))
            {
                XmlUtils.SaveXmlToStream(xElement, stream2, null, throwOnError: true);
            }
            if (worldSettings.GameMode != value)
            {
                if (worldSettings.GameMode == GameMode.Adventure)
                {
                    TakeWorldSnapshot(directoryName, "AdventureRestart");
                }
                else
                {
                    DeleteWorldSnapshot(directoryName, "AdventureRestart");
                }
            }
        }
Exemplo n.º 7
0
        public static WorldInfo CreateWorld(WorldSettings worldSettings)
        {
            string unusedWorldDirectoryName = GetUnusedWorldDirectoryName();

            Storage.CreateDirectory(unusedWorldDirectoryName);
            if (!ValidateWorldName(worldSettings.Name))
            {
                throw new InvalidOperationException($"World name \"{worldSettings.Name}\" is invalid.");
            }
            int num;

            if (string.IsNullOrEmpty(worldSettings.Seed))
            {
                num = (int)(long)(Time.RealTime * 1000.0);
            }
            else if (worldSettings.Seed == "0")
            {
                num = 0;
            }
            else
            {
                num = 0;
                int    num2 = 1;
                string seed = worldSettings.Seed;
                foreach (char c in seed)
                {
                    num  += c * num2;
                    num2 += 29;
                }
            }
            ValuesDictionary valuesDictionary = new ValuesDictionary();

            worldSettings.Save(valuesDictionary, liveModifiableParametersOnly: false);
            valuesDictionary.SetValue("WorldDirectoryName", unusedWorldDirectoryName);
            valuesDictionary.SetValue("WorldSeed", num);
            ValuesDictionary valuesDictionary2 = new ValuesDictionary();

            valuesDictionary2.SetValue("Players", new ValuesDictionary());
            DatabaseObject databaseObject = DatabaseManager.GameDatabase.Database.FindDatabaseObject("GameProject", DatabaseManager.GameDatabase.ProjectTemplateType, throwIfNotFound: true);
            XElement       xElement       = new XElement("Project");

            XmlUtils.SetAttributeValue(xElement, "Guid", databaseObject.Guid);
            XmlUtils.SetAttributeValue(xElement, "Name", "GameProject");
            XmlUtils.SetAttributeValue(xElement, "Version", VersionsManager.SerializationVersion);
            XElement xElement2 = new XElement("Subsystems");

            xElement.Add(xElement2);
            XElement xElement3 = new XElement("Values");

            XmlUtils.SetAttributeValue(xElement3, "Name", "GameInfo");
            valuesDictionary.Save(xElement3);
            xElement2.Add(xElement3);
            XElement xElement4 = new XElement("Values");

            XmlUtils.SetAttributeValue(xElement4, "Name", "Players");
            valuesDictionary2.Save(xElement4);
            xElement2.Add(xElement4);
            using (Stream stream = Storage.OpenFile(Storage.CombinePaths(unusedWorldDirectoryName, "Project.xml"), OpenFileMode.Create))
            {
                XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true);
            }
            return(GetWorldInfo(unusedWorldDirectoryName));
        }
Exemplo n.º 8
0
 public override void Save(ValuesDictionary valuesDictionary)
 {
     WorldSettings.Save(valuesDictionary, liveModifiableParametersOnly: false);
     valuesDictionary.SetValue("WorldSeed", WorldSeed);
     valuesDictionary.SetValue("TotalElapsedGameTime", TotalElapsedGameTime);
 }
Exemplo n.º 9
0
 public override void Enter(object[] parameters)
 {
     m_worldSettings         = (WorldSettings)parameters[0];
     m_isExistingWorld       = (bool)parameters[1];
     m_descriptionLabel.Text = StringsManager.GetString("EnvironmentBehaviorMode." + m_worldSettings.EnvironmentBehaviorMode.ToString() + ".Description");
 }
Exemplo n.º 10
0
        public void UpdateWidgets()
        {
            ComponentRider componentRider = m_componentPlayer.ComponentRider;
            ComponentSleep componentSleep = m_componentPlayer.ComponentSleep;
            ComponentInput componentInput = m_componentPlayer.ComponentInput;
            WorldSettings  worldSettings  = m_subsystemGameInfo.WorldSettings;
            GameMode       gameMode       = worldSettings.GameMode;

            UpdateSidePanelsAnimation();
            if (m_modalPanelAnimationData != null)
            {
                UpdateModalPanelAnimation();
            }
            if (m_message != null)
            {
                double realTime = Time.RealTime;
                m_largeMessageWidget.IsVisible = true;
                LabelWidget labelWidget  = m_largeMessageWidget.Children.Find <LabelWidget>("LargeLabel");
                LabelWidget labelWidget2 = m_largeMessageWidget.Children.Find <LabelWidget>("SmallLabel");
                labelWidget.Text       = m_message.LargeText;
                labelWidget2.Text      = m_message.SmallText;
                labelWidget.IsVisible  = !string.IsNullOrEmpty(m_message.LargeText);
                labelWidget2.IsVisible = !string.IsNullOrEmpty(m_message.SmallText);
                float num = (float)MathUtils.Min(MathUtils.Saturate(2.0 * (realTime - m_message.StartTime)), MathUtils.Saturate(2.0 * (m_message.StartTime + (double)m_message.Duration - realTime)));
                labelWidget.Color  = new Color(num, num, num, num);
                labelWidget2.Color = new Color(num, num, num, num);
                if (Time.RealTime > m_message.StartTime + (double)m_message.Duration)
                {
                    m_message = null;
                }
            }
            else
            {
                m_largeMessageWidget.IsVisible = false;
            }
            ControlsContainerWidget.IsVisible        = (m_componentPlayer.PlayerData.IsReadyForPlaying && m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled && componentSleep.SleepFactor <= 0f);
            m_moveRectangleContainerWidget.IsVisible = (!SettingsManager.HideMoveLookPads && componentInput.IsControlledByTouch);
            m_lookRectangleContainerWidget.IsVisible = (!SettingsManager.HideMoveLookPads && componentInput.IsControlledByTouch && (SettingsManager.LookControlMode != LookControlMode.EntireScreen || SettingsManager.MoveControlMode != MoveControlMode.Buttons));
            m_lookPadContainerWidget.IsVisible       = (SettingsManager.LookControlMode != LookControlMode.SplitTouch);
            MoveRoseWidget.IsVisible               = componentInput.IsControlledByTouch;
            m_moreContentsWidget.IsVisible         = m_moreButtonWidget.IsChecked;
            HealthBarWidget.IsVisible              = (gameMode != GameMode.Creative);
            FoodBarWidget.IsVisible                = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            TemperatureBarWidget.IsVisible         = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            LevelLabelWidget.IsVisible             = (gameMode != 0 && worldSettings.AreAdventureSurvivalMechanicsEnabled);
            m_creativeFlyButtonWidget.IsVisible    = (gameMode == GameMode.Creative);
            m_timeOfDayButtonWidget.IsVisible      = (gameMode == GameMode.Creative);
            m_lightningButtonWidget.IsVisible      = (gameMode == GameMode.Creative);
            m_moveButtonsContainerWidget.IsVisible = (SettingsManager.MoveControlMode == MoveControlMode.Buttons);
            m_movePadContainerWidget.IsVisible     = (SettingsManager.MoveControlMode == MoveControlMode.Pad);
            if (SettingsManager.LeftHandedLayout)
            {
                m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
                m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
                m_moveRectangleWidget.FlipHorizontal      = true;
                m_lookRectangleWidget.FlipHorizontal      = false;
            }
            else
            {
                m_moveContainerWidget.HorizontalAlignment = WidgetAlignment.Near;
                m_lookContainerWidget.HorizontalAlignment = WidgetAlignment.Far;
                m_moveRectangleWidget.FlipHorizontal      = false;
                m_lookRectangleWidget.FlipHorizontal      = true;
            }
            m_sneakButtonWidget.IsChecked       = m_componentPlayer.ComponentBody.IsSneaking;
            m_creativeFlyButtonWidget.IsChecked = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
            m_inventoryButtonWidget.IsChecked   = IsInventoryVisible();
            m_clothingButtonWidget.IsChecked    = IsClothingVisible();
            if (IsActiveSlotEditable() || m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue)
            {
                m_sneakButtonWidget.IsVisible = false;
                m_mountButtonWidget.IsVisible = false;
                m_editItemButton.IsVisible    = true;
            }
            else if (componentRider != null && componentRider.Mount != null)
            {
                m_sneakButtonWidget.IsVisible = false;
                m_mountButtonWidget.IsChecked = true;
                m_mountButtonWidget.IsVisible = true;
                m_editItemButton.IsVisible    = false;
            }
            else
            {
                m_mountButtonWidget.IsChecked = false;
                if (componentRider != null && Time.FrameStartTime - m_lastMountableCreatureSearchTime > 0.5)
                {
                    m_lastMountableCreatureSearchTime = Time.FrameStartTime;
                    if (componentRider.FindNearestMount() != null)
                    {
                        m_sneakButtonWidget.IsVisible = false;
                        m_mountButtonWidget.IsVisible = true;
                        m_editItemButton.IsVisible    = false;
                    }
                    else
                    {
                        m_sneakButtonWidget.IsVisible = true;
                        m_mountButtonWidget.IsVisible = false;
                        m_editItemButton.IsVisible    = false;
                    }
                }
            }
            if (!m_componentPlayer.IsAddedToProject || m_componentPlayer.ComponentHealth.Health == 0f || componentSleep.IsSleeping || m_componentPlayer.ComponentSickness.IsPuking)
            {
                ModalPanelWidget = null;
            }
            if (m_componentPlayer.ComponentSickness.IsSick)
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(166, 175, 103);
            }
            else if (m_componentPlayer.ComponentFlu.HasFlu)
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(0, 48, 255);
            }
            else
            {
                m_componentPlayer.ComponentGui.HealthBarWidget.LitBarColor = new Color(224, 24, 0);
            }
        }