More additions, lucky card based on day, redo of migrations because i messed up
This commit is contained in:
42
TOOHUCardAPI/Data/Services/GameConfigurationService.cs
Normal file
42
TOOHUCardAPI/Data/Services/GameConfigurationService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user