diff --git a/code/ryzom/client/src/commands.cpp b/code/ryzom/client/src/commands.cpp index 7c33edb90..e8c1178c8 100644 --- a/code/ryzom/client/src/commands.cpp +++ b/code/ryzom/client/src/commands.cpp @@ -475,14 +475,17 @@ bool randomFromString(std::string const& str, sint16& val, sint16 min = -32768, return false; } -NLMISC_COMMAND(random, "Roll a dice and say the result around","[] ") +NLMISC_COMMAND(random, "Roll a dice and say the result around","[] [h|ide]") { // Check parameters. - if (args.size()<1 || args.size()>2) + if (args.size() < 1 || args.size() > 3) return false; sint16 min = 1; sint16 max; + + bool hide = args[args.size()-1][0] == 'h'; + if (!randomFromString(args[0], max)) { CInterfaceManager *pIM = CInterfaceManager::getInstance(); @@ -491,13 +494,13 @@ NLMISC_COMMAND(random, "Roll a dice and say the result around","[] ") pIM->displaySystemInfo(msg); return false; } - if (args.size()==2) + if (args.size() > 1 && args[1][0] != 'h') { if (!randomFromString(args[1], min)) { CInterfaceManager *pIM = CInterfaceManager::getInstance(); ucstring msg = CI18N::get("uiRandomBadParameter"); - strFindReplace(msg, "%s", args[0] ); + strFindReplace(msg, "%s", args[1] ); pIM->displaySystemInfo(msg); return false; } @@ -506,7 +509,7 @@ NLMISC_COMMAND(random, "Roll a dice and say the result around","[] ") std::swap(min, max); if (UserEntity != NULL) - UserEntity->rollDice(min, max); + UserEntity->rollDice(min, max, hide); return true; } diff --git a/code/ryzom/client/src/user_entity.cpp b/code/ryzom/client/src/user_entity.cpp index 25096f304..81a9e5a3a 100644 --- a/code/ryzom/client/src/user_entity.cpp +++ b/code/ryzom/client/src/user_entity.cpp @@ -3091,8 +3091,29 @@ void CUserEntity::setAFK(bool b, string afkTxt) //----------------------------------------------- // rollDice //----------------------------------------------- -void CUserEntity::rollDice(sint16 min, sint16 max) +void CUserEntity::rollDice(sint16 min, sint16 max, bool local) { + if (local) + { + // no need to broadcast over network here + static NLMISC::CRandom* dice = (NLMISC::CRandom*)NULL; + if (!dice) + { + dice = new NLMISC::CRandom; + dice->srand(CTickEventHandler::getGameCycle()); + } + sint16 roll = min + (sint16)dice->rand(max-min); + + ucstring msg = CI18N::get("msgRollDiceLocal"); + strFindReplace(msg, "%min", std::to_string(min)); + strFindReplace(msg, "%max", std::to_string(max)); + strFindReplace(msg, "%roll", std::to_string(roll)); + + CInterfaceManager *pIM= CInterfaceManager::getInstance(); + + pIM->displaySystemInfo(msg, getStringCategory(msg, msg)); + return; + } const string msgName = "COMMAND:RANDOM"; CBitMemStream out; if (GenericMsgHeaderMngr.pushNameToStream(msgName, out)) diff --git a/code/ryzom/client/src/user_entity.h b/code/ryzom/client/src/user_entity.h index ae4730f32..8a4a27c16 100644 --- a/code/ryzom/client/src/user_entity.h +++ b/code/ryzom/client/src/user_entity.h @@ -225,7 +225,7 @@ public: void setAFK(bool b, std::string afkTxt=""); /// Roll a dice and tell the result around - void rollDice(sint16 min, sint16 max); + void rollDice(sint16 min, sint16 max, bool local); /// return true if user can engage melee combat, else return false and display system msg bool canEngageCombat();