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:
Warpten
2012-10-12 22:13:28 +02:00
parent b06e9cfd41
commit c8c4291c6f
3 changed files with 49 additions and 12 deletions

View File

@@ -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;