Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quest API] Add secondstotime(duration) to Perl and Lua. #1281

Merged
2 commits merged into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions zone/embparser_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions zone/lua_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions zone/questmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions zone/questmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down