示例#1
0
        internal static Brush ProcessReplace(BrushArgs args, bool not)
        {
            string[] parts = args.Message.SplitSpaces();
            if (args.Message.Length == 0)
            {
                args.Player.Message("You need at least one block to replace."); return(null);
            }

            int count = parts.Length == 1 ? 1 : parts.Length - 1;

            BlockID[] toAffect = GetBlocks(args.Player, 0, count, parts);
            if (toAffect == null)
            {
                return(null);
            }

            BlockID target;

            if (!GetTargetBlock(args, parts, out target))
            {
                return(null);
            }

            if (not)
            {
                return(new ReplaceNotBrush(toAffect, target));
            }
            return(new ReplaceBrush(toAffect, target));
        }
示例#2
0
        static void GetRaw(string[] parts, Predicate <string> filter, BrushArgs args,
                           out BlockID[] blocks, out int[] count)
        {
            int bCount = 0;

            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i].Length == 0 || filter(parts[i]))
                {
                    continue;
                }
                bCount++;
            }

            // For 0 or 1 blocks given, treat second block as 'unchanged'.
            blocks = new BlockID[Math.Max(2, bCount)];
            count  = new int[blocks.Length];
            for (int i = 0; i < count.Length; i++)
            {
                count[i]  = 1;
                blocks[i] = Block.Invalid;
            }

            // No blocks given, assume first is held block
            if (bCount == 0)
            {
                blocks[0] = args.Block;
            }
        }
示例#3
0
        public override Brush Construct(BrushArgs args)
        {
            CopyState cState = args.Player.CurrentCopy;

            if (cState == null)
            {
                args.Player.Message("You haven't copied anything yet.");
                return(null);
            }

            if (args.Message.Length == 0)
            {
                return(new SimplePasteBrush(cState));
            }
            string[] parts = args.Message.SplitSpaces();

            if (parts[0].CaselessEq("not"))
            {
                PasteNotBrush brush = new PasteNotBrush(cState);
                brush.Exclude = ReplaceBrushFactory.GetBlocks(args.Player, 1, parts.Length, parts);
                return(brush.Exclude == null ? null : brush);
            }
            else
            {
                PasteBrush brush = new PasteBrush(cState);
                brush.Include = ReplaceBrushFactory.GetBlocks(args.Player, 0, parts.Length, parts);
                return(brush.Include == null ? null : brush);
            }
        }
示例#4
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message == "")
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(null);
                }
                return(new CheckeredBrush(args.Block, args.ExtBlock, 0, 0));
            }
            string[] parts = args.Message.Split(' ');

            byte extBlock1;
            int  block1 = DrawCmd.GetBlockIfAllowed(args.Player, parts[0], out extBlock1);

            if (block1 == -1)
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new CheckeredBrush((byte)block1, extBlock1, Block.Invalid, 0));
            }

            byte extBlock2;
            int  block2 = DrawCmd.GetBlockIfAllowed(args.Player, parts[1], out extBlock2);

            if (block2 == -1)
            {
                return(null);
            }
            return(new CheckeredBrush((byte)block1, extBlock1, (byte)block2, extBlock2));
        }
示例#5
0
        public static Brush Process(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(new CheckeredBrush(args.Type, args.ExtType, 0, 0));
            }
            string[] parts = args.Message.Split(' ');
            byte     extType1;
            byte     type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1);

            if (type1 == Block.Zero)
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new CheckeredBrush(type1, extType1, Block.Zero, 0));
            }

            byte extType2;
            byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2);

            if (type2 == Block.Zero)
            {
                return(null);
            }
            return(new CheckeredBrush(type1, extType1, type2, extType2));
        }
示例#6
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message.Length == 0)
            {
                if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block))
                {
                    return(null);
                }
                return(new StripedBrush(args.Block, Block.Air));
            }
            string[] parts = args.Message.SplitSpaces();

            BlockID block1;

            if (!CommandParser.GetBlockIfAllowed(args.Player, parts[0], out block1, true))
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new StripedBrush(block1, Block.Air));
            }

            BlockID block2;

            if (!CommandParser.GetBlockIfAllowed(args.Player, parts[1], out block2, true))
            {
                return(null);
            }
            return(new StripedBrush(block1, block2));
        }
示例#7
0
        public static ExtBlock[] GetBlocks(BrushArgs args, out int[] count,
                                           Predicate <string> filter, Predicate <string> handler)
        {
            string[] parts = args.Message.Split(' ');
            Player   p     = args.Player;

            ExtBlock[] blocks;
            GetRaw(parts, filter, args, out blocks, out count);

            // check if we're allowed to place the held block
            if (blocks[0].Block != Block.Invalid &&
                !DrawCmd.CheckBlock(p, blocks[0].Block))
            {
                return(null);
            }

            for (int i = 0, j = 0; i < parts.Length; i++)
            {
                if (parts[i] == "")
                {
                    continue;
                }

                // Brush specific args
                if (!filter(parts[i]))
                {
                    if (!handler(parts[i]))
                    {
                        return(null);
                    }
                    continue;
                }

                byte   extBlock  = 0;
                int    sepIndex  = parts[i].IndexOf('/');
                string blockName = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
                int    block     = DrawCmd.GetBlockIfAllowed(p, blockName, out extBlock);
                if (block == -1)
                {
                    return(null);
                }

                blocks[j].Block = (byte)block; blocks[j].Ext = extBlock;
                if (sepIndex < 0)
                {
                    j++; continue;
                }

                int chance;
                if (!int.TryParse(parts[i].Substring(sepIndex + 1), out chance) ||
                    chance <= 0 || chance > 10000)
                {
                    Player.Message(p, "frequency must be an integer between 1 and 10,000."); return(null);
                }
                count[j] = chance;
                j++;
            }
            return(blocks);
        }
示例#8
0
        public static ExtBlock[] GetBlocks(BrushArgs args, out int[] count,
                                           Predicate <string> argFilter, Predicate <string> argHandler)
        {
            string[] parts = args.Message.SplitSpaces();
            Player   p     = args.Player;

            ExtBlock[] blocks;
            GetRaw(parts, argFilter, args, out blocks, out count);

            // check if we're allowed to place the held block
            if (!blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with", blocks[0]))
            {
                return(null);
            }

            for (int i = 0, j = 0; i < parts.Length; i++)
            {
                if (parts[i].Length == 0)
                {
                    continue;
                }

                // Brush specific args
                if (argFilter(parts[i]))
                {
                    if (!argHandler(parts[i]))
                    {
                        return(null);
                    }
                    continue;
                }

                ExtBlock block;
                int      sepIndex = parts[i].IndexOf('/');
                string   name     = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
                if (!CommandParser.GetBlockIfAllowed(p, name, out block, true))
                {
                    return(null);
                }

                blocks[j] = block;
                if (sepIndex < 0)
                {
                    j++; continue;
                }

                int chance = 0;
                if (!CommandParser.GetInt(p, parts[i].Substring(sepIndex + 1), "Frequency", ref chance, 1, 10000))
                {
                    return(null);
                }

                count[j] = chance;
                j++;
            }
            return(blocks);
        }
示例#9
0
 public override Brush Construct(BrushArgs args)
 {
     if (args.Player.CopyBuffer == null)
     {
         args.Player.SendMessage("You haven't copied anything yet.");
         return(null);
     }
     return(new PasteBrush(args.Player.CopyBuffer));
 }
示例#10
0
 public static Brush Process(BrushArgs args)
 {
     if (args.Player.CopyBuffer == null)
     {
         args.Player.SendMessage("You haven't copied anything yet.");
         return(null);
     }
     return(new PasteBrush(args.Player.CopyBuffer));
 }
示例#11
0
        public override bool Validate(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(true);
            }
            byte extBlock;

            return(DrawCmd.GetBlockIfAllowed(args.Player, args.Message, out extBlock) != -1);
        }
示例#12
0
        public override bool Validate(BrushArgs args)
        {
            if (args.Message.Length == 0)
            {
                return(true);
            }
            BlockID block;

            return(CommandParser.GetBlockIfAllowed(args.Player, args.Message, out block));
        }
示例#13
0
 static bool GetTargetBlock(BrushArgs args, string[] parts, out BlockID target) {
     Player p = args.Player;
     target = 0;
     
     if (parts.Length == 1) {
         if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return false;
         
         target = args.Block; return true;
     }            
     return CommandParser.GetBlockIfAllowed(p, parts[parts.Length - 1], "draw with", out target);
 }
示例#14
0
 public static Brush Process(BrushArgs args)
 {
     if (args.Message == "random")
     {
         return(new RandomRainbowBrush());
     }
     if (args.Message == "bw")
     {
         return(new BWRainbowBrush());
     }
     return(new RainbowBrush());
 }
示例#15
0
        public override Brush Construct(BrushArgs args)
        {
            int[]     count;
            BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => false, null);

            if (toAffect == null)
            {
                return(null);
            }
            BlockID[] blocks = FrequencyBrush.Combine(toAffect, count);
            return(new RandomBrush(blocks));
        }
示例#16
0
 public override Brush Construct(BrushArgs args)
 {
     if (args.Message.CaselessEq("random"))
     {
         return(new RandomRainbowBrush());
     }
     if (args.Message.CaselessEq("bw"))
     {
         return(new BWRainbowBrush());
     }
     return(new RainbowBrush());
 }
示例#17
0
        static bool GetTargetBlock(BrushArgs args, string[] parts, out BlockID target)
        {
            target = 0;
            if (parts.Length == 1)
            {
                if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block))
                {
                    return(false);
                }

                target = args.Block; return(true);
            }
            return(CommandParser.GetBlockIfAllowed(args.Player, parts[parts.Length - 1], out target));
        }
示例#18
0
        public static Brush Process(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(new SolidBrush(args.Type, args.ExtType));
            }
            byte extType;
            byte type = DrawCmd.GetBlock(args.Player, args.Message, out extType);

            if (type == Block.Zero)
            {
                return(null);
            }
            return(new SolidBrush(type, extType));
        }
示例#19
0
 public static Brush Process(BrushArgs args) {
     if (args.Message == "")
         return new StripedBrush(args.Type, args.ExtType, 0, 0);
     string[] parts = args.Message.Split(' ');
     byte extType1;
     byte type1 = DrawCmd.GetBlock(args.Player, parts[0], out extType1);
     if (type1 == Block.Zero) return null;
     if (parts.Length == 1)
         return new StripedBrush(type1, extType1, 0, 0);
     
     byte extType2;
     byte type2 = DrawCmd.GetBlock(args.Player, parts[1], out extType2);
     if (type2 == Block.Zero) return null;
     return new StripedBrush(type1, extType1, type2, extType2);
 }
示例#20
0
        public override Brush Construct(BrushArgs args)
        {
            Player p = args.Player;

            if (args.Message.Length == 0)
            {
                if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block))
                {
                    return(null);
                }
                return(new CheckeredBrush(args.Block, Block.Invalid));
            }
            string[] parts = args.Message.SplitSpaces();

            BlockID block1;

            if (!CommandParser.GetBlockIfAllowed(p, parts[0], "draw with", out block1, true))
            {
                return(null);
            }
            if (parts.Length == 1)
            {
                return(new CheckeredBrush(block1, Block.Invalid));
            }

            if (parts.Length == 2)
            {
                BlockID block2;
                if (!CommandParser.GetBlockIfAllowed(p, parts[1], "draw with", out block2, true))
                {
                    return(null);
                }
                return(new CheckeredBrush(block1, block2));
            }

            BlockID[] blocks = new BlockID[parts.Length];
            for (int i = 0; i < blocks.Length; i++)
            {
                if (!CommandParser.GetBlockIfAllowed(p, parts[i], "draw with", out blocks[i], true))
                {
                    return(null);
                }
            }
            return(new CheckeredPaletteBrush(blocks));
        }
示例#21
0
        public static Brush Process(BrushArgs args)
        {
            string[] parts = args.Message.Split(' ');
            if (parts.Length < 2)
            {
                args.Player.SendMessage("You need to provide a target block, and at least one block to replace."); return(null);
            }

            ExtBlock[] toAffect = GetBlocks(args.Player, 0, parts.Length - 1, parts);
            ExtBlock   target;

            target.Type = DrawCmd.GetBlock(args.Player, parts[parts.Length - 1], out target.ExtType);
            if (target.Type == Block.Zero)
            {
                return(null);
            }
            return(target.Type == Block.Zero ? null : new ReplaceBrush(toAffect, target));
        }
示例#22
0
        public static Brush Process(BrushArgs args)
        {
            if (args.Message == "")
            {
                return(new RandomBrush(new[] { new ExtBlock(args.Type, args.ExtType),
                                               new ExtBlock(Block.Zero, 0) }));
            }

            string[]   parts    = args.Message.Split(' ');
            int[]      count    = new int[parts.Length];
            ExtBlock[] toAffect = GetBlocks(args.Player, parts.Length, parts, count);
            if (toAffect == null)
            {
                return(null);
            }

            ExtBlock[] blocks = Combine(toAffect, count);
            return(new RandomBrush(blocks));
        }
示例#23
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message.Length == 0)
            {
                if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block))
                {
                    return(null);
                }
                return(new SolidBrush(args.Block));
            }

            BlockID block;

            if (!CommandParser.GetBlockIfAllowed(args.Player, args.Message, out block))
            {
                return(null);
            }
            return(new SolidBrush(block));
        }
示例#24
0
        public override Brush Construct(BrushArgs args)
        {
            if (args.Message == "")
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(null);
                }
                return(new SolidBrush(args.Block, args.ExtBlock));
            }

            byte extBlock;
            int  block = DrawCmd.GetBlockIfAllowed(args.Player, args.Message, out extBlock);

            if (block == -1)
            {
                return(null);
            }
            return(new SolidBrush((byte)block, extBlock));
        }
示例#25
0
        static bool GetTargetBlock(BrushArgs args, string[] parts, out ExtBlock target)
        {
            target = default(ExtBlock);
            if (parts.Length == 1)
            {
                if (!DrawCmd.CheckBlock(args.Player, args.Block))
                {
                    return(false);
                }
                target = new ExtBlock(args.Block, args.ExtBlock);
                return(true);
            }

            int block = DrawCmd.GetBlockIfAllowed(args.Player, parts[parts.Length - 1], out target.Ext);

            if (block == -1)
            {
                return(false);
            }
            target.Block = (byte)block;
            return(true);
        }
示例#26
0
        public override Brush Construct(BrushArgs args)
        {
            NoiseArgs n = default(NoiseArgs);

            // Constants borrowed from fCraft to match it
            n.Amplitude   = 1;
            n.Frequency   = 0.08f;
            n.Octaves     = 3;
            n.Seed        = int.MinValue;
            n.Persistence = 0.75f;
            n.Lacunarity  = 2;

            int[]     count;
            BlockID[] toAffect = FrequencyBrush.GetBlocks(args, out count,
                                                          Filter, arg => Handler(arg, args.Player, ref n));

            if (toAffect == null)
            {
                return(null);
            }
            return(new CloudyBrush(toAffect, count, n));
        }
示例#27
0
 public override Brush Construct(BrushArgs args)
 {
     return(ProcessReplace(args, false));
 }
示例#28
0
 public override Brush Construct(BrushArgs args)
 {
     return(new BWRainbowBrush());
 }
示例#29
0
 /// <summary> Validates the given arguments, returning false if they are invalid. </summary>
 public virtual bool Validate(BrushArgs args)
 {
     return(Construct(args) != null);
 }
示例#30
0
 public override Brush Construct(BrushArgs args)
 {
     return(ReplaceBrushFactory.ProcessReplace(args, true));
 }