예제 #1
0
        static void PerformRedo(Player p)
        {
            UndoDrawOpEntry[] entries = p.DrawOps.Items;
            if (entries.Length == 0)
            {
                p.Message("You have no &T/Undo %Sor &T/Undo [seconds] %Sto redo."); return;
            }

            for (int i = entries.Length - 1; i >= 0; i--)
            {
                UndoDrawOpEntry entry = entries[i];
                if (entry.DrawOpName != "UndoSelf")
                {
                    continue;
                }
                p.DrawOps.Remove(entry);

                RedoSelfDrawOp op = new RedoSelfDrawOp();
                op.Start = entry.Start; op.End = entry.End;
                DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal });
                p.Message("Redo performed.");
                return;
            }
            p.Message("No &T/Undo %Sor &T/Undo [timespan] %Scalls were " +
                      "found in the last 200 draw operations.");
        }
예제 #2
0
        public override void Use(Player p, string message, CommandData data)
        {
            BrushArgs args  = new BrushArgs(p, message, Block.Air);
            Brush     brush = BrushFactory.Find("Replace").Construct(args);

            if (brush == null)
            {
                return;
            }

            Vec3S32 max = new Vec3S32(p.level.Width - 1, p.level.Height - 1, p.level.Length - 1);

            Vec3S32[] marks = new Vec3S32[] { Vec3S32.Zero, max };

            MeasureDrawOp measure = new MeasureDrawOp();

            measure.Setup(p, p.level, marks);
            measure.Perform(marks, brush, null);

            if (measure.Total > p.group.DrawLimit)
            {
                p.Message("You tried to replace " + measure.Total + " blocks.");
                p.Message("You cannot draw more than " + p.group.DrawLimit + ".");
                return;
            }

            DrawOp op = new CuboidDrawOp();

            op.AffectedByTransform = false;
            if (!DrawOpPerformer.Do(op, brush, p, marks, false))
            {
                return;
            }
            p.Message("&4/replaceall finished!");
        }
예제 #3
0
        void UndoLastDrawOp(Player p)
        {
            UndoDrawOpEntry[] entries = p.DrawOps.Items;
            if (entries.Length == 0)
            {
                p.Message("You have no draw operations to undo.");
                p.Message("Try using %T/Undo [timespan] %Sinstead.");
                return;
            }

            for (int i = entries.Length - 1; i >= 0; i--)
            {
                UndoDrawOpEntry entry = entries[i];
                if (entry.DrawOpName == "UndoSelf")
                {
                    continue;
                }
                p.DrawOps.Remove(entry);

                UndoSelfDrawOp op = new UndoSelfDrawOp();
                op.who = p.name; op.ids = NameConverter.FindIds(p.name);

                op.Start = entry.Start; op.End = entry.End;
                DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal });
                p.Message("Undo performed.");
                return;
            }

            p.Message("Unable to undo any draw operations, as all of the " +
                      "past 50 draw operations are %T/Undo %Sor %T/Undo [timespan]");
            p.Message("Try using %T/Undo [timespan] %Sinstead");
        }
예제 #4
0
        void DoDrawImageCore(Player p, Vec3S32[] marks, DrawArgs dArgs)
        {
            Bitmap bmp = HeightmapGen.DecodeImage(dArgs.Data, p);

            if (bmp == null)
            {
                return;
            }

            ImagePrintDrawOp op = new ImagePrintDrawOp();

            op.LayerMode = dArgs.Layer; op.DualLayer = dArgs.Dual;
            op.CalcState(marks);

            int width  = dArgs.Width == 0 ? bmp.Width  : dArgs.Width;
            int height = dArgs.Height == 0 ? bmp.Height : dArgs.Height;

            Clamp(p, marks, op, ref width, ref height);

            if (width < bmp.Width || height < bmp.Height)
            {
                bmp = Resize(bmp, width, height);
            }

            op.SetLevel(p.level);
            op.Player = p; op.Source = bmp; op.Palette = dArgs.Pal;
            DrawOpPerformer.Do(op, null, p, marks, false);
        }
예제 #5
0
        bool DoFixGrass(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            FixGrassDrawOp op = (FixGrassDrawOp)state;

            op.AlwaysUsable = true;

            DrawOpPerformer.Do(op, null, p, marks, false);
            return(false);
        }
예제 #6
0
        bool DoPaste(Player p, Vec3S32[] m, object state, ExtBlock block)
        {
            CopyState cState = p.CopySlots[p.CurrentCopySlot];

            m[0] += cState.Offset;

            PasteDrawOp op = new PasteDrawOp();

            op.CopyState = cState;
            DrawOpPerformer.Do(op, (Brush)state, p, m);
            return(true);
        }
예제 #7
0
        void CompleteCopy(Player p, Vec3S32[] m, CopyArgs cArgs)
        {
            if (!cArgs.cut)
            {
                return;
            }
            DrawOp op = new CuboidDrawOp();

            op.Flags = BlockDBFlags.Cut;
            Brush brush = new SolidBrush(Block.Air);

            DrawOpPerformer.Do(op, brush, p, new Vec3S32[] { m[0], m[1] }, false);
        }
예제 #8
0
        bool DoRestore(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            string path   = (string)state;
            Level  source = IMapImporter.Formats[0].Read(path, "templevel", false);

            RestoreSelectionDrawOp op = new RestoreSelectionDrawOp();

            op.Source = source;
            if (DrawOpPerformer.Do(op, null, p, marks))
            {
                return(false);
            }

            // Not high enough draw limit
            source.Dispose();
            return(false);
        }
예제 #9
0
        bool DoTree(Player p, Vec3S32[] marks, object state, ExtBlock block)
        {
            DrawArgs   dArgs = (DrawArgs)state;
            TreeDrawOp op    = new TreeDrawOp();

            op.Tree = dArgs.tree;
            op.Size = dArgs.size;

            Brush brush = null;

            if (dArgs.brushMsg.Length > 0)
            {
                brush = ParseBrush(dArgs.brushMsg, p, block);
            }
            DrawOpPerformer.Do(op, brush, p, marks);
            return(true);
        }
예제 #10
0
        void UndoSelf(Player p, TimeSpan delta)
        {
            UndoDrawOp op = new UndoSelfDrawOp();

            op.Start = DateTime.UtcNow.Subtract(delta);
            op.who   = p.name; op.ids = NameConverter.FindIds(p.name);

            DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal });
            if (op.found)
            {
                p.Message("Undid your changes for the past &b{0}", delta.Shorten(true));
                Logger.Log(LogType.UserActivity, "{0} undid their own actions for the past {1}",
                           p.name, delta.Shorten(true));
            }
            else
            {
                p.Message("No changes found by you in the past &b{0}", delta.Shorten(true));
            }
        }
예제 #11
0
        bool DoWrite(Player p, Vec3S32[] marks, object state, ExtBlock block)
        {
            WriteArgs wArgs = (WriteArgs)state;

            if (marks[0].X == marks[1].X && marks[0].Z == marks[1].Z)
            {
                Player.Message(p, "No direction was selected"); return(false);
            }

            WriteDrawOp op = new WriteDrawOp();

            op.Text  = wArgs.message;
            op.Scale = wArgs.scale; op.Spacing = wArgs.spacing;

            Brush brush = new SolidBrush(block);

            DrawOpPerformer.Do(op, brush, p, marks);
            return(true);
        }
예제 #12
0
        bool DoPaste(Player p, Vec3S32[] m, object state, BlockID block)
        {
            CopyState cState = p.CurrentCopy;

            m[0] += cState.Offset;

            BrushArgs args  = (BrushArgs)state;
            Brush     brush = BrushFactory.Find("Paste").Construct(args);

            if (brush == null)
            {
                return(false);
            }

            PasteDrawOp op = new PasteDrawOp();

            op.CopyState = cState;
            DrawOpPerformer.Do(op, brush, p, m);
            return(true);
        }
예제 #13
0
        static void UndoPlayer(Player p, TimeSpan delta, string[] names, int[] ids, Vec3S32[] marks)
        {
            UndoDrawOp op = new UndoDrawOp();

            op.Start = DateTime.UtcNow.Subtract(delta);
            op.who   = names[0]; op.ids = ids;

            if (Player.IsSuper(p))
            {
                // undo them across all loaded levels
                Level[] levels = LevelInfo.Loaded.Items;
                if (p == null)
                {
                    p = new ConsolePlayer();
                }

                foreach (Level lvl in levels)
                {
                    op.SetMarks(marks);
                    op.SetLevel(lvl);
                    op.Player = p; p.level = lvl;
                    DrawOpPerformer.DoQueuedDrawOp(p, op, null, marks);
                }
            }
            else
            {
                DrawOpPerformer.Do(op, null, p, marks);
            }

            string namesStr = names.Join(name => PlayerInfo.GetColoredName(p, name));

            if (op.found)
            {
                Chat.MessageGlobal("Undid {1}%S's changes for the past &b{0}", delta.Shorten(true), namesStr);
                Logger.Log(LogType.UserActivity, "Actions of {0} for the past {1} were undone.", names.Join(), delta.Shorten(true));
            }
            else
            {
                Player.Message(p, "No changes found by {1} %Sin the past &b{0}", delta.Shorten(true), namesStr);
            }
        }
예제 #14
0
        void UndoPhysics(Player p, CommandData data, TimeSpan delta)
        {
            if (!CheckExtraPerm(p, data, 1))
            {
                return;
            }
            if (!p.group.CanExecute("Physics"))
            {
                p.Message("%WYou can only undo physics if you can use %T/Physics"); return;
            }

            CmdPhysics.SetPhysics(p.level, 0);
            UndoPhysicsDrawOp op = new UndoPhysicsDrawOp();

            op.Start = DateTime.UtcNow.Subtract(delta);
            DrawOpPerformer.Do(op, null, p, new Vec3S32[] { Vec3U16.MinVal, Vec3U16.MaxVal });

            p.level.Message("Physics were undone &b" + delta.Shorten());
            Logger.Log(LogType.UserActivity, "Physics were undone &b" + delta.Shorten());
            p.level.Save(true);
        }
예제 #15
0
        protected virtual bool DoDraw(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            DrawArgs dArgs = (DrawArgs)state;

            dArgs.Block = block;
            GetMarks(dArgs, ref marks);
            if (marks == null)
            {
                return(false);
            }

            BrushFactory factory = MakeBrush(dArgs);
            BrushArgs    bArgs   = new BrushArgs(p, dArgs.BrushArgs, dArgs.Block);
            Brush        brush   = factory.Construct(bArgs);

            if (brush == null)
            {
                return(false);
            }

            DrawOpPerformer.Do(dArgs.Op, brush, p, marks);
            return(true);
        }
예제 #16
0
        void DoDrawImageCore(Player p, Vec3S32[] m, DrawArgs dArgs)
        {
            Bitmap bmp = HeightmapGen.ReadBitmap(dArgs.name, "extra/images/", p);

            if (bmp == null)
            {
                return;
            }
            try {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            } catch (Exception ex) {
                Logger.LogError(ex);
                bmp.Dispose();
                return;
            }

            ImagePrintDrawOp op = new ImagePrintDrawOp();
            int dir;

            if (Math.Abs(m[1].X - m[0].X) > Math.Abs(m[1].Z - m[0].Z))
            {
                dir = m[1].X <= m[0].X ? 1 : 0;
            }
            else
            {
                dir = m[1].Z <= m[0].Z ? 3 : 2;
            }
            op.LayerMode = dArgs.layer; op.DualLayer = dArgs.dualLayered;
            op.CalcState(dir);

            ResizeImage(p, m, op, ref bmp);
            op.SetLevel(p.level);
            op.Player = p; op.Source = bmp;

            op.Palette = dArgs.palette; op.Filename = dArgs.name;
            DrawOpPerformer.Do(op, null, p, m, false);
        }
예제 #17
0
        static void UndoPlayer(Player p, TimeSpan delta, string[] names, int[] ids, Vec3S32[] marks)
        {
            UndoDrawOp op = new UndoDrawOp();

            op.Start        = DateTime.UtcNow.Subtract(delta);
            op.who          = names[0]; op.ids = ids;
            op.AlwaysUsable = true;

            if (p.IsSuper)
            {
                // undo them across all loaded levels
                Level[] levels = LevelInfo.Loaded.Items;

                foreach (Level lvl in levels)
                {
                    op.Setup(p, lvl, marks);
                    DrawOpPerformer.Execute(p, op, null, marks);
                }
                p.level = null;
            }
            else
            {
                DrawOpPerformer.Do(op, null, p, marks);
            }

            string namesStr = names.Join(name => p.FormatNick(name));

            if (op.found)
            {
                Chat.MessageGlobal("Undid {1}&S's changes for the past &b{0}", delta.Shorten(true), namesStr);
                Logger.Log(LogType.UserActivity, "Actions of {0} for the past {1} were undone.", names.Join(), delta.Shorten(true));
            }
            else
            {
                p.Message("No changes found by {1} &Sin the past &b{0}", delta.Shorten(true), namesStr);
            }
        }
예제 #18
0
        void DoCopyMark(Player p, Vec3S32[] m, int i, object state, BlockID block)
        {
            if (i == 2)
            {
                CopyState copy = p.CurrentCopy;
                copy.Offset.X = copy.OriginX - m[i].X;
                copy.Offset.Y = copy.OriginY - m[i].Y;
                copy.Offset.Z = copy.OriginZ - m[i].Z;
                p.Message("Set offset of where to paste from.");
                return;
            }
            if (i != 1)
            {
                return;
            }

            CopyArgs cArgs = (CopyArgs)state;
            Vec3S32  min = Vec3S32.Min(m[0], m[1]), max = Vec3S32.Max(m[0], m[1]);
            ushort   minX = (ushort)min.X, minY = (ushort)min.Y, minZ = (ushort)min.Z;
            ushort   maxX = (ushort)max.X, maxY = (ushort)max.Y, maxZ = (ushort)max.Z;

            CopyState cState = new CopyState(minX, minY, minZ, maxX - minX + 1,
                                             maxY - minY + 1, maxZ - minZ + 1);

            cState.OriginX = m[0].X; cState.OriginY = m[0].Y; cState.OriginZ = m[0].Z;

            int index = 0; cState.UsedBlocks = 0;

            cState.PasteAir = cArgs.air;

            for (ushort y = minY; y <= maxY; ++y)
            {
                for (ushort z = minZ; z <= maxZ; ++z)
                {
                    for (ushort x = minX; x <= maxX; ++x)
                    {
                        block = p.level.GetBlock(x, y, z);
                        if (!p.group.Blocks[block])
                        {
                            index++; continue;
                        }

                        if (block != Block.Air || cState.PasteAir)
                        {
                            cState.UsedBlocks++;
                        }
                        cState.Set(block, index);
                        index++;
                    }
                }
            }

            if (cState.UsedBlocks > p.group.DrawLimit)
            {
                p.Message("You tried to copy {0} blocks. You cannot copy more than {1} blocks.",
                          cState.UsedBlocks, p.group.DrawLimit);
                cState.Clear(); cState = null;
                p.ClearSelection();
                return;
            }

            cState.CopySource = "level " + p.level.name;
            p.CurrentCopy     = cState;

            if (cArgs.cut)
            {
                DrawOp op = new CuboidDrawOp();
                op.Flags = BlockDBFlags.Cut;
                Brush brush = new SolidBrush(Block.Air);
                DrawOpPerformer.Do(op, brush, p, new Vec3S32[] { min, max }, false);
            }

            p.Message("Copied &a{0} %Sblocks, origin at ({1}, {2}, {3}) corner", cState.UsedBlocks,
                      cState.OriginX == cState.X ? "Min" : "Max",
                      cState.OriginY == cState.Y ? "Min" : "Max",
                      cState.OriginZ == cState.Z ? "Min" : "Max");
            if (!cState.PasteAir)
            {
                p.Message("To also copy air blocks, use %T/Copy Air");
            }
            if (cArgs.offsetIndex != -1)
            {
                p.Message("Place a block to determine where to paste from");
            }
        }