Example #1
0
        public static void Shift(User user, string pDirectionAndAmount = "1")
        {
            try
            {
                Direction direction = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount);
                if (direction == Direction.Unknown)
                {
                    return;
                }

                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.ShiftSelection(direction.ToVec() * amount))
                {
                    user.Player.SendTemporaryMessage($"Shifted selection {amount} {direction}");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Example #2
0
        public static void Stack(User user, string pDirectionAndAmount = "1")
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.FirstPos == null || weud.SecondPos == null)
                {
                    user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!");
                    return;
                }

                var vectors = weud.GetSortedVectors();

                Direction dir = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount);

                weud.StartEditingBlocks();
                UserSession session = weud.GetNewSession();

                long changedBlocks = 0;

                for (int i = 1; i <= amount; i++)
                {
                    Vector3i offset = dir.ToVec() * (vectors.Higher - vectors.Lower) * i;

                    for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X)
                    {
                        for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++)
                        {
                            for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z)
                            {
                                var pos = new Vector3i(x, y, z);

                                weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos + offset), pos + offset);
                                var sourceBlock = Eco.World.World.GetBlock(pos);
                                WorldEditManager.SetBlock(sourceBlock.GetType(), pos + offset, session, pos, sourceBlock);
                                changedBlocks++;
                            }
                        }
                    }
                }

                //   int changedBlocks = (int)((vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z)) * amount;

                user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed.");
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Example #3
0
        public static void Move(User user, string pDirectionAndAmount = "1")
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.FirstPos == null || weud.SecondPos == null)
                {
                    user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!");
                    return;
                }

                var vectors = weud.GetSortedVectors();

                Direction dir = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount);

                weud.StartEditingBlocks();

                UserSession session = weud.GetNewSession();

                Vector3i offset = dir.ToVec() * amount;

                //     if (dir == Direction.Up)
                //          offset *= vectors.Higher.Y - vectors.Lower.Y;

                long changedBlocks = 0;

                Action <int, int, int> action = (int x, int y, int z) =>
                {
                    var pos = new Vector3i(x, y, z);

                    weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos), pos);
                    weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos + offset), pos + offset);

                    var sourceBlock = Eco.World.World.GetBlock(pos);
                    WorldEditManager.SetBlock(sourceBlock.GetType(), pos + offset, session, pos, sourceBlock);
                    WorldEditManager.SetBlock(typeof(EmptyBlock), pos, session);
                    changedBlocks++;
                };


                if (dir == Direction.Left || dir == Direction.Back || dir == Direction.Down)
                {
                    for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X)
                    {
                        for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++)
                        {
                            for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z)
                            {
                                action.Invoke(x, y, z);
                            }
                        }
                    }
                }
                else
                {
                    /*                for (int x = vectors.Higher.X - 1; x >= vectors.Lower.X; x--)
                     *                  for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--)
                     *                      for (int z = vectors.Higher.Z - 1; z >= vectors.Lower.Z; z--)*/

                    int x = vectors.Higher.X - 1;
                    if (x < 0)
                    {
                        x = x + Shared.Voxel.World.VoxelSize.X;
                    }

                    int startZ = vectors.Higher.Z - 1;
                    if (startZ < 0)
                    {
                        startZ = startZ + Shared.Voxel.World.VoxelSize.Z;
                    }

                    //           Console.WriteLine("--------------");
                    //           Console.WriteLine(vectors.Lower);
                    //            Console.WriteLine(vectors.Higher);

                    for (; x != (vectors.Lower.X - 1); x--)
                    {
                        if (x < 0)
                        {
                            x = x + Shared.Voxel.World.VoxelSize.X;
                        }
                        for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--)
                        {
                            for (int z = startZ; z != (vectors.Lower.Z - 1); z--)
                            {
                                if (z < 0)
                                {
                                    z = z + Shared.Voxel.World.VoxelSize.Z;
                                }

                                //               Console.WriteLine($"{x} {y} {z}");
                                action.Invoke(x, y, z);
                            }
                        }
                    }
                }

                // int changedBlocks = (int)((vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z)) * amount;

                user.Player.SendTemporaryMessage($"{changedBlocks} blocks moved.");
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }