예제 #1
0
        private static async ValueTask <IReadOnlyList <Mastermind> > CreateMasterminds(GameServiceClient client, IReadOnlyList <Ability> abilities, IReadOnlyList <GamePackage> packages)
        {
            ConsoleUtility.WriteLine("Creating masterminds");
            List <Mastermind> result = (await MastermindUtility.GetMastermindsAsync(client, null)).ToList();

            if (result.Any())
            {
                return(result);
            }

            foreach (var file in Directory.EnumerateFiles(@"C:\Users\Ryan\SkyDrive\code\LegendaryGameStarter\LegendaryGameModel2\GameSets", s_fileMask))
            {
                var doc = XDocument.Load(file);

                var name = doc.Element("Set").Attribute("Name").Value;
                var activeGamePackage = packages.FirstOrDefault(x => x.Name == name);
                if (activeGamePackage == null)
                {
                    ConsoleUtility.WriteLine($"Failed to find matching game package for {file}");
                }

                foreach (var mastermindElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Mastermind"))
                {
                    var request = new CreateMastermindsRequest();
                    request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates);

                    var mastermind = new Mastermind();
                    mastermind.Name          = mastermindElement.Attribute("Name").Value;
                    mastermind.GamePackageId = activeGamePackage.Id;
                    mastermind.AbilityIds.AddRange(GetMatchingItems(mastermindElement.Attribute("Abilities")?.Value, name => abilities.First(x => x.Name == name)).Select(x => x.Id));
                    mastermind.CardRequirements.AddRange(GetCardRequirements(client, mastermindElement, activeGamePackage.Id));
                    mastermind.HasEpicSide = (mastermindElement.Attribute("HasEpicSide")?.Value.ToLower() ?? "false") == "true";

                    request.Masterminds.Add(mastermind);

                    var reply = await client.CreateMastermindsAsync(request);

                    if (reply.Status.Code != 200)
                    {
                        ConsoleUtility.WriteLine($"Failed to create '{mastermind.Name}': {reply.Status.Message}");
                    }

                    result.AddRange(reply.Masterminds);
                }

                ConsoleUtility.WriteLine($"Completed: {name}");
            }

            return(result);
        }
예제 #2
0
 public override async Task <GetMastermindsReply> GetMasterminds(GetMastermindsRequest request, ServerCallContext context)
 {
     return(await MastermindUtility.GetMastermindsAsync(request, context));
 }