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}'"); } }
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); }