Ejemplo n.º 1
0
        public override InteractResult OnActRight(InteractionContext context)
        {
            try
            {
                if (context.BlockPosition == null || !context.BlockPosition.HasValue)
                {
                    return(InteractResult.Success);
                }

                Vector3i pos = context.BlockPosition.Value;

                pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X;
                pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z;

                pos.X = pos.X % Shared.Voxel.World.VoxelSize.X;
                pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z;

                UserSession userSession = WorldEditManager.GetUserSession(context.Player.User);
                userSession.SetSecondPosition(pos);

                context.Player.MsgLoc($"Second Position set to ({pos.x}, {pos.y}, {pos.z})");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
            return(InteractResult.NoOp);
        }
Ejemplo n.º 2
0
        public override InteractResult OnActRight(InteractionContext context)
        {
            try
            {
                if (context.BlockPosition == null || !context.BlockPosition.HasValue)
                {
                    return(InteractResult.Success);
                }

                var pos = context.BlockPosition.Value;

                pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X;
                pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z;

                pos.X = pos.X % Shared.Voxel.World.VoxelSize.X;
                pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z;

                WorldEditUserData weud = WorldEditManager.GetUserData(context.Player.User.Name);
                weud.SecondPos = pos;

                context.Player.SendTemporaryMessage($"Second Position set to ({pos.x}, {pos.y}, {pos.z})");
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
            return(InteractResult.NoOp);
        }
Ejemplo n.º 3
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());
            }
        }
Ejemplo n.º 4
0
        public static void Cut(User user)
        {
            try
            {
                UserSession userSession = WorldEditManager.GetUserSession(user);
                WorldRange  region      = userSession.Selection;

                WorldEditCommand command = new CopyCommand(user);
                if (command.Invoke(region))
                {
                    user.Player.MsgLoc($"Copy done in {command.ElapsedMilliseconds}ms.");
                    command = new SetCommand(user, "Empty");
                    if (command.Invoke(region))
                    {
                        user.Player.MsgLoc($"{command.BlocksChanged} blocks cleared in {command.ElapsedMilliseconds}ms.");
                    }
                }
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 5
0
 public static void RmWand(User user)
 {
     try
     {
         user.Inventory.TryRemoveItems(WorldEditManager.GetWandItemStack());
     }
     catch (Exception e)
     {
         Log.WriteError(Localizer.Do($"{e}"));
     }
 }
Ejemplo n.º 6
0
 public static void RmWand(User user)
 {
     try
     {
         user.Inventory.TryRemoveItems(WorldEditManager.getWandItemStack());
     }
     catch (Exception e)
     {
         AsphaltLog.WriteError(e.ToStringPretty());
     }
 }
Ejemplo n.º 7
0
        public static void Undo(User user, int count = 1)
        {
            try
            {
                UserSession userSession = WorldEditManager.GetUserSession(user);
                if (userSession.ExecutingCommand != null && userSession.ExecutingCommand.IsRunning)
                {
                    throw new WorldEditCommandException("You can't use undo right now!");                                                                                                 //TODO: Probably need to rework that and impliment aborting
                }
                if (count > userSession.ExecutedCommands.Count)
                {
                    count = userSession.ExecutedCommands.Count;
                }
                if (count.Equals(0))
                {
                    throw new WorldEditCommandException("Nothing to undo");
                }

                for (int i = 1; i <= count; i++)
                {
                    if (userSession.ExecutedCommands.TryPop(out WorldEditCommand command))
                    {
                        userSession.ExecutingCommand = command;
                        if (command.Undo())
                        {
                            if (count.Equals(1))
                            {
                                user.Player.MsgLoc($"Undo done.");
                                break;
                            }
                            else
                            {
                                user.Player.MsgLoc($"Undo {i}/{count} done.");
                            }
                        }
                        userSession.ExecutingCommand = null;
                    }
                    else
                    {
                        throw new WorldEditCommandException("Nothing to undo");
                    }
                }
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 8
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());
            }
        }
Ejemplo n.º 9
0
        public static void Reset(User user)
        {
            try
            {
                UserSession session = WorldEditManager.GetUserSession(user);
                session.ResetSelection();

                user.Player.MsgLoc($"WorldEdit: Positions reset");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 10
0
        public static void Distr(User user)
        {
            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();

                Dictionary <string, long> mBlocks = new Dictionary <string, long>();

                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)
                        {
                            //                 Console.WriteLine($"{x} {y} {z}");
                            var pos   = new Vector3i(x, y, z);
                            var block = Eco.World.World.GetBlock(pos).GetType().ToString();

                            long count;
                            mBlocks.TryGetValue(block, out count);
                            mBlocks[block] = count + 1;
                        }
                    }
                }

                double amountBlocks = mBlocks.Values.Sum(); // (vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z);

                user.SendMessage($"total blocks: {amountBlocks}", false);

                foreach (var entry in mBlocks)
                {
                    string percent     = (Math.Round((entry.Value / amountBlocks) * 100, 2)).ToString() + "%";
                    string nameOfBlock = entry.Key.Substring(entry.Key.LastIndexOf(".") + 1);
                    user.SendMessage($"{entry.Value.ToString().PadRight(6)} {percent.PadRight(6)} {nameOfBlock}", false);
                }
            }
            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);
        }
Ejemplo n.º 12
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());
     }
 }
Ejemplo n.º 13
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());
            }
        }
Ejemplo n.º 14
0
        public static void Selclaim(User user)
        {
            try
            {
                Vector3i    pos      = user.Position.Round;
                Vector2i    claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ);
                UserSession session  = WorldEditManager.GetUserSession(user);

                session.SetFirstPosition(claimPos.X_Z(pos.Y - 1));
                session.SetSecondPosition(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y - 1));

                user.Player.MsgLoc($"First Position set to {session.Selection.min}");
                user.Player.MsgLoc($"Second Position set to {session.Selection.max}");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 15
0
        public static void Rotate(User user, int pDegree = 90)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.RotateClipboard(pDegree))
                {
                    user.Player.SendTemporaryMessage($"Rotation in clipboard done.");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Please copy a selection first!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 16
0
        public static void Paste(User user)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.LoadSelectionFromClipboard(user, weud))
                {
                    user.Player.SendTemporaryMessage($"Paste done.");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Please copy a selection first!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 17
0
        public static void Undo(User user)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.Undo())
                {
                    user.Player.SendTemporaryMessage($"Undo done.");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"You can't use undo right now!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 18
0
        public static void Copy(User user)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.SaveSelectionToClipboard(user))
                {
                    user.Player.SendTemporaryMessage($"Copy done.");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 19
0
        public static void Import(User user, string pFileName)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.LoadClipboard(pFileName))
                {
                    user.Player.SendTemporaryMessage($"Import done. Use //paste");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Schematic file not found!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 20
0
        public static void Export(User user, string pFileName)
        {
            try
            {
                WorldEditUserData weud = WorldEditManager.GetUserData(user.Name);

                if (weud.SaveClipboard(pFileName))
                {
                    user.Player.SendTemporaryMessage($"Export done.");
                }
                else
                {
                    user.Player.SendTemporaryMessage($"Please //copy a selection first!");
                }
            }
            catch (Exception e)
            {
                AsphaltLog.WriteError(e.ToStringPretty());
            }
        }
Ejemplo n.º 21
0
        public static void SetPos2(User user)
        {
            try
            {
                Vector3 pos = user.Position;
                pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X;
                pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z;
                pos.X = pos.X % Shared.Voxel.World.VoxelSize.X;
                pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z;

                UserSession session = WorldEditManager.GetUserSession(user);
                session.SetSecondPosition(pos.Round);

                user.Player.MsgLoc($"Second Position set to {pos}");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
        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);
        }
Ejemplo n.º 23
0
        public static void Expclaim(User user, string args = "1")
        {
            try
            {
                UserSession session = WorldEditManager.GetUserSession(user);
                if (!session.Selection.IsSet())
                {
                    throw new WorldEditCommandException("Please set both points first!");
                }
                Direction direction = WorldEditUtils.ParseDirectionAndAmountArgs(user, args, out int amount);
                if (direction == Direction.Unknown ||
                    direction == Direction.None ||
                    direction == Direction.Up ||
                    direction == Direction.Down)
                {
                    throw new WorldEditCommandException("Unable to determine direction");
                }
                WorldRange range = session.Selection;
                Vector3i   pos   = default;
                if (range.min.y <= range.max.y)
                {
                    pos.y = range.min.y;
                }
                else
                {
                    pos.y = range.max.y;
                }
                switch (direction)
                {
                case Direction.Left:
                case Direction.Back:
                    if (range.min.x <= range.max.x)
                    {
                        pos.x = range.min.x;
                    }
                    else
                    {
                        pos.x = range.max.x;
                    }
                    if (range.min.z <= range.max.z)
                    {
                        pos.z = range.min.z;
                    }
                    else
                    {
                        pos.z = range.max.z;
                    }
                    break;

                case Direction.Right:
                case Direction.Forward:
                    if (range.min.x <= range.max.x)
                    {
                        pos.x = range.max.x;
                    }
                    else
                    {
                        pos.x = range.min.x;
                    }
                    if (range.min.z <= range.max.z)
                    {
                        pos.z = range.max.z;
                    }
                    else
                    {
                        pos.z = range.min.z;
                    }
                    break;
                }
                pos += direction.ToVec() * (PlotUtil.PropertyPlotLength - 1) * amount;
                Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ);
                range.ExtendToInclude(claimPos.X_Z(pos.Y));
                range.ExtendToInclude(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y));
                session.SetSelection(range);

                user.Player.MsgLoc($"First Position now at {session.Selection.min}");
                user.Player.MsgLoc($"Second Position now at {session.Selection.max}");
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 24
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());
            }
        }
Ejemplo n.º 25
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());
            }
        }
Ejemplo n.º 26
0
 public void Initialize(TimedTask timer)
 {
     WorldEditManager.UpdateBlueprintList();
 }