예제 #1
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                WorldEditManager.AddPos1(player);

                responseParams = new object[] {
                    player.Physics.BottomPosition().X,
                                                    player.Physics.BottomPosition().Y,
                                                    player.Physics.BottomPosition().Z
                };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("mods.nimbusfox.worldedit.success.pos1");
        }
예제 #2
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };

            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                if (bits.Any())
                {
                    if (bits.Skip(1).Any())
                    {
                        WorldEditManager.Import(player, bits[1]);
                    }
                }
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.load");
        }
예제 #3
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                WorldEditManager.Copy(player);

                long tileCount;

                WorldEditManager.Set(player, "staxel.tile.Sky", out tileCount, out _);
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.copy");
        }
예제 #4
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            try {
                responseParams = new object[] { };
                var repeat    = 1;
                var direction = "forwards";

                if (bits.Length >= 2)
                {
                    int.TryParse(bits[1], out repeat);
                }

                if (bits.Length >= 3)
                {
                    direction = bits[2];
                }

                WorldEditManager.Stack(WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid), repeat, direction);
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object> {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("");
        }
예제 #5
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                var tilecount = WorldEditManager.Paste(player);

                if (tilecount == 0)
                {
                    return("mods.nimbusfox.worldedit.error.emptyclipboard");
                }

                responseParams = new object[] { tilecount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }
            return("mods.nimbusfox.worldedit.success.paste");
        }
예제 #6
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                bits = bits.Skip(1).ToArray();

                var newCode = "";
                var oldCode = "";

                if (bits.Length > 0)
                {
                    newCode = TileShortCodes.GetTileCode(bits[0]);
                }

                if (bits.Length > 1)
                {
                    oldCode = TileShortCodes.GetTileCode(bits[1]);
                }

                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                long          tileCount;
                ReplaceResult result;

                WorldEditManager.Replace(player, newCode, oldCode, out tileCount, out result);

                if (result == ReplaceResult.InvalidPositions)
                {
                    return("mods.nimbusfox.worldedit.error.noregion");
                }

                if (result == ReplaceResult.InvalidTile)
                {
                    responseParams = new object[] { newCode };
                    return("mods.nimbusfox.worldedit.error.invalidtile");
                }

                responseParams = new object[] { tileCount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.replaced");
        }
예제 #7
0
 public ExportCommand(User user, string fileName) : base(user)
 {
     this.fileName = WorldEditManager.GetSchematicFileName(fileName);
     if (!Directory.Exists(WorldEditManager.GetSchematicDirectory()))
     {
         Directory.CreateDirectory(WorldEditManager.GetSchematicDirectory());
     }
     if (this.UserSession.Clipboard.Count <= 0)
     {
         throw new WorldEditCommandException($"Please /copy a selection first!");
     }
 }
예제 #8
0
 public WorldEditCommand(User user)
 {
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     this.UserSession = WorldEditManager.GetUserSession(user);
     if (this.UserSession.ExecutingCommand != null && this.UserSession.ExecutingCommand.IsRunning)
     {
         throw new WorldEditCommandException("Another command still executing");                                                                                                       //TODO: Probably need to rework that and impliment aborting
     }
 }
예제 #9
0
        private void OutputToFile(string data)
        {
            data = data.Replace("<pos=300>", "	");
            data = Regex.Replace(data, "<.*?>", String.Empty);

            if (!Directory.Exists(WorldEditManager.GetSchematicDirectory()))
            {
                Directory.CreateDirectory(WorldEditManager.GetSchematicDirectory());
            }
            string file = WorldEditManager.GetSchematicFileName(this.fileName, ".txt");

            File.WriteAllText(file, data);
        }
예제 #10
0
        public string Execute(string[] bits, Blob blob, ClientServerConnection connection, ICommandsApi api,
                              out object[] responseParams)
        {
            responseParams = new object[] { };
            try {
                var player = WorldEditManager.FoxCore.UserManager.GetPlayerEntityByUid(connection.Credentials.Uid);

                var height = 0;
                var width  = 0;
                var tile   = "staxel.tile.dirt.dirt";

                if (bits.Length >= 2)
                {
                    int.TryParse(bits[1], out width);
                    height = width;
                }

                if (bits.Length >= 3)
                {
                    int.TryParse(bits[2], out height);
                }

                if (bits.Length >= 4)
                {
                    tile = TileShortCodes.GetTileCode(bits[3]);
                }

                long tileCount;

                if (!WorldEditManager.Wall(player, width, height, out tileCount, tile))
                {
                    responseParams = new object[] { bits[3] };
                    return("mods.nimbusfox.worldedit.error.invalidtile");
                }

                responseParams = new object[] { tileCount.ToString() };
            } catch (Exception ex) {
                WorldEditManager.FoxCore.ExceptionManager.HandleException(ex,
                                                                          new Dictionary <string, object>
                {
                    { "input", bits }
                });
                responseParams    = new object[3];
                responseParams[0] = "WorldEdit";
                responseParams[1] = "WorldEdit";
                responseParams[2] = "WorldEdit";
                return("mods.nimbusfox.exception.message");
            }

            return("mods.nimbusfox.worldedit.success.set");
        }
        protected override void Execute(WorldRange selection)
        {
            WorldEditManager.UpdateBlueprintList();

            StringBuilder sb = new StringBuilder();

            sb.Append(Localizer.DoStr("File name"))
            .Append(Text.Pos(300, Localizer.DoStr("Version")))
            .Append(Text.Pos(500, Localizer.DoStr("File size")))
            .Append(Text.Pos(700, Localizer.DoStr("Date")))
            .AppendLine(Text.Pos(950, Localizer.DoStr("Player")));

            foreach (EcoBlueprintInfo info in WorldEditManager.BlueprintList.Values.OrderBy(k => k.FileName))
            {
                sb.Append(info.FileName)
                .Append(Text.Pos(300, $"ECO {info.EcoVersion} ({info.Version.ToString("0.00", CultureInfo.InvariantCulture)})"))
                .Append(Text.Pos(500, (info.FileSize / 1024).ToString() + " KB"))
                .Append(Text.Pos(700, info.FileChangedDate.ToString()))
                .AppendLine(Text.Pos(950, info.Author.Name));
            }

            this.UserSession.Player.OpenInfoPanel(Localizer.Do($"WorldEdit Blueprint List"), sb.ToString(), "WorldEditBpList");
        }
예제 #12
0
        protected override void Execute(WorldRange selection)
        {
            selection = selection.FixXZ(Shared.Voxel.World.VoxelSize);

            Dictionary <object, long> blocks = new Dictionary <object, long>();
            long emptyBlocks = 0;

            foreach (Vector3i pos in selection.XYZIterInc())
            {
                Block block     = Eco.World.World.GetBlock(pos);
                Type  blockType = null;
                switch (block)
                {
                case PlantBlock _:
                case TreeBlock _:
                    Plant plant = EcoSim.PlantSim.GetPlant(pos);
                    if (plant != null && plant.Position.Equals(pos))
                    {
                        blockType = plant.Species.GetType();
                    }
                    break;

                case WorldObjectBlock worldObjectBlock:
                    WorldObject worldObject = worldObjectBlock.WorldObjectHandle.Object;
                    if (worldObject.Position3i.Equals(pos))
                    {
                        blockType = worldObject.GetType();
                    }
                    break;

                default:
                    if (BlockContainerManager.Obj.IsBlockContained(pos))
                    {
                        WorldObject obj = ServiceHolder <IWorldObjectManager> .Obj.All.Where(x => x.Position3i.Equals(pos)).FirstOrDefault();

                        if (obj != null)
                        {
                            blockType = obj.GetType();
                        }
                    }
                    else
                    {
                        blockType = block.GetType();
                    }
                    break;
                }
                if (blockType != null)
                {
                    if (blockType == typeof(EmptyBlock))
                    {
                        emptyBlocks++; continue;
                    }
                    if (this.outputType.Equals("brief"))
                    {
                        string name = this.GetBlockFancyName(blockType);
                        blocks.TryGetValue(name, out long count);
                        blocks[name] = count + 1;
                    }
                    else
                    {
                        blocks.TryGetValue(blockType, out long count);
                        blocks[blockType] = count + 1;
                    }
                }
            }

            decimal totalBlocks = blocks.Values.Sum();             // (vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(TextLoc.Header(Localizer.DoStr("Selection Info")));
            sb.AppendLineLoc($"Region: {Text.Location(this.UserSession.Selection.min)} - {Text.Location(this.UserSession.Selection.max)}");
            sb.Append(Localizer.DoStr("Width:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc));
            sb.Append(Localizer.DoStr("Height:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.HeightInc));
            sb.Append(Localizer.DoStr("Length:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.LengthInc));
            sb.Append(Localizer.DoStr("Volume:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.VolumeInc));
            sb.Append(Localizer.DoStr("Area:").ToString().PadRight(8)).AppendLine(Text.PluralLocStr("block", "blocks", selection.WidthInc * selection.LengthInc));
            sb.AppendLocStr("Empty blocks:"); sb.AppendLine($" {emptyBlocks,8}");
            sb.AppendLocStr("Total blocks:"); sb.AppendLine($" {totalBlocks,8}");

            sb.AppendLine().AppendLine(TextLoc.Header(Localizer.DoStr("Block List")));
            foreach (KeyValuePair <object, long> entry in blocks)
            {
                decimal percent = Math.Round((entry.Value / totalBlocks) * 100, 2);

                sb.Append(this.outputType.Equals("detail") ? this.GetBlockFancyName((Type)entry.Key) : (string)entry.Key);
                sb.Append(Text.Pos(400, Text.Info(Text.Int(entry.Value))));
                sb.Append($"({percent}%)".PadLeft(10));
                if (this.outputType.Equals("detail"))
                {
                    sb.Append(Text.Pos(500, $"[{Localizer.DoStr(((Type)entry.Key).Name)}]"));
                }
                sb.AppendLine();
            }
            if (!string.IsNullOrEmpty(this.fileName))
            {
                this.OutputToFile(sb.ToString());
                this.UserSession.Player.MsgLoc($"Report saved into file with name <{WorldEditManager.SanitizeFileName(this.fileName)}.txt>");
            }
            this.UserSession.Player.OpenInfoPanel(Localizer.Do($"WorldEdit Blocks Report"), sb.ToString(), "WorldEditDistr");
        }
예제 #13
0
 public ImportCommand(User user, string fileName) : base(user)
 {
     this.fileName = WorldEditManager.GetSchematicFileName(fileName);
 }