Ejemplo n.º 1
0
        public override void Process()
        {
            //todo: use Chunk.RecalcHeightAt(int _x, int _yMaxStart, int _z)
            //todo: allow /y=-1 too be used to offset the insert when using player locs to allow sub areas to be accessed without underground clipping
            //      /y=terrain to set the bottom y co-ord to the lowest non terrain block -1
            //todo: apply a custom placeholder mapping to a block value in the area

            //todo: refactor to use CmdArea and tasks

            var world = GameManager.Instance.World;

            if (world == null)
            {
                SendOutput("World not loaded");

                return;
            }

            var    p1 = new Vector3i(int.MinValue, 0, int.MinValue);
            var    p2 = new Vector3i(int.MinValue, 0, int.MinValue);
            string blockname;
            string blockname2 = null;

            //get loc and player current pos
            EntityPlayer sender  = null;
            string       steamId = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                steamId = SenderInfo.RemoteClientInfo.ownerId;
                sender  = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                if (sender != null)
                {
                    p2 = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
            }

            if (Options.ContainsKey("undo"))
            {
                UndoInsert(sender);

                return;
            }

            switch (Params.Count)
            {
            case 2:
            case 3:
                if (steamId != null)
                {
                    p1 = BCLocation.GetPos(steamId);
                    if (p1.x == int.MinValue)
                    {
                        SendOutput("No location stored. Use bc-loc to store a location.");

                        return;
                    }

                    blockname = Params[1];
                    if (Params.Count == 3)
                    {
                        blockname2 = Params[2];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
                break;

            case 8:
            case 9:
                //parse params
                if (!int.TryParse(Params[1], out p1.x) || !int.TryParse(Params[2], out p1.y) || !int.TryParse(Params[3], out p1.z) || !int.TryParse(Params[4], out p2.x) || !int.TryParse(Params[5], out p2.y) || !int.TryParse(Params[6], out p2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                blockname = Params[7];
                if (Params.Count == 9)
                {
                    blockname2 = Params[8];
                }
                break;

            default:
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            var size = new Vector3i(Math.Abs(p1.x - p2.x) + 1, Math.Abs(p1.y - p2.y) + 1, Math.Abs(p1.z - p2.z) + 1);

            var p3 = new Vector3i(
                p1.x < p2.x ? p1.x : p2.x,
                p1.y < p2.y ? p1.y : p2.y,
                p1.z < p2.z ? p1.z : p2.z
                );

            //**************** GET BLOCKVALUE
            var bvNew = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var modifiedChunks = GetAffectedChunks(p3, size);

            //CREATE UNDO
            //create backup of area blocks will insert to
            if (!Options.ContainsKey("noundo"))
            {
                CreateUndo(sender, p3, size);
            }

            switch (Params[0])
            {
            case "scan":
                ScanBlocks(p3, size, bvNew, blockname);
                break;

            case "fill":
                FillBlocks(p3, size, bvNew, blockname, modifiedChunks);
                break;

            case "swap":
                SwapBlocks(p3, size, bvNew, blockname2, modifiedChunks);
                break;

            case "repair":
                RepairBlocks(p3, size, modifiedChunks);
                break;

            case "damage":
                DamageBlocks(p3, size, modifiedChunks);
                break;

            case "upgrade":
                UpgradeBlocks(p3, size, modifiedChunks);
                break;

            case "downgrade":
                DowngradeBlocks(p3, size, modifiedChunks);
                break;

            case "paint":
                SetPaint(p3, size, modifiedChunks);
                break;

            case "paintface":
                SetPaintFace(p3, size, modifiedChunks);
                break;

            case "paintstrip":
                RemovePaint(p3, size, modifiedChunks);
                break;

            case "density":
                SetDensity(p3, size, modifiedChunks);
                break;

            case "rotate":
                SetRotation(p3, size, modifiedChunks);
                break;

            default:
                SendOutput(GetHelp());
                break;
            }
        }
Ejemplo n.º 2
0
        protected override void Process()
        {
            if (!BCUtils.CheckWorld(out var world))
            {
                return;
            }

            if (Options.ContainsKey("undo"))
            {
                SendOutput("Please use the bc-undo command to undo changes");

                return;
            }

            var    pos1 = new Vector3i(int.MinValue, 0, int.MinValue);
            var    pos2 = new Vector3i(int.MinValue, 0, int.MinValue);
            string blockname;
            string blockname2 = null;

            //get loc and player current pos
            EntityPlayer sender  = null;
            string       steamId = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                steamId = SenderInfo.RemoteClientInfo.ownerId;
                sender  = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                if (sender != null)
                {
                    pos2 = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
            }

            switch (Params.Count)
            {
            case 2:
            case 3:
                if (steamId != null)
                {
                    pos1 = BCLocation.GetPos(steamId);
                    if (pos1.x == int.MinValue)
                    {
                        SendOutput("No location stored. Use bc-loc to store a location.");

                        return;
                    }

                    blockname = Params[1];
                    if (Params.Count == 3)
                    {
                        blockname2 = Params[2];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
                break;

            case 8:
            case 9:
                //parse params
                if (!int.TryParse(Params[1], out pos1.x) || !int.TryParse(Params[2], out pos1.y) || !int.TryParse(Params[3], out pos1.z) || !int.TryParse(Params[4], out pos2.x) || !int.TryParse(Params[5], out pos2.y) || !int.TryParse(Params[6], out pos2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                blockname = Params[7];
                if (Params.Count == 9)
                {
                    blockname2 = Params[8];
                }
                break;

            default:
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            var size = BCUtils.GetSize(pos1, pos2);

            var position = new Vector3i(
                pos1.x < pos2.x ? pos1.x : pos2.x,
                pos1.y < pos2.y ? pos1.y : pos2.y,
                pos1.z < pos2.z ? pos1.z : pos2.z
                );

            //**************** GET BLOCKVALUE
            var bvNew = int.TryParse(blockname, out var blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var modifiedChunks = BCUtils.GetAffectedChunks(new BCMCmdArea("Blocks")
            {
                Position = new BCMVector3(position),
                Size     = new BCMVector3(size),
                HasPos   = true,
                HasSize  = true,

                ChunkBounds = new BCMVector4
                {
                    x = World.toChunkXZ(position.x),
                    y = World.toChunkXZ(position.z),
                    z = World.toChunkXZ(position.x + size.x - 1),
                    w = World.toChunkXZ(position.z + size.z - 1)
                },
                HasChunkPos = true
            }, world);

            //CREATE UNDO
            //create backup of area blocks will insert to
            if (!Options.ContainsKey("noundo"))
            {
                BCUtils.CreateUndo(sender, position, size);
            }

            switch (Params[0])
            {
            case "scan":
                ScanBlocks(position, size, bvNew, blockname);
                break;

            case "fill":
                FillBlocks(position, size, bvNew, blockname, modifiedChunks);
                break;

            case "swap":
                SwapBlocks(position, size, bvNew, blockname2, modifiedChunks);
                break;

            case "repair":
                RepairBlocks(position, size, modifiedChunks);
                break;

            case "damage":
                DamageBlocks(position, size, modifiedChunks);
                break;

            case "upgrade":
                UpgradeBlocks(position, size, modifiedChunks);
                break;

            case "downgrade":
                DowngradeBlocks(position, size, modifiedChunks);
                break;

            case "paint":
                SetPaint(position, size, modifiedChunks);
                break;

            case "paintface":
                SetPaintFace(position, size, modifiedChunks);
                break;

            case "paintstrip":
                RemovePaint(position, size, modifiedChunks);
                break;

            case "density":
                SetDensity(position, size, modifiedChunks);
                break;

            case "rotate":
                SetRotation(position, size, modifiedChunks);
                break;

            case "meta1":
                SetMeta(1, position, size, modifiedChunks);
                break;

            case "meta2":
                SetMeta(2, position, size, modifiedChunks);
                break;

            case "meta3":
                SetMeta(3, position, size, modifiedChunks);
                break;

            default:
                SendOutput(GetHelp());
                break;
            }
        }
Ejemplo n.º 3
0
        public override void Process()
        {
            //todo: multidim blocks
            //      claim stones replaced need to be removed from persistent data.
            //      map visitor for unloaded chunks
            //todo: damage
            //todo: use Chunk.RecalcHeightAt(int _x, int _yMaxStart, int _z)

            //todo: change command to load chunks and offload the setblock calls to a subthread that waits for all chunks to load
            //      limit size to 512 x 512
            //      allow /y=-1 too be used to offset the insert when using player locs to allow sub areas to be accessed without underground clipping
            //      /y=terrain to set the bottom y co-ord to the lowest non terrain block -1

            //todo: apply a custom placeholder mapping to a block value in the area

            var world = GameManager.Instance.World;

            if (world == null)
            {
                SendOutput("World not loaded");

                return;
            }

            var    p1 = new Vector3i(int.MinValue, 0, int.MinValue);
            var    p2 = new Vector3i(int.MinValue, 0, int.MinValue);
            string blockname;
            string blockname2 = null;
            int    blockId;

            //get loc and player current pos
            EntityPlayer sender  = null;
            string       steamId = null;

            if (SenderInfo.RemoteClientInfo != null)
            {
                steamId = SenderInfo.RemoteClientInfo.ownerId;
                sender  = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                if (sender != null)
                {
                    p2 = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
            }

            if (Options.ContainsKey("undo"))
            {
                UndoInsert(sender);

                return;
            }

            switch (Params.Count)
            {
            case 1:
            case 2:
                if (steamId != null)
                {
                    p1 = BCLocation.GetPos(steamId);
                    if (p1.x == int.MinValue)
                    {
                        SendOutput("No location stored. Use bc-loc to store a location.");

                        return;
                    }

                    blockname = Params[0];
                    if (Params.Count == 2)
                    {
                        blockname2 = Params[1];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }
                break;

            case 7:
            case 8:
                //parse params
                if (!int.TryParse(Params[0], out p1.x) || !int.TryParse(Params[1], out p1.y) || !int.TryParse(Params[2], out p1.z) || !int.TryParse(Params[3], out p2.x) || !int.TryParse(Params[4], out p2.y) || !int.TryParse(Params[5], out p2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                blockname = Params[6];
                if (Params.Count == 8)
                {
                    blockname2 = Params[7];
                }
                break;

            default:
                //todo: make a helper method for below output SendHelp(Enum.InvalidParamCount)
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            var size = new Vector3i(Math.Abs(p1.x - p2.x) + 1, Math.Abs(p1.y - p2.y) + 1, Math.Abs(p1.z - p2.z) + 1);

            var p3 = new Vector3i(
                p1.x < p2.x ? p1.x : p2.x,
                p1.y < p2.y ? p1.y : p2.y,
                p1.z < p2.z ? p1.z : p2.z
                );

            //**************** GET BLOCKVALUE
            var bvNew = int.TryParse(blockname, out blockId) ? Block.GetBlockValue(blockId) : Block.GetBlockValue(blockname);

            var modifiedChunks = GetAffectedChunks(p3, size);

            //CREATE UNDO
            //create backup of area prefab will insert to
            if (!Options.ContainsKey("noundo"))
            {
                //todo: use BlockTools.CopyIntoStorage to get prefab, then save to cache
                CreateUndo(sender, p3, size);
            }

            if (Options.ContainsKey("swap"))
            {
                SwapBlocks(p3, size, bvNew, blockname2, modifiedChunks);
            }
            else if (Options.ContainsKey("chown"))
            {
            }
            else if (Options.ContainsKey("smooth"))
            {
                //options: randomise, smooth, default
            }
            else if (Options.ContainsKey("scan"))
            {
                ScanBlocks(size, p3, bvNew, blockname);
            }
            else
            {
                FillBlocks(p3, size, bvNew, blockname, modifiedChunks);
            }
        }
Ejemplo n.º 4
0
        public override void Process()
        {
            var world = GameManager.Instance.World;

            if (world == null)
            {
                return;
            }

            var    p1       = new Vector3i(int.MinValue, 0, int.MinValue);
            var    p2       = new Vector3i(int.MinValue, 0, int.MinValue);
            string filename = null;

            switch (Params.Count)
            {
            case 1:
                //get loc and player current pos
                if (SenderInfo.RemoteClientInfo != null)
                {
                    if (!world.Entities.dict.ContainsKey(SenderInfo.RemoteClientInfo.entityId))
                    {
                        return;
                    }

                    var      sender = world.Entities.dict[SenderInfo.RemoteClientInfo.entityId] as EntityPlayer;
                    Vector3i currentPos;
                    if (sender != null)
                    {
                        currentPos = new Vector3i((int)Math.Floor(sender.serverPos.x / 32f), (int)Math.Floor(sender.serverPos.y / 32f), (int)Math.Floor(sender.serverPos.z / 32f));
                    }
                    else
                    {
                        SendOutput("Error: unable to get player location");

                        return;
                    }

                    var steamId = SenderInfo.RemoteClientInfo.ownerId;
                    if (steamId != null)
                    {
                        p1 = BCLocation.GetPos(steamId);
                        if (p1.x == int.MinValue)
                        {
                            SendOutput("No location stored. Use bc-loc to store a location.");

                            return;
                        }
                        p2 = currentPos;

                        filename = Params[0];
                    }
                }
                else
                {
                    SendOutput("Error: unable to get player location");

                    return;
                }



                break;

            case 7:
                //parse params
                if (!int.TryParse(Params[0], out p1.x) || !int.TryParse(Params[1], out p1.y) || !int.TryParse(Params[2], out p1.z) || !int.TryParse(Params[3], out p2.x) || !int.TryParse(Params[4], out p2.y) || !int.TryParse(Params[5], out p2.z))
                {
                    SendOutput("Error: unable to parse coordinates");

                    return;
                }
                filename = Params[6];

                break;

            default:
                SendOutput("Error: Incorrect command format.");
                SendOutput(GetHelp());

                return;
            }

            if (filename == null)
            {
                SendOutput("Error: Prefab filename was null.");
            }
            else
            {
                var prefab = new Prefab();
                var p0     = prefab.CopyFromWorld(world, p1, p2);
                //_prefab.CopyFromWorldWithEntities();

                prefab.filename       = filename;
                prefab.bCopyAirBlocks = true;
                prefab.addAllChildBlocks(); //credit: DJKRose
                //todo: lock doors etc?

                //todo: parse additional config from options

                var dir = "Data/Prefabs";
                if (Options.ContainsKey("backup"))
                {
                    dir = "Data/Prefabs/Backup";
                }
                SendOutput(prefab.Save(dir, prefab.filename)
          ? $"Prefab {prefab.filename} exported @ {p0.x} {p0.y} {p0.z}, size={prefab.size.x} {prefab.size.y} {prefab.size.z}"
          : $"Error: Prefab {prefab.filename} failed to save.");
            }
        }