Changed: Random command has now private roll.
--HG-- branch : develop
This commit is contained in:
parent
ef1a51d0e4
commit
ed31302163
3 changed files with 31 additions and 7 deletions
|
@ -475,14 +475,17 @@ bool randomFromString(std::string const& str, sint16& val, sint16 min = -32768,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NLMISC_COMMAND(random, "Roll a dice and say the result around","[<min>] <max>")
|
NLMISC_COMMAND(random, "Roll a dice and say the result around","[<min>] <max> [h|ide]")
|
||||||
{
|
{
|
||||||
// Check parameters.
|
// Check parameters.
|
||||||
if (args.size()<1 || args.size()>2)
|
if (args.size() < 1 || args.size() > 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
sint16 min = 1;
|
sint16 min = 1;
|
||||||
sint16 max;
|
sint16 max;
|
||||||
|
|
||||||
|
bool hide = args[args.size()-1][0] == 'h';
|
||||||
|
|
||||||
if (!randomFromString(args[0], max))
|
if (!randomFromString(args[0], max))
|
||||||
{
|
{
|
||||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
||||||
|
@ -491,13 +494,13 @@ NLMISC_COMMAND(random, "Roll a dice and say the result around","[<min>] <max>")
|
||||||
pIM->displaySystemInfo(msg);
|
pIM->displaySystemInfo(msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.size()==2)
|
if (args.size() > 1 && args[1][0] != 'h')
|
||||||
{
|
{
|
||||||
if (!randomFromString(args[1], min))
|
if (!randomFromString(args[1], min))
|
||||||
{
|
{
|
||||||
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
CInterfaceManager *pIM = CInterfaceManager::getInstance();
|
||||||
ucstring msg = CI18N::get("uiRandomBadParameter");
|
ucstring msg = CI18N::get("uiRandomBadParameter");
|
||||||
strFindReplace(msg, "%s", args[0] );
|
strFindReplace(msg, "%s", args[1] );
|
||||||
pIM->displaySystemInfo(msg);
|
pIM->displaySystemInfo(msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +509,7 @@ NLMISC_COMMAND(random, "Roll a dice and say the result around","[<min>] <max>")
|
||||||
std::swap(min, max);
|
std::swap(min, max);
|
||||||
|
|
||||||
if (UserEntity != NULL)
|
if (UserEntity != NULL)
|
||||||
UserEntity->rollDice(min, max);
|
UserEntity->rollDice(min, max, hide);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3091,8 +3091,29 @@ void CUserEntity::setAFK(bool b, string afkTxt)
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// rollDice
|
// 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";
|
const string msgName = "COMMAND:RANDOM";
|
||||||
CBitMemStream out;
|
CBitMemStream out;
|
||||||
if (GenericMsgHeaderMngr.pushNameToStream(msgName, out))
|
if (GenericMsgHeaderMngr.pushNameToStream(msgName, out))
|
||||||
|
|
|
@ -225,7 +225,7 @@ public:
|
||||||
void setAFK(bool b, std::string afkTxt="");
|
void setAFK(bool b, std::string afkTxt="");
|
||||||
|
|
||||||
/// Roll a dice and tell the result around
|
/// 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
|
/// return true if user can engage melee combat, else return false and display system msg
|
||||||
bool canEngageCombat();
|
bool canEngageCombat();
|
||||||
|
|
Loading…
Reference in a new issue