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)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace TOOHUCardAPI.Migrations
{
public partial class playerdatadoneforfrontfacing : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "PetEffect",
table: "Users",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "PetModel",
table: "Users",
type: "TEXT",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PetEffect",
table: "Users");
migrationBuilder.DropColumn(
name: "PetModel",
table: "Users");
}
}
}

View File

@@ -965,9 +965,15 @@ namespace TOOHUCardAPI.Migrations
b.Property<int>("MaxWave")
.HasColumnType("INTEGER");
b.Property<string>("PetEffect")
.HasColumnType("TEXT");
b.Property<int>("PetLevel")
.HasColumnType("INTEGER");
b.Property<string>("PetModel")
.HasColumnType("TEXT");
b.Property<int>("Point")
.HasColumnType("INTEGER");

View File

@@ -13,6 +13,8 @@
"PointsPerLevel": "10",
"PointsPerLevelNormal": "5",
"PointsPerKey": "2",
"FirstWinBonusPoints": "2",
"FirstWinBonusPointsMin": "1",
"FirstWinBonusPointsMax": "5",
"DailyKeyBonus": "2",
"MaxKeyPurchaseAmount": "200"
}