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); }
private static CardRequirement GetCardSetRequirement(GameServiceClient client, string cardName, int gamePackageId, CardSetType cardSetType) { if (cardSetType == CardSetType.CardSetAlly) { var allies = AllyUtility.GetAlliesAsync(client, name: cardName, nameMatchStyle: NameMatchStyle.Exact).Result; if (allies.Count() != 0) { return(new CardRequirement { RequiredSetId = allies.FirstOrDefault(x => x.GamePackageId == gamePackageId, allies.First()).Id, CardSetType = CardSetType.CardSetAlly, CardRequirementType = CardRequirementType.SpecificRequiredSet }); } throw new Exception($"Couldn't find Ally named {cardName}"); } if (cardSetType == CardSetType.CardSetAdversary) { var adversaries = AdversaryUtility.GetAdversariesAsync(client, name: cardName, nameMatchStyle: NameMatchStyle.Exact).Result; if (adversaries.Count() != 0) { return(new CardRequirement { RequiredSetId = adversaries.FirstOrDefault(x => x.GamePackageId == gamePackageId, adversaries.First()).Id, CardSetType = CardSetType.CardSetAdversary, CardRequirementType = CardRequirementType.SpecificRequiredSet }); } throw new Exception($"Couldn't find Adversary named {cardName}"); } if (cardSetType == CardSetType.CardSetNeutral) { var neutrals = NeutralUtility.GetNeutralsAsync(client, name: cardName, nameMatchStyle: NameMatchStyle.Exact).Result; if (neutrals.Count() != 0) { return(new CardRequirement { RequiredSetId = neutrals.FirstOrDefault(x => x.GamePackageId == gamePackageId, neutrals.First()).Id, CardSetType = CardSetType.CardSetNeutral, CardRequirementType = CardRequirementType.SpecificRequiredSet }); } throw new Exception($"Couldn't find Neutral named {cardName}"); } if (cardSetType == CardSetType.CardSetHenchman) { var henchmen = HenchmanUtility.GetHenchmenAsync(client, name: cardName, nameMatchStyle: NameMatchStyle.Exact).Result; if (henchmen.Count() != 0) { return(new CardRequirement { RequiredSetId = henchmen.FirstOrDefault(x => x.GamePackageId == gamePackageId, henchmen.First()).Id, CardSetType = CardSetType.CardSetHenchman, CardRequirementType = CardRequirementType.SpecificRequiredSet }); } throw new Exception($"Couldn't find Henchman named {cardName}"); } throw new Exception($"Coudn't figure out how to handle {cardSetType}"); }
public override async Task <CreateAlliesReply> CreateAllies(CreateAlliesRequest request, ServerCallContext context) { return(await AllyUtility.CreateAlliesAsync(request, context)); }