update mines (#77)

* Update MinesCommand.cs

better cashout handling?
also limit mines to 8

* Update KasinoMines.cs

update cashout to have a delay before removing board message and add auto delete

* update cashout calculation

update cashout calculation
fair payout but house edge based chance for rigging
This commit is contained in:
alogindtractor
2026-02-10 06:40:43 -08:00
committed by GitHub
parent 26d1da3069
commit d71dd304fd
2 changed files with 17 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ public class MinesCommand : ICommand
{ {
public List<Regex> Patterns => [ public List<Regex> Patterns => [
//cashout //cashout
new Regex(@"^mines\s+cashout$", RegexOptions.IgnoreCase), new Regex(@"^mines\s+(?<cashout>cashout)$", RegexOptions.IgnoreCase),
//refresh //refresh
new Regex(@"^mines\s+refresh$", RegexOptions.IgnoreCase), new Regex(@"^mines\s+refresh$", RegexOptions.IgnoreCase),
//clear - admin only //clear - admin only
@@ -72,8 +72,13 @@ public class MinesCommand : ICommand
if (user.UserRight >= UserRight.TrueAndHonest) if (user.UserRight >= UserRight.TrueAndHonest)
{ {
await KasinoMines.GetSavedGames(gambler.Id); await KasinoMines.GetSavedGames(gambler.Id);
foreach (var game in KasinoMines.ActiveGames.Values)
{
await botInstance.KfClient.DeleteMessageAsync(game.LastMessageId);
}
KasinoMines.ActiveGames.Clear(); KasinoMines.ActiveGames.Clear();
await KasinoMines.SaveActiveGames(gambler.Id); await KasinoMines.SaveActiveGames(gambler.Id);
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, cleared all mines games.", true, autoDeleteAfter: cleanupDelay);
return; return;
} }
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, you don't have permission to clear saved games.", true, autoDeleteAfter: cleanupDelay); await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, you don't have permission to clear saved games.", true, autoDeleteAfter: cleanupDelay);
@@ -174,7 +179,7 @@ public class MinesCommand : ICommand
return; return;
} }
int boardSize = Convert.ToInt32(size.Value); int boardSize = Convert.ToInt32(size.Value);
if (boardSize < 2 || boardSize > 9) if (boardSize < 2 || boardSize > 8)
{ {
await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, board size must be between 2 and 9.",true, autoDeleteAfter: cleanupDelay); await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, board size must be between 2 and 9.",true, autoDeleteAfter: cleanupDelay);
return; return;
@@ -244,6 +249,7 @@ public class MinesCommand : ICommand
} }
else //if they didn't put anything else //if they didn't put anything
{ {
if (message.Message.Contains("cashout")) cashout = true;
if (cashout) if (cashout)
{ {
await KasinoMines.Cashout(KasinoMines.ActiveGames[gambler.Id]); await KasinoMines.Cashout(KasinoMines.ActiveGames[gambler.Id]);
@@ -252,6 +258,7 @@ public class MinesCommand : ICommand
await botInstance.SendChatMessageAsync( await botInstance.SendChatMessageAsync(
$"{user.FormatUsername()}, you already have a game running. !mines <picks> to reveal more spaces, !mines cashout to cash out, !mines <bet string> to place precise picks. Tool: {ToolUrl}", $"{user.FormatUsername()}, you already have a game running. !mines <picks> to reveal more spaces, !mines cashout to cash out, !mines <bet string> to place precise picks. Tool: {ToolUrl}",
true, autoDeleteAfter: cleanupDelay); true, autoDeleteAfter: cleanupDelay);
return; return;
} }

View File

@@ -294,7 +294,7 @@ public class KasinoMines
{ {
await GetSavedGames(gamblerId); await GetSavedGames(gamblerId);
//attempt to delete the message if its there //attempt to delete the message if its there
if (ActiveGames[gamblerId].LastMessageId != 0) _kfChatBot.KfClient.DeleteMessage(ActiveGames[gamblerId].LastMessageId); if (ActiveGames[gamblerId].LastMessageId != 0) await _kfChatBot.KfClient.DeleteMessageAsync(ActiveGames[gamblerId].LastMessageId);
ActiveGames?.Remove(gamblerId); ActiveGames?.Remove(gamblerId);
await SaveActiveGames(gamblerId); await SaveActiveGames(gamblerId);
} }
@@ -302,17 +302,19 @@ public class KasinoMines
public async Task Cashout(KasinoMinesGame game) public async Task Cashout(KasinoMinesGame game)
{ {
decimal payout = 0; decimal payout = 0;
decimal numGems = game.Size * game.Size - game.Mines; decimal mines = game.Mines;
decimal size2 = game.Size * game.Size;
decimal gems = size2 - mines;
for (int i = 0; i < game.BetsPlaced.Count; i++) for (int i = 0; i < game.BetsPlaced.Count; i++)
{ {
payout += game.Wager * (game.Size * game.Size / numGems); payout += game.Wager * ((size2 - i) / gems);
numGems--;
} }
var newBalance = await Money.NewWagerAsync(game.Creator.Id, game.Wager, payout, WagerGame.Mines); var newBalance = await Money.NewWagerAsync(game.Creator.Id, game.Wager, payout, WagerGame.Mines);
var net = payout - game.Wager; var net = payout - game.Wager;
await _kfChatBot.SendChatMessageAsync( await _kfChatBot.SendChatMessageAsync(
$"{game.Creator.User.FormatUsername()}, you won {await payout.FormatKasinoCurrencyAsync()} from your {await game.Wager.FormatKasinoCurrencyAsync()} bet on mines, collecting {game.BetsPlaced.Count} gems while avoiding {game.Mines} mines. Net: {await net.FormatKasinoCurrencyAsync()}. Balance: {await newBalance.FormatKasinoCurrencyAsync()}"); $"{game.Creator.User.FormatUsername()}, you won {await payout.FormatKasinoCurrencyAsync()} from your {await game.Wager.FormatKasinoCurrencyAsync()} bet on mines, collecting {game.BetsPlaced.Count} gems while avoiding {game.Mines} mines. Net: {await net.FormatKasinoCurrencyAsync()}. Balance: {await newBalance.FormatKasinoCurrencyAsync()}", true, autoDeleteAfter: TimeSpan.FromSeconds(15));
await Task.Delay(TimeSpan.FromSeconds(15));
await RemoveGame(game.Creator.Id); await RemoveGame(game.Creator.Id);
} }
@@ -413,7 +415,7 @@ public class KasinoMines
{ {
await _kfChatBot.KfClient.EditMessageAsync(invalidBetMsg.ChatMessageId!.Value, await _kfChatBot.KfClient.EditMessageAsync(invalidBetMsg.ChatMessageId!.Value,
$"{game.Creator.User.FormatUsername()}, invalid bet of {bet.r},{bet.c} removed (already placed, duplicate, or invalid coordinate)"); $"{game.Creator.User.FormatUsername()}, invalid bet of {bet.r},{bet.c} removed (already placed, duplicate, or invalid coordinate)");
await Task.Delay(3); await Task.Delay(5);
} }
else bets.Add(bet); else bets.Add(bet);
} }