Example #1
0
        private static SchemeTwistRequirement MapSchemeTwistRequirement(IDataRecord data, IReadOnlyList <int> fields)
        {
            var schemeTwistRequirement = new SchemeTwistRequirement();

            if (fields.Count == 0)
            {
                fields = DatabaseDefinition.BasicFields;
            }

            if (fields.Contains(SchemeTwistRequirement.IdFieldNumber))
            {
                schemeTwistRequirement.Id = data.Get <int>(DatabaseDefinition.GetSelectResult(SchemeTwistRequirement.IdFieldNumber));
            }
            if (fields.Contains(SchemeTwistRequirement.SchemeIdFieldNumber))
            {
                schemeTwistRequirement.SchemeId = data.Get <int>(DatabaseDefinition.GetSelectResult(SchemeTwistRequirement.SchemeIdFieldNumber));
            }
            if (fields.Contains(SchemeTwistRequirement.PlayerCountFieldNumber))
            {
                schemeTwistRequirement.PlayerCount = data.Get <int>(DatabaseDefinition.GetSelectResult(SchemeTwistRequirement.PlayerCountFieldNumber));
            }
            if (fields.Contains(SchemeTwistRequirement.SchemeTwistCountFieldNumber))
            {
                schemeTwistRequirement.SchemeTwistCount = data.Get <int>(DatabaseDefinition.GetSelectResult(SchemeTwistRequirement.SchemeTwistCountFieldNumber));
            }
            if (fields.Contains(SchemeTwistRequirement.AllowedFieldNumber))
            {
                schemeTwistRequirement.Allowed = data.Get <bool>(DatabaseDefinition.GetSelectResult(SchemeTwistRequirement.AllowedFieldNumber));
            }

            return(schemeTwistRequirement);
        }
Example #2
0
        private static CardRequirement MapCardRequirement(IDataRecord data, IReadOnlyList <int> fields)
        {
            var cardRequirement = new CardRequirement();

            if (fields.Count == 0)
            {
                fields = DatabaseDefinition.BasicFields;
            }

            if (fields.Contains(CardRequirement.CardRequirementIdFieldNumber))
            {
                cardRequirement.CardRequirementId = data.Get <int>(DatabaseDefinition.GetSelectResult(CardRequirement.CardRequirementIdFieldNumber));
            }
            if (fields.Contains(CardRequirement.RequiredSetIdFieldNumber))
            {
                cardRequirement.RequiredSetId = data.Get <int>(DatabaseDefinition.GetSelectResult(CardRequirement.RequiredSetIdFieldNumber));
            }
            if (fields.Contains(CardRequirement.AdditionalSetCountFieldNumber))
            {
                cardRequirement.AdditionalSetCount = data.Get <int>(DatabaseDefinition.GetSelectResult(CardRequirement.AdditionalSetCountFieldNumber));
            }
            if (fields.Contains(CardRequirement.RequiredSetNameFieldNumber))
            {
                cardRequirement.RequiredSetName = data.Get <string>(DatabaseDefinition.GetSelectResult(CardRequirement.RequiredSetNameFieldNumber)) ?? cardRequirement.RequiredSetName;
            }
            if (fields.Contains(CardRequirement.CardSetTypeFieldNumber))
            {
                cardRequirement.CardSetType = s_cardSetTypeIdMap[data.Get <int>(DatabaseDefinition.GetSelectResult(CardRequirement.CardSetTypeFieldNumber))];
            }
            if (fields.Contains(CardRequirement.PlayerCountFieldNumber))
            {
                cardRequirement.PlayerCount = data.Get <int>($"{TableNames.MatchedCardRequirements}_NumberOfPlayers");
            }

            return(cardRequirement);
        }
Example #3
0
        internal static async ValueTask <IReadOnlyList <CardRequirement> > GetCardRequirementsAsync(int ownerId)
        {
            using var db = new LegendaryDatabase();
            var connector = DbConnector.Create(db.Connection, new DbConnectorSettings {
                AutoOpen = true, LazyOpen = true
            });

            var fields = DatabaseDefinition.BasicFields;

            var numberOfPlayersResult = $"{TableNames.MatchedCardRequirements}_NumberOfPlayers";

            var selectStatement = DatabaseDefinition.BuildSelectStatement(fields);
            var joinStatement   = DatabaseDefinition.BuildRequiredJoins(fields);
            var whereStatement  = $"where {DatabaseDefinition.BuildWhereStatement(CardRequirement.OwnerIdFieldNumber, WhereStatementType.Equals)}";

            // Create new card requirement
            return(await connector.Command($@"
				select {selectStatement}
					from {DatabaseDefinition.DefaultTableName}
					{joinStatement}
					{whereStatement};"                    ,
                                           (DatabaseDefinition.GetSelectResult(CardRequirement.OwnerIdFieldNumber), ownerId))
                   .QueryAsync(x => MapCardRequirement(x, DatabaseDefinition.BasicFields)));
        }