Ejemplo n.º 1
0
        public override void Use(Player p, string message)
        {
            if (Player.IsSuper(p))
            {
                MessageInGameOnly(p); return;
            }
            message = message.ToLower();
            string[] parts = message.Split(' ');

            DrawArgs dArgs = default(DrawArgs);

            dArgs.Message = message;
            dArgs.Player  = p;
            dArgs.Mode    = GetMode(parts);
            dArgs.Op      = GetDrawOp(dArgs);
            if (dArgs.Op == null)
            {
                return;
            }

            // Validate the brush syntax is correct
            int          offset  = 0;
            BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset));
            BrushArgs    bArgs   = GetBrushArgs(dArgs, offset);

            if (!factory.Validate(bArgs))
            {
                return;
            }

            Player.Message(p, PlaceMessage);
            p.MakeSelection(MarksCount, dArgs, DoDraw);
        }
Ejemplo n.º 2
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                p.Message("Your current brush is: " + p.BrushName); return;
            }
            string[]     args  = message.SplitSpaces(2);
            BrushFactory brush = BrushFactory.Find(args[0]);

            if (IsListCommand(args[0]))
            {
                List(p);
            }
            else if (brush == null)
            {
                p.Message("No brush found with name \"{0}\".", args[0]);
                List(p);
            }
            else
            {
                p.Message("Set your brush to: " + brush.Name);
                p.BrushName        = brush.Name;
                p.DefaultBrushArgs = args.Length > 1 ? args[1] : "";
            }
        }
Ejemplo n.º 3
0
        bool ValidateArgs(Player p, string[] args)
        {
            if (args.Length < 2)
            {
                Help(p); return(false);
            }

            byte extBlock = 0;
            int  block    = DrawCmd.GetBlockIfAllowed(p, args[0], out extBlock);

            if (block == -1)
            {
                return(false);
            }

            BrushFactory factory = BrushFactory.Find(args[1]);

            if (factory == null)
            {
                Player.Message(p, "No brush found with name \"{0}\".", args[1]);
                Player.Message(p, "Available brushes: " + BrushFactory.Available);
                return(false);
            }

            string brushMessage = args.Length > 2 ? args[2] : "";
            byte   held, extHeld;

            held = p.GetActualHeldBlock(out extHeld);
            BrushArgs bArgs = new BrushArgs(p, brushMessage, held, extHeld);

            return(factory.Validate(bArgs));
        }
Ejemplo n.º 4
0
        public override void Use(Player p, string message)
        {
            if (message.Length == 0)
            {
                Player.Message(p, "Your current brush is: " + p.BrushName); return;
            }
            string[]     args  = message.SplitSpaces(2);
            BrushFactory brush = BrushFactory.Find(args[0]);

            if (args[0].CaselessEq("list"))
            {
                Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available);
            }
            else if (brush == null)
            {
                Player.Message(p, "No brush found with name \"{0}\".", args[0]);
                Player.Message(p, "Available brushes: " + BrushFactory.Available);
            }
            else
            {
                Player.Message(p, "Set your brush to: " + brush.Name);
                p.BrushName        = brush.Name;
                p.DefaultBrushArgs = args.Length > 1 ? args[1] : "";
            }
        }
Ejemplo n.º 5
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!");
        }
Ejemplo n.º 6
0
        bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType)
        {
            string[] args     = ((string)state).SplitSpaces(3);
            byte     extBlock = 0;
            int      block    = DrawCmd.GetBlockIfAllowed(p, args[0], out extBlock);

            if (block == -1)
            {
                return(false);
            }

            BrushFactory factory      = BrushFactory.Find(args[1]);
            string       brushMessage = args.Length > 2 ? args[2] : "";
            BrushArgs    bArgs        = new BrushArgs(p, brushMessage, type, extType);
            Brush        brush        = factory.Construct(bArgs);

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

            DrawOp op = null;

            if (ReplaceNot)
            {
                op = new ReplaceNotDrawOp((byte)block, extBlock);
            }
            else
            {
                op = new ReplaceDrawOp((byte)block, extBlock);
            }
            return(DrawOp.DoDrawOp(op, brush, p, marks));
        }
Ejemplo n.º 7
0
        protected BrushFactory MakeBrush(DrawArgs args)
        {
            args.BrushName = args.Player.BrushName;
            args.BrushArgs = "";
            GetBrush(args);

            if (args.BrushArgs.Length == 0)
            {
                args.BrushArgs = args.Player.DefaultBrushArgs;
            }
            return(BrushFactory.Find(args.BrushName));
        }
Ejemplo n.º 8
0
        public override void Help(Player p, string message)
        {
            BrushFactory brush = BrushFactory.Find(message);

            if (brush == null)
            {
                p.Message("No brush found with name \"{0}\".", message);
                List(p);
            }
            else
            {
                p.MessageLines(brush.Help);
            }
        }
Ejemplo n.º 9
0
        public override void Help(Player p, string message)
        {
            BrushFactory brush = BrushFactory.Find(message);

            if (brush == null)
            {
                Player.Message(p, "No brush found with name \"{0}\".", message);
                Player.Message(p, "%HAvailable brushes: %S" + BrushFactory.Available);
            }
            else
            {
                Player.MessageLines(p, brush.Help);
            }
        }
Ejemplo n.º 10
0
        bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType)
        {
            BrushArgs args  = new BrushArgs(p, (string)state, type, extType);
            string    name  = ReplaceNot ? "replacenot" : "replace";
            Brush     brush = BrushFactory.Find(name).Construct(args);

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

            DrawOp drawOp = new CuboidDrawOp();

            return(DrawOp.DoDrawOp(drawOp, brush, p, marks));
        }
Ejemplo n.º 11
0
        protected override DrawOp GetDrawOp(DrawArgs dArgs)
        {
            string[] args = dArgs.Message.SplitSpaces(3);
            Player   p    = dArgs.Player;

            if (args.Length < 2)
            {
                Help(p); return(null);
            }

            string replaceCmd = ReplaceNot ? "ReplaceNot" : "Replace";

            if (!p.CanUse(replaceCmd) || !p.CanUse("Brush"))
            {
                p.Message("You cannot use /brush and/or /" + replaceCmd +
                          ", so therefore cannot use this command."); return(null);
            }


            BlockID target;

            if (!CommandParser.GetBlockIfAllowed(p, args[0], out target))
            {
                return(null);
            }

            BrushFactory factory = BrushFactory.Find(args[1]);

            if (factory == null)
            {
                p.Message("No brush found with name \"{0}\".", args[1]);
                CmdBrush.List(p);
                return(null);
            }

            DrawOp op = null;

            if (ReplaceNot)
            {
                op = new ReplaceNotDrawOp(target);
            }
            else
            {
                op = new ReplaceDrawOp(target);
            }
            return(op);
        }
Ejemplo n.º 12
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (p.CurrentCopy == null)
            {
                p.Message("You haven't copied anything yet"); return;
            }

            BrushArgs args = new BrushArgs(p, message, Block.Air);

            if (!BrushFactory.Find("Paste").Validate(args))
            {
                return;
            }

            p.Message("Place a block in the corner of where you want to paste.");
            p.MakeSelection(1, "Selecting location for %SPaste", args, DoPaste);
        }
Ejemplo n.º 13
0
        static Brush ParseBrush(string raw, Player p, ExtBlock block)
        {
            string[]     parts = raw.SplitSpaces(2);
            BrushFactory brush = BrushFactory.Find(parts[0]);

            if (brush == null)
            {
                Player.Message(p, "No brush found with name \"{0}\".", parts[0]);
                Player.Message(p, "Available brushes: " + BrushFactory.Available);
                return(null);
            }

            string    brushArgs = parts.Length >= 2 ? parts[1].ToLower() : "";
            BrushArgs args      = new BrushArgs(p, brushArgs, block);

            return(brush.Construct(args));
        }
Ejemplo n.º 14
0
        public override void Use(Player p, string message)
        {
            string brushMsg = message.ToLower();
            byte   block, extBlock;

            block = p.GetActualHeldBlock(out extBlock);

            BrushArgs args = new BrushArgs(p, brushMsg, block, extBlock);
            string    name = ReplaceNot ? "replacenot" : "replace";

            if (!BrushFactory.Find(name).Validate(args))
            {
                return;
            }

            Player.Message(p, "Place two blocks to determine the edges.");
            p.MakeSelection(2, message.ToLower(), DoReplace);
        }
Ejemplo n.º 15
0
        public override void Use(Player p, string message)
        {
            if (p.CurrentCopySlot >= p.CopySlots.Count || p.CopySlots[p.CurrentCopySlot] == null)
            {
                Player.Message(p, "You haven't copied anything yet"); return;
            }

            BrushArgs args  = new BrushArgs(p, message, ExtBlock.Air);
            Brush     brush = BrushFactory.Find("paste").Construct(args);

            if (brush == null)
            {
                return;
            }

            Player.Message(p, "Place a block in the corner of where you want to paste.");
            p.MakeSelection(1, "Selecting location for %SPaste", brush, DoPaste);
        }
Ejemplo n.º 16
0
        protected virtual bool DoDraw(Player p, Vec3S32[] marks,
                                      object state, byte block, byte extBlock)
        {
            DrawArgs dArgs = (DrawArgs)state;

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

            int          offset  = 0;
            BrushFactory factory = BrushFactory.Find(GetBrush(p, dArgs, ref offset));
            BrushArgs    bArgs   = GetBrushArgs(dArgs, offset);
            Brush        brush   = factory.Construct(bArgs);

            return(brush != null && DrawOp.DoDrawOp(dArgs.Op, brush, p, marks));
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public override void Use(Player p, string message)
        {
            ushort x2 = (ushort)(p.level.Width - 1);
            ushort y2 = (ushort)(p.level.Height - 1);
            ushort z2 = (ushort)(p.level.Length - 1);

            BrushArgs args  = new BrushArgs(p, message.ToLower(), 0, 0);
            Brush     brush = BrushFactory.Find("replace").Construct(args);

            if (brush == null)
            {
                return;
            }

            DrawOp drawOp = new CuboidDrawOp();

            if (!DrawOp.DoDrawOp(drawOp, brush, p, 0, 0, 0, x2, y2, z2))
            {
                return;
            }
            Player.Message(p, "&4/replaceall finished!");
        }