public static async Task <GetAbilitiesReply> GetAbilitiesAsync(GetAbilitiesRequest request, ServerCallContext context) { using var db = new LegendaryDatabase(); var connector = DbConnector.Create(db.Connection, new DbConnectorSettings { AutoOpen = true, LazyOpen = true }); var reply = new GetAbilitiesReply { Status = new Status { Code = 200 } }; var select = DatabaseDefinition.BuildSelectStatement(request.AbilityFields); var joins = DatabaseDefinition.BuildRequiredJoins(request.AbilityFields); var where = request.GamePackageId != 0 ? $"where { DatabaseDefinition.BuildWhereStatement(AbilityField.GamePackageId, WhereStatementType.Equals)}" : request.AbilityIds.Count() != 0 ? $"where { DatabaseDefinition.BuildWhereStatement(AbilityField.Id, WhereStatementType.Includes)}" : !string.IsNullOrWhiteSpace(request.Name) ? $"where { DatabaseDefinition.BuildWhereStatement(AbilityField.Name, WhereStatementType.Like)}" : ""; var whereMatch = request.GamePackageId != 0 ? new (string, object)[] { (DatabaseDefinition.GetSelectResult(AbilityField.GamePackageId), request.GamePackageId) } :
public static async Task <GetHenchmenReply> GetHenchmenAsync(GetHenchmenRequest request, ServerCallContext context) { using var db = new LegendaryDatabase(); var connector = DbConnector.Create(db.Connection, new DbConnectorSettings { AutoOpen = true, LazyOpen = true }); var reply = new GetHenchmenReply { Status = new Status { Code = 200 } }; if (request.Fields.Count() == 0) { request.Fields.AddRange(DatabaseDefinition.BasicFields); } // Need to remove abilityIds field because it's handled separately from the main db request var includeAbilityIds = request.Fields.Remove(HenchmanField.HenchmanAbilityIds); var select = DatabaseDefinition.BuildSelectStatement(request.Fields); var joins = DatabaseDefinition.BuildRequiredJoins(request.Fields); var where = !string.IsNullOrWhiteSpace(request.Name) ? $"where { DatabaseDefinition.BuildWhereStatement(HenchmanField.HenchmanName, DatabaseUtility.GetWhereComparisonType(request.NameMatchStyle))}" : request.HenchmanIds.Count() != 0 ? $"where { DatabaseDefinition.BuildWhereStatement(HenchmanField.HenchmanId, WhereStatementType.Includes)}" : ""; var whereMatch = !string.IsNullOrWhiteSpace(request.Name) ? new (string, object)[] { (DatabaseDefinition.GetSelectResult(HenchmanField.HenchmanName), request.NameMatchStyle == NameMatchStyle.Similar ? $"%{request.Name}%" : request.Name) } :
public static async Task <GetNeutralsReply> GetNeutralsAsync(GetNeutralsRequest request, ServerCallContext context) { using var db = new LegendaryDatabase(); var connector = DbConnector.Create(db.Connection, new DbConnectorSettings { AutoOpen = true, LazyOpen = true }); var reply = new GetNeutralsReply { Status = new Status { Code = 200 } }; var select = DatabaseDefinition.BuildSelectStatement(request.Fields); var joins = DatabaseDefinition.BuildRequiredJoins(request.Fields); var where = !string.IsNullOrWhiteSpace(request.Name) ? $"where { DatabaseDefinition.BuildWhereStatement(NeutralField.NeutralName, DatabaseUtility.GetWhereComparisonType(request.NameMatchStyle))}" : request.NeutralIds.Count() != 0 ? $"where { DatabaseDefinition.BuildWhereStatement(NeutralField.NeutralId, WhereStatementType.Includes)}" : ""; var whereMatch = !string.IsNullOrWhiteSpace(request.Name) ? new (string, object)[] { (DatabaseDefinition.GetSelectResult(NeutralField.NeutralName), request.NameMatchStyle == NameMatchStyle.Similar ? $"%{request.Name}%" : request.Name) } :
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))); }