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;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
TOOHUCardAPI/Data/Services/RankService.cs
Normal file
10
TOOHUCardAPI/Data/Services/RankService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TOOHUCardAPI.Data.Services
|
||||
{
|
||||
public class RankService
|
||||
{
|
||||
private readonly ILogger<RankService> _logger;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,28 +26,29 @@ namespace TOOHUCardAPI.Data.Services
|
||||
{
|
||||
user.Point = Math.Max(0, user.Point + points);
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User with steamid {user.SteamId} was given {points} points. New total: {user.Point}");
|
||||
_logger.LogInformation("User with steamid {SteamId} was given {PointsGiven} points. New total: {PointsTotal}", user.SteamId, points, user.Point);
|
||||
}
|
||||
|
||||
public async Task<User> SaveKeyTotal(string steamId, int keyTotal, int keyUseCount)
|
||||
public async Task<User> SaveKeyTotal(long steamId, int keyTotal, int keyUseCount)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
_logger.LogInformation($"User {user.SteamId} just stored some key total data, previous total and use: ({user.KeyTotal},{user.KeyUseCount}). new ({keyTotal},{keyUseCount})");
|
||||
_logger.LogInformation("User {SteamId} just stored some key total data, previous total and use: ({OldKeyTotal},{OldKeyUseCount}). new ({NewKeyTotal},{NewKeyUseCount})", user.SteamId, user.KeyTotal, user.KeyUseCount, keyTotal, keyUseCount);
|
||||
user.KeyTotal = keyTotal;
|
||||
user.KeyUseCount = keyUseCount;
|
||||
await _userRepository.UpdateUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<int> ChangePowerMaxTotal(string steamId, int amt)
|
||||
public async Task<int> ChangePowerMaxTotal(long steamId, int amt)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
user.PowerMaxTotal = Math.Clamp(user.PowerMaxTotal + amt, 0, int.MaxValue);
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation("User {SteamId} changed the number of MaxPower items they had by {Amount}", user.SteamId, amt);
|
||||
return user.PowerMaxTotal;
|
||||
}
|
||||
|
||||
public async Task<int> LevelUpCard(string steamId, string itemName, int levelIncrease)
|
||||
public async Task<int> LevelUpCard(long steamId, string itemName, int levelIncrease)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
Card card = await _cardRepository.GetCardByItemCode(itemName);
|
||||
@@ -57,7 +58,7 @@ namespace TOOHUCardAPI.Data.Services
|
||||
Level = 0
|
||||
};
|
||||
int totalCost =
|
||||
(card.Quality == Rarity.NORMAL ? AppSettings.PointsPerLevelNormal : AppSettings.PointsPerLevel) *
|
||||
(card.Quality == Rarity.Normal ? AppSettings.PointsPerLevelNormal : AppSettings.PointsPerLevel) *
|
||||
levelIncrease;
|
||||
if (user.Point < totalCost)
|
||||
{
|
||||
@@ -70,11 +71,11 @@ namespace TOOHUCardAPI.Data.Services
|
||||
await AddPoints(-totalCost, user);
|
||||
userCardLevel.Level += levelIncrease;
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User with steamid {user.SteamId} leveled up card {card.CardName} to level {userCardLevel.Level}");
|
||||
_logger.LogInformation("User with steamid {SteamId} leveled up card {CardName} to level {Level}", user.SteamId, card.CardName, userCardLevel.Level);
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
public async Task<int> PurchaseMagicKey(int amt, string steamId)
|
||||
public async Task<int> PurchaseMagicKey(int amt, long steamId)
|
||||
{
|
||||
int totalCost = AppSettings.PointsPerKey * amt;
|
||||
amt = Math.Clamp(amt, 0, AppSettings.MaxKeyPurchaseAmount);
|
||||
@@ -87,11 +88,11 @@ namespace TOOHUCardAPI.Data.Services
|
||||
await AddPoints(-totalCost, user);
|
||||
user.KeyTotal += amt;
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User with steamid {user.SteamId} purchased {amt} keys for {totalCost} points. New point value is {user.Point}");
|
||||
_logger.LogInformation("User with steamid {SteamId} purchased {NumberKeys} keys for {TotalCost} points. New point value is {NewPoints}", user.SteamId, amt, totalCost, user.Point);
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
public async Task<int> GiveFirstWinBonus(string steamId)
|
||||
public async Task<int> GiveFirstWinBonus(long steamId)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
|
||||
@@ -104,7 +105,7 @@ namespace TOOHUCardAPI.Data.Services
|
||||
await AddPoints(points, user);
|
||||
user.LastFirstWin = DateTime.Now;
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User with steamid {user.SteamId} received first win of the day bonus, earning {points} points. New value: {user.Point}");
|
||||
_logger.LogInformation("User with steamid {SteamId} received first win of the day bonus, earning {BonusPoints} points. New value: {UserPoints}", user.SteamId, points, user.Point);
|
||||
return points;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace TOOHUCardAPI.Data.Services
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public async Task<User> LoginUser(string steamId)
|
||||
public async Task<User> LoginUser(long steamId)
|
||||
{
|
||||
_logger.LogInformation($"User {steamId} just logged in");
|
||||
_logger.LogInformation("User {SteamId} just logged in", steamId);
|
||||
User user = await _userRepository.GetOrCreateUser(steamId);
|
||||
if (user.LastDailyLoginBonus.AddDays(1) <= DateTime.Now)
|
||||
{
|
||||
@@ -35,11 +35,11 @@ namespace TOOHUCardAPI.Data.Services
|
||||
user.KeyTotal += AppSettings.DailyKeyBonus;
|
||||
user.LastDailyLoginBonus = DateTime.Now;;
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User {user.SteamId} received a daily login bonus. Keys earned: {AppSettings.DailyKeyBonus}. New Key total: {user.KeyTotal}");
|
||||
_logger.LogInformation("User {SteamId} received a daily login bonus. Keys earned: {DailyKeyBonus}. New Key total: {KeyTotal}", user.SteamId, AppSettings.DailyKeyBonus, user.KeyTotal);
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task SaveCardGroup(string steamId, string groupKey, string groupData)
|
||||
public async Task SaveCardGroup(long steamId, string groupKey, string groupData)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
|
||||
@@ -49,17 +49,17 @@ namespace TOOHUCardAPI.Data.Services
|
||||
};
|
||||
group.EncodedString = groupData;
|
||||
user.EncodedCardGroups = user.EncodedCardGroups.Where(group2 => group.Id != group2.Id).Append(group).ToList();
|
||||
_logger.LogInformation($"{user.SteamId} just stored a card group");
|
||||
_logger.LogInformation("{SteamId} just stored a card group", user.SteamId);
|
||||
await _userRepository.UpdateUser(user);
|
||||
}
|
||||
|
||||
public async Task SavePetData(string steamId, string petModel, string petEffect)
|
||||
public async Task SavePetData(long steamId, string petModel, string petEffect)
|
||||
{
|
||||
User user = await _userRepository.GetUser(steamId);
|
||||
user.PetModel = petModel;
|
||||
user.PetEffect = petEffect;
|
||||
await _userRepository.UpdateUser(user);
|
||||
_logger.LogInformation($"User {user.SteamId} saved new pet data with model: {petModel} and effect {petEffect}");
|
||||
_logger.LogInformation("User {SteamId} saved new pet data with model: {PetModel} and effect {PetEffect}", user.SteamId, petModel, petEffect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user