Esempio n. 1
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));
        }
Esempio n. 2
0
        public override void Use(Player p, string message)
        {
            string[] args = message.Split(' ');
            if (args.Length != 2)
            {
                Help(p); return;
            }
            DrawArgs dArgs = default(DrawArgs);

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

            if (block == -1)
            {
                return;
            }
            dArgs.block = (byte)block;

            int newBlock = DrawCmd.GetBlockIfAllowed(p, args[1], out dArgs.newExtBlock);

            if (newBlock == -1)
            {
                return;
            }
            dArgs.newBlock = (byte)newBlock;

            Player.Message(p, "Place two blocks to determine the edges.");
            p.MakeSelection(2, dArgs, DoOutline);
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public override void Use(Player p, string message) {
            byte ext = 0;
            int block = p.GetActualHeldBlock(out ext);
            ushort x = p.pos[0], y = (ushort)(p.pos[1] - 32), z = p.pos[2];

            try {
                string[] parts = message.Split(' ');
                switch (parts.Length) {
                    case 1: block = message == "" ? block :
                        DrawCmd.GetBlockIfAllowed(p, parts[0], out ext); break;
                    case 3:
                        x = (ushort)(ushort.Parse(parts[0]) * 32);
                        y = (ushort)(ushort.Parse(parts[1]) * 32);
                        z = (ushort)(ushort.Parse(parts[2]) * 32);
                        break;
                    case 4:
                        block = DrawCmd.GetBlockIfAllowed(p, parts[0], out ext);
                        x = (ushort)(ushort.Parse(parts[1]) * 32);
                        y = (ushort)(ushort.Parse(parts[2]) * 32);
                        z = (ushort)(ushort.Parse(parts[3]) * 32);
                        break;
                    default: Player.Message(p, "Invalid number of parameters"); return;
                }
            } catch { 
                Player.Message(p, "Invalid parameters"); return; 
            }

            if (block == -1 || block == Block.Invalid) return;
            if (!Block.canPlace(p, (byte)block)) { Formatter.MessageBlock(p, "place ", (byte)block); return; }
            Vec3U16 P = Vec3U16.ClampPos(x, y, z, p.level);
            
            P.X /= 32; P.Y /= 32; P.Z /= 32;
            p.level.UpdateBlock(p, P.X, P.Y, P.Z, (byte)block, ext, BlockDBFlags.ManualPlace);
            string blockName = p.level.BlockName((byte)block, ext);
            Player.Message(p, "{3} block was placed at ({0}, {1}, {2}).", P.X, P.Y, P.Z, blockName);
        }