Пример #1
0
        public static async Task CreateAdversaryAsync(GameServiceClient client)
        {
            var adversary = new Adversary();

            adversary.Name          = ConsoleUtility.GetUserInput("Adversary Name: ");
            adversary.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            adversary.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Adversary: '{adversary.Name}', in gamePackage '{adversary.GamePackageId}' with abilities [{adversary.AbilityIds.Select(x => x.ToString()).Join(", ")}]"))
            {
                await CreateAdversaryAsync(client);

                return;
            }

            var createRequest = new CreateAdversariesRequest();

            createRequest.Adversaries.Add(adversary);
            var createReply = await client.CreateAdversariesAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create adversary: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Adversary '{createReply.Adversaries.First().Name}' was created with Id '{createReply.Adversaries.First().Id}'");
            }
        }
Пример #2
0
        public static async Task CreateHenchmanAsync(GameServiceClient client)
        {
            var henchman = new Henchman();

            henchman.Name          = ConsoleUtility.GetUserInput("Henchman Name: ");
            henchman.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            henchman.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Henchman: '{henchman.Name}', in gamePackage '{henchman.GamePackageId}' with abilities [{henchman.AbilityIds.Select(x => x.ToString()).Join(", ")}]"))
            {
                await CreateHenchmanAsync(client);

                return;
            }

            var createRequest = new CreateHenchmenRequest();

            createRequest.Henchmen.Add(henchman);
            var createReply = await client.CreateHenchmenAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create henchman: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Henchman '{createReply.Henchmen.First().Name}' was created with Id '{createReply.Henchmen.First().Id}'");
            }
        }
Пример #3
0
 public static async Task DisplayNeutralsAsync(GameServiceClient client, IReadOnlyList <int> neutralIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var neutral in await GetNeutralsAsync(client, neutralIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{neutral}");
     }
 }
Пример #4
0
 public static async Task DisplayAlliesAsync(GameServiceClient client, IReadOnlyList <int> allyIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var ally in await GetAlliesAsync(client, allyIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{ally}");
     }
 }
Пример #5
0
        private static IEnumerable <CardRequirement> GetCardCountRequirements()
        {
            var cardType = ConsoleUtility.GetUserInputRequiredValue("What type of card count is changing?", "Ally", "Adversary", "Mastermind", "Henchman", "Bystander");
            var changesBasedOnPlayerCount = ConsoleUtility.GetUserInputBool("Does the card count change based on number of players?");

            if (!changesBasedOnPlayerCount)
            {
                int additionalSets = ConsoleUtility.GetUserInputInt("Additional sets: ");

                yield return(cardType switch
                {
                    "Ally" => new CardRequirement {
                        AdditionalSetCount = additionalSets, CardSetType = CardSetType.CardSetAlly
                    },
                    "Adversary" => new CardRequirement {
                        AdditionalSetCount = additionalSets, CardSetType = CardSetType.CardSetAdversary
                    },
                    "Mastermind" => new CardRequirement {
                        AdditionalSetCount = additionalSets, CardSetType = CardSetType.CardSetMastermind
                    },
                    "Henchman" => new CardRequirement {
                        AdditionalSetCount = additionalSets, CardSetType = CardSetType.CardSetHenchman
                    },
                    "Bystander" => new CardRequirement {
                        AdditionalSetCount = additionalSets, CardSetType = CardSetType.CardSetBystander
                    },
                    _ => throw new Exception("Failed to match on cardType")
                });
Пример #6
0
        public static async Task CreateNeutralAsync(GameServiceClient client)
        {
            var neutral = new Neutral();

            neutral.Name          = ConsoleUtility.GetUserInput("Neutral Name: ");
            neutral.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            if (!ConsoleUtility.ShouldContinue($"Creating Neutral: '{neutral.Name}', in gamePackage '{neutral.GamePackageId}'"))
            {
                await CreateNeutralAsync(client);

                return;
            }

            var createRequest = new CreateNeutralsRequest();

            createRequest.Neutrals.Add(neutral);
            var createReply = await client.CreateNeutralsAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create neutral: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Neutral '{createReply.Neutrals.First().Name}' was created with Id '{createReply.Neutrals.First().Id}'");
            }
        }
Пример #7
0
 public static async Task DisplayMastermindsAsync(GameServiceClient client, IReadOnlyList <int> mastermindIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var mastermind in await GetMastermindsAsync(client, mastermindIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{mastermind}");
     }
 }
Пример #8
0
        public static async Task DisplayGamePackageAsync(GameServiceClient client, IReadOnlyList <int> packageIds, string name)
        {
            var packagesRequest = new GetGamePackagesRequest();

            if (packageIds != null && packageIds.Count() != 0)
            {
                packagesRequest.GamePackageIds.AddRange(packageIds);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                packagesRequest.Name = name;
            }
            else
            {
                throw new ArgumentException("Either 'packageId' or 'name' must be non-null");
            }

            packagesRequest.Fields.AddRange(new[] { GamePackageField.Id, GamePackageField.Name, GamePackageField.PackageType, GamePackageField.BaseMap });
            var packagesReply = await client.GetGamePackagesAsync(packagesRequest);

            if (packagesReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine(packagesReply.Status.Message);
            }

            foreach (var gamePackage in packagesReply.Packages)
            {
                ConsoleUtility.WriteLine(gamePackage.ToString());
            }
        }
Пример #9
0
 public static async Task DisplaySchemesAsync(GameServiceClient client, IReadOnlyList <int> schemeIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var scheme in await GetSchemesAsync(client, schemeIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{scheme}");
     }
 }
Пример #10
0
 public static async Task DisplayHenchmenAsync(GameServiceClient client, IReadOnlyList <int> henchmanIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
 {
     foreach (var henchman in await GetHenchmenAsync(client, henchmanIds, name, nameMatchStyle))
     {
         ConsoleUtility.WriteLine($"{henchman}");
     }
 }
Пример #11
0
        public static async Task CreateSchemeAsync(GameServiceClient client)
        {
            var scheme = new Scheme();

            scheme.Name          = ConsoleUtility.GetUserInput("Scheme Name: ");
            scheme.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            scheme.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));
            scheme.HasEpicSide = ConsoleUtility.GetUserInputBool("Has Epic side?");
            scheme.CardRequirements.AddRange(await CardRequirementUtility.GetCardRequirements(client, scheme.GamePackageId, true));
            scheme.TwistRequirements.AddRange(TwistRequirementUtility.GetTwistRequirements(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Scheme: {scheme}"))
            {
                await CreateSchemeAsync(client);

                return;
            }

            var createRequest = new CreateSchemesRequest();

            createRequest.Schemes.Add(scheme);
            var createReply = await client.CreateSchemesAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create scheme: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Scheme '{createReply.Schemes.First().Name}' was created with Id '{createReply.Schemes.First().Id}'");
            }
        }
Пример #12
0
 public static async Task CreateItemAsync(GameServiceClient client, string[] args)
 {
     if (args.FirstOrDefault() == "t")
     {
         await CreateTeamAsync(client);
     }
     else if (args.FirstOrDefault() == "h")
     {
         await CreateHenchmanAsync(client);
     }
     else if (args.FirstOrDefault() == "n")
     {
         await CreateNeutralAsync(client);
     }
     else if (args.FirstOrDefault() == "al")
     {
         await CreateAllyAsync(client);
     }
     else if (args.FirstOrDefault() == "ad")
     {
         await CreateAdversaryAsync(client);
     }
     else if (args.FirstOrDefault() == "m")
     {
         await MastermindUtility.CreateMastermindAsync(client);
     }
     else if (args.FirstOrDefault() == "s")
     {
         await SchemeUtility.CreateSchemeAsync(client);
     }
     else
     {
         ConsoleUtility.WriteLine("Must supply the type of item you want to create. (t|h|ad|n|al|m|s)");
     }
 }
Пример #13
0
        public static async Task CreateMastermindAsync(GameServiceClient client)
        {
            var mastermind = new Mastermind();

            mastermind.Name          = ConsoleUtility.GetUserInput("Mastermind Name: ");
            mastermind.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            mastermind.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));
            mastermind.HasEpicSide = ConsoleUtility.GetUserInputBool("Has Epic side?");
            mastermind.CardRequirements.AddRange(await CardRequirementUtility.GetCardRequirements(client, mastermind.GamePackageId, true));

            if (!ConsoleUtility.ShouldContinue($"Creating Mastermind: {mastermind}"))
            {
                await CreateMastermindAsync(client);

                return;
            }

            var createRequest = new CreateMastermindsRequest();

            createRequest.Masterminds.Add(mastermind);
            var createReply = await client.CreateMastermindsAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create mastermind: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Mastermind '{createReply.Masterminds.First().Name}' was created with Id '{createReply.Masterminds.First().Id}'");
            }
        }
Пример #14
0
        public static async ValueTask <int> SelectGamePackageId(GameServiceClient client)
        {
            var gamePackageId = 0;
            IReadOnlyList <GamePackage> gamePackages = null;

            while (gamePackageId == 0)
            {
                var input = ConsoleUtility.GetUserInput("What game package is this entry associated with (? to see listing): ");
                if (input == "?")
                {
                    gamePackages = await DisplayGamePackagesSimpleAsync(client, gamePackages);
                }
                else if (!string.IsNullOrWhiteSpace(input))
                {
                    gamePackages = await GetGamePackagesAsync(client, gamePackages);

                    if (int.TryParse(input, out int id))
                    {
                        gamePackageId = gamePackages.Select(x => x.Id).FirstOrDefault(x => x == id, 0);
                        if (gamePackageId == 0)
                        {
                            ConsoleUtility.WriteLine($"Game Package Id '{input}' was not found");
                        }
                    }
                    else
                    {
                        var matchingGamePackages = gamePackages.Where(x => Regex.IsMatch(x.Name.ToLower(), input.ToLower())).ToList();
                        if (matchingGamePackages.Count == 0)
                        {
                            ConsoleUtility.WriteLine($"Game Package Name '{input}' was not found");
                        }
                        else if (matchingGamePackages.Count != 1)
                        {
                            ConsoleUtility.WriteLine($"Game Package Name '{input}' matched multiple GamePackages ({matchingGamePackages.Select(x => x.Name).Join(", ")})");
                        }
                        else
                        {
                            gamePackageId = matchingGamePackages.First().Id;
                        }
                    }
                }

                if (gamePackageId != 0)
                {
                    var gamePackage = gamePackages.First(x => x.Id == gamePackageId);
                    if (!ConsoleUtility.ShouldContinue($"Adding entry to game package '{gamePackage.Id}: {gamePackage.Name}':"))
                    {
                        gamePackageId = 0;
                    }
                }
            }

            return(gamePackageId);
        }
Пример #15
0
        public static async ValueTask <IReadOnlyList <GamePackage> > DisplayGamePackagesSimpleAsync(GameServiceClient client, IReadOnlyList <GamePackage> gamePackages)
        {
            gamePackages = await GetGamePackagesAsync(client, gamePackages);

            foreach (var gamePackage in gamePackages)
            {
                ConsoleUtility.WriteLine($"{gamePackage.Id}: {gamePackage.Name}");
            }

            return(gamePackages);
        }
Пример #16
0
        public static async Task <int> SelectTeamId(GameServiceClient client)
        {
            var teamId = 0;
            IReadOnlyList <Team> teams = null;

            while (teamId == 0)
            {
                var input = ConsoleUtility.GetUserInput("What team is this entry associated with (? to see listing): ");
                if (input == "?")
                {
                    teams = await DisplayTeamsSimpleAsync(client, teams);
                }
                else if (!string.IsNullOrWhiteSpace(input))
                {
                    teams = await GetTeamsAsync(client, teams);

                    if (int.TryParse(input, out int id))
                    {
                        teamId = teams.Select(x => x.Id).FirstOrDefault(x => x == id, 0);
                        if (teamId == 0)
                        {
                            ConsoleUtility.WriteLine($"Team Id '{input}' was not found");
                        }
                    }
                    else
                    {
                        var matchingTeams = teams.Where(x => Regex.IsMatch(x.Name.ToLower(), input.ToLower())).ToList();
                        if (matchingTeams.Count == 0)
                        {
                            ConsoleUtility.WriteLine($"Team Name '{input}' was not found");
                        }
                        else if (matchingTeams.Count != 1)
                        {
                            ConsoleUtility.WriteLine($"Team Name '{input}' matched multiple Teams ({matchingTeams.Select(x => x.Name).Join(", ")})");
                        }
                        else
                        {
                            teamId = matchingTeams.First().Id;
                        }
                    }
                }

                if (teamId != 0)
                {
                    var team = teams.First(x => x.Id == teamId);
                    if (!ConsoleUtility.ShouldContinue($"Adding entry to team '{team.Id}: {team.Name}':"))
                    {
                        teamId = 0;
                    }
                }
            }

            return(teamId);
        }
Пример #17
0
        public static async ValueTask <IReadOnlyList <Team> > DisplayTeamsSimpleAsync(GameServiceClient client, IReadOnlyList <Team> teams)
        {
            teams = await GetTeamsAsync(client, teams);

            foreach (var team in teams)
            {
                ConsoleUtility.WriteLine($"{team.Id}: {team.Name}");
            }

            return(teams);
        }
Пример #18
0
        public static async ValueTask <IReadOnlyList <Class> > DisplayClassesAsync(GameServiceClient client, IReadOnlyList <Class> classes)
        {
            classes = await GetClassesAsync(client, classes);

            foreach (var ability in classes)
            {
                ConsoleUtility.WriteLine($"{ability.Id}: {ability.Name}");
            }

            return(classes);
        }
Пример #19
0
        public static async ValueTask <IReadOnlyList <Ability> > DisplayAbilitiesAsync(GameServiceClient client, IReadOnlyList <Ability> abilities)
        {
            abilities = await GetAbilitiesAsync(client, abilities);

            foreach (var ability in abilities)
            {
                ConsoleUtility.WriteLine($"{ability.Id}: {ability.Name}");
            }

            return(abilities);
        }
Пример #20
0
        public static async ValueTask <IEnumerable <CardRequirement> > GetSingleCardRequirement(GameServiceClient client, int currentGamePackageId)
        {
            var result = ConsoleUtility.GetUserInputRequiredValue("What type of requirement is this?", "Count", "AdditionalCards");

            if (result == "Count")
            {
                return(GetCardCountRequirements());
            }
            if (result == "AdditionalCards")
            {
                return(await GetAdditionalCardRequirements(client, currentGamePackageId));
            }

            return(new CardRequirement[] { });
        }
Пример #21
0
        public static async ValueTask <IEnumerable <CardRequirement> > GetCardRequirements(GameServiceClient client, int currentGamePackageId, bool?defaultOption)
        {
            List <CardRequirement> cardRequirements = new List <CardRequirement>();

            if (ConsoleUtility.GetUserInputBool("Add card requirements:", defaultOption))
            {
                cardRequirements.AddRange(await GetSingleCardRequirement(client, currentGamePackageId));
            }

            while (cardRequirements.Count != 0 && ConsoleUtility.GetUserInputBool("Add another requirement?", false))
            {
                cardRequirements.AddRange(await GetSingleCardRequirement(client, currentGamePackageId));
            }

            return(cardRequirements);
        }
Пример #22
0
        public static async Task DisplayAllGamePackagesAsync(GameServiceClient client)
        {
            var request = new GetGamePackagesRequest();

            request.Fields.AddRange(new[] { GamePackageField.Id });
            var reply = await client.GetGamePackagesAsync(request);

            if (reply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine(reply.Status.Message);
            }

            foreach (var package in reply.Packages)
            {
                await DisplayGamePackageAsync(client, new[] { package.Id }, null);
            }
        }
Пример #23
0
        internal static IEnumerable <SchemeTwistRequirement> GetSingleTwistRequirement(GameServiceClient client)
        {
            var changesBasedOnPlayerCount = ConsoleUtility.GetUserInputBool("Does the twist requirement change based on the number of players? ", null);

            if (!changesBasedOnPlayerCount)
            {
                int twistCount = ConsoleUtility.GetUserInputInt("How many twists? ");

                yield return(new SchemeTwistRequirement
                {
                    SchemeTwistCount = twistCount,
                    Allowed = true
                });
            }
            else
            {
                bool schemeAllowedForSinglePlayer = ConsoleUtility.GetUserInputBool($"Is this scheme allowed for a single player? ");

                if (!schemeAllowedForSinglePlayer)
                {
                    yield return(new SchemeTwistRequirement
                    {
                        PlayerCount = 1,
                        Allowed = false
                    });
                }

                for (int i = schemeAllowedForSinglePlayer ? 1 : 2; i <= 5; i++)
                {
                    var playerMessage = i == 1 ? "player" : "players";
                    int twistCount    = ConsoleUtility.GetUserInputInt($"How many twists for {i} {playerMessage}? ");

                    yield return(new SchemeTwistRequirement
                    {
                        PlayerCount = i,
                        SchemeTwistCount = twistCount,
                        Allowed = true
                    });
                }
            }
        }
Пример #24
0
        public static async Task DisplayAbilitiesAsync(GameServiceClient client, IReadOnlyList <int> ids, string name)
        {
            var abilitiesRequest = new GetAbilitiesRequest();

            if (ids != null && ids.Count() != 0)
            {
                abilitiesRequest.AbilityIds.AddRange(ids);
            }
            else if (name != null)
            {
                abilitiesRequest.Name = name;
            }

            abilitiesRequest.AbilityFields.AddRange(new[] { AbilityField.Id, AbilityField.Name, AbilityField.Description, AbilityField.GamePackageName });

            var abilities = await client.GetAbilitiesAsync(abilitiesRequest);

            foreach (var ability in abilities.Abilities)
            {
                ConsoleUtility.WriteLine($"{ability.GamePackage.Name} - {ability.Name} - {ability.Description}");
            }
        }
Пример #25
0
        public static async Task DisplayTeamsAsync(GameServiceClient client, IReadOnlyList <int> teamIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
        {
            var request = new GetTeamsRequest();

            if (teamIds != null && teamIds.Count() != 0)
            {
                request.TeamIds.AddRange(teamIds);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                request.Name = name;
            }

            request.NameMatchStyle = nameMatchStyle;

            var teams = await client.GetTeamsAsync(request);

            foreach (var team in teams.Teams)
            {
                ConsoleUtility.WriteLine($"{team}");
            }
        }
Пример #26
0
        public static async Task DisplayClassesAsync(GameServiceClient client, IReadOnlyList <int> classIds = null, string name = null, NameMatchStyle nameMatchStyle = NameMatchStyle.MixedCase)
        {
            var request = new GetClassesRequest();

            if (classIds != null && classIds.Count() != 0)
            {
                request.ClassIds.AddRange(classIds);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                request.Name = name;
            }

            request.NameMatchStyle = nameMatchStyle;

            var classes = await client.GetClassesAsync(request);

            foreach (var @class in classes.Classes)
            {
                ConsoleUtility.WriteLine($"{@class}");
            }
        }
Пример #27
0
        public static async Task CreateTeamAsync(GameServiceClient client)
        {
            var teamName  = ConsoleUtility.GetUserInput("Team Name: ");
            var imagePath = ConsoleUtility.GetUserInput("Path to Image (on OneDrive): ");

            var createRequest = new CreateTeamsRequest();

            createRequest.Teams.Add(new Team {
                Name = teamName, ImagePath = imagePath
            });
            createRequest.CreateOptions.Add(CreateOptions.ErrorOnDuplicates);

            var reply = await client.CreateTeamsAsync(createRequest);

            if (reply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine(reply.Status.Message);
            }
            else
            {
                ConsoleUtility.WriteLine($"Team '{reply.Teams.First().Name}' was created with Id '{reply.Teams.First().Id}'");
            }
        }
Пример #28
0
        public static async Task DisplayAllAbilitiesAsync(GameServiceClient client)
        {
            var request = new GetGamePackagesRequest();

            request.Fields.AddRange(new[] { GamePackageField.Id, GamePackageField.Name, GamePackageField.PackageType, GamePackageField.BaseMap });
            var reply = await client.GetGamePackagesAsync(request);

            foreach (var gameData in reply.Packages.OrderBy(x => x.BaseMap).ThenBy(x => x.PackageType).ThenBy(x => x.Name))
            {
                var abilitiesRequest = new GetAbilitiesRequest
                {
                    GamePackageId = gameData.Id
                };

                abilitiesRequest.AbilityFields.AddRange(new[] { AbilityField.Id, AbilityField.Name, AbilityField.GamePackageName });

                var abilities = await client.GetAbilitiesAsync(abilitiesRequest);

                foreach (var ability in abilities.Abilities)
                {
                    ConsoleUtility.WriteLine($"{ability.GamePackage.Name} - {ability.Name}");
                }
            }
        }
Пример #29
0
        public static async ValueTask <IReadOnlyList <int> > SelectAbilityIds(GameServiceClient client)
        {
            List <int> abilityIds             = new List <int>();
            IReadOnlyList <Ability> abilities = null;

            while (true)
            {
                int abilityId = 0;

                var input = ConsoleUtility.GetUserInput("What ability is this entry associated with (? to see listing, empty to finish): ");

                if (input == "")
                {
                    if (ConsoleUtility.ShouldContinue($"Adding entry to abilities [{abilityIds.Select(x => x.ToString()).Join(", ")}]:"))
                    {
                        return(abilityIds);
                    }

                    return(await SelectAbilityIds(client));
                }

                if (input == "?")
                {
                    abilities = await DisplayAbilitiesAsync(client, abilities);
                }
                else if (!string.IsNullOrWhiteSpace(input))
                {
                    abilities = await GetAbilitiesAsync(client, abilities);

                    if (int.TryParse(input, out int id))
                    {
                        abilityId = abilities.Select(x => x.Id).FirstOrDefault(x => x == id, 0);
                        if (abilityId == 0)
                        {
                            ConsoleUtility.WriteLine($"Ability Id '{input}' was not found");
                        }
                    }
                    else
                    {
                        var matchingAbilities = abilities.Where(x => Regex.IsMatch(x.Name.ToLower(), input.ToLower())).ToList();
                        if (matchingAbilities.Count == 0)
                        {
                            ConsoleUtility.WriteLine($"Ability Name '{input}' was not found");
                        }
                        else if (matchingAbilities.Count != 1)
                        {
                            ConsoleUtility.WriteLine($"Ability Name '{input}' matched multiple Abilities({matchingAbilities.Select(x => x.Name).Join(", ")})");
                        }
                        else
                        {
                            abilityId = matchingAbilities.First().Id;
                        }
                    }
                }

                if (abilityId != 0)
                {
                    var ability = abilities.First(x => x.Id == abilityId);
                    if (ConsoleUtility.ShouldContinue($"Adding entry to ability '{ability.Id}: {ability.Name}':"))
                    {
                        abilityIds.Add(abilityId);
                    }
                }
            }
        }
Пример #30
0
        internal static async ValueTask <IEnumerable <ClassInfo> > SelectClassIds(GameServiceClient client)
        {
            List <ClassInfo>      classInfos = new List <ClassInfo>();
            IReadOnlyList <Class> classes    = null;

            while (true)
            {
                int classId = 0;

                int classCount = classInfos.Sum(x => x.Count);

                var input = ConsoleUtility.GetUserInput("What class is this entry associated with (? to see listing, empty to finish): ");

                if (input == "")
                {
                    if (classCount < 14)
                    {
                        ConsoleUtility.WriteLine($"Must supply a class count of at least 14 (currently {classCount})");
                    }
                    else
                    {
                        if (ConsoleUtility.ShouldContinue($"Adding entry to classes [{classInfos.Select(x => x.ToString()).Join(", ")}] (Total {classCount}):"))
                        {
                            return(classInfos);
                        }

                        return(await SelectClassIds(client));
                    }
                }

                if (input == "?")
                {
                    classes = await DisplayClassesAsync(client, classes);
                }
                else if (!string.IsNullOrWhiteSpace(input))
                {
                    classes = await GetClassesAsync(client, classes);

                    if (int.TryParse(input, out int id))
                    {
                        classId = classes.Select(x => x.Id).FirstOrDefault(x => x == id, 0);
                        if (classId == 0)
                        {
                            ConsoleUtility.WriteLine($"Class Id '{input}' was not found");
                        }
                    }
                    else
                    {
                        var matchingClasses = classes.Where(x => Regex.IsMatch(x.Name.ToLower(), input.ToLower())).ToList();
                        if (matchingClasses.Count == 0)
                        {
                            ConsoleUtility.WriteLine($"Class Name '{input}' was not found");
                        }
                        else if (matchingClasses.Count != 1)
                        {
                            ConsoleUtility.WriteLine($"Class Name '{input}' matched multiple Classes ({matchingClasses.Select(x => x.Name).Join(", ")})");
                        }
                        else
                        {
                            classId = matchingClasses.First().Id;
                        }
                    }
                }

                if (classId != 0)
                {
                    var @class    = classes.First(x => x.Id == classId);
                    var cardCount = ConsoleUtility.GetUserInputInt("Enter number of cards for this class: ");

                    var classInfo = new ClassInfo {
                        ClassId = @class.Id, Count = cardCount
                    };

                    if (ConsoleUtility.ShouldContinue($"Adding entry to clases '{@class.Id}: {@class.Name}', count '{classInfo.Count}':"))
                    {
                        classInfos.Add(classInfo);
                    }
                }
            }
        }