mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-06 12:27:48 +00:00
refactor(Scripts/Commands): convert cs_modify to new system (#9474)
This commit is contained in:
@@ -19,7 +19,9 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Containers.h"
|
#include "Containers.h"
|
||||||
#include "IpAddress.h"
|
#include "IpAddress.h"
|
||||||
|
#include "StringConvert.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "Tokenize.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/core/demangle.hpp>
|
#include <boost/core/demangle.hpp>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@@ -185,41 +187,55 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 MoneyStringToMoney(const std::string& moneyString)
|
Optional<int32> MoneyStringToMoney(std::string_view moneyString)
|
||||||
{
|
{
|
||||||
int32 money = 0;
|
int32 money = 0;
|
||||||
|
|
||||||
if (!(std::count(moneyString.begin(), moneyString.end(), 'g') == 1 ||
|
bool hadG = false;
|
||||||
std::count(moneyString.begin(), moneyString.end(), 's') == 1 ||
|
bool hadS = false;
|
||||||
std::count(moneyString.begin(), moneyString.end(), 'c') == 1))
|
bool hadC = false;
|
||||||
{
|
|
||||||
return 0; // Bad format
|
|
||||||
}
|
|
||||||
|
|
||||||
Tokenizer tokens(moneyString, ' ');
|
for (std::string_view token : Acore::Tokenize(moneyString, ' ', false))
|
||||||
for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
|
|
||||||
{
|
{
|
||||||
std::string tokenString(*itr);
|
uint32 unit;
|
||||||
size_t gCount = std::count(tokenString.begin(), tokenString.end(), 'g');
|
switch (token[token.length() - 1])
|
||||||
size_t sCount = std::count(tokenString.begin(), tokenString.end(), 's');
|
|
||||||
size_t cCount = std::count(tokenString.begin(), tokenString.end(), 'c');
|
|
||||||
if (gCount + sCount + cCount != 1)
|
|
||||||
{
|
{
|
||||||
return 0;
|
case 'g':
|
||||||
|
if (hadG)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
hadG = true;
|
||||||
|
unit = 100 * 100;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (hadS)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
hadS = true;
|
||||||
|
unit = 100;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
if (hadC)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
hadC = true;
|
||||||
|
unit = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 amount = atoi(*itr);
|
Optional<uint32> amount = Acore::StringTo<uint32>(token.substr(0, token.length() - 1));
|
||||||
if (gCount == 1)
|
if (amount)
|
||||||
{
|
{
|
||||||
money += amount * 100 * 100;
|
money += (unit * *amount);
|
||||||
}
|
}
|
||||||
else if (sCount == 1)
|
else
|
||||||
{
|
{
|
||||||
money += amount * 100;
|
return std::nullopt;
|
||||||
}
|
|
||||||
else if (cCount == 1)
|
|
||||||
{
|
|
||||||
money += amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "Containers.h"
|
#include "Containers.h"
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
|
#include "Optional.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@@ -74,7 +75,7 @@ tm TimeBreakdown(time_t t);
|
|||||||
|
|
||||||
void stripLineInvisibleChars(std::string& src);
|
void stripLineInvisibleChars(std::string& src);
|
||||||
|
|
||||||
int32 MoneyStringToMoney(const std::string& moneyString);
|
AC_COMMON_API Optional<int32> MoneyStringToMoney(std::string_view moneyString);
|
||||||
|
|
||||||
std::string secsToTimeString(uint64 timeInSecs, bool shortText = false);
|
std::string secsToTimeString(uint64 timeInSecs, bool shortText = false);
|
||||||
uint32 TimeStringToSecs(const std::string& timestring);
|
uint32 TimeStringToSecs(const std::string& timestring);
|
||||||
|
|||||||
@@ -25,10 +25,16 @@
|
|||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] =
|
constexpr std::array<uint32, MAX_REPUTATION_RANK> ReputationRankStrIndex =
|
||||||
{
|
{
|
||||||
LANG_REP_HATED, LANG_REP_HOSTILE, LANG_REP_UNFRIENDLY, LANG_REP_NEUTRAL,
|
LANG_REP_HATED,
|
||||||
LANG_REP_FRIENDLY, LANG_REP_HONORED, LANG_REP_REVERED, LANG_REP_EXALTED
|
LANG_REP_HOSTILE,
|
||||||
|
LANG_REP_UNFRIENDLY,
|
||||||
|
LANG_REP_NEUTRAL,
|
||||||
|
LANG_REP_FRIENDLY,
|
||||||
|
LANG_REP_HONORED,
|
||||||
|
LANG_REP_REVERED,
|
||||||
|
LANG_REP_EXALTED
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint32 RepListID;
|
typedef uint32 RepListID;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user