[Quest API] Add commify to Perl/Lua. (#2099)

- Add quest::commify(number) to Perl.
- Add eq.commify(number) to Lua.
This commit is contained in:
Kinglykrab 2022-05-03 19:44:22 -04:00 committed by GitHub
parent c4f05c3864
commit 9b075c28b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 23 deletions

View File

@ -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<int>(number.length());
int i = 0;
for (i = string_length - 3; i >= 0; i -= 3) {
if (i > 0) {
temp_string = "," + number.substr(static_cast<unsigned long>(i), 3) + temp_string;
} else {
temp_string = number.substr(static_cast<unsigned long>(i), 3) + temp_string;
}
}
if (i < 0) {
temp_string = number.substr(0, static_cast<unsigned long>(3 + i)) + temp_string;
}
return temp_string;
}

View File

@ -194,6 +194,7 @@ std::string JoinString(const std::vector<std::string>& 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

View File

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

View File

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

View File

@ -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<int>(number.length());
int i = 0;
for (i = string_length - 3; i >= 0; i -= 3) {
if (i > 0) {
temp_string = "," + number.substr(static_cast<unsigned long>(i), 3) + temp_string;
}
else {
temp_string = number.substr(static_cast<unsigned long>(i), 3) + temp_string;
}
}
if (i < 0) {
temp_string = number.substr(0, static_cast<unsigned long>(3 + i)) + temp_string;
}
return temp_string;
}
inline std::string GetMobAttributeByString(Mob *mob, const std::string &attribute)
{
std::string entity_variable = "modify_stat_" + attribute;