forked from EllieBotDevs/elliebot
Added unclaimed waifu decay to gambling.yml
Fixed regular decay. It was doing the opposite of what the comment says. All waifu decays will be reset
This commit is contained in:
parent
e324d49cbc
commit
d478a6ca72
5 changed files with 142 additions and 100 deletions
|
@ -11,7 +11,7 @@ namespace EllieBot.Modules.Gambling.Common;
|
|||
public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
||||
{
|
||||
[Comment("""DO NOT CHANGE""")]
|
||||
public int Version { get; set; } = 2;
|
||||
public int Version { get; set; } = 8;
|
||||
|
||||
[Comment("""Currency settings""")]
|
||||
public CurrencyConfig Currency { get; set; }
|
||||
|
@ -278,7 +278,13 @@ public sealed partial class WaifuConfig
|
|||
Set 0 to disable
|
||||
For example if a waifu has a price of 500$, setting this value to 10 would reduce the waifu value by 10% (50$)
|
||||
""")]
|
||||
public int Percent { get; set; } = 0;
|
||||
public int UnclaimedDecayPercent { get; set; } = 0;
|
||||
|
||||
[Comment("""
|
||||
Claimed waifus will decay by this percentage (0 - 100).
|
||||
Default is 0 (disabled)
|
||||
""")]
|
||||
public int ClaimedDecayPercent { get; set; } = 0;
|
||||
|
||||
[Comment("""How often to decay waifu values, in hours""")]
|
||||
public int HourInterval { get; set; } = 24;
|
||||
|
|
|
@ -190,5 +190,14 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||
c.Version = 7;
|
||||
});
|
||||
}
|
||||
|
||||
if (data.Version < 8)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 8;
|
||||
c.Waifu.Decay.UnclaimedDecayPercent = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -531,11 +531,18 @@ public class WaifuService : IEService, 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,15 +561,29 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
|
||||
await _cache.AddAsync(_waifuDecayKey, nowB);
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
Log.Error(ex, "Unexpected error occured in waifu decay loop: {ErrorMessage}", ex.Message);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# DO NOT CHANGE
|
||||
version: 7
|
||||
version: 8
|
||||
# Currency settings
|
||||
currency:
|
||||
# What is the emoji/character which represents the currency
|
||||
|
@ -128,7 +128,10 @@ waifu:
|
|||
# Percentage (0 - 100) of the waifu value to reduce.
|
||||
# Set 0 to disable
|
||||
# For example if a waifu has a price of 500$, setting this value to 10 would reduce the waifu value by 10% (50$)
|
||||
percent: 0
|
||||
unclaimedDecayPercent: 0
|
||||
# Claimed waifus will decay by this percentage (0 - 100).
|
||||
# Default is 0 (disabled)
|
||||
claimedDecayPercent: 0
|
||||
# How often to decay waifu values, in hours
|
||||
hourInterval: 24
|
||||
# Minimum waifu price required for the decay to be applied.
|
||||
|
|
Reference in a new issue