Пример #1
0
        internal static async ValueTask <int> AddCardRequirement(CardRequirement requirement)
        {
            using var db = new LegendaryDatabase();
            var connector = DbConnector.Create(db.Connection, new DbConnectorSettings {
                AutoOpen = true, LazyOpen = true
            });

            // Create new card requirement
            var insertColumnInfo   = GetInsertColumnValue(requirement);
            var insertCardTypeInfo = await GetInsertCardTypeValue(requirement, connector);

            var query = $@"insert into {TableNames.CardRequirements} ({insertColumnInfo.Name}, {insertCardTypeInfo.Name}) values (@{insertColumnInfo.Name}, @{insertCardTypeInfo.Name}); select last_insert_id();";

            return((int)await connector.Command(query,
                                                insertColumnInfo,
                                                insertCardTypeInfo)
                   .QuerySingleAsync <ulong>());
        }
Пример #2
0
        private static (string Name, object Value) GetInsertColumnValue(CardRequirement requirement)
        {
            if (requirement.CardRequirementType == CardRequirementType.AdditionalSetCount)
            {
                return(DatabaseDefinition.ColumnName[CardRequirement.AdditionalSetCountFieldNumber], requirement.AdditionalSetCount);
            }
            if (requirement.CardRequirementType == CardRequirementType.SpecificRequiredSet)
            {
                return(DatabaseDefinition.ColumnName[CardRequirement.RequiredSetIdFieldNumber], requirement.RequiredSetId);
            }
            if (requirement.CardRequirementType == CardRequirementType.NamedSet)
            {
                return(DatabaseDefinition.ColumnName[CardRequirement.RequiredSetNameFieldNumber], requirement.RequiredSetName);
            }
            if (requirement.CardRequirementType == CardRequirementType.Unset)
            {
                throw new Exception($"Client must set CardRequirementType");
            }

            throw new Exception($"Didn't know how to handle {requirement}.");
        }
Пример #3
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);
        }
Пример #4
0
 public static async ValueTask <(string Name, int Value)> GetInsertCardTypeValue(CardRequirement requirement, DbConnector connector)
 {
     return(await GetInsertCardTypeValue(requirement.CardSetType, connector));
 }