public static async Task CreateAllyAsync(GameServiceClient client) { var ally = new Ally(); ally.Name = ConsoleUtility.GetUserInput("Ally Name: "); ally.GamePackageId = await GamePackageUtility.SelectGamePackageId(client); ally.TeamId = await TeamUtility.SelectTeamId(client); ally.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client)); ally.Classes.AddRange(await ClassUtility.SelectClassIds(client)); if (!ConsoleUtility.ShouldContinue($"Creating Ally: '{ally.Name}', in gamePackage '{ally.GamePackageId}' on team '{ally.TeamId}' with abilities [{ally.AbilityIds.Select(x => x.ToString()).Join(", ")}]")) { await CreateAllyAsync(client); return; } var createRequest = new CreateAlliesRequest(); createRequest.Allies.Add(ally); var createReply = await client.CreateAlliesAsync(createRequest); if (createReply.Status.Code != 200) { ConsoleUtility.WriteLine($"Failed to create ally: {createReply.Status.Message}"); } else { ConsoleUtility.WriteLine($"Ally '{createReply.Allies.First().Name}' was created with Id '{createReply.Allies.First().Id}'"); } }
private static async ValueTask <IReadOnlyList <Ally> > CreateAllies(GameServiceClient client, IReadOnlyList <GamePackage> packages, IReadOnlyList <Ability> abilities, IReadOnlyList <Team> teams, IReadOnlyList <Class> classes) { ConsoleUtility.WriteLine("Creating allies"); List <Ally> result = (await AllyUtility.GetAlliesAsync(client, null)).ToList(); if (result.Any()) { return(result); } var noTeam = teams.First(x => x.Name == "None"); 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 allyElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Ally")) { var request = new CreateAlliesRequest(); request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates); var ally = new Ally(); ally.Name = allyElement.Attribute("Name").Value; ally.GamePackageId = activeGamePackage.Id; ally.AbilityIds.AddRange(GetMatchingItems(allyElement.Attribute("Abilities")?.Value, name => abilities.First(x => x.Name == name)).Select(x => x.Id)); ally.TeamId = GetMatchingItems(allyElement.Attribute("Team")?.Value, name => teams.FirstOrDefault(x => x.Name == name, noTeam)).First().Id; ally.Classes.AddRange(GetMatchingItems(allyElement.Attribute("Classes")?.Value, name => ParseClassInfo(classes, name))); request.Allies.Add(ally); var reply = await client.CreateAlliesAsync(request); if (reply.Status.Code != 200) { ConsoleUtility.WriteLine($"Failed to create '{ally.Name}': {reply.Status.Message}"); } result.AddRange(reply.Allies); } ConsoleUtility.WriteLine($"Completed: {name}"); } return(result); }