Using declarations and other code reformats

This commit is contained in:
Kwoth
2021-12-26 03:22:45 +01:00
parent d18f9429c6
commit b85ba177cd
64 changed files with 2349 additions and 2736 deletions

View File

@@ -30,15 +30,13 @@ public partial class Gambling
var num1 = gen / 10;
var num2 = gen % 10;
using (var img1 = GetDice(num1))
using (var img2 = GetDice(num2))
using (var img = new[] { img1, img2 }.Merge(out var format))
await using (var ms = img.ToStream(format))
{
await ctx.Channel.SendFileAsync(ms,
$"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " + GetText(strs.dice_rolled(Format.Code(gen.ToString()))));
}
using var img1 = GetDice(num1);
using var img2 = GetDice(num2);
using var img = new[] { img1, img2 }.Merge(out var format);
await using var ms = img.ToStream(format);
await ctx.Channel.SendFileAsync(ms,
$"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " + GetText(strs.dice_rolled(Format.Code(gen.ToString()))));
}
[NadekoCommand, Aliases]
@@ -108,21 +106,19 @@ public partial class Gambling
values.Insert(toInsert, randomNumber);
}
using (var bitmap = dice.Merge(out var format))
await using (var ms = bitmap.ToStream(format))
using var bitmap = dice.Merge(out var format);
await using var ms = bitmap.ToStream(format);
foreach (var d in dice)
{
foreach (var d in dice)
{
d.Dispose();
}
await ctx.Channel.SendFileAsync(ms, $"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " +
GetText(strs.dice_rolled_num(Format.Bold(values.Count.ToString()))) +
" " + GetText(strs.total_average(
Format.Bold(values.Sum().ToString()),
Format.Bold((values.Sum() / (1.0f * values.Count)).ToString("N2")))));
d.Dispose();
}
await ctx.Channel.SendFileAsync(ms, $"dice.{format.FileExtensions.First()}",
Format.Bold(ctx.User.ToString()) + " " +
GetText(strs.dice_rolled_num(Format.Bold(values.Count.ToString()))) +
" " + GetText(strs.total_average(
Format.Bold(values.Sum().ToString()),
Format.Bold((values.Sum() / (1.0f * values.Count)).ToString("N2")))));
}
private async Task InternallDndRoll(string arg, bool ordered)
@@ -211,11 +207,9 @@ public partial class Gambling
if (num == 10)
{
var images = _images.Dice;
using (var imgOne = Image.Load(images[1]))
using (var imgZero = Image.Load(images[0]))
{
return new[] { imgOne, imgZero }.Merge();
}
using var imgOne = Image.Load(images[1]);
using var imgZero = Image.Load(images[0]);
return new[] { imgOne, imgZero }.Merge();
}
return Image.Load(_images.Dice[num]);
}

View File

@@ -44,22 +44,21 @@ public partial class Gambling
cardObjects.Add(currentCard);
images.Add(Image.Load(_images.GetCard(currentCard.ToString().ToLowerInvariant().Replace(' ', '_'))));
}
using (var img = images.Merge())
using var img = images.Merge();
foreach (var i in images)
{
foreach (var i in images)
{
i.Dispose();
}
var toSend = $"{Format.Bold(ctx.User.ToString())}";
if (cardObjects.Count == 5)
toSend += $" drew `{Deck.GetHandValue(cardObjects)}`";
if (guildId != null)
toSend += "\n" + GetText(strs.cards_left(Format.Bold(cards.CardPool.Count.ToString())));
return (img.ToStream(), toSend);
i.Dispose();
}
var toSend = $"{Format.Bold(ctx.User.ToString())}";
if (cardObjects.Count == 5)
toSend += $" drew `{Deck.GetHandValue(cardObjects)}`";
if (guildId != null)
toSend += "\n" + GetText(strs.cards_left(Format.Bold(cards.CardPool.Count.ToString())));
return (img.ToStream(), toSend);
}
[NadekoCommand, Aliases]

View File

@@ -47,20 +47,19 @@ public partial class Gambling
tailCount++;
}
}
using (var img = imgs.Merge(out var format))
await using (var stream = img.ToStream(format))
using var img = imgs.Merge(out var format);
await using var stream = img.ToStream(format);
foreach (var i in imgs)
{
foreach (var i in imgs)
{
i.Dispose();
}
var msg = count != 1
? Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_results(count, headCount, tailCount))
: Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flipped(headCount > 0
? Format.Bold(GetText(strs.heads))
: Format.Bold(GetText(strs.tails))));
await ctx.Channel.SendFileAsync(stream, $"{count} coins.{format.FileExtensions.First()}", msg).ConfigureAwait(false);
i.Dispose();
}
var msg = count != 1
? Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flip_results(count, headCount, tailCount))
: Format.Bold(ctx.User.ToString()) + " " + GetText(strs.flipped(headCount > 0
? Format.Bold(GetText(strs.heads))
: Format.Bold(GetText(strs.tails))));
await ctx.Channel.SendFileAsync(stream, $"{count} coins.{format.FileExtensions.First()}", msg).ConfigureAwait(false);
}
public enum BetFlipGuess

View File

@@ -538,10 +538,8 @@ public partial class Gambling : GamblingModule<GamblingService>
}
else
{
await using (var uow = _db.GetDbContext())
{
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
}
await using var uow = _db.GetDbContext();
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
}
await ctx.SendPaginatedConfirmAsync(page, curPage =>
@@ -553,10 +551,8 @@ public partial class Gambling : GamblingModule<GamblingService>
List<DiscordUser> toSend;
if (!opts.Clean)
{
using (var uow = _db.GetDbContext())
{
toSend = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage);
}
using var uow = _db.GetDbContext();
toSend = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, curPage);
}
else
{

View File

@@ -41,21 +41,20 @@ public class GamblingService : INService
if (config.Decay.Percent <= 0 || config.Decay.Percent > 1 || maxDecay < 0)
return;
using (var uow = _db.GetDbContext())
{
var lastCurrencyDecay = _cache.GetLastCurrencyDecay();
using var uow = _db.GetDbContext();
var lastCurrencyDecay = _cache.GetLastCurrencyDecay();
if (DateTime.UtcNow - lastCurrencyDecay < TimeSpan.FromHours(config.Decay.HourInterval))
return;
if (DateTime.UtcNow - lastCurrencyDecay < TimeSpan.FromHours(config.Decay.HourInterval))
return;
Log.Information($"Decaying users' currency - decay: {config.Decay.Percent * 100}% " +
$"| max: {maxDecay} " +
$"| threshold: {config.Decay.MinThreshold}");
Log.Information($"Decaying users' currency - decay: {config.Decay.Percent * 100}% " +
$"| max: {maxDecay} " +
$"| threshold: {config.Decay.MinThreshold}");
if (maxDecay == 0)
maxDecay = int.MaxValue;
if (maxDecay == 0)
maxDecay = int.MaxValue;
uow.Database.ExecuteSqlInterpolated($@"
uow.Database.ExecuteSqlInterpolated($@"
UPDATE DiscordUser
SET CurrencyAmount=
CASE WHEN
@@ -67,9 +66,8 @@ SET CurrencyAmount=
END
WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentUser.Id};");
_cache.SetLastCurrencyDecay();
uow.SaveChanges();
}
_cache.SetLastCurrencyDecay();
uow.SaveChanges();
}, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
}
}

View File

@@ -44,18 +44,16 @@ public class PlantPickService : INService
_gss = gss;
cmd.OnMessageNoTrigger += PotentialFlowerGeneration;
using (var uow = db.GetDbContext())
{
var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow.Set<GuildConfig>()
.AsQueryable()
.Include(x => x.GenerateCurrencyChannelIds)
.Where(x => guildIds.Contains(x.GuildId))
.ToList();
using var uow = db.GetDbContext();
var guildIds = client.Guilds.Select(x => x.Id).ToList();
var configs = uow.Set<GuildConfig>()
.AsQueryable()
.Include(x => x.GenerateCurrencyChannelIds)
.Where(x => guildIds.Contains(x.GuildId))
.ToList();
_generationChannels = new(configs
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
}
_generationChannels = new(configs
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
}
private string GetText(ulong gid, LocStr str)
@@ -64,39 +62,35 @@ public class PlantPickService : INService
public bool ToggleCurrencyGeneration(ulong gid, ulong cid)
{
bool enabled;
using (var uow = _db.GetDbContext())
{
var guildConfig = uow.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds));
using var uow = _db.GetDbContext();
var guildConfig = uow.GuildConfigsForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds));
var toAdd = new GCChannelId() { ChannelId = cid };
if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
{
guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
_generationChannels.Add(cid);
enabled = true;
}
else
{
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
if (toDelete != null)
{
uow.Remove(toDelete);
}
_generationChannels.TryRemove(cid);
enabled = false;
}
uow.SaveChanges();
var toAdd = new GCChannelId() { ChannelId = cid };
if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
{
guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
_generationChannels.Add(cid);
enabled = true;
}
else
{
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
if (toDelete != null)
{
uow.Remove(toDelete);
}
_generationChannels.TryRemove(cid);
enabled = false;
}
uow.SaveChanges();
return enabled;
}
public IEnumerable<GuildConfigExtensions.GeneratingChannel> GetAllGeneratingChannels()
{
using (var uow = _db.GetDbContext())
{
var chs = uow.GuildConfigs.GetGeneratingChannels();
return chs;
}
using var uow = _db.GetDbContext();
var chs = uow.GuildConfigs.GetGeneratingChannels();
return chs;
}
/// <summary>
@@ -139,31 +133,29 @@ public class PlantPickService : INService
{
// draw lower, it looks better
pass = pass.TrimTo(10, true).ToLowerInvariant();
using (var img = Image.Load<Rgba32>(curImg, out var format))
using var img = Image.Load<Rgba32>(curImg, out var format);
// choose font size based on the image height, so that it's visible
var font = _fonts.NotoSans.CreateFont(img.Height / 12, FontStyle.Bold);
img.Mutate(x =>
{
// choose font size based on the image height, so that it's visible
var font = _fonts.NotoSans.CreateFont(img.Height / 12, FontStyle.Bold);
img.Mutate(x =>
{
// measure the size of the text to be drawing
var size = TextMeasurer.Measure(pass, new(font, new PointF(0, 0)));
// measure the size of the text to be drawing
var size = TextMeasurer.Measure(pass, new(font, new PointF(0, 0)));
// fill the background with black, add 5 pixels on each side to make it look better
x.FillPolygon(Color.ParseHex("00000080"),
new PointF(0, 0),
new PointF(size.Width + 5, 0),
new PointF(size.Width + 5, size.Height + 10),
new PointF(0, size.Height + 10));
// fill the background with black, add 5 pixels on each side to make it look better
x.FillPolygon(Color.ParseHex("00000080"),
new PointF(0, 0),
new PointF(size.Width + 5, 0),
new PointF(size.Width + 5, size.Height + 10),
new PointF(0, size.Height + 10));
// draw the password over the background
x.DrawText(pass,
font,
SixLabors.ImageSharp.Color.White,
new(0, 0));
});
// return image as a stream for easy sending
return (img.ToStream(format), format.FileExtensions.FirstOrDefault() ?? "png");
}
// draw the password over the background
x.DrawText(pass,
font,
SixLabors.ImageSharp.Color.White,
new(0, 0));
});
// return image as a stream for easy sending
return (img.ToStream(format), format.FileExtensions.FirstOrDefault() ?? "png");
}
private Task PotentialFlowerGeneration(IUserMessage imsg)
@@ -309,13 +301,11 @@ public class PlantPickService : INService
msgToSend += " " + GetText(gid, strs.pick_sn(prefix));
//get the image
await using (var stream = GetRandomCurrencyImage(pass, out var ext))
{
// send it
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false);
// return sent message's id (in order to be able to delete it when it's picked)
return msg.Id;
}
await using var stream = GetRandomCurrencyImage(pass, out var ext);
// send it
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false);
// return sent message's id (in order to be able to delete it when it's picked)
return msg.Id;
}
catch
{
@@ -353,18 +343,16 @@ public class PlantPickService : INService
private async Task AddPlantToDatabase(ulong gid, ulong cid, ulong uid, ulong mid, long amount, string pass)
{
await using (var uow = _db.GetDbContext())
await using var uow = _db.GetDbContext();
uow.PlantedCurrency.Add(new()
{
uow.PlantedCurrency.Add(new()
{
Amount = amount,
GuildId = gid,
ChannelId = cid,
Password = pass,
UserId = uid,
MessageId = mid,
});
await uow.SaveChangesAsync();
}
Amount = amount,
GuildId = gid,
ChannelId = cid,
Password = pass,
UserId = uid,
MessageId = mid,
});
await uow.SaveChangesAsync();
}
}

View File

@@ -37,49 +37,47 @@ public class WaifuService : INService
var settings = _gss.Data;
await using (var uow = _db.GetDbContext())
{
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow.GetOrCreateUser(owner);
await using var uow = _db.GetDbContext();
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow.GetOrCreateUser(owner);
// owner has to be the owner of the waifu
if (waifu is null || waifu.ClaimerId != ownerUser.Id)
return false;
// owner has to be the owner of the waifu
if (waifu is null || waifu.ClaimerId != ownerUser.Id)
return false;
// if waifu likes the person, gotta pay the penalty
if (waifu.AffinityId == ownerUser.Id)
// if waifu likes the person, gotta pay the penalty
if (waifu.AffinityId == ownerUser.Id)
{
if (!await _cs.RemoveAsync(owner.Id,
"Waifu Transfer - affinity penalty",
(int)(waifu.Price * 0.6),
true))
{
if (!await _cs.RemoveAsync(owner.Id,
"Waifu Transfer - affinity penalty",
(int)(waifu.Price * 0.6),
true))
{
// unable to pay 60% penalty
return false;
}
waifu.Price = (int)(waifu.Price * 0.7); // half of 60% = 30% price reduction
if (waifu.Price < settings.Waifu.MinPrice)
waifu.Price = settings.Waifu.MinPrice;
}
else // if not, pay 10% fee
{
if (!await _cs.RemoveAsync(owner.Id, "Waifu Transfer", waifu.Price / 10, gamble: true))
{
return false;
}
waifu.Price = (int) (waifu.Price * 0.95); // half of 10% = 5% price reduction
if (waifu.Price < settings.Waifu.MinPrice)
waifu.Price = settings.Waifu.MinPrice;
// unable to pay 60% penalty
return false;
}
//new claimerId is the id of the new owner
var newOwnerUser = uow.GetOrCreateUser(newOwner);
waifu.ClaimerId = newOwnerUser.Id;
await uow.SaveChangesAsync();
waifu.Price = (int)(waifu.Price * 0.7); // half of 60% = 30% price reduction
if (waifu.Price < settings.Waifu.MinPrice)
waifu.Price = settings.Waifu.MinPrice;
}
else // if not, pay 10% fee
{
if (!await _cs.RemoveAsync(owner.Id, "Waifu Transfer", waifu.Price / 10, gamble: true))
{
return false;
}
waifu.Price = (int) (waifu.Price * 0.95); // half of 10% = 5% price reduction
if (waifu.Price < settings.Waifu.MinPrice)
waifu.Price = settings.Waifu.MinPrice;
}
//new claimerId is the id of the new owner
var newOwnerUser = uow.GetOrCreateUser(newOwner);
waifu.ClaimerId = newOwnerUser.Id;
await uow.SaveChangesAsync();
return true;
}
@@ -87,67 +85,63 @@ public class WaifuService : INService
public int GetResetPrice(IUser user)
{
var settings = _gss.Data;
using (var uow = _db.GetDbContext())
{
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
using var uow = _db.GetDbContext();
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
if (waifu is null)
return settings.Waifu.MinPrice;
if (waifu is null)
return settings.Waifu.MinPrice;
var divorces = uow.WaifuUpdates.Count(x => x.Old != null &&
x.Old.UserId == user.Id &&
x.UpdateType == WaifuUpdateType.Claimed &&
x.New == null);
var affs = uow.WaifuUpdates
.AsQueryable()
.Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged &&
w.New != null)
.ToList()
.GroupBy(x => x.New)
.Count();
var divorces = uow.WaifuUpdates.Count(x => x.Old != null &&
x.Old.UserId == user.Id &&
x.UpdateType == WaifuUpdateType.Claimed &&
x.New == null);
var affs = uow.WaifuUpdates
.AsQueryable()
.Where(w => w.User.UserId == user.Id && w.UpdateType == WaifuUpdateType.AffinityChanged &&
w.New != null)
.ToList()
.GroupBy(x => x.New)
.Count();
return (int) Math.Ceiling(waifu.Price * 1.25f) +
((divorces + affs + 2) * settings.Waifu.Multipliers.WaifuReset);
}
return (int) Math.Ceiling(waifu.Price * 1.25f) +
((divorces + affs + 2) * settings.Waifu.Multipliers.WaifuReset);
}
public async Task<bool> TryReset(IUser user)
{
await using (var uow = _db.GetDbContext())
{
var price = GetResetPrice(user);
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
return false;
await using var uow = _db.GetDbContext();
var price = GetResetPrice(user);
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
return false;
var affs = uow.WaifuUpdates
.AsQueryable()
.Where(w => w.User.UserId == user.Id
&& w.UpdateType == WaifuUpdateType.AffinityChanged
&& w.New != null);
var affs = uow.WaifuUpdates
.AsQueryable()
.Where(w => w.User.UserId == user.Id
&& w.UpdateType == WaifuUpdateType.AffinityChanged
&& w.New != null);
var divorces = uow.WaifuUpdates
.AsQueryable()
.Where(x => x.Old != null &&
x.Old.UserId == user.Id &&
x.UpdateType == WaifuUpdateType.Claimed &&
x.New == null);
var divorces = uow.WaifuUpdates
.AsQueryable()
.Where(x => x.Old != null &&
x.Old.UserId == user.Id &&
x.UpdateType == WaifuUpdateType.Claimed &&
x.New == null);
//reset changes of heart to 0
uow.WaifuUpdates.RemoveRange(affs);
//reset divorces to 0
uow.WaifuUpdates.RemoveRange(divorces);
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
//reset price, remove items
//remove owner, remove affinity
waifu.Price = 50;
waifu.Items.Clear();
waifu.ClaimerId = null;
waifu.AffinityId = null;
//reset changes of heart to 0
uow.WaifuUpdates.RemoveRange(affs);
//reset divorces to 0
uow.WaifuUpdates.RemoveRange(divorces);
var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id);
//reset price, remove items
//remove owner, remove affinity
waifu.Price = 50;
waifu.Items.Clear();
waifu.ClaimerId = null;
waifu.AffinityId = null;
//wives stay though
//wives stay though
uow.SaveChanges();
}
uow.SaveChanges();
return true;
}
@@ -302,10 +296,8 @@ public class WaifuService : INService
public IEnumerable<WaifuLbResult> GetTopWaifusAtPage(int page)
{
using (var uow = _db.GetDbContext())
{
return uow.WaifuInfo.GetTop(9, page * 9);
}
using var uow = _db.GetDbContext();
return uow.WaifuInfo.GetTop(9, page * 9);
}
public ulong GetWaifuUserId(ulong ownerId, string name)
@@ -372,85 +364,79 @@ public class WaifuService : INService
return false;
}
await using (var uow = _db.GetDbContext())
await using var uow = _db.GetDbContext();
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
set => set.Include(x => x.Items)
.Include(x => x.Claimer));
if (w is null)
{
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
set => set.Include(x => x.Items)
.Include(x => x.Claimer));
if (w is null)
uow.WaifuInfo.Add(w = new()
{
uow.WaifuInfo.Add(w = new()
{
Affinity = null,
Claimer = null,
Price = 1,
Waifu = uow.GetOrCreateUser(giftedWaifu),
});
}
Affinity = null,
Claimer = null,
Price = 1,
Waifu = uow.GetOrCreateUser(giftedWaifu),
});
}
if (!itemObj.Negative)
if (!itemObj.Negative)
{
w.Items.Add(new()
{
w.Items.Add(new()
{
Name = itemObj.Name.ToLowerInvariant(),
ItemEmoji = itemObj.ItemEmoji,
});
Name = itemObj.Name.ToLowerInvariant(),
ItemEmoji = itemObj.ItemEmoji,
});
if (w.Claimer?.UserId == from.Id)
{
w.Price += (int)(itemObj.Price * _gss.Data.Waifu.Multipliers.GiftEffect);
}
else
{
w.Price += itemObj.Price / 2;
}
if (w.Claimer?.UserId == @from.Id)
{
w.Price += (int)(itemObj.Price * _gss.Data.Waifu.Multipliers.GiftEffect);
}
else
{
w.Price -= (int)(itemObj.Price * _gss.Data.Waifu.Multipliers.NegativeGiftEffect);
if (w.Price < 1)
w.Price = 1;
w.Price += itemObj.Price / 2;
}
await uow.SaveChangesAsync();
}
else
{
w.Price -= (int)(itemObj.Price * _gss.Data.Waifu.Multipliers.NegativeGiftEffect);
if (w.Price < 1)
w.Price = 1;
}
await uow.SaveChangesAsync();
return true;
}
public WaifuInfoStats GetFullWaifuInfoAsync(ulong targetId)
{
using (var uow = _db.GetDbContext())
using var uow = _db.GetDbContext();
var wi = uow.GetWaifuInfo(targetId);
if (wi is null)
{
var wi = uow.GetWaifuInfo(targetId);
if (wi is null)
wi = new()
{
wi = new()
{
AffinityCount = 0,
AffinityName = null,
ClaimCount = 0,
ClaimerName = null,
Claims = new(),
Fans = new(),
DivorceCount = 0,
FullName = null,
Items = new(),
Price = 1
};
}
return wi;
AffinityCount = 0,
AffinityName = null,
ClaimCount = 0,
ClaimerName = null,
Claims = new(),
Fans = new(),
DivorceCount = 0,
FullName = null,
Items = new(),
Price = 1
};
}
return wi;
}
public WaifuInfoStats GetFullWaifuInfoAsync(IGuildUser target)
{
using (var uow = _db.GetDbContext())
{
var du = uow.GetOrCreateUser(target);
using var uow = _db.GetDbContext();
var du = uow.GetOrCreateUser(target);
return GetFullWaifuInfoAsync(target.Id);
}
return GetFullWaifuInfoAsync(target.Id);
}
public string GetClaimTitle(int count)

View File

@@ -41,18 +41,18 @@ public partial class Gambling
public sealed class SlotMachine
{
public const int MaxValue = 5;
public const int MAX_VALUE = 5;
static readonly List<Func<int[], int>> _winningCombos = new()
private static readonly List<Func<int[], int>> _winningCombos = new()
{
//three flowers
arr => arr.All(a=>a==MaxValue) ? 30 : 0,
arr => arr.All(a=>a==MAX_VALUE) ? 30 : 0,
//three of the same
arr => !arr.Any(a => a != arr[0]) ? 10 : 0,
//two flowers
arr => arr.Count(a => a == MaxValue) == 2 ? 4 : 0,
arr => arr.Count(a => a == MAX_VALUE) == 2 ? 4 : 0,
//one flower
arr => arr.Any(a => a == MaxValue) ? 1 : 0,
arr => arr.Any(a => a == MAX_VALUE) ? 1 : 0,
};
public static SlotResult Pull()
@@ -60,7 +60,7 @@ public partial class Gambling
var numbers = new int[3];
for (var i = 0; i < numbers.Length; i++)
{
numbers[i] = new NadekoRandom().Next(0, MaxValue + 1);
numbers[i] = new NadekoRandom().Next(0, MAX_VALUE + 1);
}
var multi = 0;
foreach (var t in _winningCombos)
@@ -84,6 +84,8 @@ public partial class Gambling
}
}
}
public Task Test() => Task.CompletedTask;
[NadekoCommand, Aliases]
[OwnerOnly]
@@ -124,7 +126,6 @@ public partial class Gambling
}
var sb = new StringBuilder();
const int bet = 1;
var payout = 0;
foreach (var key in dict.Keys.OrderByDescending(x => x))
{
@@ -132,7 +133,7 @@ public partial class Gambling
payout += key * dict[key];
}
await SendConfirmAsync("Slot Test Results", sb.ToString(),
footer: $"Total Bet: {tests * bet} | Payout: {payout * bet} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
footer: $"Total Bet: {tests} | Payout: {payout} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
}
[NadekoCommand, Aliases]
@@ -170,7 +171,7 @@ public partial class Gambling
.FirstOrDefault(x => x.UserId == ctx.User.Id)
?.CurrencyAmount ?? 0;
}
using (var bgImage = Image.Load<Rgba32>(_images.SlotBackground, out var format))
{
var numbers = new int[3];
@@ -216,22 +217,20 @@ public partial class Gambling
for (var i = 0; i < 3; i++)
{
using (var img = Image.Load(_images.SlotEmojis[numbers[i]]))
{
bgImage.Mutate(x => x.DrawImage(img, new Point(148 + (105 * i), 217), 1f));
}
using var img = Image.Load(_images.SlotEmojis[numbers[i]]);
bgImage.Mutate(x => x.DrawImage(img, new Point(148 + (105 * i), 217), 1f));
}
var msg = GetText(strs.better_luck);
if (result.Multiplier > 0)
{
if (result.Multiplier == 1f)
if (Math.Abs(result.Multiplier - 1f) <= float.Epsilon)
msg = GetText(strs.slot_single(CurrencySign, 1));
else if (result.Multiplier == 4f)
else if (Math.Abs(result.Multiplier - 4f) < float.Epsilon)
msg = GetText(strs.slot_two(CurrencySign, 4));
else if (result.Multiplier == 10f)
else if (Math.Abs(result.Multiplier - 10f) <= float.Epsilon)
msg = GetText(strs.slot_three(10));
else if (result.Multiplier == 30f)
else if (Math.Abs(result.Multiplier - 30f) <= float.Epsilon)
msg = GetText(strs.slot_jackpot(30));
}