diff --git a/common/string_util.cpp b/common/string_util.cpp index e9efceaf9..be4a9136d 100644 --- a/common/string_util.cpp +++ b/common/string_util.cpp @@ -1265,3 +1265,24 @@ std::string ConvertMoneyToString(uint32 platinum, uint32 gold, uint32 silver, ui } return money_string; } + +std::string commify(const std::string &number) { + std::string temp_string; + + auto string_length = static_cast(number.length()); + + int i = 0; + for (i = string_length - 3; i >= 0; i -= 3) { + if (i > 0) { + temp_string = "," + number.substr(static_cast(i), 3) + temp_string; + } else { + temp_string = number.substr(static_cast(i), 3) + temp_string; + } + } + + if (i < 0) { + temp_string = number.substr(0, static_cast(3 + i)) + temp_string; + } + + return temp_string; +} diff --git a/common/string_util.h b/common/string_util.h index 6ec211835..33bb0ac78 100644 --- a/common/string_util.h +++ b/common/string_util.h @@ -194,6 +194,7 @@ std::string JoinString(const std::vector& ar, const std::string &de void find_replace(std::string& string_subject, const std::string& search_string, const std::string& replace_string); std::string replace_string(std::string subject, const std::string &search, const std::string &replace); void ParseAccountString(const std::string &s, std::string &account, std::string &loginserver); +std::string commify(const std::string &number); //const char based diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 8e42e6d8d..a1cc13460 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -8175,6 +8175,22 @@ XS(XS__getenvironmentaldamagename) { XSRETURN(1); } +XS(XS__commify); +XS(XS__commify) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::commify(std::string number)"); + + dXSTARG; + std::string number = (std::string) SvPV_nolen(ST(0)); + std::string commified_number = commify(number); + + sv_setpv(TARG, commified_number.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + /* This is the callback perl will look for to setup the quest package's XSUBs @@ -8268,6 +8284,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "clear_zone_flag"), XS__clear_zone_flag, file); newXS(strcpy(buf, "clearspawntimers"), XS__clearspawntimers, file); newXS(strcpy(buf, "collectitems"), XS__collectitems, file); + newXS(strcpy(buf, "commify"), XS__commify, file); newXS(strcpy(buf, "completedtasksinset"), XS__completedtasksinset, file); newXS(strcpy(buf, "countitem"), XS__countitem, file); newXS(strcpy(buf, "countspawnednpcs"), XS__countspawnednpcs, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index b6362df7c..9531b7455 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -3388,6 +3388,10 @@ std::string lua_get_environmental_damage_name(uint8 damage_type) { return quest_manager.getenvironmentaldamagename(damage_type); } +std::string lua_commify(std::string number) { + return commify(number); +} + #define LuaCreateNPCParse(name, c_type, default_value) do { \ cur = table[#name]; \ if(luabind::type(cur) != LUA_TNIL) { \ @@ -3840,6 +3844,7 @@ luabind::scope lua_register_general() { luabind::def("get_body_type_name", &lua_get_body_type_name), luabind::def("get_consider_level_name", &lua_get_consider_level_name), luabind::def("get_environmental_damage_name", &lua_get_environmental_damage_name), + luabind::def("commify", &lua_commify), /* Cross Zone diff --git a/zone/mob_info.cpp b/zone/mob_info.cpp index 12da818fd..b10a45fa2 100644 --- a/zone/mob_info.cpp +++ b/zone/mob_info.cpp @@ -22,31 +22,9 @@ #include "mob.h" #include "../common/races.h" #include "../common/say_link.h" +#include "../common/string_util.h" #include "npc_scale_manager.h" -std::string commify(const std::string &number) -{ - std::string temp_string; - - auto string_length = static_cast(number.length()); - - int i = 0; - for (i = string_length - 3; i >= 0; i -= 3) { - if (i > 0) { - temp_string = "," + number.substr(static_cast(i), 3) + temp_string; - } - else { - temp_string = number.substr(static_cast(i), 3) + temp_string; - } - } - - if (i < 0) { - temp_string = number.substr(0, static_cast(3 + i)) + temp_string; - } - - return temp_string; -} - inline std::string GetMobAttributeByString(Mob *mob, const std::string &attribute) { std::string entity_variable = "modify_stat_" + attribute;