Exemplo n.º 1
0
        public static bool DoDrawOp(DrawOp op, Brush brush, Player p, Vec3U16[] marks)
        {
            op.Origin = marks[0]; op.Min = marks[0]; op.Max = marks[0];
            for (int i = 1; i < marks.Length; i++)
            {
                op.Min = Vec3U16.Min(op.Min, marks[i]);
                op.Max = Vec3U16.Max(op.Max, marks[i]);
            }
            op.Level = p.level;
            if (!op.Level.DrawingAllowed)
            {
                Player.SendMessage(p, "Drawing commands are turned off on this map.");
                return(false);
            }

            long affected = 0;

            if (!op.CanDraw(marks, p, out affected))
            {
                return(false);
            }
            if (brush != null && affected != -1)
            {
                const string format = "{0}({1}): affecting up to {2} blocks";
                Player.SendMessage(p, String.Format(format, op.Name, brush.Name, affected));
            }
            else if (affected != -1)
            {
                const string format = "{0}: affecting up to {1} blocks";
                Player.SendMessage(p, String.Format(format, op.Name, affected));
            }

            AppendDrawOp(p, op, brush, marks, affected);
            return(true);
        }
Exemplo n.º 2
0
        internal static void Execute(Player p, DrawOp op, Brush brush, Vec3S32[] marks)
        {
            UndoDrawOpEntry entry = new UndoDrawOpEntry();

            entry.Init(op.Name, op.Level.name);

            if (brush != null)
            {
                brush.Configure(op, p);
            }
            Level           lvl       = op.Level;
            DrawOpOutputter outputter = new DrawOpOutputter(op);

            if (op.AffectedByTransform)
            {
                p.Transform.Perform(marks, p, lvl, op, brush, outputter.Output);
            }
            else
            {
                op.Perform(marks, brush, outputter.Output);
            }
            bool needsReload = op.TotalModified >= outputter.reloadThreshold;

            if (op.Undoable)
            {
                entry.Finish(p);
            }
            if (needsReload)
            {
                DoReload(p, op.Level);
            }
            op.TotalModified = 0; // reset total modified (as drawop instances are reused in static mode)
        }
Exemplo n.º 3
0
        static void AppendDrawOp(Player p, DrawOp op, Brush brush, Vec3S32[] marks, long affected)
        {
            if (p == null)
            {
                BufferedBlockSender buffer = new BufferedBlockSender(op.Level);
                op.Perform(marks, brush, b => ConsoleOutputBlock(b, op.Level, buffer));
                buffer.Send(true);
                return;
            }

            PendingDrawOp item = new PendingDrawOp();

            item.Op    = op;
            item.Brush = brush;
            item.Marks = marks;

            lock (p.pendingDrawOpsLock) {
                p.PendingDrawOps.Add(item);
                // Another thread is already processing draw ops.
                if (p.PendingDrawOps.Count > 1)
                {
                    return;
                }
            }
            ProcessDrawOps(p);
        }
Exemplo n.º 4
0
        public static Level Setup(DrawOp op, Player p, Vec3S32[] marks)
        {
            op.SetMarks(marks);
            Level lvl = p.level;

            op.SetLevel(lvl);
            op.Player = p;
            return(lvl);
        }
Exemplo n.º 5
0
        static void OutputBlock(DrawOpBlock b, DrawOp op)
        {
            if (b.Block == Block.Invalid)
            {
                return;
            }
            Level  lvl = op.Level;
            Player p = op.Player;
            byte   old = lvl.GetTile(b.X, b.Y, b.Z), oldExt = 0;

            if (old == Block.custom_block)
            {
                oldExt = lvl.GetExtTile(b.X, b.Y, b.Z);
            }

            if (op.TotalModified > Server.DrawReloadLimit)
            {
                if (old == Block.Invalid)
                {
                    return;
                }
                bool same = old == b.Block;
                if (same && b.Block == Block.custom_block)
                {
                    same = lvl.GetExtTile(b.X, b.Y, b.Z) == b.ExtBlock;
                }
                if (same || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block, b.ExtBlock))
                {
                    return;
                }

                lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock, op.Flags);
                p.IncrementBlockStats(b.Block, true);
            }
            else if (op.TotalModified == Server.DrawReloadLimit)
            {
                Player.Message(p, "Affected over {0} blocks, prepared to reload map..", Server.DrawReloadLimit);
                lock (lvl.queueLock)
                    lvl.blockqueue.Clear();
            }
            else
            {
                if (!lvl.DoBlockchange(p, b.X, b.Y, b.Z, b.Block, b.ExtBlock, true))
                {
                    return;
                }

                lvl.BlockDB.Add(p, b.X, b.Y, b.Z, op.Flags,
                                old, oldExt, b.Block, b.ExtBlock);
                int index = lvl.PosToInt(b.X, b.Y, b.Z);
                BlockQueue.Addblock(p, index, b.Block, b.ExtBlock);
            }
            op.TotalModified++;
        }
Exemplo n.º 6
0
 public static bool DoDrawOp(DrawOp op, Brush brush, Player p,
                             ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2)
 {
     Vec3U16[] marks = new [] { new Vec3U16(x1, y1, z1), new Vec3U16(x2, y2, z2) };
     if (op.MinMaxCoords)
     {
         marks[0].X = Math.Min(x1, x2); marks[1].X = Math.Max(x1, x2);
         marks[0].Y = Math.Min(y1, y2); marks[1].Y = Math.Max(y1, y2);
         marks[0].Z = Math.Min(z1, z2); marks[1].Z = Math.Max(z1, z2);
     }
     return(DoDrawOp(op, brush, p, marks));
 }
Exemplo n.º 7
0
        public static bool Do(DrawOp op, Brush brush, Player p,
                              Vec3S32[] marks, bool checkLimit = true)
        {
            Level lvl = p.level;

            op.Setup(p, lvl, marks);

            if (lvl != null && !lvl.Config.Drawing && !op.AlwaysUsable)
            {
                p.Message("Drawing commands are turned off on this map.");
                return(false);
            }
            if (lvl != null && CannotBuildIn(p, lvl))
            {
                return(false);
            }

            long affected = op.BlocksAffected(lvl, marks);

            if (op.AffectedByTransform)
            {
                p.Transform.GetBlocksAffected(ref affected);
            }
            if (checkLimit && !op.CanDraw(marks, p, affected))
            {
                return(false);
            }

            if (brush != null && affected != -1)
            {
                const string format = "{0}({1}): affecting up to {2} blocks";
                if (!p.Ignores.DrawOutput)
                {
                    p.Message(format, op.Name, brush.Name, affected);
                }
            }
            else if (affected != -1)
            {
                const string format = "{0}: affecting up to {1} blocks";
                if (!p.Ignores.DrawOutput)
                {
                    p.Message(format, op.Name, affected);
                }
            }

            DoQueuedDrawOp(p, op, brush, marks);
            return(true);
        }
Exemplo n.º 8
0
        static void DoQueuedDrawOp(Player p, DrawOp op, Brush brush, Vec3S32[] marks)
        {
            PendingDrawOp item = new PendingDrawOp();

            item.Op = op; item.Brush = brush; item.Marks = marks;

            lock (p.pendingDrawOpsLock) {
                p.PendingDrawOps.Add(item);
                // Another thread is already processing draw ops.
                if (p.PendingDrawOps.Count > 1)
                {
                    return;
                }
            }
            ProcessDrawOps(p);
        }
Exemplo n.º 9
0
        public static bool Do(DrawOp op, Brush brush, Player p,
                              Vec3S32[] marks, bool checkLimit = true)
        {
            Level lvl = Setup(op, p, marks);

            if (lvl != null && !lvl.Config.DrawingAllowed)
            {
                Player.Message(p, "Drawing commands are turned off on this map.");
                return(false);
            }
            if (lvl != null && !lvl.BuildAccess.CheckDetailed(p))
            {
                Player.Message(p, "Hence you cannot use draw commands on this map.");
                return(false);
            }

            long affected = op.BlocksAffected(lvl, marks);

            if (p != null && op.AffectedByTransform)
            {
                p.Transform.GetBlocksAffected(ref affected);
            }
            if (checkLimit && !op.CanDraw(marks, p, affected))
            {
                return(false);
            }

            if (brush != null && affected != -1)
            {
                const string format = "{0}({1}): affecting up to {2} blocks";
                if (p == null || !p.Ignores.DrawOutput)
                {
                    Player.Message(p, format, op.Name, brush.Name, affected);
                }
            }
            else if (affected != -1)
            {
                const string format = "{0}: affecting up to {1} blocks";
                if (p == null || !p.Ignores.DrawOutput)
                {
                    Player.Message(p, format, op.Name, affected);
                }
            }

            DoQueuedDrawOp(p, op, brush, marks);
            return(true);
        }
Exemplo n.º 10
0
        public static bool DoDrawOp(DrawOp op, Brush brush, Player p,
                                    Vec3S32[] marks, bool checkLimit = true)
        {
            op.SetMarks(marks);
            op.Level  = p == null ? null : p.level;
            op.Player = p;

            if (op.Level != null && !op.Level.DrawingAllowed)
            {
                Player.Message(p, "Drawing commands are turned off on this map.");
                return(false);
            }
            if (op.Level != null && op.Level.BuildAccess.Check(p) == LevelAccess.Blacklisted)
            {
                Player.Message(p, "You are blacklisted from building in this map, " +
                               "hence you cannot draw in this map");
                return(false);
            }

            long affected = op.BlocksAffected(op.Level, marks);

            if (p != null && op.AffectedByTransform)
            {
                p.Transform.GetBlocksAffected(ref affected);
            }

            if (checkLimit && !op.CanDraw(marks, p, affected))
            {
                return(false);
            }
            if (brush != null && affected != -1)
            {
                const string format = "{0}({1}): affecting up to {2} blocks";
                Player.Message(p, format, op.Name, brush.Name, affected);
            }
            else if (affected != -1)
            {
                const string format = "{0}: affecting up to {1} blocks";
                Player.Message(p, format, op.Name, affected);
            }

            AppendDrawOp(p, op, brush, marks, affected);
            return(true);
        }
Exemplo n.º 11
0
        static void AppendDrawOp(Player p, DrawOp op, Brush brush, Vec3U16[] marks, long affected)
        {
            PendingDrawOp pending = new PendingDrawOp();

            pending.Op       = op;
            pending.Brush    = brush;
            pending.Marks    = marks;
            pending.Affected = affected;
            pending.Level    = p.level;

            lock (p.pendingDrawOpsLock) {
                p.PendingDrawOps.Add(pending);
                // Another thread is already processing draw ops.
                if (p.PendingDrawOps.Count > 1)
                {
                    return;
                }
            }
            ProcessDrawOps(p);
        }
Exemplo n.º 12
0
 public DrawOpOutputter(DrawOp op)
 {
     this.op         = op;
     reloadThreshold = op.Level.ReloadThreshold;
 }
Exemplo n.º 13
0
 public PyramidDrawOp(DrawOp baseOp, int yDir)
 {
     this.baseOp = baseOp;
     this.yDir   = yDir;
 }
Exemplo n.º 14
0
 public PyramidReverseDrawOp() : base(new CuboidDrawOp(), -1)
 {
     wallOp   = new CuboidWallsDrawOp();
     airBrush = new SolidBrush(Block.air, 0);
 }
Exemplo n.º 15
0
 public static bool DoDrawOp(DrawOp op, Brush brush, Player p,
                             ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2)
 {
     Vec3S32[] marks = new [] { new Vec3S32(x1, y1, z1), new Vec3S32(x2, y2, z2) };
     return(DoDrawOp(op, brush, p, marks));
 }