mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
fix plinko spam, allow multiple slot spins within the same image (#40)
* spam reduction spam reduction * Update SlotsCommand to handle multiple spins Update SlotsCommand to handle multiple spins
This commit is contained in:
@@ -172,6 +172,8 @@ public class PlinkoCommand : ICommand
|
|||||||
}
|
}
|
||||||
breakCounter = 0;
|
breakCounter = 0;
|
||||||
var logger = LogManager.GetCurrentClassLogger();
|
var logger = LogManager.GetCurrentClassLogger();
|
||||||
|
string lastPayoutMessage = "";
|
||||||
|
string PlinkoMessage = "";
|
||||||
while (ballsNotInPlay.Count > 0 || ballsInPlay.Count > 0)
|
while (ballsNotInPlay.Count > 0 || ballsInPlay.Count > 0)
|
||||||
{
|
{
|
||||||
breakCounter++;
|
breakCounter++;
|
||||||
@@ -182,7 +184,8 @@ public class PlinkoCommand : ICommand
|
|||||||
ballsInPlay.Add(ballsNotInPlay[0]);
|
ballsInPlay.Add(ballsNotInPlay[0]);
|
||||||
ballsNotInPlay.RemoveAt(0);
|
ballsNotInPlay.RemoveAt(0);
|
||||||
}
|
}
|
||||||
await botInstance.KfClient.EditMessageAsync(plinkoMessageID.ChatMessageId!.Value,PlinkoBoardDisplay(ballsInPlay));
|
PlinkoMessage = PlinkoBoardDisplay(ballsInPlay) + "[br]" + lastPayoutMessage;
|
||||||
|
await botInstance.KfClient.EditMessageAsync(plinkoMessageID.ChatMessageId!.Value,PlinkoMessage);
|
||||||
if (ballsInPlay[0].POSITION.row == DIFFICULTY - 1) //once your ball has reached the bottom calculate the payout
|
if (ballsInPlay[0].POSITION.row == DIFFICULTY - 1) //once your ball has reached the bottom calculate the payout
|
||||||
{
|
{
|
||||||
currentPayout = wager * PlinkoPayoutBoard[ballsInPlay[0].POSITION.col];
|
currentPayout = wager * PlinkoPayoutBoard[ballsInPlay[0].POSITION.col];
|
||||||
@@ -190,13 +193,11 @@ public class PlinkoCommand : ICommand
|
|||||||
if (currentPayout == wager * 25) logger.Info($"Plinko: Max win on plinko, ball position: ({ballsInPlay[0].POSITION.row}, {ballsInPlay[0].POSITION.col})");
|
if (currentPayout == wager * 25) logger.Info($"Plinko: Max win on plinko, ball position: ({ballsInPlay[0].POSITION.row}, {ballsInPlay[0].POSITION.col})");
|
||||||
if (currentPayout > wager)
|
if (currentPayout > wager)
|
||||||
{
|
{
|
||||||
await botInstance.SendChatMessageAsync(
|
lastPayoutMessage = ($"{user.FormatUsername()}, you [color={settings[BuiltIn.Keys.KiwiFarmsGreenColor].Value!}]won[/color] ${currentPayout} KKK from a plinko ball worth {wager}!");
|
||||||
$"{user.FormatUsername()}, you [color={settings[BuiltIn.Keys.KiwiFarmsGreenColor].Value!}]won[/color] ${currentPayout} KKK from a plinko ball worth {wager}!", true, autoDeleteAfter: TimeSpan.FromSeconds(5));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await botInstance.SendChatMessageAsync(
|
lastPayoutMessage = ($"{user.FormatUsername()}, you [color={settings[BuiltIn.Keys.KiwiFarmsRedColor].Value!}]lost[/color] ${wager-currentPayout} KKK from a plinko ball worth {wager}.");
|
||||||
$"{user.FormatUsername()}, you [color={settings[BuiltIn.Keys.KiwiFarmsRedColor].Value!}]lost[/color] ${wager-currentPayout} KKK from a plinko ball worth {wager}.", true, autoDeleteAfter: TimeSpan.FromSeconds(5));
|
|
||||||
}
|
}
|
||||||
ballsInPlay.RemoveAt(0);
|
ballsInPlay.RemoveAt(0);
|
||||||
}
|
}
|
||||||
@@ -205,9 +206,10 @@ public class PlinkoCommand : ICommand
|
|||||||
ball.Iterate();
|
ball.Iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(250, ctx);
|
await Task.Delay(300, ctx);
|
||||||
await botInstance.KfClient.EditMessageAsync(plinkoMessageID.ChatMessageId!.Value,PlinkoBoardDisplay(ballsInPlay));
|
PlinkoMessage = PlinkoBoardDisplay(ballsInPlay) + "[br]" + lastPayoutMessage;
|
||||||
await Task.Delay(250, ctx);
|
await botInstance.KfClient.EditMessageAsync(plinkoMessageID.ChatMessageId!.Value, PlinkoMessage);
|
||||||
|
await Task.Delay(300, ctx);
|
||||||
|
|
||||||
}
|
}
|
||||||
var newBalance = await Money.NewWagerAsync(gambler.Id, wager*numberOfBalls, payout-(wager*numberOfBalls), WagerGame.Plinko, ct: ctx);
|
var newBalance = await Money.NewWagerAsync(gambler.Id, wager*numberOfBalls, payout-(wager*numberOfBalls), WagerGame.Plinko, ct: ctx);
|
||||||
|
|||||||
@@ -23,9 +23,13 @@ namespace KfChatDotNetBot.Commands.Kasino;
|
|||||||
public class SlotsCommand : ICommand
|
public class SlotsCommand : ICommand
|
||||||
{
|
{
|
||||||
public List<Regex> Patterns => [
|
public List<Regex> Patterns => [
|
||||||
|
new Regex(@"^slots (?<amount>\d+) (?<spins>\d+)$", RegexOptions.IgnoreCase),
|
||||||
|
new Regex(@"^slots (?<amount>\d+\.\d+) (?<spins>\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex(@"^slots (?<amount>\d+)$", RegexOptions.IgnoreCase),
|
new Regex(@"^slots (?<amount>\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex(@"^slots (?<amount>\d+\.\d+)$", RegexOptions.IgnoreCase),
|
new Regex(@"^slots (?<amount>\d+\.\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex("^slots$", RegexOptions.IgnoreCase),
|
new Regex("^slots$", RegexOptions.IgnoreCase),
|
||||||
|
new Regex(@"^sluts (?<amount>\d+) (?<spins>\d+)$", RegexOptions.IgnoreCase),
|
||||||
|
new Regex(@"^sluts (?<amount>\d+\.\d+) (?<spins>\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex(@"^sluts (?<amount>\d+)$", RegexOptions.IgnoreCase),
|
new Regex(@"^sluts (?<amount>\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex(@"^sluts (?<amount>\d+\.\d+)$", RegexOptions.IgnoreCase),
|
new Regex(@"^sluts (?<amount>\d+\.\d+)$", RegexOptions.IgnoreCase),
|
||||||
new Regex("^sluts", RegexOptions.IgnoreCase)
|
new Regex("^sluts", RegexOptions.IgnoreCase)
|
||||||
@@ -66,11 +70,22 @@ public class SlotsCommand : ICommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int spins = 0;
|
||||||
|
if (!arguments.TryGetValue("spins", out var spinsArg)) spins = 1;
|
||||||
|
else spins = Convert.ToInt32(spinsArg.Value);
|
||||||
|
|
||||||
|
if (spins < 1 || spins > 10)
|
||||||
|
{
|
||||||
|
await botInstance.SendChatMessageAsync($"{user.FormatUsername()} you can only do between 1 and 10 spins.", true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var wager = Convert.ToDecimal(amount.Value);
|
var wager = Convert.ToDecimal(amount.Value);
|
||||||
var gambler = await Money.GetGamblerEntityAsync(user.Id, ct: ctx);
|
var gambler = await Money.GetGamblerEntityAsync(user.Id, ct: ctx);
|
||||||
if (gambler == null)
|
if (gambler == null)
|
||||||
throw new InvalidOperationException($"Caught a null when retrieving gambler for {user.KfUsername}");
|
throw new InvalidOperationException($"Caught a null when retrieving gambler for {user.KfUsername}");
|
||||||
if (gambler.Balance < wager)
|
if (gambler.Balance < wager * spins)
|
||||||
{
|
{
|
||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
$"{user.FormatUsername()}, your balance of {await gambler.Balance.FormatKasinoCurrencyAsync()} isn't enough for this wager.",
|
$"{user.FormatUsername()}, your balance of {await gambler.Balance.FormatKasinoCurrencyAsync()} isn't enough for this wager.",
|
||||||
@@ -82,7 +97,7 @@ public class SlotsCommand : ICommand
|
|||||||
using (var board = new KiwiSlotBoard(wager))
|
using (var board = new KiwiSlotBoard(wager))
|
||||||
{
|
{
|
||||||
board.LoadAssets();
|
board.LoadAssets();
|
||||||
board.ExecuteGameLoop();
|
board.ExecuteGameLoop(spins);
|
||||||
using (var finalImageStream = board.ExportAndCleanup())
|
using (var finalImageStream = board.ExportAndCleanup())
|
||||||
{
|
{
|
||||||
if (finalImageStream == null)
|
if (finalImageStream == null)
|
||||||
@@ -101,17 +116,17 @@ public class SlotsCommand : ICommand
|
|||||||
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
|
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor
|
||||||
]);
|
]);
|
||||||
decimal newBalance;
|
decimal newBalance;
|
||||||
if (winnings == 0) //dud spin
|
if (winnings == 0) //dud spin(s)
|
||||||
{
|
{
|
||||||
newBalance = await Money.NewWagerAsync(gambler.Id, wager, -wager, WagerGame.Slots, ct: ctx);
|
newBalance = await Money.NewWagerAsync(gambler.Id, wager*spins, -wager*spins, WagerGame.Slots, ct: ctx);
|
||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
$"{user.FormatUsername()} you [color={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]lost[/color]. Current balance: {await newBalance.FormatKasinoCurrencyAsync()}",
|
$"{user.FormatUsername()} you [color={colors[BuiltIn.Keys.KiwiFarmsRedColor].Value}]lost[/color]. Current balance: {await newBalance.FormatKasinoCurrencyAsync()}",
|
||||||
true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
winnings -= wager;
|
winnings -= wager*spins;
|
||||||
newBalance = await Money.NewWagerAsync(gambler.Id, wager, winnings, WagerGame.Slots, ct: ctx);
|
newBalance = await Money.NewWagerAsync(gambler.Id, wager*spins, winnings, WagerGame.Slots, ct: ctx);
|
||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]won[/color] {await winnings.FormatKasinoCurrencyAsync()}! Current balance: {await newBalance.FormatKasinoCurrencyAsync()}", true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
$"{user.FormatUsername()}, you [color={colors[BuiltIn.Keys.KiwiFarmsGreenColor].Value}]won[/color] {await winnings.FormatKasinoCurrencyAsync()}! Current balance: {await newBalance.FormatKasinoCurrencyAsync()}", true, autoDeleteAfter: TimeSpan.FromSeconds(30));
|
||||||
}
|
}
|
||||||
@@ -307,7 +322,7 @@ public class SlotsCommand : ICommand
|
|||||||
AnimatedImage.Frames.RemoveFrame(0);
|
AnimatedImage.Frames.RemoveFrame(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteGameLoop(int featureSpins = 0)
|
public void ExecuteGameLoop(int spins, int featureSpins = 0)
|
||||||
{
|
{
|
||||||
GeneratePreBoard(featureSpins);
|
GeneratePreBoard(featureSpins);
|
||||||
var fCount = 0;
|
var fCount = 0;
|
||||||
@@ -322,7 +337,7 @@ public class SlotsCommand : ICommand
|
|||||||
|
|
||||||
ProcessReelsAndWins();
|
ProcessReelsAndWins();
|
||||||
var total = _activeFeatureTier switch { 3 => 3, 4 => 5, 5 => 10, _ => 0 };
|
var total = _activeFeatureTier switch { 3 => 3, 4 => 5, 5 => 10, _ => 0 };
|
||||||
if (featureSpins == 0) for (var s = 1; s <= total; s++) ExecuteGameLoop(s);
|
if (featureSpins == 0) for (var s = 1; s <= total; s++) ExecuteGameLoop(1,s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessReelsAndWins()
|
private void ProcessReelsAndWins()
|
||||||
@@ -410,4 +425,4 @@ public class SlotsCommand : ICommand
|
|||||||
AnimatedImage?.Dispose();
|
AnimatedImage?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user