add: Added unclaimed waifu decay to gambling.yml

fix: Fixed regular decay. It was doing the opposite of what the comment says. All waifu decays will be reset
This commit is contained in:
Kwoth
2024-08-24 23:53:03 +00:00
parent 436f9ed074
commit 67b186a1a5
4 changed files with 137 additions and 98 deletions

View File

@@ -531,11 +531,18 @@ public class WaifuService : INService, IReadyExecutor
{
try
{
var multi = _gss.Data.Waifu.Decay.Percent / 100f;
var minPrice = _gss.Data.Waifu.Decay.MinPrice;
var decayInterval = _gss.Data.Waifu.Decay.HourInterval;
var decay = _gss.Data.Waifu.Decay;
if (multi is < 0f or > 1f || decayInterval < 0)
var unclaimedMulti = 1 - (decay.UnclaimedDecayPercent / 100f);
var claimedMulti = 1 - (decay.ClaimedDecayPercent / 100f);
var minPrice = decay.MinPrice;
var decayInterval = decay.HourInterval;
if (decayInterval <= 0)
continue;
if ((unclaimedMulti < 0 || unclaimedMulti > 1) && (claimedMulti < 0 || claimedMulti > 1))
continue;
var now = DateTime.UtcNow;
@@ -554,14 +561,28 @@ public class WaifuService : INService, IReadyExecutor
await _cache.AddAsync(_waifuDecayKey, nowB);
await using var uow = _db.GetDbContext();
if (unclaimedMulti is > 0 and <= 1)
{
await using var uow = _db.GetDbContext();
await uow.GetTable<WaifuInfo>()
.Where(x => x.Price > minPrice && x.ClaimerId == null)
.UpdateAsync(old => new()
{
Price = (long)(old.Price * multi)
});
await uow.GetTable<WaifuInfo>()
.Where(x => x.Price > minPrice && x.ClaimerId == null)
.UpdateAsync(old => new()
{
Price = (long)(old.Price * unclaimedMulti)
});
}
if (claimedMulti is > 0 and <= 1)
{
await using var uow = _db.GetDbContext();
await uow.GetTable<WaifuInfo>()
.Where(x => x.Price > minPrice && x.ClaimerId == null)
.UpdateAsync(old => new()
{
Price = (long)(old.Price * claimedMulti)
});
}
}
catch (Exception ex)
{

View File

@@ -63,6 +63,8 @@ public static class WaifuExtensions
public static async Task<WaifuInfoStats> GetWaifuInfoAsync(this DbContext ctx, ulong userId)
{
await ctx.EnsureUserCreatedAsync(userId);
await ctx.Set<WaifuInfo>()
.ToLinqToDBTable()
.InsertOrUpdateAsync(() => new()
@@ -78,7 +80,8 @@ public static class WaifuExtensions
WaifuId = ctx.Set<DiscordUser>().Where(x => x.UserId == userId).Select(x => x.Id).First()
});
var toReturn = ctx.Set<WaifuInfo>().AsQueryable()
var toReturn = ctx.Set<WaifuInfo>()
.AsQueryable()
.Where(w => w.WaifuId
== ctx.Set<DiscordUser>()
.AsQueryable()