mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-27 20:32:21 +01:00
Core/Commands: Allow .modify money to take another parameter structure:
Example uses: * .modify money 325g 25s 12c is the same as .modify money 3252512 * .modify money -12g is the same as .modify money -120000 * .modify money -12g 45s is the same as .modify money -115500 * .modify money 25c 18g is the same as .modify money 18g 25c
This commit is contained in:
@@ -150,6 +150,37 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
int32 MoneyStringToMoney(const std::string& moneyString)
|
||||
{
|
||||
int32 money = 0;
|
||||
|
||||
if (!(std::count(moneyString.begin(), moneyString.end(), 'g') == 1 ||
|
||||
std::count(moneyString.begin(), moneyString.end(), 's') == 1 ||
|
||||
std::count(moneyString.begin(), moneyString.end(), 'c') == 1))
|
||||
return 0; // Bad format
|
||||
|
||||
Tokenizer tokens(moneyString, ' ');
|
||||
for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
|
||||
{
|
||||
std::string tokenString(*itr);
|
||||
uint32 gCount = std::count(tokenString.begin(), tokenString.end(), 'g');
|
||||
uint32 sCount = std::count(tokenString.begin(), tokenString.end(), 's');
|
||||
uint32 cCount = std::count(tokenString.begin(), tokenString.end(), 'c');
|
||||
if (gCount + sCount + cCount != 1)
|
||||
return 0;
|
||||
|
||||
uint32 amount = atoi(*itr);
|
||||
if (gCount == 1)
|
||||
money += amount * 100 * 100;
|
||||
else if (sCount == 1)
|
||||
money += amount * 100;
|
||||
else if (cCount == 1)
|
||||
money += amount;
|
||||
}
|
||||
|
||||
return money;
|
||||
}
|
||||
|
||||
uint32 TimeStringToSecs(const std::string& timestring)
|
||||
{
|
||||
uint32 secs = 0;
|
||||
|
||||
Reference in New Issue
Block a user