mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 00:54:53 -07:00
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:
parent
c95cc1dd9d
commit
ce8092318e
36 changed files with 184 additions and 58 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include "debug_pb_message.h"
|
||||
|
||||
#include "stringsizes.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ message Command_RollDie {
|
|||
optional Command_RollDie ext = 1005;
|
||||
}
|
||||
optional uint32 sides = 1;
|
||||
optional uint32 count = 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ message Event_RollDie {
|
|||
}
|
||||
optional uint32 sides = 1;
|
||||
optional uint32 value = 2;
|
||||
repeated uint32 values = 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ public:
|
|||
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges) const;
|
||||
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#include "server_game.h"
|
||||
#include "server_player.h"
|
||||
#include "server_room.h"
|
||||
#include "stringsizes.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "pb/serverinfo_room.pb.h"
|
||||
#include "server_game.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "stringsizes.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
// max sizes of strings used in the protocol
|
||||
#ifndef STRINGSIZES_H
|
||||
#define STRINGSIZES_H
|
||||
#ifndef TRICE_LIMITS_H
|
||||
#define TRICE_LIMITS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
|
@ -11,6 +10,11 @@ constexpr int MAX_TEXT_LENGTH = 0xfff;
|
|||
// max size for deck files and pictures
|
||||
constexpr int MAX_FILE_LENGTH = 0xfffff; // about a megabyte
|
||||
|
||||
constexpr uint MINIMUM_DIE_SIDES = 2;
|
||||
constexpr uint MAXIMUM_DIE_SIDES = 1000000;
|
||||
constexpr uint MINIMUM_DICE_TO_ROLL = 1;
|
||||
constexpr uint MAXIMUM_DICE_TO_ROLL = 100;
|
||||
|
||||
// optimized functions to get qstrings that are at most that long
|
||||
static inline QString nameFromStdString(const std::string &_string)
|
||||
{
|
||||
|
|
@ -25,4 +29,4 @@ static inline QString fileFromStdString(const std::string &_string)
|
|||
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_FILE_LENGTH));
|
||||
}
|
||||
|
||||
#endif // STRINGSIZES_H
|
||||
#endif // TRICE_LIMITS_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue