public static void Mountain(Point3 Start, int Radius, int Size, SubsystemTerrain subsystemTerrain, int id, int id1, int id2, ComponentPlayer player)
 {
     Task.Run(() =>
     {
         Game.Random random = new Game.Random();
         double num1        = Math.PI / 2.0;
         float num2         = (float)Size + 0.8f;
         int num3           = 0;
         double num4        = 10.0;
         double num5        = 15.0;
         float num6         = random.UniformFloat((float)num4, (float)num5) + 10f;
         for (int index1 = -Radius; index1 < Radius; ++index1)
         {
             for (int index2 = -Radius; index2 < Radius; ++index2)
             {
                 double num7  = Math.Cos(num1 * (double)index1 / (double)Radius) * Math.Cos(num1 * (double)index2 / (double)Radius) * (double)num2;
                 double num8  = Math.Sin(num1 * (double)index1 * 1.39999997615814 / (double)Radius + 4.0) * Math.Cos(num1 * (double)index2 * 1.39999997615814 / (double)Radius + 7.0) * (double)num2 * 0.25;
                 double num9  = Math.Cos(num1 * (double)index1 * 1.39999997615814 * 2.0 / (double)Radius + 4.0 * (double)num6) * Math.Sin(num1 * (double)index2 * 1.39999997615814 * 2.0 / (double)Radius + 8.0 * (double)num6) * (double)num2 * 0.200000002980232;
                 double num10 = Math.Sin(num1 * (double)index1 * 1.39999997615814 * 4.0 / (double)Radius + 4.0 * (double)num6 * 1.5) * Math.Sin(num1 * (double)index2 * 1.39999997615814 * 4.0 / (double)Radius + 8.0 * (double)num6 * 1.5) * (double)num2 * 0.150000005960464;
                 double num11 = num8;
                 double num12 = num7 - num11 + num9 - num10;
                 if (num12 > 0.0)
                 {
                     for (int index3 = 0; (double)index3 <= num12; ++index3)
                     {
                         if (index3 > 3)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12 - index3, Start.Z + index2, id, true);
                             ++num3;
                         }
                         else if (index3 > 0)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12 - index3, Start.Z + index2, id1, true);
                             ++num3;
                         }
                         else if (index3 == 0)
                         {
                             subsystemTerrain.ChangeCell(Start.X + index1, Start.Y + (int)num12, Start.Z + index2, id2, true);
                             ++num3;
                         }
                     }
                 }
             }
         }
         player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", num3), true, true);
     });
 }
示例#2
0
        public void DropAllItems(Vector3 position)
        {
            Game.Random        random             = new Game.Random();
            SubsystemPickables subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);

            for (int i = 0; i < SlotsCount; i++)
            {
                int slotCount = GetSlotCount(i);
                if (slotCount > 0)
                {
                    int     slotValue = GetSlotValue(i);
                    int     count     = RemoveSlotItems(i, slotCount);
                    Vector3 value     = random.UniformFloat(5f, 10f) * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(1f, 2f), random.UniformFloat(-1f, 1f)));
                    subsystemPickables.AddPickable(slotValue, count, position, value, null);
                }
            }
        }
        public void generateMineralLikeCoal(TerrainChunk chunk, int value, int replacevalue, int minHeight, int maxHeight) //生成矿物算法-类似煤的生成概率
        {
            int cx = chunk.Coords.X;
            int cy = chunk.Coords.Y;
            List <TerrainBrush> terrainBrushes = new List <TerrainBrush>();

            Game.Random random = new Game.Random(17);
            for (int i = 0; i < 16; i++)
            {//煤块的生成概率
                TerrainBrush terrainBrush = new TerrainBrush();
                int          num          = random.UniformInt(4, 12);
                for (int j = 0; j < num; j++)
                {
                    Vector3 vector = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f)));
                    int     num2   = random.UniformInt(3, 8);
                    Vector3 zero   = Vector3.Zero;
                    for (int k = 0; k < num2; k++)
                    {
                        terrainBrush.AddBox((int)MathUtils.Floor(zero.X), (int)MathUtils.Floor(zero.Y), (int)MathUtils.Floor(zero.Z), 1, 1, 1, value);
                        zero += vector;
                    }
                }
                if (i == 0)
                {
                    terrainBrush.AddCell(0, 0, 0, 150);
                }
                terrainBrush.Compile();
                terrainBrushes.Add(terrainBrush);
            }
            for (int i = cx - 1; i <= cx + 1; i++)
            {
                for (int j = cy - 1; j <= cy + 1; j++)
                {
                    float num2 = CalculateMountainRangeFactor(i * 16, j * 16);
                    int   num3 = (int)(5f + 2f * num2 * SimplexNoise.OctavedNoise(i, j, 0.33f, 1, 1f, 1f));
                    for (int l = 0; l < num3; l++)
                    {
                        int x2 = i * 16 + random.UniformInt(0, 15);
                        int y2 = random.UniformInt(minHeight, maxHeight);
                        int cz = j * 16 + random.UniformInt(0, 15);
                        terrainBrushes[random.UniformInt(0, terrainBrushes.Count - 1)].PaintFastSelective(chunk, x2, y2, cz, replacevalue);
                    }
                }
            }
        }
示例#4
0
        /*private Vector2? islandSize;
         *
         * private static float TGSurfaceMultiplier;
         * public bool TGWater;
         * public bool TGExtras;
         * public bool TGCavesAndPockets;*/

        public CreatorNormalTerrain(SubsystemTerrain subsystemTerrain)
        {
            this.subsystemTerrain = subsystemTerrain;
            this.subsystemBottomSuckerBlockBehavior = subsystemTerrain.Project.FindSubsystem <SubsystemBottomSuckerBlockBehavior>(true);
            SubsystemGameInfo subsystemGameInfo = subsystemTerrain.Project.FindSubsystem <SubsystemGameInfo>(true);

            this.worldSettings = subsystemGameInfo.WorldSettings;
            this.worldSeed     = subsystemGameInfo.WorldSeed;
            OldRandom oldRandom = new OldRandom(100 + this.worldSeed);

            Game.Random random = new Game.Random(this.worldSeed);
            float       num    = float.MaxValue;

            this.oceanCorner                = new Vector2(random.UniformFloat(-100f, -100f), random.UniformFloat(-100f, -100f));
            this.temperatureOffset          = new Vector2(random.UniformFloat(-2000f, 2000f), random.UniformFloat(-2000f, 2000f));
            this.humidityOffset             = new Vector2(random.UniformFloat(-2000f, 2000f), random.UniformFloat(-2000f, 2000f));
            this.mountainsOffset            = new Vector2(random.UniformFloat(-2000f, 2000f), random.UniformFloat(-2000f, 2000f));
            this.riversOffset               = new Vector2(random.UniformFloat(-2000f, 2000f), random.UniformFloat(-2000f, 2000f));
            this.TGNewBiomeNoise            = true;
            this.TGBiomeScaling             = 2.5f * this.worldSettings.BiomeSize;
            this.TGShoreFluctuations        = MathUtils.Clamp(2f * num, 0f, 150f);
            this.TGShoreFluctuationsScaling = MathUtils.Clamp(0.04f * num, 0.5f, 3f);
            this.TGOceanSlope               = 0.006f;
            this.TGOceanSlopeVariation      = 0.004f;
            this.TGIslandsFrequency         = 0.01f;
            this.TGDensityBias              = 55f;
            this.TGHeightBias               = 1f;
            this.TGRiversStrength           = 3f;
            this.TGMountainsStrength        = 125f;
            this.TGMountainsPeriod          = 0.0015f;
            this.TGMountainsPercentage      = 0.15f;
            this.TGHillsStrength            = 8f;
            this.TGTurbulenceStrength       = 35f;
            this.TGTurbulenceTopOffset      = 0f;
            this.TGTurbulencePower          = 0.3f;
            TerrainContentsGenerator.TGSurfaceMultiplier = 2f;

            /*this.TGWater = true;
             * this.TGExtras = true;
             * this.TGCavesAndPockets = true;*/
        }
示例#5
0
        public override void Update()
        {
            this.num_1.Text = $"参数1 :{(int)num1.Value}";
            this.num_2.Text = $"参数2 :{(int)num2.Value}";
            this.num_3.Text = $"参数3 :{(int)num3.Value}";
            if (this.restting.IsClicked)
            {
                this.num1.Value   = 0f;
                this.num2.Value   = 0f;
                this.num3.Value   = 100f;
                this.TextBox.Text = "3:2:8";
            }
            if (this.cancelButton.IsClicked)
            {
                DialogsManager.HideDialog(this);
            }
            if (this.OK.IsClicked)
            {
                int      BlockID_1;
                int?     BlockID_2 = null, BlockID_3 = null;
                string[] texts = TextBox.Text.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (texts.Length == 2)
                {
                    if (!int.TryParse(texts[0], out BlockID_1))
                    {
                        BlockID_1 = 0;
                    }
                    int id;
                    if (int.TryParse(texts[1], out id))
                    {
                        BlockID_2 = id;
                    }
                }
                else if (texts.Length >= 3)
                {
                    if (!int.TryParse(texts[0], out BlockID_1))
                    {
                        BlockID_1 = 0;
                    }
                    int id;
                    if (int.TryParse(texts[1], out id))
                    {
                        BlockID_2 = id;
                    }
                    if (int.TryParse(texts[2], out id))
                    {
                        BlockID_3 = id;
                    }
                }
                else
                {
                    if (!int.TryParse(TextBox.Text, out BlockID_1))
                    {
                        BlockID_1 = 0;
                    }
                }
                Vector3 vector = new Vector3
                {
                    X = num1.Value,
                    Y = num2.Value,
                    Z = num3.Value
                };

                Point3 Start = creatorAPI.Position[0];
                Point3 End   = creatorAPI.Position[1];
                CreatorMain.Math.StartEnd(ref Start, ref End);
                float X_Radius = (Start.X - End.X) / 2f;
                float Z_Radius = (Start.Z - End.Z) / 2f;
                float Radius   = X_Radius > Z_Radius ? X_Radius : Z_Radius;
                float radius   = X_Radius > Z_Radius ? Z_Radius : X_Radius;
                Radius = Math.Abs(Math.Abs(Radius) - 2f + vector.X);
                if (BlockID_2 == null)
                {
                    BlockID_2 = BlockID_1;
                }
                if (BlockID_3 == null)
                {
                    BlockID_3 = BlockID_2;
                }
                Task.Run(() =>
                {
                    ChunkData chunkData   = new ChunkData(this.creatorAPI);
                    creatorAPI.revokeData = new ChunkData(this.creatorAPI);
                    Game.Random random    = new Game.Random();
                    double pi             = Math.PI * 0.5f;
                    int number            = 0;
                    float num             = 1.25f + (vector.Y / 99f);
                    float rand            = random.UniformFloat(18f, 25f + (vector.Z / 10f));
                    for (int x = (int)-X_Radius; x <= (int)X_Radius; x++)
                    {
                        for (int z = (int)-Z_Radius; z <= Z_Radius; z++)
                        {
                            var a  = (Math.Cos(pi * x / Radius) * Math.Cos(pi * z / radius)) * (Start.Y - End.Y);
                            var b  = (Math.Sin(pi * x * num / radius + 2f) * Math.Cos(pi * z * num / Radius + 7f)) * (Start.Y - End.Y) * 0.35f;
                            var c  = (Math.Sin(pi * x * num * 2f / Radius + 2f * rand) * Math.Sin(pi * z * num * 2f / radius + 8f * rand)) * (Start.Y - End.Y) * 0.2f;
                            var e  = (Math.Sin(pi * x * num * 3.5f / radius + 2f * rand * 1.5f) * Math.Sin(pi * z * num * 3.5f / Radius + 12f * rand * 1.5f)) * (Start.Y - End.Y) * 0.15f;
                            var ls = a - b + c - e;
                            if (ls > 0f)
                            {
                                for (var i = 0; i <= ls; i++)
                                {
                                    Point3 point3 = new Point3((Start.X + End.X) / 2 + x, End.Y + (int)ls - i, (Start.Z + End.Z) / 2 + z);
                                    if (i > 5)
                                    {
                                        creatorAPI.CreateBlock(point3, BlockID_1, chunkData);
                                    }
                                    else if (i > 0)
                                    {
                                        creatorAPI.CreateBlock(point3, (int)BlockID_2, chunkData);
                                    }
                                    else if (i == 0)
                                    {
                                        creatorAPI.CreateBlock(point3, (int)BlockID_3, chunkData);
                                    }
                                    number++;
                                    if (!creatorAPI.launch)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    chunkData.Render();
                    this.player.ComponentGui.DisplaySmallMessage($"操作成功,共生成{number}个方块", true, true);
                });
                DialogsManager.HideDialog(this);
            }
        }
示例#6
0
        void AddHakoRandom()
        {
            Vector2Int[] _candi    = new Vector2Int[Data.Size.x * Data.Size.y];
            int          _maxCount = 0;

            int[] _typeCount = new int[] { 0, 0, 0, 0, 0, 0 };
            // 出現位置は:まず、外周以外にランダム。
            for (int x = 1; x < Data.Size.x - 1; x++)
            {
                for (int y = 1; y < Data.Size.y - 1; y++)
                {
                    if (HakoManaer.Instance.Map[x, y] < 0)
                    {
                        _candi[_maxCount] = new Vector2Int(x, y);
                        _maxCount++;
                    }
                    else
                    {
                        _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[x, y]].Type]++;
                    }
                }
            }
            // 出現位置は:つぎに、外周にランダム。
            if (_maxCount <= 0)
            {
                Vector2Int _start = Vector2Int.zero;
                for (int i = 0; i < 4; i++)
                {
                    Vector2Int _dir = HakoManaer.Instance.DirVector(InputManager.GetIntToDir(i));
                    int        _max = i % 2 == 0?Data.Size.y - 1:Data.Size.x - 1;
                    for (int j = 0; j < _max; j++)
                    {
                        Vector2Int _target = _start + _dir * j;
                        if (HakoManaer.Instance.Map[_target.x, _target.y] < 0)
                        {
                            _candi[_maxCount] = _target;
                            _maxCount++;
                        }
                        else
                        {
                            _typeCount[(int)HakoManaer.Instance.Hakos[HakoManaer.Instance.Map[_target.x, _target.y]].Type]++;
                        }
                    }
                    _start += _dir * _max;
                }
            }
            if (_maxCount > 0)
            {
                HakoType _type       = 0;
                int      _typeRandom = 0;
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom += (Data.MaxHakos - _typeCount[i]);
                }
                _typeRandom = Random.Range(0, _typeRandom - 1);
                for (int i = 1; i < 5; i++)
                {
                    _typeRandom -= (Data.MaxHakos - _typeCount[i]);
                    if (_typeRandom < 0)
                    {
                        _type = HakoManaer.Instance.GetIntToType(i);
                        break;
                    }
                }
                Vector2Int _pos = _candi[Random.Range(0, _maxCount)];
                HakoManaer.Instance.AddHako(_type, _pos, 1.0f / Data.AppearTimes[Level]);
            }
        }