diff --git a/changelog.txt b/changelog.txt index abb096988..77ccc5f49 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,8 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- == 12/28/2015 == Kinglykrab: Added GetInstanceTimer() to Perl and Lua. + - Added GetInstanceTimerByID(instance_id) to Perl and Lua. + - Note: If you do not provide an instance id in the method it defaults to instance id 0 and returns 0 for time remaining. == 12/21/2015 == Natedog: Updated item table fields and added a few missing fields for evolving items diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 8ac6d61bf..c7d4b1a1f 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -2930,6 +2930,18 @@ XS(XS__GetInstanceTimer) { XSRETURN_UV(timer); } +XS(XS__GetInstanceTimerByID); +XS(XS__GetInstanceTimerByID) { + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: GetInstanceTimerByID(instance_id)"); + + uint16 instance_id = (uint16)SvUV(ST(0)); + uint32 timer = quest_manager.GetInstanceTimerByID(instance_id); + + XSRETURN_UV(timer); +} + XS(XS__GetInstanceID); XS(XS__GetInstanceID) { dXSARGS; @@ -3662,6 +3674,7 @@ EXTERN_C XS(boot_quest) newXS(strcpy(buf, "DestroyInstance"), XS__DestroyInstance, file); newXS(strcpy(buf, "UpdateInstanceTimer"), XS__UpdateInstanceTimer, file); newXS(strcpy(buf, "GetInstanceTimer"), XS__GetInstanceTimer, file); + newXS(strcpy(buf, "GetInstanceTimerByID"), XS__GetInstanceTimerByID, file); newXS(strcpy(buf, "FlagInstanceByGroupLeader"), XS__FlagInstanceByGroupLeader, file); newXS(strcpy(buf, "FlagInstanceByRaidLeader"), XS__FlagInstanceByRaidLeader, file); newXS(strcpy(buf, "FlyMode"), XS__FlyMode, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 0af3ed365..f731263a1 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -812,6 +812,10 @@ uint32 lua_get_instance_timer() { return quest_manager.GetInstanceTimer(); } +uint32 lua_get_instance_timer_by_id(uint16 instance_id) { + return quest_manager.GetInstanceTimerByID(instance_id); +} + int lua_get_instance_id(const char *zone, uint32 version) { return quest_manager.GetInstanceID(zone, version); } diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index d1cf87dad..690d70bf0 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -2606,6 +2606,21 @@ uint32 QuestManager::GetInstanceTimer() { return 0; } +uint32 QuestManager::GetInstanceTimerByID(uint16 instance_id) { + if (instance_id == 0) + return 0; + + std::string query = StringFormat("SELECT ((start_time + duration) - UNIX_TIMESTAMP()) AS `remaining` FROM `instance_list` WHERE `id` = %lu", (unsigned long)instance_id); + auto results = database.QueryDatabase(query); + + if (results.Success()) { + auto row = results.begin(); + uint32 timer = atoi(row[0]); + return timer; + } + return 0; +} + uint16 QuestManager::GetInstanceID(const char *zone, int16 version) { QuestManagerCurrentQuestVars(); diff --git a/zone/questmgr.h b/zone/questmgr.h index 276fcfeca..2b8963b70 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -219,6 +219,7 @@ public: uint16 CreateInstance(const char *zone, int16 version, uint32 duration); void UpdateInstanceTimer(uint16 instance_id, uint32 new_duration); uint32 GetInstanceTimer(); + uint32 GetInstanceTimerByID(uint16 instance_id = 0); void DestroyInstance(uint16 instance_id); uint16 GetInstanceID(const char *zone, int16 version); void AssignToInstance(uint16 instance_id);