コード例 #1
0
        public override MapGeneratorParameters CreateParameters(Player player, CommandReader cmd)
        {
            string themeName = cmd.Next();

            if (themeName == null)
            {
                return(CreateDefaultParameters());
            }

            MapGenTheme theme;
            RealisticMapGenTerrainType terrainType;

            string templateName = cmd.Next();

            if (templateName == null)
            {
                player.Message("SetGen: Realistic MapGen requires both a theme and a terrainType. " +
                               "See &H/Help SetGen Realistic&S or check wiki.fCraft.net for details");
                return(null);
            }

            // parse theme
            bool swapThemeAndTemplate;

            if (EnumUtil.TryParse(themeName, out theme, true))
            {
                swapThemeAndTemplate = false;
            }
            else if (EnumUtil.TryParse(templateName, out theme, true))
            {
                swapThemeAndTemplate = true;
            }
            else
            {
                player.Message("SetGen: Unrecognized theme \"{0}\". Available themes are: {1}",
                               themeName,
                               Enum.GetNames(typeof(MapGenTheme)).JoinToString());
                return(null);
            }

            // parse terrainType
            if (swapThemeAndTemplate && !EnumUtil.TryParse(themeName, out terrainType, true))
            {
                MessageTemplateList(themeName, player);
                return(null);
            }
            else if (!EnumUtil.TryParse(templateName, out terrainType, true))
            {
                MessageTemplateList(templateName, player);
                return(null);
            }

            // TODO: optional parameters for preset customization
            return(CreateParameters(terrainType, theme));
        }
コード例 #2
0
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string urlstr = cmd.Next();

            if (!WorldCommands.parseUrl(ref urlstr, Player))
            {
                return(false);
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(urlstr, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }

            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                Palette = BlockPalette.FindPalette(paletteName);
                if (Palette == null)
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name));
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.FindPalette("Light");
            }

            // All set
            return(true);
        }
コード例 #3
0
        static void BrushHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            string brushName = cmd.Next();

            if (brushName == null)
            {
                player.Message("Brush: {0}", player.BrushDescription);
            }
            else
            {
                IBrushFactory brushFactory = GetBrushFactory(brushName);
                if (brushFactory == null)
                {
                    player.Message("Unrecognized brush \"{0}\"", brushName);
                }
                else
                {
                    player.BrushSet(brushFactory);
                    if (cmd.HasNext)
                    {
                        player.ConfigureBrush(cmd);
                    }
                    player.Message("Brush set to {0}", player.BrushDescription);
                }
            }
        }
コード例 #4
0
ファイル: BrushManager.cs プロジェクト: TheDireMaster/fCraft
        static void BrushHandler(Player player, CommandReader cmd)
        {
            string brushName = cmd.Next();

            if (brushName == null)
            {
                player.Message(player.Brush.Description);
            }
            else
            {
                IBrushFactory brushFactory = GetBrushFactory(brushName);
                if (brushFactory == null)
                {
                    player.Message("Unrecognized brush \"{0}\"", brushName);
                }
                else
                {
                    IBrush newBrush = brushFactory.MakeBrush(player, cmd);
                    if (newBrush != null)
                    {
                        player.Brush = newBrush;
                        player.Message("Brush set to {0}", player.Brush.Description);
                    }
                }
            }
        }
コード例 #5
0
ファイル: ReplaceBrushBrush.cs プロジェクト: fragmer/fCraft
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            if( !cmd.HasNext ) {
                player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                return null;
            }

            Block block;
            if( !cmd.NextBlock( player, false, out block ) ) return null;

            string brushName = cmd.Next();
            if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
                player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                return null;
            }
            IBrushFactory brushFactory = BrushManager.GetBrushFactory( brushName );

            if( brushFactory == null ) {
                player.Message( "Unrecognized brush \"{0}\"", brushName );
                return null;
            }

            IBrush newBrush = brushFactory.MakeBrush( player, cmd );
            if( newBrush == null ) {
                return null;
            }

            return new ReplaceBrushBrush( block, newBrush );
        }
コード例 #6
0
        public override bool ReadParams(CommandReader cmd) {
            // get image URL
            string urlString = cmd.Next();
            if (string.IsNullOrWhiteSpace(urlString)) {
                return false;
            }

            if (urlString.StartsWith("http://imgur.com/")) {
                urlString = "http://i.imgur.com/" + urlString.Substring("http://imgur.com/".Length) + ".png";
            }
            // if string starts with "++", load image from imgur
            if (urlString.StartsWith("++")) {
                urlString = "http://i.imgur.com/" + urlString.Substring(2) + ".png";
            }
            // prepend the protocol, if needed (assume http)
            if (!urlString.ToLower().StartsWith("http://") && !urlString.ToLower().StartsWith("https://")) {
                urlString = "http://" + urlString;
            }
            if (!urlString.ToLower().StartsWith("http://i.imgur.com")) {
                Player.Message("For safety reasons we only accept images uploaded to &9http://imgur.com/ &sSorry for this inconvenience.");
                return false;
            }
            if (!urlString.ToLower().EndsWith(".png") && !urlString.ToLower().EndsWith(".jpg") && !urlString.ToLower().EndsWith(".gif")) {
                Player.Message("URL must be a link to an image");
                return false;
            }

            // validate the image URL
            Uri url;
            if (!Uri.TryCreate(urlString, UriKind.Absolute, out url)) {
                Player.Message("DrawImage: Invalid URL given.");
                return false;
            } else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps)) {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return false;
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();
            if (paletteName != null) {
                StandardBlockPalette paletteType;
                if (EnumUtil.TryParse(paletteName, out paletteType, true)) {
                    Palette = BlockPalette.GetPalette(paletteType);
                } else {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName,
                                   Enum.GetNames(typeof(StandardBlockPalette)).JoinToString());
                    return false;
                }
            } else {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.Light;
            }

            // All set
            return true;
        }
コード例 #7
0
ファイル: RealisticMapGen.cs プロジェクト: fragmer/fCraft
        public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) {
            string themeName = cmd.Next();
            if( themeName == null ) {
                return CreateDefaultParameters();
            }

            MapGenTheme theme;
            RealisticMapGenTerrainType terrainType;

            string templateName = cmd.Next();
            if( templateName == null ) {
                player.Message( "SetGen: Realistic MapGen requires both a theme and a terrainType. " +
                                "See &H/Help SetGen Realistic&S or check wiki.fCraft.net for details" );
                return null;
            }

            // parse theme
            bool swapThemeAndTemplate;
            if( EnumUtil.TryParse( themeName, out theme, true ) ) {
                swapThemeAndTemplate = false;

            } else if( EnumUtil.TryParse( templateName, out theme, true ) ) {
                swapThemeAndTemplate = true;

            } else {
                player.Message( "SetGen: Unrecognized theme \"{0}\". Available themes are: {1}",
                                themeName,
                                Enum.GetNames( typeof( MapGenTheme ) ).JoinToString() );
                return null;
            }

            // parse terrainType
            if( swapThemeAndTemplate && !EnumUtil.TryParse( themeName, out terrainType, true ) ) {
                MessageTemplateList( themeName, player );
                return null;
            } else if( !EnumUtil.TryParse( templateName, out terrainType, true ) ) {
                MessageTemplateList( templateName, player );
                return null;
            }

            // TODO: optional parameters for preset customization
            return CreateParameters( terrainType, theme );
        }
コード例 #8
0
ファイル: ReplaceBrushBrush.cs プロジェクト: mstefarov/fCraft
        public IBrushInstance MakeInstance(Player player, CommandReader cmd, DrawOperation op)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            if (cmd.HasNext)
            {
                Block block;
                if (!cmd.NextBlock(player, false, out block))
                {
                    return(null);
                }

                string brushName = cmd.Next();
                if (brushName == null || !CommandManager.IsValidCommandName(brushName))
                {
                    player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                    return(null);
                }
                IBrushFactory brushFactory = BrushManager.GetBrushFactory(brushName);

                if (brushFactory == null)
                {
                    player.Message("Unrecognized brush \"{0}\"", brushName);
                    return(null);
                }

                IBrush replacement = brushFactory.MakeBrush(player, cmd);
                if (replacement == null)
                {
                    return(null);
                }
                Block       = block;
                Replacement = replacement;
            }

            ReplacementInstance = Replacement.MakeInstance(player, cmd, op);
            if (ReplacementInstance == null)
            {
                return(null);
            }

            return(new ReplaceBrushBrush(this));
        }
コード例 #9
0
 public void Execute( string text )
 {
     CommandReader reader = new CommandReader( text );
     if( reader.TotalArgs == 0 ) {
         game.Chat.Add( "&e/client: No command name specified. See /client commands for a list of commands." );
         return;
     }
     string commandName = reader.Next();
     Command cmd = GetMatchingCommand( commandName );
     if( cmd != null ) {
         cmd.Execute( reader );
     }
 }
コード例 #10
0
 public void Execute( string text )
 {
     CommandReader reader = new CommandReader( text );
     if( reader.TotalArgs == 0 ) {
         game.Chat.Add( "&eList of client commands:" );
         PrintDefinedCommands( game );
         game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
         return;
     }
     string commandName = reader.Next();
     Command cmd = GetMatchingCommand( commandName );
     if( cmd != null ) {
         cmd.Execute( reader );
     }
 }
コード例 #11
0
ファイル: FlatMapGen.cs プロジェクト: fragmer/fCraft
 public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) {
     string themeName = cmd.Next();
     MapGeneratorParameters newParams;
     if( themeName != null ) {
         newParams = CreateParameters( themeName );
         if( newParams == null ) {
             player.Message( "SetGen: \"{0}\" is not a recognized flat theme name. Available themes are: {1}",
                             themeName, Presets.JoinToString() );
             return null;
         }
     } else {
         newParams = CreateDefaultParameters();
     }
     return newParams;
 }
コード例 #12
0
 public override void Execute( CommandReader reader )
 {
     string cmdName = reader.Next();
     if( cmdName == null ) {
         game.Chat.Add( "&e/client help: No command name specified. See /client commands for a list of commands." );
     } else {
         Command cmd = game.CommandManager.GetMatchingCommand( cmdName );
         if( cmd != null ) {
             string[] help = cmd.Help;
             for( int i = 0; i < help.Length; i++ ) {
                 game.Chat.Add( help[i] );
             }
         }
     }
 }
コード例 #13
0
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            if (!cmd.HasNext)
            {
                player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                return(null);
            }

            Block block;

            if (!cmd.NextBlock(player, false, out block))
            {
                return(null);
            }

            string brushName = cmd.Next();

            if (brushName == null || !CommandManager.IsValidCommandName(brushName))
            {
                player.Message("ReplaceBrush usage: &H/Brush rb <Block> <BrushName>");
                return(null);
            }
            IBrushFactory brushFactory = BrushManager.GetBrushFactory(brushName);

            if (brushFactory == null)
            {
                player.Message("Unrecognized brush \"{0}\"", brushName);
                return(null);
            }

            IBrush newBrush = brushFactory.MakeBrush(player, cmd);

            if (newBrush == null)
            {
                return(null);
            }

            return(new ReplaceBrushBrush(block, newBrush));
        }
コード例 #14
0
        public override void Execute( CommandReader reader )
        {
            game.UserEvents.BlockChanged -= BlockChanged;
            block = 0xFF;
            mark1 = new Vector3I( int.MaxValue );
            mark2 = new Vector3I( int.MaxValue );
            persist = false;

            if( !ParseBlock( reader ) ) return;
            string arg = reader.Next();
            if( arg != null && Utils.CaselessEquals( arg, "yes" ) )
                persist = true;

            game.Chat.Add( "&eCuboid: &fPlace or delete a block.", MessageType.ClientStatus3 );
            game.UserEvents.BlockChanged += BlockChanged;
        }
コード例 #15
0
ファイル: BrushManager.cs プロジェクト: fragmer/fCraft
 static void BrushHandler( Player player, CommandReader cmd ) {
     string brushName = cmd.Next();
     if( brushName == null ) {
         player.Message( player.Brush.Description );
     } else {
         IBrushFactory brushFactory = GetBrushFactory( brushName );
         if( brushFactory == null ) {
             player.Message( "Unrecognized brush \"{0}\"", brushName );
         } else {
             IBrush newBrush = brushFactory.MakeBrush( player, cmd );
             if( newBrush != null ) {
                 player.Brush = newBrush;
                 player.Message( "Brush set to {0}", player.Brush.Description );
             }
         }
     }
 }
コード例 #16
0
ファイル: FlatMapGen.cs プロジェクト: TheDireMaster/fCraft
        public override MapGeneratorParameters CreateParameters(Player player, CommandReader cmd)
        {
            string themeName = cmd.Next();
            MapGeneratorParameters newParams;

            if (themeName != null)
            {
                newParams = CreateParameters(themeName);
                if (newParams == null)
                {
                    player.Message("SetGen: \"{0}\" is not a recognized flat theme name. Available themes are: {1}",
                                   themeName, Presets.JoinToString());
                    return(null);
                }
            }
            else
            {
                newParams = CreateDefaultParameters();
            }
            return(newParams);
        }
コード例 #17
0
        bool ParseBlock( CommandReader reader )
        {
            string id = reader.Next();
            if( id == null ) return true;
            if( Utils.CaselessEquals( id, "yes" ) ) { persist = true; return true; }

            byte blockID = 0;
            if( !byte.TryParse( id, out blockID ) ) {
                game.Chat.Add( "&eCuboid: &c\"" + id + "\" is not a valid block id." ); return false;
            }
            if( blockID >= BlockInfo.CpeCount && game.BlockInfo.Name[blockID] == "Invalid" ) {
                game.Chat.Add( "&eCuboid: &cThere is no block with id \"" + id + "\"." ); return false;
            }
            block = blockID;
            return true;
        }
コード例 #18
0
ファイル: CloudyBrush.cs プロジェクト: fragmer/fCraft
        public IBrush MakeBrush( Player player, CommandReader cmd ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );

            List<Block> blocks = new List<Block>();
            List<int> blockRatios = new List<int>();
            bool scaleSpecified = false,
                 turbulenceSpecified = false,
                 seedSpecified = false;
            int scale = 100,
                turbulence = 100;
            UInt16 seed = CloudyBrush.NextSeed();

            while( true ) {
                int offset = cmd.Offset;
                string rawNextParam = cmd.Next();
                if( rawNextParam == null ) break;

                if( rawNextParam.EndsWith( "%" ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempScale;
                    if( !Int32.TryParse( numPart, out tempScale ) ) {
                        player.Message( "Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%)." );
                        return null;
                    }
                    if( scaleSpecified ) {
                        player.Message( "Cloudy brush: Scale has been specified twice." );
                        return null;
                    }
                    if( scale < 1 || tempScale > CloudyBrush.MaxScale ) {
                        player.Message( "Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                        scale, CloudyBrush.MaxScale );
                        return null;
                    }
                    scale = tempScale;
                    scaleSpecified = true;
                    continue;

                } else if( rawNextParam.EndsWith( "T", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    int tempTurbulence;
                    if( Int32.TryParse( numPart, out tempTurbulence ) ) {
                        if( turbulenceSpecified ) {
                            player.Message( "Cloudy brush: Turbulence has been specified twice." );
                            return null;
                        }
                        if( turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale ) {
                            player.Message( "Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                            turbulence, CloudyBrush.MaxScale );
                            return null;
                        }
                        turbulence = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }

                } else if( rawNextParam.EndsWith( "S", StringComparison.OrdinalIgnoreCase ) ) {
                    string numPart = rawNextParam.Substring( 0, rawNextParam.Length - 1 );
                    try {
                        seed = UInt16.Parse( numPart, System.Globalization.NumberStyles.HexNumber );
                        if( seedSpecified ) {
                            player.Message( "Cloudy brush: Seed has been specified twice." );
                            return null;
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int ratio;
                Block block;
                if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null;
                if( ratio < 1 || ratio > CloudyBrush.MaxRatio ) {
                    player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                    ratio, CloudyBrush.MaxRatio );
                    return null;
                }
                blocks.Add( block );
                blockRatios.Add( ratio );
            }

            CloudyBrush madeBrush;
            if( blocks.Count == 0 ) {
                madeBrush = new CloudyBrush();
            } else if( blocks.Count == 1 ) {
                madeBrush = new CloudyBrush( blocks[0], blockRatios[0] );
            } else {
                madeBrush = new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() );
            }

            madeBrush.Frequency /= ( scale / 100f );
            madeBrush.Persistence *= ( turbulence / 100f );
            madeBrush.Seed = seed;

            return madeBrush;
        }
コード例 #19
0
        private static void TrollHandler(Player player, CommandReader cmd)
        {
            string Name = cmd.Next();

            if (Name == null)
            {
                player.Message("Player not found. Please specify valid name.");
                return;
            }
            if (!Player.IsValidPlayerName(Name))
            {
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, Name, SearchOptions.Default);

            if (target == null)
            {
                return;
            }
            string options = cmd.Next();

            if (options == null)
            {
                CdTroll.PrintUsage(player);
                return;
            }
            string Message = cmd.NextAll();

            if (Message.Length < 1 && !options.CaselessEquals("leave"))
            {
                player.Message("&WError: Please enter a message for {0}.", target.ClassyName);
                return;
            }
            switch (options.ToLower())
            {
            case "pm":
                if (player.Can(Permission.UseColorCodes) && Message.Contains("%"))
                {
                    Message = Chat.ReplacePercentColorCodes(Message, false);
                }
                Server.Players.Message("&Pfrom {0}: {1}",
                                       target.Name, Message);
                break;

            case "st":
            case "staff":
                Chat.SendStaff(target, Message);
                break;

            case "i":
            case "impersonate":
            case "msg":
            case "message":
            case "m":
                Server.Message("{0}&S&F: {1}",
                               target.ClassyName, Message);
                break;

            case "leave":
            case "disconnect":
            case "gtfo":
                Server.Players.Message("&SPlayer {0}&S left the server.",
                                       target.ClassyName);
                break;

            default:
                player.Message("Invalid option. Please choose st, ac, pm, message or leave");
                break;
            }
        }
コード例 #20
0
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string urlString = cmd.Next();

            if (String.IsNullOrWhiteSpace(urlString))
            {
                return(false);
            }

            // if string starts with "++", load image from imgur
            if (urlString.StartsWith("++"))
            {
                urlString = "http://i.imgur.com/" + urlString.Substring(2);
            }

            // prepend the protocol, if needed (assume http)
            if (!urlString.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
            {
                urlString = "http://" + urlString;
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(urlString, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                StandardBlockPalette paletteType;
                if (EnumUtil.TryParse(paletteName, out paletteType, true))
                {
                    Palette = BlockPalette.GetPalette(paletteType);
                }
                else
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName,
                                   Enum.GetNames(typeof(StandardBlockPalette)).JoinToString());
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.Light;
            }

            // All set
            return(true);
        }
コード例 #21
0
 public override void Execute( CommandReader reader )
 {
     string cmdName = reader.Next();
     if( cmdName == null ) {
         game.Chat.Add( "&eList of client commands:" );
         game.CommandManager.PrintDefinedCommands( game );
         game.Chat.Add( "&eTo see a particular command's help, type /client help [cmd name]" );
     } else {
         Command cmd = game.CommandManager.GetMatchingCommand( cmdName );
         if( cmd != null ) {
             string[] help = cmd.Help;
             for( int i = 0; i < help.Length; i++ ) {
                 game.Chat.Add( help[i] );
             }
         }
     }
 }
コード例 #22
0
 public override void Execute( CommandReader reader )
 {
     string property = reader.Next();
     if( property == null ) {
         game.Chat.Add( "&e/client rendertype: &cYou didn't specify a new render type." );
     } else if( Utils.CaselessEquals( property, "legacyfast" ) ) {
         SetNewRenderType( true, true );
         game.Chat.Add( "&e/client rendertype: &fRender type is now fast legacy." );
     } else if( Utils.CaselessEquals( property, "legacy" ) ) {
         SetNewRenderType( true, false );
         game.Chat.Add( "&e/client rendertype: &fRender type is now legacy." );
     } else if( Utils.CaselessEquals( property, "normal" ) ) {
         SetNewRenderType( false, false );
         game.Chat.Add( "&e/client rendertype: &fRender type is now normal." );
     } else if( Utils.CaselessEquals( property, "normalfast" ) ) {
         SetNewRenderType( false, true );
         game.Chat.Add( "&e/client rendertype: &fRender type is now normalfast." );
     }
 }
コード例 #23
0
 public override void Execute( CommandReader reader )
 {
     string name = reader.Next();
     if( String.IsNullOrEmpty( name ) ) {
         game.Chat.Add( "&e/client model: &cYou didn't specify a model name." );
     } else {
         game.LocalPlayer.SetModel( name );
     }
 }
コード例 #24
0
 public override void Execute( CommandReader reader )
 {
     string property = reader.Next();
     if( property == null ) {
         game.Chat.Add( "&e/client info: &cYou didn't specify a property." );
     } else if( Utils.CaselessEquals( property, "pos" ) ) {
         game.Chat.Add( "Feet: " + game.LocalPlayer.Position );
         game.Chat.Add( "Eye: " + game.LocalPlayer.EyePosition );
         Vector3I p = Vector3I.Floor( game.LocalPlayer.Position );
         game.Chat.Add( game.World.GetLightHeight( p.X, p.Z ).ToString() );
     } else if( Utils.CaselessEquals( property, "target" ) ) {
         PickedPos pos = game.SelectedPos;
         if( !pos.Valid ) {
             game.Chat.Add( "Currently not targeting a block" );
         } else {
             game.Chat.Add( "Currently targeting at: " + pos.BlockPos );
             game.Chat.Add( "ID of block targeted: " + game.World.SafeGetBlock( pos.BlockPos ) );
         }
     } else if( Utils.CaselessEquals( property, "dimensions" ) ) {
         game.Chat.Add( "map width: " + game.World.Width );
         game.Chat.Add( "map height: " + game.World.Height );
         game.Chat.Add( "map length: " + game.World.Length );
     } else {
         game.Chat.Add( "&e/client info: Unrecognised property: \"&f" + property + "&e\"." );
     }
 }
コード例 #25
0
ファイル: ReplaceBrushBrush.cs プロジェクト: fragmer/fCraft
        public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation op ) {
            if( player == null ) throw new ArgumentNullException( "player" );
            if( cmd == null ) throw new ArgumentNullException( "cmd" );
            if( op == null ) throw new ArgumentNullException( "op" );

            if( cmd.HasNext ) {
                Block block;
                if( !cmd.NextBlock( player, false, out block ) ) return null;

                string brushName = cmd.Next();
                if( brushName == null || !CommandManager.IsValidCommandName( brushName ) ) {
                    player.Message( "ReplaceBrush usage: &H/Brush rb <Block> <BrushName>" );
                    return null;
                }
                IBrushFactory brushFactory = BrushManager.GetBrushFactory( brushName );

                if( brushFactory == null ) {
                    player.Message( "Unrecognized brush \"{0}\"", brushName );
                    return null;
                }

                IBrush replacement = brushFactory.MakeBrush( player, cmd );
                if( replacement == null ) {
                    return null;
                }
                Block = block;
                Replacement = replacement;
            }

            ReplacementInstance = Replacement.MakeInstance( player, cmd, op );
            if( ReplacementInstance == null ) return null;

            return new ReplaceBrushBrush( this );
        }
コード例 #26
0
ファイル: CloudyBrush.cs プロジェクト: TheDireMaster/fCraft
        public IBrush MakeBrush(Player player, CommandReader cmd)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            List <Block> blocks              = new List <Block>();
            List <int>   blockRatios         = new List <int>();
            bool         scaleSpecified      = false,
                         turbulenceSpecified = false,
                         seedSpecified       = false;
            int scale      = 100,
                turbulence = 100;
            UInt16 seed    = CloudyBrush.NextSeed();

            while (true)
            {
                int    offset       = cmd.Offset;
                string rawNextParam = cmd.Next();
                if (rawNextParam == null)
                {
                    break;
                }

                if (rawNextParam.EndsWith("%"))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempScale;
                    if (!Int32.TryParse(numPart, out tempScale))
                    {
                        player.Message("Cloudy brush: To specify scale, write a number followed by a percentage (e.g. 100%).");
                        return(null);
                    }
                    if (scaleSpecified)
                    {
                        player.Message("Cloudy brush: Scale has been specified twice.");
                        return(null);
                    }
                    if (scale < 1 || tempScale > CloudyBrush.MaxScale)
                    {
                        player.Message("Cloudy brush: Invalid scale ({0}). Must be between 1 and {1}",
                                       scale, CloudyBrush.MaxScale);
                        return(null);
                    }
                    scale          = tempScale;
                    scaleSpecified = true;
                    continue;
                }
                else if (rawNextParam.EndsWith("T", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    int    tempTurbulence;
                    if (Int32.TryParse(numPart, out tempTurbulence))
                    {
                        if (turbulenceSpecified)
                        {
                            player.Message("Cloudy brush: Turbulence has been specified twice.");
                            return(null);
                        }
                        if (turbulence < 1 || tempTurbulence > CloudyBrush.MaxScale)
                        {
                            player.Message("Cloudy brush: Invalid turbulence ({0}). Must be between 1 and {1}",
                                           turbulence, CloudyBrush.MaxScale);
                            return(null);
                        }
                        turbulence          = tempTurbulence;
                        turbulenceSpecified = true;
                        continue;
                    }
                }
                else if (rawNextParam.EndsWith("S", StringComparison.OrdinalIgnoreCase))
                {
                    string numPart = rawNextParam.Substring(0, rawNextParam.Length - 1);
                    try {
                        seed = UInt16.Parse(numPart, System.Globalization.NumberStyles.HexNumber);
                        if (seedSpecified)
                        {
                            player.Message("Cloudy brush: Seed has been specified twice.");
                            return(null);
                        }
                        seedSpecified = true;
                        continue;
                    } catch {
                        seed = CloudyBrush.NextSeed();
                    }
                }

                cmd.Offset = offset;
                int   ratio;
                Block block;
                if (!cmd.NextBlockWithParam(player, true, out block, out ratio))
                {
                    return(null);
                }
                if (ratio < 1 || ratio > CloudyBrush.MaxRatio)
                {
                    player.Message("Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.",
                                   ratio, CloudyBrush.MaxRatio);
                    return(null);
                }
                blocks.Add(block);
                blockRatios.Add(ratio);
            }

            CloudyBrush madeBrush;

            if (blocks.Count == 0)
            {
                madeBrush = new CloudyBrush();
            }
            else if (blocks.Count == 1)
            {
                madeBrush = new CloudyBrush(blocks[0], blockRatios[0]);
            }
            else
            {
                madeBrush = new CloudyBrush(blocks.ToArray(), blockRatios.ToArray());
            }

            madeBrush.Frequency   /= (scale / 100f);
            madeBrush.Persistence *= (turbulence / 100f);
            madeBrush.Seed         = seed;

            return(madeBrush);
        }
コード例 #27
0
 public override void Execute( CommandReader reader )
 {
     string property = reader.Next();
     if( property == null ) {
         game.Chat.Add( "&e/client info: &cYou didn't specify a property." );
     } else if( Utils.CaselessEquals( property, "pos" ) ) {
         game.Chat.Add( "Feet: " + game.LocalPlayer.Position );
         game.Chat.Add( "Eye: " + game.LocalPlayer.EyePosition );
     } else if( Utils.CaselessEquals( property, "target" ) ) {
         PickedPos pos = game.SelectedPos;
         if( !pos.Valid ) {
             game.Chat.Add( "Currently not targeting a block" );
         } else {
             game.Chat.Add( "Currently targeting at: " + pos.BlockPos );
         }
     } else if( Utils.CaselessEquals( property, "dimensions" ) ) {
         game.Chat.Add( "map width: " + game.Map.Width );
         game.Chat.Add( "map height: " + game.Map.Height );
         game.Chat.Add( "map length: " + game.Map.Length );
     } else if( Utils.CaselessEquals( property, "jumpheight" ) ) {
         float jumpHeight = game.LocalPlayer.JumpHeight;
         game.Chat.Add( jumpHeight.ToString( "F2" ) + " blocks" );
     } else {
         game.Chat.Add( "&e/client info: Unrecognised property: \"&f" + property + "&e\"." );
     }
 }
コード例 #28
0
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string str = cmd.Next();

            if (str.NullOrWhiteSpace())
            {
                return(false);
            }

            // if string starts with "++", load image from imgur
            if (str.StartsWith("++"))
            {
                str = "http://i.imgur.com/" + str.Substring(2) + ".png";
            }
            // prepend the protocol, if needed (assume http)
            if (!str.CaselessStarts("http://") && !str.CaselessStarts("https://"))
            {
                str = "http://" + str;
            }

            // Convert imgur web page url to direct image url
            if (str.StartsWith("http://imgur.com/"))
            {
                str = "http://i.imgur.com/" + str.Substring("http://imgur.com/".Length) + ".png";
            }
            if (str.StartsWith("https://imgur.com/"))
            {
                str = "https://i.imgur.com/" + str.Substring("https://imgur.com/".Length) + ".png";
            }

            if (!str.CaselessEnds(".png") && !str.CaselessEnds(".jpg") && !str.CaselessEnds(".gif"))
            {
                Player.Message("URL must be a link to an image");
                return(false);
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(str, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }
            else if (!url.Host.CaselessEquals("i.imgur.com"))
            {
                Player.Message("For safety reasons we only accept images uploaded to &9http://imgur.com/ &SSorry for this inconvenience.");
                return(false);
            }
            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                Palette = BlockPalette.FindPalette(paletteName);
                if (Palette == null)
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name));
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.FindPalette("Light");
            }

            // All set
            return(true);
        }