From bc875ae554588b2d9153ecbd7a0efb9c78ffdc8a Mon Sep 17 00:00:00 2001 From: KayenEQ Date: Wed, 13 Apr 2022 11:20:03 -0400 Subject: [PATCH] [API] Methods for getting more information on quest timers. (#2060) * hastimer * [API] Check quest timer duration, timer remaining and if timer exists. * [API] Methods for getting more information on quest timers. * [API] Methods for getting more information on quest timers. * [API] Methods for getting more information on quest timers. --- zone/embparser_api.cpp | 53 +++++++++++++++++++++++++++++++++++++ zone/lua_general.cpp | 15 +++++++++++ zone/questmgr.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++ zone/questmgr.h | 3 +++ 4 files changed, 131 insertions(+) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index db814234b..8e42e6d8d 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -590,6 +590,56 @@ XS(XS__zoneraid) { XSRETURN_EMPTY; } +XS(XS__hastimer); +XS(XS__hastimer) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::hastimer(string timer_name)"); + + bool RETVAL; + char *timer_name = (char *)SvPV_nolen(ST(0)); + + RETVAL = quest_manager.hastimer(timer_name); + + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + XSRETURN(1); +} + +XS(XS__getremainingtimeMS); +XS(XS__getremainingtimeMS) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::getremainingtimeMS(string timer_name)"); + + uint32 RETVAL; + dXSTARG; + char *timer_name = (char *)SvPV_nolen(ST(0)); + + RETVAL = quest_manager.getremainingtimeMS(timer_name); + + XSprePUSH; + PUSHu((IV)RETVAL); + XSRETURN(1); +} + +XS(XS__gettimerdurationMS); +XS(XS__gettimerdurationMS) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: quest::gettimerdurationMS(string timer_name)"); + + uint32 RETVAL; + dXSTARG; + char *timer_name = (char *)SvPV_nolen(ST(0)); + + RETVAL = quest_manager.gettimerdurationMS(timer_name); + + XSprePUSH; + PUSHu((IV)RETVAL); + XSRETURN(1); +} + XS(XS__settimer); XS(XS__settimer) { dXSARGS; @@ -8439,6 +8489,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "getinventoryslotname"), XS__getinventoryslotname, file); newXS(strcpy(buf, "getraididbycharid"), XS__getraididbycharid, file); newXS(strcpy(buf, "getracename"), XS__getracename, file); + newXS(strcpy(buf, "getremainingtimeMS"), XS__getremainingtimeMS, file); newXS(strcpy(buf, "getspell"), XS__getspell, file); newXS(strcpy(buf, "getspellname"), XS__getspellname, file); newXS(strcpy(buf, "get_spell_level"), XS__get_spell_level, file); @@ -8450,10 +8501,12 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "getplayercorpsecountbyzoneid"), XS__getplayercorpsecountbyzoneid, file); newXS(strcpy(buf, "gettaskactivitydonecount"), XS__gettaskactivitydonecount, file); newXS(strcpy(buf, "gettaskname"), XS__gettaskname, file); + newXS(strcpy(buf, "gettimerdurationMS"), XS__gettimerdurationMS, file); newXS(strcpy(buf, "givecash"), XS__givecash, file); newXS(strcpy(buf, "gmmove"), XS__gmmove, file); newXS(strcpy(buf, "gmsay"), XS__gmsay, file); newXS(strcpy(buf, "has_zone_flag"), XS__has_zone_flag, file); + newXS(strcpy(buf, "hastimer"), XS__hastimer, file); newXS(strcpy(buf, "incstat"), XS__incstat, file); newXS(strcpy(buf, "isdisctome"), XS__isdisctome, file); newXS(strcpy(buf, "isdooropen"), XS__isdooropen, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 067050a1a..d794e6d09 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -361,6 +361,18 @@ bool lua_is_paused_timer(const char *timer) { return quest_manager.ispausedtimer(timer); } +bool lua_has_timer(const char *timer) { + return quest_manager.hastimer(timer); +} + +uint32 lua_get_remaining_time(const char *timer) { + return quest_manager.getremainingtimeMS(timer); +} + +uint32 lua_get_timer_duration(const char *timer) { + return quest_manager.gettimerdurationMS(timer); +} + void lua_depop() { quest_manager.depop(0); } @@ -3583,6 +3595,9 @@ luabind::scope lua_register_general() { luabind::def("spawn_from_spawn2", (Lua_Mob(*)(uint32))&lua_spawn_from_spawn2), luabind::def("enable_spawn2", &lua_enable_spawn2), luabind::def("disable_spawn2", &lua_disable_spawn2), + luabind::def("has_timer", (bool(*)(const char*))&lua_has_timer), + luabind::def("get_remaining_time", (uint32(*)(const char*))&lua_get_remaining_time), + luabind::def("get_timer_duration", (uint32(*)(const char*))&lua_get_timer_duration), luabind::def("set_timer", (void(*)(const char*, int))&lua_set_timer), luabind::def("set_timer", (void(*)(const char*, int, Lua_ItemInst))&lua_set_timer), luabind::def("set_timer", (void(*)(const char*, int, Lua_Mob))&lua_set_timer), diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 9fb6d79e7..59a7d20d0 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -683,6 +683,66 @@ bool QuestManager::ispausedtimer(const char *timer_name) { return false; } +bool QuestManager::hastimer(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator cur = QTimerList.begin(), end; + + end = QTimerList.end(); + while (cur != end) + { + if (cur->mob && cur->mob == owner && cur->name == timer_name) + { + if (cur->Timer_.Enabled()) + { + return true; + } + } + ++cur; + } + return false; +} + +uint32 QuestManager::getremainingtimeMS(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator cur = QTimerList.begin(), end; + + end = QTimerList.end(); + while (cur != end) + { + if (cur->mob && cur->mob == owner && cur->name == timer_name) + { + if (cur->Timer_.Enabled()) + { + return cur->Timer_.GetRemainingTime(); + } + } + ++cur; + } + return 0; +} + +uint32 QuestManager::gettimerdurationMS(const char *timer_name) { + QuestManagerCurrentQuestVars(); + + std::list::iterator cur = QTimerList.begin(), end; + + end = QTimerList.end(); + while (cur != end) + { + if (cur->mob && cur->mob == owner && cur->name == timer_name) + { + if (cur->Timer_.Enabled()) + { + return cur->Timer_.GetDuration(); + } + } + ++cur; + } + return 0; +} + void QuestManager::emote(const char *str) { QuestManagerCurrentQuestVars(); if (!owner) { diff --git a/zone/questmgr.h b/zone/questmgr.h index f859a012d..01e245da9 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -94,6 +94,9 @@ public: void pausetimer(const char *timer_name); void resumetimer(const char *timer_name); bool ispausedtimer(const char *timer_name); + bool hastimer(const char *timer_name); + uint32 getremainingtimeMS(const char *timer_name); + uint32 gettimerdurationMS(const char *timer_name); void emote(const char *str); void shout(const char *str); void shout2(const char *str);