Пример #1
0
        private void btnGenerateRandomSeedIdea_Click(object sender, EventArgs e)
        {
            RandomHelper.SetRandomSeed();
            switch (RandomHelper.Next(4))
            {
            case 0:
                txtWorldSeed.Text = "{" + RandomHelper.RandomString("Your name", "A friend's name",
                                                                    "Your pet's name", "Your shoe size", "Your lucky number") + "}";
                break;

            case 1:
                txtWorldSeed.Text = "{Your favourite " + RandomHelper.RandomString(
                    "food", "place", "activity", "Buffy character", "film", "book", "website", "game",
                    "mathematician", "tv show", "subject", "colour", "letter", "breed of hippo",
                    "celebrity", "c# hashtable key", "animal", "drink", "minecraft block", "potion",
                    "tv character", "colonel", "film character", "shade of green", "cluedo weapon",
                    "minecraft enemy", "capital", "ore", "keen commander", "dancing ghost") + "}";
                break;

            case 2:
                txtWorldSeed.Text = RandomHelper.RandomFileLine(Path.Combine("Resources", "Adjectives.txt")).ToLower().Trim();
                break;

            case 3:
                txtWorldSeed.Text = RandomHelper.RandomFileLine(Path.Combine("Resources", "Nouns.txt")).ToLower().Trim();
                break;

            default:
                txtWorldSeed.Text = "";
                break;
            }
        }
Пример #2
0
        public static string GenerateWorldName()
        {
            RandomHelper.SetRandomSeed();
            string strFolder = String.Empty;
            string strWorldName = String.Empty;
            string strType, strStart, strEnd;

            do
            {
                strType      = RandomHelper.RandomFileLine(Path.Combine("Resources", "WorldTypes.txt"));
                strStart     = RandomHelper.RandomFileLine(Path.Combine("Resources", "Adjectives.txt"));
                strEnd       = RandomHelper.RandomFileLine(Path.Combine("Resources", "Nouns.txt"));
                strWorldName = strType + " of " + strStart + strEnd;
                strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
            } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder) || (strStart + strEnd).Length > 14);
            return(strWorldName);
        }
Пример #3
0
        // todo low: long code is long
        static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed,
                                    string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes,
                                    int ChunksBetweenCities, string strSpawnPoint)
        {
            worldCities = new WorldCity[TotalCities];
            lstCityNames.Clear();

            RandomHelper.SetRandomSeed();

            #region create minecraft world directory from a random unused city name
            string strFolder = String.Empty, strWorldName = String.Empty;

            UserWorldName = Utils.SafeFilename(UserWorldName);
            if (UserWorldName.Trim().Length == 0)
            {
                UserWorldName = "random";
            }

            if (UserWorldName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDirectory(UserWorldName)))
                {
                    if (MessageBox.Show("A world called \"" + UserWorldName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.", false, false);
                        return;
                    }
                }
                else
                {
                    strWorldName = UserWorldName;
                    strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
                }
            }
            if (strWorldName.Length == 0)
            {
                strWorldName = Utils.GenerateWorldName();
                strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
            }
            Directory.CreateDirectory(strFolder);
            frmLogForm.UpdateLog("World name: " + strWorldName, false, true);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld worldDest = BetaWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            BetaChunkManager cmDest = worldDest.GetChunkManager();
            BlockManager     bmDest = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region Determine themes
            // "how does this work, robson?"
            // well, I'm glad you asked!
            // we keep selecting a random unused checked theme, until they've all been used once.
            // after that, all other cities will have a random checked theme
            strCheckedThemes = RandomHelper.ShuffleArray(strCheckedThemes);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                if (CurrentCityID <= strCheckedThemes.GetUpperBound(0))
                {
                    worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID];
                }
                else
                {
                    worldCities[CurrentCityID].ThemeName = RandomHelper.RandomString(strCheckedThemes);
                }
                Debug.WriteLine(worldCities[CurrentCityID].ThemeName);
                City.ThemeName = worldCities[CurrentCityID].ThemeName;
                worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size");
            }
            #endregion

            GenerateCityLocations(TotalCities, ChunksBetweenCities);

            int intRandomCity = RandomHelper.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID);
                GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z);
                #region set spawn point
                if (City.ID == intRandomCity)
                {
                    switch (strSpawnPoint)
                    {
                    case "Away from the cities":
                        worldDest.Level.Spawn = new SpawnPoint(0, 65, 0);
                        break;

                    case "Inside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + 30) * 16) + (City.MapLength / 2));
                        break;

                    case "Outside a random city":
                        if (City.HasFarms)
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 16) + 20);
                        }
                        else
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 16) + 2);
                        }
                        break;

                    default:
                        Debug.Fail("invalid spawn point");
                        break;
                    }
                    frmLogForm.UpdateLog("Spawn point set to " + worldDest.Level.Spawn.X + "," + worldDest.Level.Spawn.Y + "," + worldDest.Level.Spawn.Z, false, true);
                }
                #endregion
            }

            City.ID = TotalCities;
            frmLogForm.UpdateProgress(0);

            #region weather
#if RELEASE
            frmLogForm.UpdateLog("Setting weather", false, true);
            worldDest.Level.Time = RandomHelper.Next(24000);
            if (RandomHelper.NextDouble() < 0.2)
            {
                frmLogForm.UpdateLog("Rain", false, true);
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    frmLogForm.UpdateLog("Thunder", false, true);
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            #region lighting
            frmLogForm.UpdateLog("\nCreating world lighting data", false, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            #endregion

            #region world details
            worldDest.Level.LevelName = strWorldName;
            frmLogForm.UpdateLog("Setting world type: " + strWorldType, false, true);
            switch (strWorldType.ToLower())
            {
            case "creative":
                worldDest.Level.GameType = GameType.CREATIVE;
                break;

            case "survival":
                worldDest.Level.GameType = GameType.SURVIVAL;
                break;

            case "hardcore":
                worldDest.Level.GameType        = GameType.SURVIVAL;
                worldDest.Level.UseHardcoreMode = true;
                break;

            default:
                Debug.Fail("Invalidate world type selected.");
                break;
            }
            frmLogForm.UpdateLog("World map features: " + booWorldMapFeatures.ToString(), false, true);
            worldDest.Level.UseMapFeatures = booWorldMapFeatures;
            if (strWorldSeed != String.Empty)
            {
                worldDest.Level.RandomSeed = Utils.JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            else
            {
                worldDest.Level.RandomSeed = RandomHelper.Next();
                frmLogForm.UpdateLog("Random world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            worldDest.Level.LastPlayed = (DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000;
            frmLogForm.UpdateLog("World time: " + worldDest.Level.LastPlayed, false, true);
            #endregion

            worldDest.Save();
            frmLogForm.UpdateProgress(1);

            frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false);
            frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false);

            // todo low: export schematic
            #region export schematic
            //if (booExportSchematic)
            //{
            //    frmLogForm.UpdateLog("Creating schematic");
            //    AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength);
            //    for (int x = 0; x < intMapLength; x++)
            //    {
            //        for (int z = 0; z < intMapLength; z++)
            //        {
            //            for (int y = 0; y < 128; y++)
            //            {
            //                abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z));
            //            }
            //        }
            //    }
            //    Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength);
            //    CitySchematic.Blocks = abcExport;
            //    CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic");
            //}
            #endregion
        }