IBrushInstance IBrush.MakeInstance( Player player, CommandReader cmd, DrawOperation op ) { if( ReadParams( cmd ) ) { return this; } else { return null; } }
public IBrush MakeBrush(Player player, CommandReader cmd) { if (player == null) throw new ArgumentNullException("player"); if (cmd == null) throw new ArgumentNullException("cmd"); Stack<Block> blocks = new Stack<Block>(); while (cmd.HasNext) { Block block; if (!cmd.NextBlock(player, false, out block)) return null; blocks.Push(block); } switch (blocks.Count) { case 0: player.Message("{0} brush: Please specify the replacement block type.", Name); return null; case 1: return new ReplaceNotBrush(blocks.ToArray(), Block.None); default: { Block replacement = blocks.Pop(); return new ReplaceNotBrush(blocks.ToArray(), replacement); } } }
public IBrush MakeBrush(Player player, CommandReader cmd) { if (player == null) throw new ArgumentNullException("player"); if (cmd == null) throw new ArgumentNullException("cmd"); // read the block filter list HashSet<Block> blocks = new HashSet<Block>(); while (cmd.HasNext) { Block block; if (!cmd.NextBlock(player, false, out block)) { return null; } if (!blocks.Add(block)) { // just a warning -- don't abort player.Message("{0}: {1} was specified twice!", Name, block); } } // create a brush if (blocks.Count > 0) { return new PasteBrush(blocks.ToArray(), Not); } else if (Not) { player.Message("PasteNot brush requires at least 1 block."); return null; } else { return new PasteBrush(); } }
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>(); while( cmd.HasNext ) { int ratio; Block block; if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null; if( block == Block.None ) return null; if( ratio < 0 || ratio > 1000 ) { player.Message( "{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.", Name, ratio ); return null; } blocks.Add( block ); blockRatios.Add( ratio ); } switch( blocks.Count ) { case 0: return new RandomBrush(); case 1: return new RandomBrush( blocks[0], blockRatios[0] ); default: return new RandomBrush( blocks.ToArray(), blockRatios.ToArray() ); } }
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>(); while( cmd.HasNext ) { int ratio; Block block; if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null; if( ratio < 1 || ratio > RandomBrush.MaxRatio ) { player.Message( "Random brush: Invalid block ratio ({0}). Must be between 1 and {1}.", ratio, RandomBrush.MaxRatio ); return null; } blocks.Add( block ); blockRatios.Add( ratio ); } if( blocks.Count == 0 ) { return new RandomBrush(); } else if( blocks.Count == 1 ) { return new RandomBrush( blocks[0], blockRatios[0] ); } else { return new RandomBrush( blocks.ToArray(), blockRatios.ToArray() ); } }
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 ); }
public IBrush MakeBrush( Player player, CommandReader cmd ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); Block block, altBlock; cmd.NextBlock( player, true, out block ); cmd.NextBlock( player, true, out altBlock ); return new CheckeredBrush( block, altBlock ); }
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; }
public void TestCoordinatesOK() { CommandReader test = new CommandReader(_mockView.Object, _mockRobotCleanerServices.Object); _mockView.Setup(x => x.ReadLine()).Returns("10 22"); Coordinate result = test.ReadStartingCoordinate(); Assert.AreEqual(10, result.X); Assert.AreEqual(22, result.Y); }
public static bool OpenYS_Command_Weather_Night_Method(Client ThisClient, CommandReader Command) { OpenYS.SetServerTimeTicks(0); Settings.Weather.Time = 0000; SettingsHandler.SaveAll(); //OpenYS.AdvancedWeatherOptions._LastDayNightCycleRestart = DateTime.Now; ThisClient.SendMessage("&aServer time set to NIGHT."); Clients.AllClients.Exclude(ThisClient).SendMessage("&a" + ThisClient.Username + " set the time to NIGHT."); return(true); }
public static void Main() { MenuCatalog menu = new MenuCatalog(); CommandReader commandReader = new CommandReader("data\\menu.txt"); menu.ReadFromFile(commandReader); menu.PrintPizzasMenu(); menu.PrintPastaMenu(); read(); }
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)); }
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)); }
public void SetFileTest() { CommandReader target = new CommandReader(); string filename = "testfilename"; target.AddFile(filename); string expected = "testfilename"; string actual = target.Accessor(); Assert.AreEqual(expected, actual); }
public void ParseGetCommand() { CommandReader reader = new CommandReader("get users:1:name"); CommandInfo command = reader.NextCommand(); Assert.IsNotNull(command); Assert.AreEqual("get", command.Verb); Assert.AreEqual("users:1:name", command.Key); Assert.IsNull(command.Parameters); }
static void Main(string[] args) { using (var commandLog = new StreamWriter(@"log.txt")) { commandLog.WriteLine($"New game: {DateTime.Now}"); } var inputReader = new CommandReader(); inputReader.CommandRecieved += InputReader_CommandRecieved; inputReader.Run(); }
public void StandardPicRequestWithoutEndMssg() { byte[] request = new CommandBuilder().Request(CameraRequest.SendFullResImage).AddParam("thing", "xtbb").Build(); byte[] rawRequest = new byte[request.Length - Constants.EndOfMessage.Length]; Array.Copy(request, rawRequest, rawRequest.Length); CommandReader result = new CommandReader(rawRequest); Assert.True(result.Request == CameraRequest.SendFullResImage); Assert.True(result.Parameters.Count == 1); }
IBrushInstance IBrush.MakeInstance(Player player, CommandReader cmd, DrawOperation op) { if (ReadParams(cmd)) { return(this); } else { return(null); } }
public void StandardPicRequestWithEmpty() { byte[] request = new CommandBuilder().Request(CameraRequest.SendFullResImage).Build(); byte[] rawRequest = new byte[request.Length + 12]; request.CopyTo(rawRequest, 0); CommandReader result = new CommandReader(rawRequest); Assert.True(result.Request == CameraRequest.SendFullResImage); Assert.True(result.Parameters.Count == 0); }
public IBrush MakeBrush(Player player, CommandReader cmd) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } return(this); }
private void QueueReadCommand(NamedConnection connection) { lock (_lock) { _runningCommands.Add(Task.Factory.StartNew <CommandRead>(() => { ICommandReader reader = new CommandReader(); MqttCommand cmd = reader.Read(connection.Connection); return(new CommandRead(cmd, connection)); }, TaskCreationOptions.LongRunning)); } }
static void Main() { while (true) { string[] command = ConsoleRead.CommandInput(); object value = CommandReader.FunctionCall(command[0], command); if (value != null) { Console.WriteLine($"Got -> {value}"); } } }
public override bool ReadParams( CommandReader cmd ) { if( cmd.HasNext ) { Block replacement; if( cmd.NextBlock( Player, false, out replacement ) ) { ReplacementBlock = replacement; } else { return false; } } Brush = this; return true; }
internal CommandCalledEventArgs([NotNull] CommandReader command, [NotNull] Player player) { if (command == null) { throw new ArgumentNullException("command"); } if (player == null) { throw new ArgumentNullException("player"); } Command = command; Player = player; }
public void ParseSetCommand() { CommandReader reader = new CommandReader("set users:1:name \"Adam\""); CommandInfo command = reader.NextCommand(); Assert.IsNotNull(command); Assert.AreEqual("set", command.Verb); Assert.AreEqual("users:1:name", command.Key); Assert.IsNotNull(command.Parameters); Assert.AreEqual(1, command.Parameters.Count); Assert.AreEqual("Adam", command.Parameters[0]); }
private static void Main() { ICommandInputProvider commandInput = new CommandReader(); IInfoInputProvider menuInput = new Menu(); IInputProvider inputProvider = new ConsoleInputProvider(commandInput, menuInput); IInfoRenderer infoPanel = new InfoPanel(); IPlayFieldRenderer playFieldPanel = new PlayFieldPanel(); ILadderRenderer topScoresPanel = new TopScoresPanel(); IRenderer consoleRenderer = new ConsoleRender(infoPanel, playFieldPanel, topScoresPanel); LabyrinthFacade.Start(consoleRenderer, inputProvider, FileLogger.Instance()); }
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 ); } }
private bool GlobalizationMenuState() { int val = -CommandReader.GetIntTriggerDown("vertical", Controlador.teclado); globalMenu.ChangeOption(val); if (Input.GetKeyDown(KeyCode.Return)) { OpcoesDoGlobalizationMenu(globalMenu.SelectedOption); } return(false); }
public void ReadFromFileTest() { string[] args = { "read test" }; CommandReader target = new CommandReader(args); string ResultLine = string.Empty; string ResultLineExpected = ""; string expected = null; string actual = null; //actual = target.ReadFromFile(ref ResultLine); Assert.AreEqual(ResultLineExpected, ResultLine); Assert.AreEqual(expected, actual); }
// Update is called once per frame void Update() { if (podeMudar) { float quanto = CommandReader.GetAxis("horizontal", GlobalController.g.Control) + CommandReader.GetAxis("HDpad", GlobalController.g.Control); if (quanto > 0) { VerificaModificacao(true); } else if (quanto < 0) { VerificaModificacao(false); } else { quanto = UiDeOpcoes.VerificaMudarOpcao(true); if (quanto > 0) { opcaoSelecionada = ContadorCiclico.AlteraContador(1, opcaoSelecionada, destaques.Length); } else if (quanto < 0) { opcaoSelecionada = ContadorCiclico.AlteraContador(-1, opcaoSelecionada, destaques.Length); } if (quanto != 0) { ColocarDestaqueSelecionado(); } } bool foi = ActionManager.ButtonUp(0, GlobalController.g.Control); if (CommandReader.ButtonDown(2, GlobalController.g.Control) || (foi && opcaoSelecionada == destaques.Length - 1)) { BotaoVoltar(); } else if (foi && opcaoSelecionada == 2) { BotaoTodasHabilidades(); } } }
public static bool ButtonUp(int n, Controlador c) { bool press = CommandReader.ButtonUp(n, c); if (!esteQuadro && press) { AgendaEsseQuadro(); return(true); } else { return(false); } }
public static bool OpenYS_Command_Racing_CreateTT_Method(Client ThisClient, CommandReader Command) { #region Didn't Specify Path if (Command._CmdArguments.Count() < 1) { ThisClient.SendMessage("&eYou need to specify a path to race on!"); return(false); } #endregion #region Don't Have the Path if (!World.Objects.PathList .Where(y => y.Type == 15) .Select(x => x.Identify.ToUpperInvariant()) .Contains(Command._CmdArguments[0] .ToUpperInvariant())) { ThisClient.SendMessage("Path not found - use /ListPaths to see compatible racing paths!"); return(false); } #endregion #region Specified Duration TimeSpan RaceDuration = new TimeSpan(0, 0, 0); if (Command._CmdArguments.Count() > 1) { double Duration = 0; bool Failed = !Double.TryParse(Command._CmdArguments[1], out Duration); if (Failed) { ThisClient.SendMessage("Duration in Minutes given was not an integer! Durations must be in numeric format!"); return(false); } RaceDuration = new TimeSpan(0, 0, 0, 0, (int)(Duration * 60 * 1000)); } #endregion Games.Racing2.Race NewTT = new Games.Racing2.Race(); NewTT.Path = World.Objects.PathList .Where(y => y.Identify.ToUpperInvariant() == Command._CmdArguments[0].ToUpperInvariant()).ToArray()[0]; NewTT.Owner = ThisClient; NewTT.FastestSectors = new float[NewTT.Path.Points.Count]; NewTT.CumulativeSectors = new float[NewTT.Path.Points.Count]; NewTT.RaceTypeSetTimeTrial(); NewTT.RaceEnds = DateTime.Now + RaceDuration; ThisClient.SendMessage("&eTimeTrial Created on Path: \"" + NewTT.Path.Identify + "\". To join in, type \"&c/JoinRace " + NewTT.ID + "&e\"."); Clients.AllClients.Exclude(ThisClient).SendMessage("&e" + ThisClient.Username + " created a TimeTrial at " + NewTT.Path.Identify + ". To join in, type \"&c/JoinRace " + NewTT.ID + "&e\"."); Games.Racing2.Races.Add(NewTT); return(true); }
/// <addBuyer> /// This method takes from the console information for a new buyer. /// (nickname, the nickname of an existing dealer) /// It adds the new dealer to the database, /// and assigns the new buyer to the dealer. /// </addBuyer> public void AddBuyer() { string nickname; string dNickname; int dealerID; Dealer dealer; try { Dictionary <string, string> dict = CommandReader.AddBuyer(); nickname = dict["nickname"]; dNickname = dict["dealerNickname"]; if (nickname == "" || dNickname == "") { throw new InvalidOperationException(ConstantStrings.Blank); } OutputPrinter.Connecting(); List <string> nicknames = c.Buyers.Select(e => e.Nickname).ToList(); if (nicknames.Contains(nickname)) { throw new InvalidOperationException(ConstantStrings.Buyer + $" with nickname '{nickname}' " + ConstantStrings.AlreadyExists); } try { dealer = c.Dealers.Single(e => e.Nickname == dNickname); dealerID = dealer.Id; } catch (Exception) { throw new InvalidOperationException(ConstantStrings.Dealer + $" with nickname '{nickname}' " + ConstantStrings.NotFound); } var buyer = new Buyer() { Nickname = nickname, DealerId = dealerID }; Add(buyer); OutputPrinter.Done(); } catch (Exception e) { Console.WriteLine(e.Message); OutputPrinter.InvalidCommand(); } }
private bool ColorCircleState() { bool foi = false; bool effective = false; Vector2 V = new Vector2( CommandReader.GetAxis("horizontal", Controlador.teclado), CommandReader.GetAxis("vertical", Controlador.teclado) ); float val = (Input.GetKey(KeyCode.Q) ? 1 : 0) + (Input.GetKey(KeyCode.E) ? -1 : 0); val *= Time.deltaTime * velValForGreyScale; myGetColor.MoveMark(V * velValForColor, val); if (Input.GetKeyDown(KeyCode.Escape)) { effective = false; foi = true; } else if (Input.GetKeyDown(KeyCode.Return)) { effective = true; foi = true; } else if (Input.GetKeyDown(KeyCode.Alpha1)) { EndColorCircle(); ChangeToColorGrid(); } else if (Input.GetKeyDown(KeyCode.Alpha2) && secManager.GetTargetColorReg != RegistroDeCores.skin) { EndColorCircle(); globalCM.StartHud(myGetColor.CurrentColor, secManager.GuardOriginalColor.cor, secManager.VerifyColorReg(), secManager.GetTargetColorReg); StartGlobalColorMenu(); } if (foi) { EndColorCircle(); secManager.EndChangeColor(effective); estado = EstadoDoMenu.main; } return(true); }
private static async Task RunAppAsync() { try { var getChangeService = UnityConfigurationBase.Container.Resolve <IGetChangeService>(); var coinBoxService = UnityConfigurationBase.Container.Resolve <ICoinBoxService>(); var commandReader = new CommandReader(getChangeService, coinBoxService); await commandReader.ReadCommands(); } catch (Exception e) { Console.WriteLine(e); } }
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] ); } } } }
public void IgnoresUnparseableCommands() { var commands = new string[] { "REPORT", "LEFT", "FFSJKF", "PLACE 0,0,FOO", "RIGHT", }; var results = CommandReader.Read(commands).ToList(); Check.That(results).HasSize(3); }
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; }
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 ); } }
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)); }
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>(); while (cmd.HasNext) { int ratio; Block block; if (!cmd.NextBlockWithParam(player, true, out block, out ratio)) { return(null); } if (block == Block.None) { return(null); } if (ratio < 0 || ratio > 1000) { player.Message("{0} brush: Invalid block ratio ({1}). Must be between 1 and 1000.", Name, ratio); return(null); } blocks.Add(block); blockRatios.Add(ratio); } switch (blocks.Count) { case 0: return(new MarbledBrush()); case 1: return(new MarbledBrush(blocks[0], blockRatios[0])); default: return(new MarbledBrush(blocks.ToArray(), blockRatios.ToArray())); } }
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); }
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; }
public IBrush MakeBrush(Player player, CommandReader cmd) { if (player == null) { throw new ArgumentNullException("player"); } if (cmd == null) { throw new ArgumentNullException("cmd"); } Block block, altBlock; cmd.NextBlock(player, true, out block); cmd.NextBlock(player, true, out altBlock); return(new CheckeredBrush(block, altBlock)); }
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>(); while (cmd.HasNext) { Block block; if (!cmd.NextBlock(player, true, out block)) { return null; } blocks.Add(block); } return new NormalBrush(blocks.ToArray()); }
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 ); } } } }
public override void Execute( CommandReader reader ) { List<string> commandNames = new List<string>(); StringBuilder buffer = new StringBuilder( 64 ); foreach( Command cmd in game.CommandManager.RegisteredCommands ) { string name = cmd.Name; if( buffer.Length + name.Length > 64 ) { commandNames.Add( buffer.ToString() ); buffer.Length = 0; } buffer.Append( name + ", " ); } if( buffer.Length > 0 ) { commandNames.Add( buffer.ToString() ); } foreach( string part in commandNames ) { game.Chat.Add( part ); } }
public IBrush MakeBrush( Player player, CommandReader cmd ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); Stack<Block> blocks = new Stack<Block>(); while( cmd.HasNext ) { Block block; if( !cmd.NextBlock( player, false, out block ) ) return null; blocks.Push( block ); } if( blocks.Count == 0 ) { return new ReplaceNotBrush(); } else if( blocks.Count == 1 ) { return new ReplaceNotBrush( blocks.ToArray(), Block.None ); } else { Block replacement = blocks.Pop(); return new ReplaceNotBrush( blocks.ToArray(), replacement ); } }
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 ); }
public IBrush MakeBrush(Player player, CommandReader cmd) { if (player == null) throw new ArgumentNullException("player"); if (cmd == null) throw new ArgumentNullException("cmd"); Block block, altBlock; // first block type is required if (!cmd.NextBlock(player, true, out block)) { player.Message("{0}: Please specify at least one block type.", Name); return null; } // second block type is optional if (cmd.HasNext) { if (!cmd.NextBlock(player, true, out altBlock)) return null; } else { altBlock = Block.None; } return new CheckeredBrush(block, altBlock); }
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, altBlock; if( !cmd.NextBlock( player, true, out block ) ) return null; if( cmd.HasNext ) { if( !cmd.NextBlock( player, true, out altBlock ) ) return null; } else { altBlock = Block.None; } Block1 = block; Block2 = altBlock; } else if( Block1 == Block.None ) { player.Message( "{0}: Please specify one or two blocks.", Factory.Name ); return null; } return new CheckeredBrush( this ); }
public override void Execute( CommandReader reader ) { int width, height, length; if( !reader.NextInt( out width ) || !reader.NextInt( out height ) || !reader.NextInt( out length ) ) { game.Chat.Add( "&e/client generate: &cInvalid dimensions." ); } else { if( width < 16 || height < 16 || length < 16 ) { game.Chat.Add( "&e/client generate: &cDimensions too small." ); return; } if( width > 1024 || height > 1024 || length > 1024 ) { game.Chat.Add( "&e/client generate: &cDimensions too large." ); return; } if( !( game.Network is SinglePlayerServer ) ) { game.Chat.Add( "&e/client generate: &cThis command only works in singleplayer mode." ); return; } SinglePlayerServer server = (SinglePlayerServer)game.Network; server.NewMap(); game.chatInInputBuffer = null; server.MakeMap( width, height, length ); } }
public override bool ReadParams(CommandReader cmd) { if (Player.GetCopyState() == null) { Player.Message("Nothing to paste! Copy something first."); return false; } List<Block> blocks = new List<Block>(); while (cmd.HasNext) { Block block; if (!cmd.NextBlock(Player, false, out block)) return false; blocks.Add(block); } if (blocks.Count > 0) { Blocks = blocks.ToArray(); } else if (Not) { Player.Message("PasteNot requires at least 1 block."); return false; } Brush = this; return true; }
public override bool ReadParams(CommandReader cmd) { return true; }
public IBrushInstance MakeInstance( Player player, CommandReader cmd, DrawOperation state ) { if( player == null ) throw new ArgumentNullException( "player" ); if( cmd == null ) throw new ArgumentNullException( "cmd" ); if( state == null ) throw new ArgumentNullException( "state" ); List<Block> blocks = new List<Block>(); List<int> blockRatios = new List<int>(); while( cmd.HasNext ) { int ratio; Block block; if( !cmd.NextBlockWithParam( player, true, out block, out ratio ) ) return null; if( ratio < 1 || ratio > MaxRatio ) { player.Message( "Cloudy brush: Invalid block ratio ({0}). Must be between 1 and {1}.", ratio, MaxRatio ); return null; } blocks.Add( block ); blockRatios.Add( ratio ); } if( blocks.Count == 0 ) { if( Blocks.Length == 0 ) { player.Message( "{0} brush: Please specify at least one block.", Factory.Name ); return null; } else { return new CloudyBrush( this ); } } else if( blocks.Count == 1 ) { return new CloudyBrush( blocks[0], blockRatios[0] ); } else { return new CloudyBrush( blocks.ToArray(), blockRatios.ToArray() ); } }
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; }
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" ); Stack<Block> blocks = new Stack<Block>(); while( cmd.HasNext ) { Block block; if( !cmd.NextBlock( player, false, out block ) ) return null; blocks.Push( block ); } if( blocks.Count == 0 && Blocks == null ) { player.Message( "ReplaceNot brush requires at least 1 block." ); return null; } if( blocks.Count > 0 ) { if( blocks.Count > 1 ) Replacement = blocks.Pop(); Blocks = blocks.ToArray(); } return new ReplaceNotBrush( this ); }
public override MapGeneratorParameters CreateParameters( Player player, CommandReader cmd ) { if( cmd.HasNext ) { player.Message( "Vanilla map generator does not take any parameters; using defaults." ); } return new VanillaMapGenParameters(); }
IBrush IBrushFactory.MakeBrush( Player player, CommandReader cmd ) { return this; }
public abstract bool ReadParams( CommandReader cmd );