From c8c4291c6f57616489f7d511595c07a63bd230bc Mon Sep 17 00:00:00 2001 From: Warpten Date: Fri, 12 Oct 2012 22:13:28 +0200 Subject: 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 --- src/server/shared/Utilities/Util.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/server/shared/Utilities/Util.cpp') diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index 0897c8814ab..407d0704619 100755 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -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; -- cgit v1.2.3