コード例 #1
0
        public static async Task CreateHenchmanAsync(GameServiceClient client)
        {
            var henchman = new Henchman();

            henchman.Name          = ConsoleUtility.GetUserInput("Henchman Name: ");
            henchman.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            henchman.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));

            if (!ConsoleUtility.ShouldContinue($"Creating Henchman: '{henchman.Name}', in gamePackage '{henchman.GamePackageId}' with abilities [{henchman.AbilityIds.Select(x => x.ToString()).Join(", ")}]"))
            {
                await CreateHenchmanAsync(client);

                return;
            }

            var createRequest = new CreateHenchmenRequest();

            createRequest.Henchmen.Add(henchman);
            var createReply = await client.CreateHenchmenAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create henchman: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Henchman '{createReply.Henchmen.First().Name}' was created with Id '{createReply.Henchmen.First().Id}'");
            }
        }
コード例 #2
0
        private static async ValueTask <IReadOnlyList <Henchman> > CreateHenchmen(GameServiceClient client, IReadOnlyList <GamePackage> packages, IReadOnlyList <Ability> abilities)
        {
            ConsoleUtility.WriteLine("Creating henchmen");
            List <Henchman> result = (await HenchmanUtility.GetHenchmenAsync(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 henchmanElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Henchman"))
                {
                    var request = new CreateHenchmenRequest();
                    request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates);

                    var henchman = new Henchman();
                    henchman.Name          = henchmanElement.Attribute("Name").Value;
                    henchman.GamePackageId = activeGamePackage.Id;
                    henchman.AbilityIds.AddRange(GetMatchingItems(henchmanElement.Attribute("Abilities")?.Value, name => abilities.First(x => x.Name == name)).Select(x => x.Id));

                    request.Henchmen.Add(henchman);

                    var reply = await client.CreateHenchmenAsync(request);

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

                    result.AddRange(reply.Henchmen);
                }

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

            return(result);
        }
コード例 #3
0
        public static async Task <CreateHenchmenReply> CreateHenchmenAsync(CreateHenchmenRequest request, ServerCallContext context)
        {
            using var db = new LegendaryDatabase();
            var connector = DbConnector.Create(db.Connection, new DbConnectorSettings {
                AutoOpen = true, LazyOpen = true
            });

            var reply = new CreateHenchmenReply {
                Status = new Status {
                    Code = 200
                }
            };

            List <int> newHenchmenIds = new List <int>();

            foreach (var henchman in request.Henchmen)
            {
                // Validate the GamePackageId
                var packageRequest = new GetGamePackagesRequest();
                packageRequest.GamePackageIds.Add(henchman.GamePackageId);
                packageRequest.Fields.Add(GamePackageField.Id);
                var packageReply = await GamePackageUtility.GetGamePackagesAsync(packageRequest, context);

                if (packageReply.Status.Code != 200)
                {
                    reply.Status = packageReply.Status;
                    return(reply);
                }

                // Validate the AbilityIds
                var abilitiesRequest = new GetAbilitiesRequest();
                abilitiesRequest.AbilityIds.AddRange(henchman.AbilityIds);
                abilitiesRequest.AbilityFields.Add(AbilityField.Id);
                var abilitiesReply = await AbilityUtility.GetAbilitiesAsync(abilitiesRequest, context);

                if (abilitiesReply.Status.Code != 200)
                {
                    reply.Status = abilitiesReply.Status;
                    return(reply);
                }

                // Verify that this henchman doesn't already exist
                var henchmanRequest = new GetHenchmenRequest();
                henchmanRequest.Name = henchman.Name;
                henchmanRequest.Fields.AddRange(new[] { HenchmanField.HenchmanId, HenchmanField.HenchmanName, HenchmanField.HenchmanGamePackageId });
                henchmanRequest.NameMatchStyle = NameMatchStyle.MixedCase;
                var henchmanReply = await GetHenchmenAsync(henchmanRequest, context);

                if (henchmanReply.Status.Code == 200 && henchmanReply.Henchmen.Any())
                {
                    var matchingHenchman = henchmanReply.Henchmen.First();
                    reply.Status = new Status {
                        Code = 400, Message = $"Henchman {matchingHenchman.Id} with name '{matchingHenchman.Name}' was found in game package '{matchingHenchman.GamePackageId}'"
                    };
                    return(reply);
                }

                // Create the henchman
                var newHenchmanId = ((int)(await connector.Command($@"
					insert
						into {DatabaseDefinition.DefaultTableName}
							({DatabaseDefinition.ColumnName[HenchmanField.HenchmanName]})
									values (@HenchmanName);
								select last_insert_id();"                                ,
                                                                   ("HenchmanName", henchman.Name))
                                           .QuerySingleAsync <ulong>()));

                // Add to game package
                await connector.Command(
                    $@"
						insert
							into {TableNames.GamePackageHenchmen}
								({DatabaseDefinition.ColumnName[HenchmanField.HenchmanId]}, {GamePackageUtility.DatabaseDefinition.ColumnName[GamePackageField.Id]})
							values (@HenchmanId, @GamePackageId);"                            ,
                    ("HenchmanId", newHenchmanId),
                    ("GamePackageId", henchman.GamePackageId))
                .ExecuteAsync();

                // Link abilities
                foreach (var abilityId in henchman.AbilityIds)
                {
                    await connector.Command(
                        $@"
							insert
								into {TableNames.HenchmanAbilities}
									({DatabaseDefinition.ColumnName[HenchmanField.HenchmanId]}, {AbilityUtility.DatabaseDefinition.ColumnName[AbilityField.Id]})
								values (@HenchmanId, @AbilityId);"                                ,
                        ("HenchmanId", newHenchmanId),
                        ("AbilityId", abilityId))
                    .ExecuteAsync();
                }

                newHenchmenIds.Add(newHenchmanId);
            }

            // Get all of the created henchmen
            var finalRequest = new GetHenchmenRequest();

            finalRequest.HenchmanIds.AddRange(newHenchmenIds);
            var finalReply = await GetHenchmenAsync(finalRequest, context);

            reply.Status = finalReply.Status;
            reply.Henchmen.AddRange(finalReply.Henchmen);

            return(reply);
        }
コード例 #4
0
 public override async Task <CreateHenchmenReply> CreateHenchmen(CreateHenchmenRequest request, ServerCallContext context)
 {
     return(await HenchmanUtility.CreateHenchmenAsync(request, context));
 }