Forfeit if balance drops too low for Krash

This commit is contained in:
barelyprofessional
2026-04-09 21:15:53 -05:00
parent d4d499aebd
commit 7a58976c16

View File

@@ -133,6 +133,7 @@ public class KasinoKrash : IDisposable
var preGameTimer = TimeSpan.FromSeconds(30); var preGameTimer = TimeSpan.FromSeconds(30);
var interval = TimeSpan.FromSeconds(1); var interval = TimeSpan.FromSeconds(1);
var timer = new PeriodicTimer(interval); var timer = new PeriodicTimer(interval);
await _kfChatBot.WaitForChatMessageAsync(msg, ct: _ct);
while (await timer.WaitForNextTickAsync(_ct)) //timer before starting the game while (await timer.WaitForNextTickAsync(_ct)) //timer before starting the game
{ {
@@ -144,8 +145,8 @@ public class KasinoKrash : IDisposable
else bets += " on freehand!"; else bets += " on freehand!";
bets += "[br]"; bets += "[br]";
} }
await _kfChatBot.KfClient.EditMessageAsync(msg.ChatMessageUuid, await _kfChatBot.KfClient.EditMessageAsync(msg.ChatMessageUuid!,
$"{TheGame.Creator.User.FormatUsername()} started a Krash! You have [b]{preGameTimer}[/b] to place your bets.[br]{bets}"); $"{TheGame.Creator.User.FormatUsername()} started a Krash! You have [b]{preGameTimer}[/b] to place your bets. [ditto]!krash[/ditto] <amount> <optional multi>[br]{bets}");
preGameTimer -= interval; preGameTimer -= interval;
if (preGameTimer <= TimeSpan.Zero) if (preGameTimer <= TimeSpan.Zero)
{ {
@@ -180,6 +181,14 @@ public class KasinoKrash : IDisposable
await _kfChatBot.KfClient.EditMessageAsync(msg.ChatMessageUuid!, $"[center][b][size=200][color=red]{TheGame.FinalMulti}x"); await _kfChatBot.KfClient.EditMessageAsync(msg.ChatMessageUuid!, $"[center][b][size=200][color=red]{TheGame.FinalMulti}x");
foreach (var bet in TheGame.Bets) foreach (var bet in TheGame.Bets)
{ {
var freshBalance = await Money.GetGamblerEntityAsync(bet.Gambler.User.Id, ct: _ct);
if (freshBalance?.Balance < bet.Wager)
{
await _kfChatBot.SendChatMessageAsync(
$"Forfeited {bet.Gambler.User.FormatUsername()} as they no longer have a sufficient balance for their wager",
true, autoDeleteAfter: TimeSpan.FromSeconds(10));
continue;
}
if (bet.Multi <= TheGame.FinalMulti && bet.Multi != -1) if (bet.Multi <= TheGame.FinalMulti && bet.Multi != -1)
{ {
//you win //you win
@@ -211,7 +220,7 @@ public class KasinoKrash : IDisposable
HOUSE_EDGE = 0.98m; HOUSE_EDGE = 0.98m;
//now close the game //now close the game
await Task.Delay(5000); await Task.Delay(5000, _ct);
await _kfChatBot.KfClient.DeleteMessageAsync(msg.ChatMessageUuid!); await _kfChatBot.KfClient.DeleteMessageAsync(msg.ChatMessageUuid!);
await RemoveKrashState(); await RemoveKrashState();
} }