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}'"); } }
private static async ValueTask <IReadOnlyList <Adversary> > CreateAdversaries(GameServiceClient client, IReadOnlyList <GamePackage> packages, IReadOnlyList <Ability> abilities) { ConsoleUtility.WriteLine("Creating adversaries"); List <Adversary> result = (await AdversaryUtility.GetAdversariesAsync(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 adversaryElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Adversary")) { var request = new CreateAdversariesRequest(); request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates); var adversary = new Adversary(); adversary.Name = adversaryElement.Attribute("Name").Value; adversary.GamePackageId = activeGamePackage.Id; adversary.AbilityIds.AddRange(GetMatchingItems(adversaryElement.Attribute("Abilities")?.Value, name => abilities.First(x => x.Name == name)).Select(x => x.Id)); request.Adversaries.Add(adversary); var reply = await client.CreateAdversariesAsync(request); if (reply.Status.Code != 200) { ConsoleUtility.WriteLine($"Failed to create '{adversary.Name}': {reply.Status.Message}"); } result.AddRange(reply.Adversaries); } ConsoleUtility.WriteLine($"Completed: {name}"); } return(result); }