Пример #1
0
        /// <summary>
        /// Undoes previous block changes.
        /// </summary>
        /// <param name="steps">Number of blocks to undo</param>
        public void Undo(int steps)
        {
            if (CS.UndoObjects.Count == 0)
                return;

            if (steps - 1 > (CS.CurrentIndex))
                steps = (CS.CurrentIndex + 1);

            if (CS.CurrentIndex == -1)
                return;

            for (var i = CS.CurrentIndex; i > (CS.CurrentIndex - steps); i--) {
                var item = new BlockQueueItem {
                    Last = CS.CurrentMap.GetBlock(CS.UndoObjects[i].X, CS.UndoObjects[i].Y, CS.UndoObjects[i].Z),
                    Map = CS.CurrentMap,
                    Material = CS.UndoObjects[i].OldBlock,
                    Physics = false,
                    PlayerId = CS.Id,
                    Priority = 100,
                    Undo = false,
                    X = CS.UndoObjects[i].X,
                    Y = CS.UndoObjects[i].Y,
                    Z = CS.UndoObjects[i].Z,
                };

                HypercubeMap.ActionQueue.Enqueue(item);
            }

            CS.CurrentIndex -= (steps - 1);
        }
Пример #2
0
        public void BuildLine(NetworkClient client, short x, short y, short z, short x2, short y2, short z2, Block material, short priority, bool undo, bool physics)
        {
            var dx = x2 - x;
            var dy = y2 - y;
            var dz = z2 - z;

            var blocks = 1;

            if (blocks < Math.Abs(dx))
                blocks = Math.Abs(dx);

            if (blocks < Math.Abs(dy))
                blocks = Math.Abs(dy);

            if (blocks < Math.Abs(dz))
                blocks = Math.Abs(dz);

            var mx = dx / (float) blocks;
            var my = dy / (float)blocks;
            var mz = dz / (float)blocks;

            for (var i = 0; i < blocks; i++) {
                var item = new BlockQueueItem {
                    Last = GetBlock((short)(x + mx * i), (short)(y + my * i), (short)(z + mz * i)),
                    Map = this,
                    Material = material,
                    Physics = physics,
                    PlayerId = client.CS.Id,
                    Priority = priority,
                    Undo = undo,
                    X = (short)(x + mx * i),
                    Y = (short)(y + my * i),
                    Z = (short)(z + mz * i),
                };

                ActionQueue.Enqueue(item);
            }
        }
Пример #3
0
        /// <summary>
        /// Redoes previous block changes.
        /// </summary>
        /// <param name="steps">Number of blocks to redo</param>
        public void Redo(int steps)
        {
            if (CS.UndoObjects.Count == 0) // -- If the user has nothing in their undo queue, they can't redo nothing!
                return;

            if (steps > (CS.UndoObjects.Count - CS.CurrentIndex)) // -- If the user wants to redo more than they have in their redo/undo queue..
                steps = (CS.UndoObjects.Count - CS.CurrentIndex); // -- Set the steps to be exactly the number they have left in their undo/redo queue.

            if (CS.CurrentIndex == CS.UndoObjects.Count - 1) // -- If we're currently on the latest object in the queue...
                return; // -- Then we can't redo anymore, return.

            if (CS.CurrentIndex == -1) // -- Makes sure we arn't at a negative index (happens sometimes with repeated undos and redos)
                CS.CurrentIndex = 0;

            for (var i = CS.CurrentIndex; i < (CS.CurrentIndex + steps); i++) { // -- Iterates through each block in the range the client wants to redo
                // -- Creates and queues the redone block to be sent to clients, processed by the map, physics, ect.
                var item = new BlockQueueItem {
                    Last = CS.CurrentMap.GetBlock(CS.UndoObjects[i].X, CS.UndoObjects[i].Y, CS.UndoObjects[i].Z),
                    Map = CS.CurrentMap,
                    Material = CS.UndoObjects[i].NewBlock,
                    Physics = false,
                    PlayerId = CS.Id,
                    Priority = 100,
                    Undo = false,
                    X = CS.UndoObjects[i].X,
                    Y = CS.UndoObjects[i].Y,
                    Z = CS.UndoObjects[i].Z,
                };

                HypercubeMap.ActionQueue.Enqueue(item);
            }
            CS.CurrentIndex += (steps - 1); // -- Update the users current position in the undo system.
        }
Пример #4
0
        public void BuildBox(NetworkClient client, short x, short y, short z, short x2, short y2, short z2, Block material, Block replaceMaterial, bool hollow, short priority, bool undo, bool physics)
        {
            if (x > x2) {
                var temp = x;
                x = x2;
                x2 = temp;
            }
            if (y > y2) {
                var temp = y;
                y = y2;
                y2 = temp;
            }
            if (z > z2) {
                var temp = z;
                z = z2;
                z2 = temp;
            }

            for (var ix = x; ix < x2 + 1; ix++) {
                for (var iy = y; iy < y2 + 1; iy++) {
                    for (var iz = z; iz < z2 + 1; iz++) {
                        if (replaceMaterial.Id != 99 && replaceMaterial != GetBlock(ix, iy, iz))
                            continue;

                        var item = new BlockQueueItem {
                            Last = GetBlock(ix, iy, iz),
                            Map = this,
                            Material = material,
                            Physics = physics,
                            PlayerId = client.CS.Id,
                            Priority = priority,
                            Undo = undo,
                            X = ix,
                            Y = iy,
                            Z = iz,
                        };

                        if (ix == x || ix == x2 || iy == y || iy == y2 || iz == z || iz == z2)
                            ActionQueue.Enqueue(item);
                        else if (hollow == false)
                            ActionQueue.Enqueue(item);
                    }
                }
            }
        }