Draw operation that creates a simple cuboid.
Inheritance: DrawOperation
Esempio n. 1
0
        static void ReplaceHandlerInternal( IBrush factory, Player player, CommandReader cmd ) {
            CuboidDrawOperation op = new CuboidDrawOperation( player );
            IBrushInstance brush = factory.MakeInstance( player, cmd, op );
            if( brush == null ) return;
            op.Brush = brush;

            player.SelectionStart( 2, DrawOperationCallback, op, Permission.Draw );
            player.MessageNow( "{0}: Click or &H/Mark&S 2 blocks.",
                               op.Brush.InstanceDescription );
        }
Esempio n. 2
0
        public void Remove(Player requester)
        {
            NormalBrush brush = new NormalBrush(Block.Air, Block.Air);
            DrawOperation removeOperation = new CuboidDrawOperation(requester);
            removeOperation.AnnounceCompletion = false;
            removeOperation.Brush = brush;
            removeOperation.Context = BlockChangeContext.Portal;

            if (this.AffectedBlocks == null)
            {
                this.AffectedBlocks = new Vector3I[2];
                this.AffectedBlocks[0] = new Vector3I(Range.Xmin, Range.Ymin, Range.Zmin);
                this.AffectedBlocks[1] = new Vector3I(Range.Xmax, Range.Ymax, Range.Zmax);
            }

            if (!removeOperation.Prepare(this.AffectedBlocks))
            {
                throw new PortalException("Unable to remove portal.");
            }

            removeOperation.Begin();

            lock (requester.World.Portals.SyncRoot)
            {
                requester.World.Portals.Remove(this);
            }

            PortalDB.Save();
        }
Esempio n. 3
0
        private static void PortalH(Player player, Command command)
        {
            try
            {
                String option = command.Next();

                if (option == null)
                {
                    CdPortal.PrintUsage(player);
                }
                else if (option.ToLower().Equals("create"))
                {
                    if (player.Can(Permission.ManagePortal))
                    {
                        string world = command.Next();

                        if (world != null && WorldManager.FindWorldExact(world) != null)
                        {
                            DrawOperation operation = new CuboidDrawOperation(player);
                            NormalBrush brush = new NormalBrush(Block.Water, Block.Water);

                            string blockTypeOrName = command.Next();

                            if (blockTypeOrName != null && blockTypeOrName.ToLower().Equals("lava"))
                            {
                                brush = new NormalBrush(Block.Lava, Block.Lava);
                            }
                            else if (blockTypeOrName != null && !blockTypeOrName.ToLower().Equals("water"))
                            {
                                player.Message("Invalid block, choose between water or lava.");
                                return;
                            }

                            string portalName = command.Next();

                            if (portalName == null)
                            {
                                player.PortalName = null;
                            }
                            else
                            {
                                if (!Portal.DoesNameExist(player.World, portalName))
                                {
                                    player.PortalName = portalName;
                                }
                                else
                                {
                                    player.Message("A portal with name {0} already exists in this world.", portalName);
                                    return;
                                }
                            }

                            operation.Brush = brush;
                            player.PortalWorld = world;

                            player.SelectionStart(operation.ExpectedMarks, PortalCreateCallback, operation, Permission.Draw);
                            player.Message("Click {0} blocks or use &H/Mark&S to mark the area of the portal.", operation.ExpectedMarks);
                        }
                        else
                        {
                            if (world == null)
                            {
                                player.Message("No world specified.");
                            }
                            else
                            {
                                player.MessageNoWorld(world);
                            }
                        }
                    }
                    else
                    {
                        player.MessageNoAccess(Permission.ManagePortal);
                    }
                }
                else if (option.ToLower().Equals("remove"))
                {
                    if (player.Can(Permission.ManagePortal))
                    {
                        string portalName = command.Next();

                        if (portalName == null)
                        {
                            player.Message("No portal name specified.");
                        }
                        else
                        {
                            if (player.World.Portals != null && player.World.Portals.Count > 0)
                            {
                                bool found = false;
                                Portal portalFound = null;

                                lock (player.World.Portals.SyncRoot)
                                {
                                    foreach (Portal portal in player.World.Portals)
                                    {
                                        if (portal.Name.Equals(portalName))
                                        {
                                            portalFound = portal;
                                            found = true;
                                            break;
                                        }
                                    }

                                    if (!found)
                                    {
                                        player.Message("Could not find portal by name {0}.", portalName);
                                    }
                                    else
                                    {
                                        portalFound.Remove(player);
                                        player.Message("Portal was removed.");
                                    }
                                }
                            }
                            else
                            {
                                player.Message("Could not find portal as this world doesn't contain a portal.");
                            }
                        }
                    }
                    else
                    {
                        player.MessageNoAccess(Permission.ManagePortal);
                    }
                }
                else if (option.ToLower().Equals("info"))
                {
                    string portalName = command.Next();

                    if (portalName == null)
                    {
                        player.Message("No portal name specified.");
                    }
                    else
                    {
                        if (player.World.Portals != null && player.World.Portals.Count > 0)
                        {
                            bool found = false;

                            lock (player.World.Portals.SyncRoot)
                            {
                                foreach (Portal portal in player.World.Portals)
                                {
                                    if (portal.Name.Equals(portalName))
                                    {
                                        World portalWorld = WorldManager.FindWorldExact(portal.World);
                                        player.Message("Portal {0}&S was created by {1}&S at {2} and teleports to world {3}&S.",
                                            portal.Name, PlayerDB.FindPlayerInfoExact(portal.Creator).ClassyName, portal.Created, portalWorld.ClassyName);
                                        found = true;
                                    }
                                }
                            }

                            if (!found)
                            {
                                player.Message("Could not find portal by name {0}.", portalName);
                            }
                        }
                        else
                        {
                            player.Message("Could not find portal as this world doesn't contain a portal.");
                        }
                    }
                }
                else if (option.ToLower().Equals("list"))
                {
                    if (player.World.Portals == null || player.World.Portals.Count == 0)
                    {
                        player.Message("There are no portals in {0}&S.", player.World.ClassyName);
                    }
                    else
                    {
                        String[] portalNames = new String[player.World.Portals.Count];
                        StringBuilder output = new StringBuilder("There are " + player.World.Portals.Count + " portals in " + player.World.ClassyName + "&S: ");

                        for (int i = 0; i < player.World.Portals.Count; i++)
                        {
                            portalNames[i] = ((Portal)player.World.Portals[i]).Name;
                        }

                        output.Append(portalNames.JoinToString(", "));

                        player.Message(output.ToString());
                    }
                }
                else if (option.ToLower().Equals("enable"))
                {
                    player.PortalsEnabled = true;
                    player.Message("You enabled the use of portals.");
                }
                else if (option.ToLower().Equals("disable"))
                {
                    player.PortalsEnabled = false;
                    player.Message("You disabled the use of portals, type /portal enable to re-enable portals.");
                }
                else
                {
                    CdPortal.PrintUsage(player);
                }
            }
            catch (PortalException ex)
            {
                player.Message(ex.Message);
                Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex);
            }
            catch (Exception ex)
            {
                player.Message("Unexpected error: " + ex);
                Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex);
            }
        }
Esempio n. 4
0
        static void ReplaceAllHandlerInternal([NotNull] IBrushFactory factory, [NotNull] Player player,
                                           [NotNull] CommandReader cmd) {
            CuboidDrawOperation op = new CuboidDrawOperation(player);
            IBrush brush = factory.MakeBrush(player, cmd);
            if (brush == null)
                return;
            op.Brush = brush;

            player.SelectionStart(2, DrawOperationCallback, op, Permission.Draw);
            Map map = player.WorldMap;
            Vector3I coordsMin;
            Vector3I coordsMax;
            coordsMin.X = 0;
            coordsMin.Y = 0;
            coordsMin.Z = 0;
            coordsMax.X = map.Width - 1;
            coordsMax.Y = map.Length - 1;
            coordsMax.Z = map.Height - 1;
            player.SelectionResetMarks();
            player.SelectionAddMark(coordsMin, false, false);
            player.SelectionAddMark(coordsMax, true, true);
        }
Esempio n. 5
0
        static void ReplaceHandlerInternal([NotNull] IBrushFactory factory, [NotNull] Player player,
                                           [NotNull] CommandReader cmd) {
            if (factory == null)
                throw new ArgumentNullException("factory");
            if (player == null)
                throw new ArgumentNullException("player");
            if (cmd == null)
                throw new ArgumentNullException("cmd");

            CuboidDrawOperation op = new CuboidDrawOperation(player);

            IBrush brush = factory.MakeBrush(player, cmd);
            if (brush == null)
                return;

            op.Brush = brush;

            player.SelectionStart(2, DrawOperationCallback, op, Permission.Draw);
            player.Message("{0}: Click or &H/Mark&S 2 blocks.", op.Brush.Description);
        }
Esempio n. 6
0
        private static void PortalH(Player player, CommandReader cmd) {
            try {
                string option = cmd.Next();
                if (string.IsNullOrEmpty(option)) {
                    CdPortal.PrintUsage(player);
                    return;
                }
                switch (option.ToLower()) {
                    case "create":
                    case "add":
                        if (player.Can(Permission.CreatePortals)) {
                            string addWorld = cmd.Next();
                            if (!string.IsNullOrEmpty(addWorld) && WorldManager.FindWorldExact(addWorld) != null) {
                                DrawOperation operation = new CuboidDrawOperation(player);
                                NormalBrush brush = new NormalBrush(Block.Water, Block.Water);

                                string blockTypeOrName = cmd.Next();
                                Block pblock;
                                if (blockTypeOrName != null && Map.GetBlockByName(blockTypeOrName, false, out pblock)) {
                                    if ((!validPBlocks.Contains(pblock) && pblock <= Block.StoneBrick) || (pblock == Block.Air && player.Info.Rank != RankManager.HighestRank)) {
                                        player.Message("Invalid block, choose a non-solid block");
                                        return;
                                    } else {
                                        brush = new NormalBrush(pblock, pblock);
                                    }
                                }
                                string addPortalName = cmd.Next();
                                if (string.IsNullOrEmpty(addPortalName)) {
                                    player.PortalName = null;
                                } else {
                                    if (!Portal.DoesNameExist(player.World, addPortalName)) {
                                        player.PortalName = addPortalName;
                                    } else {
                                        player.Message("A portal with name {0} already exists in this world.", addPortalName);
                                        return;
                                    }
                                }
                                World tpWorld = WorldManager.FindWorldExact(addWorld);
                                if (cmd.HasNext) {
                                    int x, y, z, rot = player.Position.R, lot = player.Position.L;
                                    if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
                                        if (cmd.HasNext && cmd.HasNext) {
                                            if (cmd.NextInt(out rot) && cmd.NextInt(out lot)) {
                                                if (rot > 255 || rot < 0) {
                                                    player.Message("R must be inbetween 0 and 255. Set to player R");
                                                    rot = player.Position.R;
                                                }
                                                if (lot > 255 || lot < 0) {
                                                    player.Message("L must be inbetween 0 and 255. Set to player L");
                                                    lot = player.Position.L;
                                                }
                                            }
                                        }
                                        if (x < 1 || x >= 1024 || y < 1 || y >= 1024 || z < 1 || z >= 1024) {
                                            player.Message("Coordinates are outside the valid range!");
                                            return;
                                        } else {
                                            player.PortalTPPos = new Position((short)(x * 32), (short)(y * 32), (short)(z * 32), (byte)rot, (byte)lot);
                                        }
                                    } else {
                                        player.PortalTPPos = tpWorld.map == null ? new Position(0, 0, 0) : tpWorld.map.Spawn;
                                    }
                                } else {
                                    player.PortalTPPos = tpWorld.map == null ? new Position(0, 0, 0) : tpWorld.map.Spawn;
                                }
                                operation.Brush = brush;
                                player.PortalWorld = addWorld;
                                player.SelectionStart(operation.ExpectedMarks, PortalCreateCallback, operation, Permission.CreatePortals);
                                player.Message("Click {0} blocks or use &H/Mark&S to mark the area of the portal.", operation.ExpectedMarks);
                            } else {
                                if (string.IsNullOrEmpty(addWorld)) {
                                    player.Message("No world specified.");
                                } else {
                                    player.MessageNoWorld(addWorld);
                                }
                            }
                        } else {
                            player.MessageNoAccess(Permission.CreatePortals);
                        }
                        break;
                    case "remove":
                    case "delete":
                        if (player.Can(Permission.CreatePortals)) {
                            string remPortalName = cmd.Next();
                            string remWString = cmd.Next();
                            World remWorld = player.World;
                            if (!string.IsNullOrEmpty(remWString)) {
                                remWorld = WorldManager.FindWorldOrPrintMatches(player, remWString);
                            }
                            if (remWorld == null) {
                                return;
                            }
                            if (string.IsNullOrEmpty(remPortalName)) {
                                player.Message("No portal name specified.");
                            } else {
                                if (remWorld.Portals != null && remWorld.Portals.Count > 0) {
                                    bool found = false;
                                    Portal portalFound = null;
                                    lock (remWorld.Portals.SyncRoot) {
                                        foreach (Portal portal in remWorld.Portals) {
                                            if (portal.Name.ToLower().Equals(remPortalName.ToLower())) {
                                                portalFound = portal;
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found) {
                                            player.Message("Could not find portal by name {0}.", remPortalName);
                                        } else {
                                            portalFound.Remove(player, remWorld);
                                            player.Message("Portal was removed.");
                                        }
                                    }
                                } else {
                                    player.Message("Could not find portal as this world doesn't contain a portal.");
                                }
                            }
                        } else {
                            player.MessageNoAccess(Permission.CreatePortals);
                        }
                        break;
                    case "info":
                    case "i":
                        string iPortalName = cmd.Next();
                        string iWString = cmd.Next();
                        World iWorld = player.World;
                        if (!string.IsNullOrEmpty(iWString)) {
                            iWorld = WorldManager.FindWorldOrPrintMatches(player, iWString);
                        }
                        if (iWorld == null) {
                            return;
                        }
                        if (string.IsNullOrEmpty(iPortalName)) {
                            player.Message("No portal name specified.");
                        } else {
                            if (iWorld.Portals != null && iWorld.Portals.Count > 0) {
                                bool found = false;

                                lock (iWorld.Portals.SyncRoot) {
                                    foreach (Portal portal in iWorld.Portals) {
                                        if (portal.Name.ToLower().Equals(iPortalName.ToLower())) {
                                            World portalWorld = WorldManager.FindWorldExact(portal.World);
                                            player.Message("Portal {0}&S was created by {1}&S at {2} and teleports to world {3} at {4}&S.",
                                                portal.Name, PlayerDB.FindPlayerInfoExact(portal.Creator).ClassyName, portal.Created, portalWorld.ClassyName, portal.position().ToString());
                                            found = true;
                                        }
                                    }
                                }
                                if (!found) {
                                    player.Message("Could not find portal by name {0}.", iPortalName);
                                }
                            } else {
                                player.Message("Could not find portal as this world doesn't contain a portal.");
                            }
                        }
                        break;
                    case "list":
                    case "l":
                        string lWString = cmd.Next();
                        World lWorld = player.World;
                        if (!string.IsNullOrEmpty(lWString)) {
                            lWorld = WorldManager.FindWorldOrPrintMatches(player, lWString);
                        }
                        if (lWorld == null) {
                            return;
                        }
                        if (lWorld.Portals == null || lWorld.Portals.Count == 0) {
                            player.Message("There are no portals in {0}&S.", lWorld.ClassyName);
                        } else {
                            string[] portalNames = new string[lWorld.Portals.Count];
                            StringBuilder output = new StringBuilder("There are " + lWorld.Portals.Count + " portals in " + lWorld.ClassyName + "&S: ");
                            for (int i = 0; i < lWorld.Portals.Count; i++) {
                                portalNames[i] = ((Portal)lWorld.Portals[i]).Name;
                            }
                            output.Append(portalNames.JoinToString(", "));
                            player.Message(output.ToString());
                        }
                        break;
                    case "enable":
                    case "on":
                        player.PortalsEnabled = true;
                        player.Message("You enabled the use of portals.");
                        break;
                    case "disable":
                    case "off":
                        player.PortalsEnabled = false;
                        player.Message("You disabled the use of portals, type /portal enable to re-enable portals.");
                        break;
                    default:
                        CdPortal.PrintUsage(player);
                        break;
                }
            } catch (PortalException ex) {
                player.Message(ex.Message);
                Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex);
            } catch (Exception ex) {
                player.Message("Unexpected error: " + ex);
                Logger.Log(LogType.Error, "WorldCommands.PortalH: " + ex);
            }
        }