Return new balance when it's modified and use that for display so it accounts for concurrent games

This commit is contained in:
barelyprofessional
2025-12-09 23:40:15 -06:00
parent 5af2015d46
commit 4671bb3d25
6 changed files with 20 additions and 24 deletions

View File

@@ -50,19 +50,18 @@ public class DiceCommand : ICommand
return;
}
var rolled = Money.GetRandomDouble(gambler);
decimal newBalance;
var colors =
await SettingsProvider.GetMultipleValuesAsync([
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
]);
// print dice game slider
await botInstance.SendChatMessageAsync($"{ConstructDiceGameOutput(rolled)}",true, autoDeleteAfter: cleanupDelay);
decimal newBalance;
if (rolled > 0.5 + _houseEdge)
{
// you win dice
var effect = wager;
await Money.NewWagerAsync(gambler.Id, wager, effect, WagerGame.Dice, ct: ctx);
newBalance = gambler.Balance + effect;
newBalance = await Money.NewWagerAsync(gambler.Id, wager, effect, WagerGame.Dice, ct: ctx);
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, you rolled a {rolled * 100:N2} and [B][COLOR={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]WON![/COLOR][/B] " +
$"You won {await effect.FormatKasinoCurrencyAsync()} and your balance is now {await newBalance.FormatKasinoCurrencyAsync()}",
@@ -71,8 +70,7 @@ public class DiceCommand : ICommand
else
{
// you lose dice
await Money.NewWagerAsync(gambler.Id, wager, -wager, WagerGame.Dice, ct: ctx);
newBalance = gambler.Balance - wager;
newBalance = await Money.NewWagerAsync(gambler.Id, wager, -wager, WagerGame.Dice, ct: ctx);
await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, you rolled a {rolled * 100:N2} and [B][COLOR={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]LOST![/COLOR][/B] " +
$"Your balance is now {await newBalance.FormatKasinoCurrencyAsync()}",