diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 0fa68aa646..57674ede19 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -6404,6 +6404,23 @@ XS(XS__createitem) { XSRETURN(1); } +XS(XS__secondstotime); +XS(XS__secondstotime) { + dXSARGS; + if (items != 1) { + Perl_croak(aTHX_ "Usage: quest::secondstotime(int duration)"); + } + + dXSTARG; + std::string time_string; + int duration = (int) SvIV(ST(0)); + time_string = quest_manager.secondstotime(duration); + sv_setpv(TARG, time_string.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + /* This is the callback perl will look for to setup the quest package's XSUBs @@ -6696,6 +6713,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "say"), XS__say, file); newXS(strcpy(buf, "saylink"), XS__saylink, file); newXS(strcpy(buf, "scribespells"), XS__scribespells, file); + newXS(strcpy(buf, "secondstotime"), XS__secondstotime, file); newXS(strcpy(buf, "selfcast"), XS__selfcast, file); newXS(strcpy(buf, "set_proximity"), XS__set_proximity, file); newXS(strcpy(buf, "set_zone_flag"), XS__set_zone_flag, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index b903ca7746..a4fd774491 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -2300,6 +2300,10 @@ void lua_remove_all_expedition_lockouts_by_char_id(uint32 char_id, std::string e Expedition::RemoveLockoutsByCharacterID(char_id, expedition_name); } +std::string lua_seconds_to_time(int duration) { + return quest_manager.secondstotime(duration); +} + #define LuaCreateNPCParse(name, c_type, default_value) do { \ cur = table[#name]; \ if(luabind::type(cur) != LUA_TNIL) { \ @@ -2836,6 +2840,7 @@ luabind::scope lua_register_general() { luabind::def("debug", (void(*)(std::string))&lua_debug), luabind::def("debug", (void(*)(std::string, int))&lua_debug), luabind::def("log_combat", (void(*)(std::string))&lua_log_combat), + luabind::def("seconds_to_time", &lua_seconds_to_time), /** * Expansions diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index c3c8ac8b11..3ffc505dd5 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -4251,3 +4251,32 @@ EQ::ItemInstance *QuestManager::CreateItem(uint32 item_id, int16 charges, uint32 } return nullptr; } + +std::string QuestManager::secondstotime(int duration) { + int timer_length = duration; + int hours = int(timer_length / 3600); + timer_length %= 3600; + int minutes = int(timer_length / 60); + timer_length %= 60; + int seconds = timer_length; + std::string time_string = "Unknown"; + std::string hour_string = (hours == 1 ? "Hour" : "Hours"); + std::string minute_string = (minutes == 1 ? "Minute" : "Minutes"); + std::string second_string = (seconds == 1 ? "Second" : "Seconds"); + if (hours > 0 && minutes > 0 && seconds > 0) { + time_string = fmt::format("{} {}, {} {}, and {} {}", hours, hour_string, minutes, minute_string, seconds, second_string); + } else if (hours > 0 && minutes > 0 && seconds == 0) { + time_string = fmt::format("{} {} and {} {}", hours, hour_string, minutes, minute_string); + } else if (hours > 0 && minutes == 0 && seconds > 0) { + time_string = fmt::format("{} {} and {} {}", hours, hour_string, seconds, second_string); + } else if (hours > 0 && minutes == 0 && seconds == 0) { + time_string = fmt::format("{} {}", hours, hour_string); + } else if (hours == 0 && minutes > 0 && seconds > 0) { + time_string = fmt::format("{} {} and {} {}", minutes, minute_string, seconds, second_string); + } else if (hours == 0 && minutes > 0 && seconds == 0) { + time_string = fmt::format("{} {}", minutes, minute_string); + } else if (hours == 0 && minutes == 0 && seconds > 0) { + time_string = fmt::format("{} {}", seconds, second_string); + } + return time_string; +} \ No newline at end of file diff --git a/zone/questmgr.h b/zone/questmgr.h index 0ce21ccc42..b5d2adfe20 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -369,6 +369,7 @@ class QuestManager { bool DisableRecipe(uint32 recipe_id); void ClearNPCTypeCache(int npctype_id); void ReloadZoneStaticData(); + std::string secondstotime(int duration); Client *GetInitiator() const; NPC *GetNPC() const;