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]);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        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>();
 }
Exemplo n.º 5
0
        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
                {
                }
            }
        }
Exemplo n.º 6
0
        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()));
        }
Exemplo n.º 7
0
 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);
     }
 }
Exemplo n.º 8
0
        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}");
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        public void TestSpammy(string input, bool state)
        {
            var result = StringsUtil.IsSpammyString(input);

            result.Should().Be(state);
        }
Exemplo n.º 11
0
        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);
 }
Exemplo n.º 13
0
 private void txtValorInicial_Leave(object sender, EventArgs e)
 {
     txtValorInicial.Text = Convert.ToDouble(StringsUtil.StringIsNullOrEmptyOrWhiteSpace(txtValorInicial.Text) ? "0" : txtValorInicial.Text).ToString("n2");
 }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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}");
                    }
                }
            }
        }
Exemplo n.º 16
0
 private bool ValidateBilling(Billing billing)
 {
     return(billing != null && StringsUtil.ValidateString(billing.Document) && StringsUtil.ValidateString(billing.Email) &&
            StringsUtil.ValidateString(billing.Firstname) && StringsUtil.ValidateString(billing.Lastname));
 }
Exemplo n.º 17
0
 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));
 }
Exemplo n.º 18
0
 private bool hasErrors(OrderHeaderViewModel model)
 {
     return(StringsUtil.ValidateString(model.PaymentMethod) && StringsUtil.ValidateString(model.ShippingMethod) &&
            ValidateShipping(model.Shipping) && ValidateBilling(model.Billing));
 }