mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 06:21:28 +00:00
[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:
parent
ac4a993259
commit
cd08c96fa4
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -369,6 +369,7 @@ public:
|
||||
bool DisableRecipe(uint32 recipe_id);
|
||||
void ClearNPCTypeCache(int npctype_id);
|
||||
void ReloadZoneStaticData();
|
||||
std::string secondstotime(int duration);
|
||||
|
||||
Client *GetInitiator() const;
|
||||
NPC *GetNPC() const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user