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

- Add quest::converttime(duration) to Perl.
- Add eq.convert_time(duration) to Lua.
This commit is contained in:
Alex
2021-03-11 21:38:47 -05:00
committed by GitHub
parent ac4a993259
commit cd08c96fa4
4 changed files with 53 additions and 0 deletions
+29
View File
@@ -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;
}