public override void Execute(Game game) { var settlers = game.Settlement.Settlers.Where(settler => StringsUtil.IsMatchingStartIgnoreCase(settler, SettlerNameArgument.Contents)).ToList(); if (settlers.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: No settlers with name starting with \"{SettlerNameArgument.Contents}\" found"); } else if (settlers.Count > 1) { if (AllTag.Used) { foreach (var settler in settlers) { ListRelationships(settler); } } else { CustomConsole.WriteLine($"Settlers with name starting with \"{SettlerNameArgument.Contents}\":"); IOManager.ListInConsole(settlers); } } else if (settlers.Count == 1) { ListRelationships(settlers[0]); } }
public override void Execute(Game game) { var name = TechNameArgument.IsFilled ? TechNameArgument.Contents : ""; var list = game.Settlement.TechManager.GetAvailableTech(game.Settlement) .Where(tech => StringsUtil.IsMatchingStartIgnoreCase(tech, name)).ToList(); if (list.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: No technology with name starting with \"{name}\" found!"); } else if (list.Count == 1) { var tech = list[0]; game.Settlement.TechManager.CurrentResearch = tech; CustomConsole.WriteLine($"Switched research to {tech} {tech.Progress}/{tech.Cost} ({MathUtil.RoundUp((tech.Cost - tech.Progress) / (double) game.Settlement.ResearchRate)} days)"); } else { if (name != "") { CustomConsole.WriteLine($"Technologies starting with \"{name}\""); } else { CustomConsole.WriteLine("Available Technologies:"); } IOManager.ListInConsole(list); } }
public void FindAndExecute(string commandName, string[] args, Game game) { var literalCommands = GetCurrentCommandList(game).Where(c => c.Aliases.Any(alias => alias == commandName)).ToList(); var commands = GetCurrentCommandList(game).Where(c => c.Aliases.Any(alias => StringsUtil.IsMatchingStartIgnoreCase(alias, commandName))).ToList(); if (commands.Count == 0 && literalCommands.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: The Commmand \"{commandName}\" does not exist."); var command = (!game.IsInMenu ? MenuCommands : GameCommands).FirstOrDefault(com => com.Aliases.Any(alias => alias == commandName)); if (command != null) { if (game.IsInMenu) { CustomConsole.WriteLine($"{CustomConsole.Gray}The command \"{command}\" is not available in menu."); } else { CustomConsole.WriteLine( $"{CustomConsole.Gray}The command \"{command}\" is only available in menu."); } } } else if (commands.Count > 1 && literalCommands.Count == 0) { CustomConsole.WriteLine($"Commands starting with \"{commandName}\":"); IOManager.ListInConsole(commands); } else { var command = commands[0]; if (command == null) { } else { try { command.AttemptExecution(args, game); command.Clear(); } catch (FormatException e) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: {e.Message}"); CustomConsole.WriteLine( $"The format of \"{command.Name}\" is: {CustomConsole.Gray}{command.Aliases[0]} {command.Format}"); } catch (NotImplementedException e) { CustomConsole.WriteLine($"{CustomConsole.Yellow}Sorry! This feature hasn't been implemented!"); } } } }
public OrderHeader(float totalPaid, string paymentMethod, string shippingMethod, Billing billing, Shipping shipping) { Reference = StringsUtil.RandomString(QuantityCharsReference); TotalPaid = totalPaid; PaymentMethod = paymentMethod; ShippingMethod = shippingMethod; Billing = billing; Shipping = shipping; Details = new List <OrderDetail>(); }
public override void Execute(Game game) { if (!ResidenceNameArgument.IsFilled) { var settlerList = game.Settlement.Settlers.Where(settler => StringsUtil.IsMatchingStartIgnoreCase(settler, SettlerNameArgument.Contents)).ToList(); if (settlerList.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: No settler with name starting with \"{SettlerNameArgument.Contents}\" found!"); } else if (settlerList.Count == 1) { var settler = settlerList[0]; var home = settler.Family.Home ?? null; if (home != null) { CustomConsole.TitleLine(); CustomConsole.WriteLine($"{settler.Name.ToUpper()}'S HOME:"); CustomConsole.WriteLine($"{home.Name}"); CustomConsole.WriteLine($"{home.Description}"); CustomConsole.WriteLine($"Heat: {home.GetIndoorTemperature(game.Settlement)}"); CustomConsole.WriteLine($"Residents:"); foreach (var family in home.ResidentFamilies) { foreach (var member in family.Members) { CustomConsole.WriteLine($"{member} ({family.Name})"); } } } else { CustomConsole.WriteLine($"{settler}{CustomConsole.Red} is homeless!"); } } else { CustomConsole.WriteLine($"Settlers with name starting with \"{SettlerNameArgument.Contents}\":"); IOManager.ListInConsole(settlerList); } } else { if (NaturalNumberArgument.IsFilled) { } else { } } }
public string MajorTraits() { var strings = new List <string>(); foreach (var(trait, level) in Traits.Dictionary) { if (level >= TraitLevel.High) { strings.Add(trait.PositiveDescriptor); } else if (level <= TraitLevel.Low) { strings.Add(trait.NegativeDescriptor); } } return(StringsUtil.CommaList(strings.ToArray())); }
public override bool AdditionalFilter(Model.Settler.Settler item) { if (GenderTag.Used) { if (item is IGendered <BinaryGender> gendered) { return(StringsUtil.IsMatchingStartIgnoreCase(gendered.Gender, GenderArgument.Contents) || string.Equals(gendered.Gender.Symbol, GenderArgument.Contents, StringComparison.CurrentCultureIgnoreCase)); } else { return(false); } } else { return(true); } }
public override void Display(Model.Settler.Settler settler) { CustomConsole.WriteLine($"{StringsUtil.ToUpperIgnoreColor(settler.ToString())}:"); CustomConsole.TitleLine(); var traits = settler.MajorTraits(); if (traits != "") { CustomConsole.WriteLine($"{traits}"); } if (settler is IGendered <Gender> gendered) { CustomConsole.WriteLine($"Gender: {gendered.Gender}"); } CustomConsole.WriteLine($"Prestige: {settler.PrestigeLevel}"); }
public override void Execute(Game game) { var blueprints = game.Settlement.Blueprints.Where(bp => StringsUtil.IsMatchingStartIgnoreCase(bp, BlueprintNameArgument.Contents)).ToList(); if (blueprints.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}ERROR: No blueprints with name starting with {BlueprintNameArgument.Contents} found!"); } else if (blueprints.Count == 1) { Construct(game.Settlement, blueprints[0]); } else { CustomConsole.WriteLine($"Choose a blueprint to construct:"); IOManager.ListInConsole(blueprints); } }
public void TestSpammy(string input, bool state) { var result = StringsUtil.IsSpammyString(input); result.Should().Be(state); }
public void TestSanitize(string input, string output) { var result = StringsUtil.Sanitize(input); result.Should().Be(output); }
private void Display(List <T> list, string settlement) { CustomConsole.TitleLine(); CustomConsole.WriteLine($"{StringsUtil.ToUpperIgnoreColor(Type)}S IN {StringsUtil.ToUpperIgnoreColor(settlement)}"); IOManager.ListInConsole(list, NumberedTag.Used, SeparatedTag.Used); }
private void txtValorInicial_Leave(object sender, EventArgs e) { txtValorInicial.Text = Convert.ToDouble(StringsUtil.StringIsNullOrEmptyOrWhiteSpace(txtValorInicial.Text) ? "0" : txtValorInicial.Text).ToString("n2"); }
public Returns SolicitarCalculo(decimal valorInicial, int meses) { // Utilizando HttpClient para comunicação de alto nível using (httpClient = new HttpClient()) { HttpResponseMessage httpResponseMessage = null; // Camo os métodos da classe HttpClient são assíncronos, vamos crias uma tarefa e forçá-la ser // síncrono para que possamos manipular em uma outra situação processos assíncronos Task.Run(async() => { httpResponseMessage = await httpClient.GetAsync($"{Properties.Resources.URL_API_CAL_WEB}?{Properties.Resources.PAR_VALOR_INICIAL}={valorInicial}&{Properties.Resources.PAR_MESES}={meses}"); }) .ContinueWith(OnExceptionErroHandler) .Wait(); if (httpResponseMessage == null) { return(new Returns { StatusCode = -1, Message = "Sem conexão com a internet ou o servidor está offline!" }); } string retornoApi = string.Empty; Returns returns = null; switch (httpResponseMessage.StatusCode) { case System.Net.HttpStatusCode.OK: { // Forçar tarefa para síncrono Task.Run(async() => { retornoApi = await httpResponseMessage.Content.ReadAsStringAsync(); }) .ContinueWith(OnExceptionErroHandler) .Wait(); if (!StringsUtil.StringIsNullOrEmptyOrWhiteSpace(retornoApi)) { returns = JsonConvert.DeserializeObject <Returns>(retornoApi); } } break; case System.Net.HttpStatusCode.BadRequest: { // Forçar tarefa para síncrono Task.Run(async() => { retornoApi = await httpResponseMessage.Content.ReadAsStringAsync(); }) .ContinueWith(OnExceptionErroHandler) .Wait(); if (!StringsUtil.StringIsNullOrEmptyOrWhiteSpace(retornoApi)) { returns = JsonConvert.DeserializeObject <Returns>(retornoApi); } } break; case System.Net.HttpStatusCode.NotAcceptable: { // Forçar tarefa para síncrono Task.Run(async() => { retornoApi = await httpResponseMessage.Content.ReadAsStringAsync(); }) .ContinueWith(OnExceptionErroHandler) .Wait(); if (!StringsUtil.StringIsNullOrEmptyOrWhiteSpace(retornoApi)) { returns = JsonConvert.DeserializeObject <Returns>(retornoApi); } } break; default: { // Caso dê algum statuscode não tratato vamos retorno ele para que possa ser visível na aplicação returns = new Returns { StatusCode = (int)httpResponseMessage.StatusCode, Message = "Ocorre um erro!" }; } break; } return(returns); } }
public override void Execute(Game game) { var rate = game.Settlement.ResearchRate; if (TechNameArgument.IsFilled) { var name = TechNameArgument.Contents; var techs = game.Settlement.TechManager.Tree.Technologies .Where(tech => StringsUtil.IsMatchingStartIgnoreCase(tech, name)).ToList(); if (techs.Count == 0) { CustomConsole.WriteLine($"{CustomConsole.Red}No techs with name starting with \"{name}\""); } else if (techs.Count > 1) { foreach (var tech in techs) { CustomConsole.WriteLine($"{tech}"); } } else { var tech = techs[0]; CustomConsole.TitleLine(); CustomConsole.WriteLine($"{tech.Name.ToUpper()}:"); CustomConsole.WriteLine($"{tech.Description}"); if (game.Settlement.TechManager.Discovered.Contains(tech)) { CustomConsole.WriteLine("[Discovered]"); } else if (game.Settlement.TechManager.GetAvailableTech(game.Settlement).Contains(tech)) { CustomConsole.WriteLine($"Progress: {tech.Progress}/{tech.Cost} ({MathUtil.RoundUp((tech.Cost - tech.Progress) / (double) rate)} days)"); } else { var list = new List <string>(tech.TechRequirements.Select(t => t.ToString())); if (game.Settlement.Rank < tech.RankRequirement) { list.Add($"Player Rank {tech.RankRequirement}"); } CustomConsole.WriteLine($"Requires: {StringsUtil.CommaList(list.ToArray())}"); } } } else { var currentTech = game.Settlement.TechManager.CurrentResearch; var available = game.Settlement.TechManager.GetAvailableTech(game.Settlement); var discovered = game.Settlement.TechManager.Discovered; if (currentTech == null) { CustomConsole.WriteLine($"{CustomConsole.Red}Not currently researching any tech."); } else { CustomConsole.TitleLine(); CustomConsole.WriteLine($"Currently researching {currentTech}"); CustomConsole.WriteLine($"Progress: {currentTech.Progress}/{currentTech.Cost} ({MathUtil.RoundUp((currentTech.Cost - currentTech.Progress) / (double) rate)} days)"); } CustomConsole.TitleLine(); if (!DiscoveredTag.Used && available.Count > 0) { CustomConsole.WriteLine("Available techs:"); } else if (DiscoveredTag.Used && discovered.Count > 0) { CustomConsole.WriteLine("Discovered techs:"); } else if (!DiscoveredTag.Used) { CustomConsole.WriteLine("No available techs!"); } else { CustomConsole.WriteLine("No discovered techs!"); } if (!DiscoveredTag.Used) { foreach (var tech in available) { CustomConsole.WriteLine($"{tech}: {tech.Progress}/{tech.Cost} ({MathUtil.RoundUp((tech.Cost - tech.Progress) / (double) rate)} days)"); } } else { foreach (var tech in discovered) { CustomConsole.WriteLine($"{tech}"); } } } }
private bool ValidateBilling(Billing billing) { return(billing != null && StringsUtil.ValidateString(billing.Document) && StringsUtil.ValidateString(billing.Email) && StringsUtil.ValidateString(billing.Firstname) && StringsUtil.ValidateString(billing.Lastname)); }
private bool ValidateShipping(Shipping shipping) { return(shipping != null && StringsUtil.ValidateString(shipping.Address) && StringsUtil.ValidateString(shipping.City) && StringsUtil.ValidateString(shipping.Firstname) && StringsUtil.ValidateString(shipping.Lastname) && StringsUtil.ValidateString(shipping.Province) && StringsUtil.ValidateString(shipping.ZipCode)); }
private bool hasErrors(OrderHeaderViewModel model) { return(StringsUtil.ValidateString(model.PaymentMethod) && StringsUtil.ValidateString(model.ShippingMethod) && ValidateShipping(model.Shipping) && ValidateBilling(model.Billing)); }