예제 #1
0
        /// <summary>
        /// Instantiates level data using the properties of the connection (seed, size, difficulty)
        /// </summary>
        public LevelData(LocationConnection locationConnection)
        {
            Seed             = locationConnection.Locations[0].BaseName + locationConnection.Locations[1].BaseName;
            Biome            = locationConnection.Biome;
            Type             = LevelType.LocationConnection;
            GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.LocationConnection, Biome);
            Difficulty       = locationConnection.Difficulty;

            float sizeFactor = MathUtils.InverseLerp(
                MapGenerationParams.Instance.SmallLevelConnectionLength,
                MapGenerationParams.Instance.LargeLevelConnectionLength,
                locationConnection.Length);
            int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, sizeFactor);

            Size = new Point(
                (int)MathUtils.Round(width, Level.GridCellSize),
                (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize));

            var rand = new MTRandom(ToolBox.StringToInt(Seed));

            InitialDepth = (int)MathHelper.Lerp(GenerationParams.InitialDepthMin, GenerationParams.InitialDepthMax, (float)rand.NextDouble());

            //minimum difficulty of the level before hunting grounds can appear
            float huntingGroundsDifficultyThreshold = 25;
            //probability of hunting grounds appearing in 100% difficulty levels
            float maxHuntingGroundsProbability = 0.3f;

            HasHuntingGrounds = OriginallyHadHuntingGrounds = rand.NextDouble() < MathUtils.InverseLerp(huntingGroundsDifficultyThreshold, 100.0f, Difficulty) * maxHuntingGroundsProbability;

            HasBeaconStation = !HasHuntingGrounds && rand.NextDouble() < locationConnection.Locations.Select(l => l.Type.BeaconStationChance).Max();
            IsBeaconActive   = false;
        }
예제 #2
0
        public static LevelData CreateRandom(string seed = "", float?difficulty = null, LevelGenerationParams generationParams = null)
        {
            if (string.IsNullOrEmpty(seed))
            {
                seed = Rand.Range(0, int.MaxValue, Rand.RandSync.Server).ToString();
            }

            Rand.SetSyncedSeed(ToolBox.StringToInt(seed));

            LevelType type = generationParams == null ? LevelData.LevelType.LocationConnection : generationParams.Type;

            if (generationParams == null)
            {
                generationParams = LevelGenerationParams.GetRandom(seed, type);
            }
            var biome =
                LevelGenerationParams.GetBiomes().FirstOrDefault(b => generationParams.AllowedBiomes.Contains(b)) ??
                LevelGenerationParams.GetBiomes().GetRandom(Rand.RandSync.Server);

            return(new LevelData(
                       seed,
                       difficulty ?? Rand.Range(30.0f, 80.0f, Rand.RandSync.Server),
                       Rand.Range(0.0f, 1.0f, Rand.RandSync.Server),
                       generationParams,
                       biome));
        }
예제 #3
0
        public static LevelData CreateRandom(string seed = "", float?difficulty = null, LevelGenerationParams generationParams = null)
        {
            if (string.IsNullOrEmpty(seed))
            {
                seed = Rand.Range(0, int.MaxValue, Rand.RandSync.Server).ToString();
            }

            Rand.SetSyncedSeed(ToolBox.StringToInt(seed));

            LevelType type = generationParams == null ? LevelData.LevelType.LocationConnection : generationParams.Type;

            if (generationParams == null)
            {
                generationParams = LevelGenerationParams.GetRandom(seed, type);
            }
            var biome =
                LevelGenerationParams.GetBiomes().FirstOrDefault(b => generationParams.AllowedBiomes.Contains(b)) ??
                LevelGenerationParams.GetBiomes().GetRandom(Rand.RandSync.Server);

            var levelData = new LevelData(
                seed,
                difficulty ?? Rand.Range(30.0f, 80.0f, Rand.RandSync.Server),
                Rand.Range(0.0f, 1.0f, Rand.RandSync.Server),
                generationParams,
                biome);

            if (type == LevelType.LocationConnection)
            {
                float beaconRng = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server);
                levelData.HasBeaconStation = beaconRng < 0.5f;
                levelData.IsBeaconActive   = beaconRng > 0.25f;
            }
            GameMain.GameSession?.GameMode?.Mission?.AdjustLevelData(levelData);
            return(levelData);
        }
예제 #4
0
        /// <summary>
        /// Instantiates level data using the properties of the connection (seed, size, difficulty)
        /// </summary>
        public LevelData(LocationConnection locationConnection)
        {
            Seed             = locationConnection.Locations[0].BaseName + locationConnection.Locations[1].BaseName;
            Biome            = locationConnection.Biome;
            Type             = LevelType.LocationConnection;
            GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.LocationConnection, Biome);
            Difficulty       = locationConnection.Difficulty;

            float sizeFactor = MathUtils.InverseLerp(
                MapGenerationParams.Instance.SmallLevelConnectionLength,
                MapGenerationParams.Instance.LargeLevelConnectionLength,
                locationConnection.Length);
            int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, sizeFactor);

            Size = new Point(
                (int)MathUtils.Round(width, Level.GridCellSize),
                (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize));

            var rand = new MTRandom(ToolBox.StringToInt(Seed));

            InitialDepth = (int)MathHelper.Lerp(GenerationParams.InitialDepthMin, GenerationParams.InitialDepthMax, (float)rand.NextDouble());

            HasBeaconStation = rand.NextDouble() < locationConnection.Locations.Select(l => l.Type.BeaconStationChance).Max();
            IsBeaconActive   = false;
        }
예제 #5
0
        public static Level CreateRandom(string seed = "")
        {
            if (seed == "")
            {
                seed = Rand.Range(0, int.MaxValue, Rand.RandSync.Server).ToString();
            }

            Rand.SetSyncedSeed(ToolBox.StringToInt(seed));

            return(new Level(seed, Rand.Range(30.0f, 80.0f, Rand.RandSync.Server), LevelGenerationParams.GetRandom(seed)));
        }
예제 #6
0
        /// <summary>
        /// Instantiates level data using the properties of the location
        /// </summary>
        public LevelData(Location location)
        {
            Seed             = location.BaseName;
            Biome            = location.Biome;
            Type             = LevelType.Outpost;
            GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.Outpost, Biome);
            Difficulty       = 0.0f;

            var rand  = new MTRandom(ToolBox.StringToInt(Seed));
            int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, (float)rand.NextDouble());

            Size = new Point(
                (int)MathUtils.Round(width, Level.GridCellSize),
                (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize));
        }
예제 #7
0
        /// <summary>
        /// Instantiates level data using the properties of the connection (seed, size, difficulty)
        /// </summary>
        public LevelData(LocationConnection locationConnection)
        {
            Seed             = locationConnection.Locations[0].BaseName + locationConnection.Locations[1].BaseName;
            Biome            = locationConnection.Biome;
            Type             = LevelType.LocationConnection;
            GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.LocationConnection, Biome);
            Difficulty       = locationConnection.Difficulty;

            float sizeFactor = MathUtils.InverseLerp(
                MapGenerationParams.Instance.SmallLevelConnectionLength,
                MapGenerationParams.Instance.LargeLevelConnectionLength,
                locationConnection.Length);
            int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, sizeFactor);

            Size = new Point(
                (int)MathUtils.Round(width, Level.GridCellSize),
                (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize));
        }
예제 #8
0
        public static Level CreateRandom(LocationConnection locationConnection)
        {
            string seed = locationConnection.Locations[0].Name + locationConnection.Locations[1].Name;

            return(new Level(seed, locationConnection.Difficulty, LevelGenerationParams.GetRandom(seed, locationConnection.Biome)));
        }