Ejemplo n.º 1
0
        static void MarkHandler( Player player, Command cmd )
        {
            Map map = player.WorldMap;
            int x, y, z;
            Vector3I coords;
            if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) {
                if( cmd.HasNext ) {
                    CdMark.PrintUsage( player );
                    return;
                }
                coords = new Vector3I( x, y, z );
            } else {
                coords = player.Position.ToBlockCoords();
            }
            coords.X = Math.Min( map.Width - 1, Math.Max( 0, coords.X ) );
            coords.Y = Math.Min( map.Length - 1, Math.Max( 0, coords.Y ) );
            coords.Z = Math.Min(map.Height - 1, Math.Max(0, coords.Z));

            if (player.SelectionMarksExpected > 0)
            {
                player.SelectionAddMark(coords, true);
            }
            else if(player.markSet > 0)
            {
                player.selectedMarks.Add(coords);
                player.SelectMarks();
            }
            else
            {
                player.MessageNow("Cannot mark - no selection in progress.");
            }
        }
Ejemplo n.º 2
0
        static void HighlightHandler(Player player, Command cmd)
        {
            string option = cmd.Next();
            if (String.IsNullOrEmpty(option))
            {
                CdHighlight.PrintUsage(player);
                return;
            }

            switch (option.ToLower())
            {
                case "create":
                case "new":
                case "add":
                    string name = cmd.Next();
                    if (String.IsNullOrEmpty(name))
                    {
                        player.Message("Usage is /Highlight create [highlight name]");
                        return;
                    }

                    if (Server.Highlights.Keys.Contains(name))
                    {
                        player.Message("A highlight with that name already exists!");
                        return;
                    }
                    System.Drawing.Color systemColor;

                    string color = cmd.Next();
                    if (String.IsNullOrEmpty(color))
                    {
                        player.Message("Usage is /Highlight create [highlight name] [color or #htmlcolor] [Percent Opaque]");
                        return;
                    }

                    if (color.Contains('#'))
                    {
                        try
                        {
                            systemColor = System.Drawing.ColorTranslator.FromHtml(color);
                        }
                        catch
                        {
                            player.Message("Unrecognized color! Please use a valid color name or html color code.");
                            return;
                        }
                    }
                    else
                    {
                        try
                        {
                            systemColor = System.Drawing.Color.FromName(color);
                        }
                        catch
                        {
                            player.Message("Unrecognized color! Please use a valid color name or html color code.");
                            return;
                        }
                    }

                    string opacity = cmd.Next();
                    int percentOpacity;
                    if (String.IsNullOrEmpty(opacity))
                    {
                        player.Message("Usage is /Highlight create [highlight name] [color or #htmlcolor] [Percent Opaque]");
                        return;
                    }

                    if (!Int32.TryParse(opacity, out percentOpacity))
                    {
                        player.Message("Percent opacity must be from 0-100, where 0 would be transparent, and 100 would be completely opaque.");
                        return;
                    }

                    player.highlightName = name;
                    player.cmd = cmd.Name;
                    player.color = systemColor;
                    player.percentOpacity = percentOpacity;
                    player.SelectMarks();
                    break;
                case "remove":
                case "delete":
                    string targetHighlight = cmd.Next();
                    if (String.IsNullOrEmpty(targetHighlight))
                    {
                        CdHighlight.PrintUsage(player);
                            return;
                    }
                    if(!Server.Highlights.Keys.Contains(targetHighlight))
                    {
                        player.Message("That highlight zone was not found! Please make sure you spelled it correctly!");
                        return;
                    }

                    Tuple<int, Vector3I, Vector3I, System.Drawing.Color, int> ID;
                    Server.Highlights.TryGetValue(targetHighlight, out ID);

                    player.World.Players.Send(PacketWriter.RemoveSelectionCuboid((byte)ID.Item1));

                    break;
                case "list":
                case "show":
                    string worldName = cmd.Next();
                    if (String.IsNullOrEmpty(worldName))
                    {
                        CdHighlight.PrintUsage(player);
                        return;
                    }

                    if (worldName == "all")
                    {
                        player.Message("_Listing all the highlights on {0}_", ConfigKey.ServerName.GetString());
                        foreach (string s in Server.Highlights.Keys)
                        {
                            player.Message(s);
                        }
                    }
                    else
                    {
                        World targetWorld = WorldManager.FindWorldOrPrintMatches(player, worldName);
                        if (targetWorld == null)
                        {
                            return;
                        }

                        player.Message("_Listing all highlights on {0}_", targetWorld.Name);
                        foreach (string s in targetWorld.Highlights.Keys)
                        {
                            player.Message(s);
                        }
                    }
                    break;
                case "clear":
                case "empty":
                    string worldTarget = cmd.Next();
                    if (String.IsNullOrEmpty(worldTarget))
                    {
                        CdHighlight.PrintUsage(player);
                        return;
                    }

                    if (worldTarget == "all")
                    {
                        player.Message("_Removing all highlights {0}_", ConfigKey.ServerName.GetString());
                        foreach (Player p in Server.Players)
                        {
                            //physically remove all highlights where players are connected to specific worlds
                            if (p.World.Highlights.Count > 0)
                            {
                                foreach (var i in p.World.Highlights.Values)
                                {
                                    p.Send(PacketWriter.RemoveSelectionCuboid((byte)i.Item1));
                                }
                            }
                        }

                        //remove all traces of highlights on each world
                        var worldWithHighlights = from w in WorldManager.Worlds
                                                  where w.Highlights.Count > 0
                                                  select w;

                        foreach (World world in worldWithHighlights)
                        {
                            world.Highlights.Clear();
                        }

                        //remove all traces of highlights on the server
                        Server.Highlights.Clear();
                    }
                    else
                    {
                        World targetWorld = WorldManager.FindWorldOrPrintMatches(player, worldTarget);
                        if (targetWorld == null)
                        {
                            return;
                        }

                        player.Message("_Removing all highlights on {0}_", targetWorld.Name);
                        foreach (Player p  in targetWorld.Players)
                        {
                            foreach (var i in targetWorld.Highlights.Values)
                            {
                                p.Send(PacketWriter.RemoveSelectionCuboid((byte)i.Item1));
                            }
                        }

                        targetWorld.Highlights.Clear();
                    }
                    break;
                default:
                    CdHighlight.PrintUsage(player);
                    break;
            }
        }