Allow up to 100 dice to be rolled at a time (#5047)

* Allow up to 100 dice to be rolled at a time
- Fix #4276
This commit is contained in:
Zach H
2024-06-12 08:37:04 -04:00
committed by GitHub
parent c95cc1dd9d
commit ce8092318e
36 changed files with 184 additions and 58 deletions

View File

@@ -79,7 +79,7 @@
#include "server_database_interface.h"
#include "server_game.h"
#include "server_room.h"
#include "stringsizes.h"
#include "trice_limits.h"
#include <QDebug>
#include <algorithm>
@@ -1060,7 +1060,7 @@ Server_Player::cmdMulligan(const Command_Mulligan &cmd, ResponseContainer & /*rc
}
Response::ResponseCode
Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges)
Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) const
{
if (spectator) {
return Response::RespFunctionNotAllowed;
@@ -1069,9 +1069,15 @@ Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/
return Response::RespContextError;
}
const auto validatedSides = static_cast<int>(std::min(std::max(cmd.sides(), MINIMUM_DIE_SIDES), MAXIMUM_DIE_SIDES));
const auto validatedDiceToRoll =
static_cast<int>(std::min(std::max(cmd.count(), MINIMUM_DICE_TO_ROLL), MAXIMUM_DICE_TO_ROLL));
Event_RollDie event;
event.set_sides(cmd.sides());
event.set_value(rng->rand(1, cmd.sides()));
event.set_sides(validatedSides);
for (auto i = 0; i < validatedDiceToRoll; ++i) {
event.add_values(rng->rand(1, validatedSides));
}
ges.enqueueGameEvent(event, playerId);
return Response::RespOk;