Migration and daily login change

This commit is contained in:
2021-10-31 14:06:11 -04:00
parent a3a50a5e07
commit e33aaa5f7b
8 changed files with 1092 additions and 6 deletions

View File

@@ -7,7 +7,9 @@ namespace TOOHUCardAPI.Data
{
public static int PointsPerLevel { get; set; }
public static int PointsPerLevelNormal { get; set; }
public static int FirstWinBonusPoints { get; set; }
public static int FirstWinBonusPointsMin { get; set; }
public static int FirstWinBonusPointsMax { get; set; }
public static int DailyKeyBonus { get; set; }
public static int PointsPerKey { get; set; }
public static int MaxKeyPurchaseAmount { get; set; }
public static void Init(IConfiguration configuration)

View File

@@ -19,6 +19,7 @@ namespace TOOHUCardAPI.Data.Models
public bool Ban { get; set; }
public int Point { get; set; }
public DateTime LastFirstWin { get; set; }
public DateTime LastDailyLoginBonus { get; set; }
public int PowerMaxTotal { get; set; }
public string PetModel { get; set; }
public string PetEffect { get; set; }

View File

@@ -99,11 +99,13 @@ namespace TOOHUCardAPI.Data.Services
{
throw new NotFirstWinException();
}
await AddPoints(AppSettings.FirstWinBonusPoints, user);
int points = new Random().Next(AppSettings.FirstWinBonusPointsMin, AppSettings.FirstWinBonusPointsMax + 1);
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 {AppSettings.FirstWinBonusPoints} points. New value: {user.Point}");
return AppSettings.FirstWinBonusPoints;
_logger.LogInformation($"User with steamid {user.SteamId} received first win of the day bonus, earning {points} points. New value: {user.Point}");
return points;
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@@ -20,7 +21,20 @@ namespace TOOHUCardAPI.Data.Services
public async Task<User> LoginUser(string steamId)
{
_logger.LogInformation($"User {steamId} just logged in");
return await _userRepository.GetOrCreateUser(steamId);
User user = await _userRepository.GetOrCreateUser(steamId);
if (user.LastDailyLoginBonus.AddDays(1) <= DateTime.Now)
{
user = await HandleDailyLoginBonus(user);
}
return user;
}
private async Task<User> HandleDailyLoginBonus(User user)
{
user.KeyTotal += AppSettings.DailyKeyBonus;
await _userRepository.UpdateUser(user);
return user;
}
public async Task SaveCardGroup(string steamId, string groupKey, string groupData)