More additions, lucky card based on day, redo of migrations because i messed up

This commit is contained in:
2021-11-01 14:59:36 -04:00
parent 685f09a889
commit 0b94455b4b
48 changed files with 284 additions and 7404 deletions

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using TOOHUCardAPI.Data.Repositories;
using TOOHUCardAPI.DTO;
namespace TOOHUCardAPI.Data.Services
{
public class GameConfigurationService
{
private readonly ILogger<GameConfigurationService> _logger;
private readonly CardRepository _cardRepository;
private List<string> _cardBlacklist = new()
{
"_",
"BonusEgg"
};
public GameConfigurationService(ILogger<GameConfigurationService> logger, CardRepository cardRepository)
{
_logger = logger;
_cardRepository = cardRepository;
}
public async Task<GameConfigResponse> GetGameConfiguration()
{
var random = new Random(DateTime.Now.Date.GetHashCode());
GameConfigResponse response = new GameConfigResponse();
var cards = await _cardRepository.GetAllCards();
var validCards =
cards.Where(card => _cardBlacklist.Select(bl => !card.CardName.Contains(bl)).All(res => res))
.Select(card => card.CardName).Append("all");
var enumerable = validCards as string[] ?? validCards.ToArray();
var index = random.Next(0, enumerable.Length);
response.LuckCard = enumerable.ElementAt(index);
return response;
}
}
}