[AB-66] adding min mines ratio and other input restrictions for mines game which should avoid some too easy setups

This commit is contained in:
Sheldan
2022-12-02 21:16:32 +01:00
parent 4e1db26df7
commit 9ddd386c6f
8 changed files with 48 additions and 12 deletions

View File

@@ -81,7 +81,8 @@ public class Mines extends AbstractConditionableCommand {
mines = slashCommandParameterService.getCommandOption(MINES_PARAMETER, event, Integer.class);
}
Integer credit = null;
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, event.getGuild().getIdLong());
long serverId = event.getGuild().getIdLong();
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
if(economyEnabled){
credit = 50;
if(slashCommandParameterService.hasCommandOption(CREDITS_PARAMETER, event)) {
@@ -97,10 +98,10 @@ public class Mines extends AbstractConditionableCommand {
throw new NotEnoughCreditsException();
}
}
MineBoard board = gameService.createBoard(width, height, mines);
MineBoard board = gameService.createBoard(width, height, mines, serverId);
board.setCreditsEnabled(economyEnabled);
board.setUserId(event.getMember().getIdLong());
board.setServerId(event.getGuild().getIdLong());
board.setServerId(serverId);
board.setCredits(credit);
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board);
return interactionService.replyMessageToSend(messageToSend, event)
@@ -128,7 +129,8 @@ public class Mines extends AbstractConditionableCommand {
mines = (Integer) parameters.get(2);
}
Integer credit = null;
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, commandContext.getGuild().getIdLong());
long serverId = commandContext.getGuild().getIdLong();
boolean economyEnabled = featureFlagService.getFeatureFlagValue(EntertainmentFeatureDefinition.ECONOMY, serverId);
if(economyEnabled){
credit = 50;
if(parameters.size() == 4) {
@@ -144,10 +146,10 @@ public class Mines extends AbstractConditionableCommand {
throw new NotEnoughCreditsException();
}
}
MineBoard board = gameService.createBoard(width, height, mines);
MineBoard board = gameService.createBoard(width, height, mines, serverId);
board.setCreditsEnabled(economyEnabled);
board.setUserId(commandContext.getAuthor().getIdLong());
board.setServerId(commandContext.getGuild().getIdLong());
board.setServerId(serverId);
board.setCredits(credit);
MessageToSend messageToSend = templateService.renderEmbedTemplate(MINE_BOARD_TEMPLATE_KEY, board);
List<CompletableFuture<Message>> futures = channelService.sendMessageToSendToChannel(messageToSend, commandContext.getChannel());

View File

@@ -39,6 +39,9 @@ public class MinesButtonClickedListener implements ButtonClickedListener {
@Override
public ButtonClickedListenerResult execute(ButtonClickedListenerModel model) {
MineBoardPayload payload = (MineBoardPayload) model.getDeserializedPayload();
if(model.getEvent().getUser().getIdLong() != payload.getMineBoard().getUserId()) {
return ButtonClickedListenerResult.IGNORED;
}
MineBoard mineBoard = payload.getMineBoard();
if(!mineBoard.getState().equals(GameService.MineResult.CONTINUE)) {
return ButtonClickedListenerResult.IGNORED;

View File

@@ -23,6 +23,7 @@ import java.security.SecureRandom;
import java.util.*;
import java.util.stream.Collectors;
import static dev.sheldan.abstracto.entertainment.config.EconomyFeatureConfig.MINES_MINIMUM_MINES_RATIO;
import static dev.sheldan.abstracto.entertainment.config.GamesFeatureConfig.MINES_CREDITS_FACTOR;
@Component
@@ -51,9 +52,13 @@ public class GameServiceBean implements GameService {
private ConfigService configService;
@Override
public MineBoard createBoard(Integer width, Integer height, Integer mines) {
if(mines >= width * height || width > 5 || height > 5 || mines <= 0 || height == 0 || width == 0) {
throw new InvalidGameBoardException();
public MineBoard createBoard(Integer width, Integer height, Integer mines, Long serverId) {
double minMinesRatio = configService.getDoubleValueOrConfigDefault(MINES_MINIMUM_MINES_RATIO, serverId);
if(mines >= width * height || width > 5 || height > 5 || mines <= 1 || height <= 1 || width <= 1) {
throw new InvalidGameBoardException(minMinesRatio);
}
if((double) mines / (width * height) < minMinesRatio) {
throw new InvalidGameBoardException(minMinesRatio);
}
MineBoard mineBoard = generateEmptyBoard(width, height);
mineBoard.setMineCount(mines);

View File

@@ -26,6 +26,9 @@ abstracto.featureFlags.games.enabled=false
abstracto.systemConfigs.minesCreditsFactor.name=minesCreditsFactor
abstracto.systemConfigs.minesCreditsFactor.doubleValue=5
abstracto.systemConfigs.minesMinMineRatio.name=minesMinMineRatio
abstracto.systemConfigs.minesMinMineRatio.doubleValue=0.2
# for now this is fine
abstracto.systemConfigs.creditGambleJackpot.name=creditGambleJackpot
abstracto.systemConfigs.creditGambleJackpot.longValue=1000