Merge branch 'master' into getclassname

This commit is contained in:
Alex 2020-04-06 16:25:29 -04:00 committed by GitHub
commit c6e4b5647f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 180 additions and 0 deletions

View File

@ -941,6 +941,22 @@ const char* Database::GetCharNameByID(uint32 char_id) {
return row[0];
}
const char* Database::GetNPCNameByID(uint32 npc_id) {
std::string query = fmt::format("SELECT `name` FROM `npc_types` WHERE id = {}", npc_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
return "";
}
if (results.RowCount() == 0) {
return "";
}
auto row = results.begin();
return row[0];
}
bool Database::LoadVariables() {
auto results = QueryDatabase(StringFormat("SELECT varname, value, unix_timestamp() FROM variables where unix_timestamp(ts) >= %d", varcache.last_update));
@ -2389,3 +2405,4 @@ int Database::GetInstanceID(uint32 char_id, uint32 zone_id) {
return 0;
}

View File

@ -139,6 +139,7 @@ public:
void GetAccountName(uint32 accountid, char* name, uint32* oLSAccountID = 0);
void GetCharName(uint32 char_id, char* name);
const char *GetCharNameByID(uint32 char_id);
const char *GetNPCNameByID(uint32 npc_id);
void LoginIP(uint32 AccountID, const char* LoginIP);
/* Instancing */

View File

@ -822,6 +822,22 @@ XS(XS__isdisctome) {
XSRETURN(1);
}
XS(XS__getracename);
XS(XS__getracename) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getracename(uint16 race_id)");
dXSTARG;
uint16 race_id = (int) SvIV(ST(0));
std::string race_name = quest_manager.getracename(race_id);
sv_setpv(TARG, race_name.c_str());
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
XS(XS__getspellname);
XS(XS__getspellname) {
dXSARGS;
@ -838,6 +854,22 @@ XS(XS__getspellname) {
XSRETURN(1);
}
XS(XS__getskillname);
XS(XS__getskillname) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getskillname(int skill_id)");
dXSTARG;
int skill_id = (int) SvIV(ST(0));
std::string skill_name = quest_manager.getskillname(skill_id);
sv_setpv(TARG, skill_name.c_str());
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
XS(XS__safemove);
XS(XS__safemove) {
dXSARGS;
@ -2858,6 +2890,22 @@ XS(XS__getitemname) {
XSRETURN(1);
}
XS(XS__getnpcnamebyid);
XS(XS__getnpcnamebyid) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getnpcnamebyid(uint32 npc_id)");
dXSTARG;
uint32 npc_id = (int) SvIV(ST(0));
const char *npc_name = quest_manager.getnpcnamebyid(npc_id);
sv_setpv(TARG, npc_name);
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
XS(XS__UpdateSpawnTimer);
XS(XS__UpdateSpawnTimer) {
dXSARGS;
@ -3282,6 +3330,39 @@ XS(XS__getclassname) {
sv_setpv(TARG, RETVAL.c_str());
XSprePUSH;
PUSHTARG;
XSRETURN(1);
}
XS(XS__getcurrencyitemid);
XS(XS__getcurrencyitemid) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getcurrencyitemid(int currency_id)");
dXSTARG;
int RETVAL;
int currency_id = (int) SvUV(ST(0));
RETVAL = quest_manager.getcurrencyitemid(currency_id);
XSprePUSH;
PUSHi((IV)RETVAL);
XSRETURN(1);
}
XS(XS__getcurrencyid);
XS(XS__getcurrencyid) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: quest::getcurrencyid(uint32 item_id)");
dXSTARG;
int RETVAL;
uint32 item_id = (int) SvUV(ST(0));;
RETVAL = quest_manager.getcurrencyid(item_id);
XSprePUSH;
PUSHi((IV)RETVAL);
XSRETURN(1);
}
@ -4128,16 +4209,21 @@ EXTERN_C XS(boot_quest) {
newXS(strcpy(buf, "forcedooropen"), XS__forcedooropen, file);
newXS(strcpy(buf, "getcharidbyname"), XS__getcharidbyname, file);
newXS(strcpy(buf, "getclassname"), XS__getclassname, file);
newXS(strcpy(buf, "getcurrencyid"), XS__getcurrencyid, file);
newXS(strcpy(buf, "getinventoryslotid"), XS__getinventoryslotid, file);
newXS(strcpy(buf, "getitemname"), XS__getitemname, file);
newXS(strcpy(buf, "getItemName"), XS_qc_getItemName, file);
newXS(strcpy(buf, "getnpcnamebyid"), XS__getnpcnamebyid, file);
newXS(strcpy(buf, "get_spawn_condition"), XS__get_spawn_condition, file);
newXS(strcpy(buf, "getcharnamebyid"), XS__getcharnamebyid, file);
newXS(strcpy(buf, "getcurrencyitemid"), XS__getcurrencyitemid, file);
newXS(strcpy(buf, "getguildnamebyid"), XS__getguildnamebyid, file);
newXS(strcpy(buf, "getguildidbycharid"), XS__getguildidbycharid, file);
newXS(strcpy(buf, "getgroupidbycharid"), XS__getgroupidbycharid, file);
newXS(strcpy(buf, "getraididbycharid"), XS__getraididbycharid, file);
newXS(strcpy(buf, "getracename"), XS__getracename, file);
newXS(strcpy(buf, "getspellname"), XS__getspellname, file);
newXS(strcpy(buf, "getskillname"), XS__getskillname, file);
newXS(strcpy(buf, "getlevel"), XS__getlevel, file);
newXS(strcpy(buf, "getplayerburiedcorpsecount"), XS__getplayerburiedcorpsecount, file);
newXS(strcpy(buf, "getplayercorpsecount"), XS__getplayercorpsecount, file);

View File

@ -393,10 +393,18 @@ bool lua_is_disc_tome(int item_id) {
return quest_manager.isdisctome(item_id);
}
std::string lua_get_race_name(uint32 race_id) {
return quest_manager.getracename(race_id);
}
std::string lua_get_spell_name(uint32 spell_id) {
return quest_manager.getspellname(spell_id);
}
std::string lua_get_skill_name(int skill_id) {
return quest_manager.getskillname(skill_id);
}
void lua_safe_move() {
quest_manager.safemove();
}
@ -886,6 +894,14 @@ std::string lua_get_class_name(uint8 class_id, uint8 level) {
return quest_manager.getclassname(class_id, level);
}
int lua_get_currency_id(uint32 item_id) {
return quest_manager.getcurrencyid(item_id)
}
int lua_get_currency_item_id(int currency_id) {
return quest_manager.getcurrencyitemid(currency_id);
}
const char *lua_get_guild_name_by_id(uint32 guild_id) {
return quest_manager.getguildnamebyid(guild_id);
}
@ -898,6 +914,10 @@ int lua_get_group_id_by_char_id(uint32 char_id) {
return database.GetGroupIDByCharID(char_id);
}
const char *lua_get_npc_name_by_id(uint32 npc_id) {
return quest_manager.getnpcnamebyid(npc_id);
}
int lua_get_raid_id_by_char_id(uint32 char_id) {
return database.GetRaidIDByCharID(char_id);
}
@ -1680,7 +1700,9 @@ luabind::scope lua_register_general() {
luabind::def("depop_zone", &lua_depop_zone),
luabind::def("repop_zone", &lua_repop_zone),
luabind::def("is_disc_tome", &lua_is_disc_tome),
luabind::def("get_race_name", (std::string(*)(uint16))&lua_get_race_name),
luabind::def("get_spell_name", (std::string(*)(uint32))&lua_get_spell_name),
luabind::def("get_skill_name", (std::string(*)(int))&lua_get_skill_name),
luabind::def("safe_move", &lua_safe_move),
luabind::def("rain", &lua_rain),
luabind::def("snow", &lua_snow),
@ -1783,9 +1805,12 @@ luabind::scope lua_register_general() {
luabind::def("get_char_id_by_name", (uint32(*)(const char*))&lua_get_char_id_by_name),
luabind::def("get_class_name", (std::string(*)(uint8))&lua_get_class_name),
luabind::def("get_class_name", (std::string(*)(uint8,uint8))&lua_get_class_name),
luabind::def("get_currency_id", &lua_get_currency_id),
luabind::def("get_currency_item_id", &lua_get_currency_item_id),
luabind::def("get_guild_name_by_id", &lua_get_guild_name_by_id),
luabind::def("get_guild_id_by_char_id", &lua_get_guild_id_by_char_id),
luabind::def("get_group_id_by_char_id", &lua_get_group_id_by_char_id),
luabind::def("get_npc_name_by_id", &lua_get_npc_name_by_id),
luabind::def("get_raid_id_by_char_id", &lua_get_raid_id_by_char_id),
luabind::def("create_instance", &lua_create_instance),
luabind::def("destroy_instance", &lua_destroy_instance),

View File

@ -906,6 +906,10 @@ bool QuestManager::isdisctome(int item_id) {
return(true);
}
std::string QuestManager::getracename(uint16 race_id) {
return GetRaceIDName(race_id);
}
std::string QuestManager::getspellname(uint32 spell_id) {
if (!IsValidSpell(spell_id)) {
return "INVALID SPELL ID IN GETSPELLNAME";
@ -915,6 +919,18 @@ std::string QuestManager::getspellname(uint32 spell_id) {
return spell_name;
}
std::string QuestManager::getskillname(int skill_id) {
if (skill_id >= 0 && skill_id < EQEmu::skills::SkillCount) {
std::map<EQEmu::skills::SkillType, std::string> Skills = EQEmu::skills::GetSkillTypeMap();
for (auto skills_iter : Skills) {
if (skill_id == skills_iter.first) {
return skills_iter.second;
}
}
}
return std::string();
}
void QuestManager::safemove() {
QuestManagerCurrentQuestVars();
if (initiator && initiator->IsClient())
@ -2725,6 +2741,13 @@ std::string QuestManager::getitemname(uint32 item_id) {
return item_name;
}
const char *QuestManager::getnpcnamebyid(uint32 npc_id) {
if (npc_id > 0) {
return database.GetNPCNameByID(npc_id);
}
return "";
}
uint16 QuestManager::CreateInstance(const char *zone, int16 version, uint32 duration)
{
QuestManagerCurrentQuestVars();
@ -2943,6 +2966,29 @@ std::string QuestManager::getclassname(uint8 class_id, uint8 level) {
return GetClassIDName(class_id, level);
}
int QuestManager::getcurrencyid(uint32 item_id) {
auto iter = zone->AlternateCurrencies.begin();
while (iter != zone->AlternateCurrencies.end()) {
if (item_id == (*iter).item_id) {
return (*iter).id;
}
++iter;
}
return 0;
}
int QuestManager::getcurrencyitemid(int currency_id) {
if (currency_id > 0) {
auto iter = zone->AlternateCurrencies.begin();
while (iter != zone->AlternateCurrencies.end()) {
if (currency_id == (*iter).id) {
return (*iter).item_id;
}
++iter;
}
return 0;
}
const char* QuestManager::getguildnamebyid(int guild_id) {
if (guild_id > 0)
return guild_mgr.GetGuildName(guild_id);

View File

@ -107,7 +107,9 @@ public:
void level(int newlevel);
void traindisc(int discipline_tome_item_id);
bool isdisctome(int item_id);
std::string getracename(uint16 race_id);
std::string getspellname(uint32 spell_id);
std::string getskillname(int skill_id);
void safemove();
void rain(int weather);
void snow(int weather);
@ -258,9 +260,12 @@ public:
const char* getcharnamebyid(uint32 char_id);
uint32 getcharidbyname(const char* name);
std::string getclassname(uint8 class_id, uint8 level = 0);
int getcurrencyid(uint32 item_id);
int getcurrencyitemid(int currency_id);
const char* getguildnamebyid(int guild_id);
int getguildidbycharid(uint32 char_id);
int getgroupidbycharid(uint32 char_id);
const char* getnpcnamebyid(uint32 npc_id);
int getraididbycharid(uint32 char_id);
void SetRunning(bool val);
bool IsRunning();