Example #1
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 #2
0
 public static void Up(User user, int pCount = 1)
 {
     try
     {
         Vector3 pos    = user.Player.Position;
         var     newpos = new Vector3i((int)pos.X, (int)pos.Y + pCount, (int)pos.Z);
         WorldEditManager.SetBlock(typeof(StoneBlock), newpos);
         newpos.Y += 2;
         user.Player.SetPosition(newpos);
     }
     catch (Exception e)
     {
         AsphaltLog.WriteError(e.ToStringPretty());
     }
 }
        public bool Undo()
        {
            if (mLastCommandBlocks == null)
            {
                return(false);
            }

            UserSession session = GetNewSession();

            foreach (var entry in mLastCommandBlocks)
            {
                WorldEditManager.SetBlock(entry, session);
            }
            return(true);
        }
Example #4
0
        public static void Set(User user, string pTypeName)
        {
            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;
                }

                Type blockType = BlockUtils.GetBlockType(pTypeName);

                if (blockType == null)
                {
                    user.Player.SendTemporaryMessage($"No BlockType with name {pTypeName} found!");
                    return;
                }

                var vectors = weud.GetSortedVectors();

                weud.StartEditingBlocks();

                long changedBlocks = 0;

                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), pos);
                            WorldEditManager.SetBlock(blockType, pos);
                            changedBlocks++;
                        }
                    }
                }

                user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed.");
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
        public bool LoadSelectionFromClipboard(User pUser, WorldEditUserData pWeud)
        {
            if (mClipboard == null)
            {
                return(false);
            }

            StartEditingBlocks();
            var currentPos = pUser.Player.Position.Round;

            UserSession session = pWeud.GetNewSession();

            foreach (var entry in mClipboard)
            {
                var web = entry.Clone();
                web.Position += currentPos;

                AddBlockChangedEntry(Eco.World.World.GetBlock(web.Position), web.Position);
                WorldEditManager.SetBlock(web.Type, web.Position, session, null, null, web.Data);
            }
            return(true);
        }
Example #6
0
        public static void Replace(User user, string pTypeNames = "")
        {
            try
            {
                string[] splitted = pTypeNames.Split(' ');
                string   toFind   = splitted[0].ToLower();

                string toReplace = string.Empty;

                if (splitted.Length >= 2)
                {
                    toReplace = pTypeNames.Split(' ')[1].ToLower();
                }

                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;
                }

                Type blockTypeToFind = BlockUtils.GetBlockType(toFind);
                if (blockTypeToFind == null)
                {
                    user.Player.SendTemporaryMessage($"No BlockType with name {toFind} found!");
                    return;
                }

                Type blockTypeToReplace = null;

                if (toReplace != string.Empty)
                {
                    blockTypeToReplace = BlockUtils.GetBlockType(toReplace);
                    if (blockTypeToReplace == null)
                    {
                        user.Player.SendTemporaryMessage($"No BlockType with name { toReplace } found!");
                        return;
                    }
                }

                var vectors = weud.GetSortedVectors();

                long changedBlocks = 0;


                //if toReplace is string empty we will replace everything except empty with toFind type

                weud.StartEditingBlocks();

                if (toReplace != string.Empty)
                {
                    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);
                                var block = Eco.World.World.GetBlock(pos);

                                if (block != null && block.GetType() == blockTypeToFind)
                                {
                                    weud.AddBlockChangedEntry(block, pos);
                                    WorldEditManager.SetBlock(blockTypeToReplace, pos);
                                    changedBlocks++;
                                }
                            }
                        }
                    }
                }
                else
                {
                    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);
                                var block = Eco.World.World.GetBlock(pos);

                                if (block != null && block.GetType() != typeof(EmptyBlock))
                                {
                                    weud.AddBlockChangedEntry(block, pos);
                                    WorldEditManager.SetBlock(blockTypeToFind, pos);
                                    changedBlocks++;
                                }
                            }
                        }
                    }
                }

                user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed.");
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Example #7
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());
            }
        }