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

fix: format VIP time remaining message #3183

Closed
wants to merge 11 commits into from
6 changes: 5 additions & 1 deletion data/libs/systems/vip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@ function Player.sendVipStatus(self)
return true
end

self:sendTextMessage(MESSAGE_LOGIN, string.format("You have %s of VIP time remaining.", getFormattedTimeRemaining(playerVipTime)))
local remainingTime = playerVipTime - os.time()
local timeStr = Game.getTimeInWords(remainingTime)

self:sendTextMessage(MESSAGE_LOGIN, string.format("You have %s of VIP time remaining.", timeStr))
return true
end
8 changes: 0 additions & 8 deletions src/lua/functions/core/game/global_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void GlobalFunctions::init(lua_State* L) {
Lua::registerGlobalMethod(L, "rawgetmetatable", GlobalFunctions::luaRawGetMetatable);
Lua::registerGlobalMethod(L, "createTable", GlobalFunctions::luaCreateTable);
Lua::registerGlobalMethod(L, "systemTime", GlobalFunctions::luaSystemTime);
Lua::registerGlobalMethod(L, "getFormattedTimeRemaining", GlobalFunctions::luaGetFormattedTimeRemaining);
Lua::registerGlobalMethod(L, "reportError", GlobalFunctions::luaReportError);
}

Expand Down Expand Up @@ -877,13 +876,6 @@ int GlobalFunctions::luaSystemTime(lua_State* L) {
return 1;
}

int GlobalFunctions::luaGetFormattedTimeRemaining(lua_State* L) {
// getFormattedTimeRemaining(time)
const time_t time = Lua::getNumber<uint32_t>(L, 1);
lua_pushstring(L, getFormattedTimeRemaining(time).c_str());
return 1;
}

int GlobalFunctions::luaReportError(lua_State* L) {
// reportError(errorDescription)
const auto errorDescription = Lua::getString(L, 1);
Expand Down
1 change: 0 additions & 1 deletion src/lua/functions/core/game/global_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class GlobalFunctions {
static int luaRawGetMetatable(lua_State* L);
static int luaCreateTable(lua_State* L);
static int luaSystemTime(lua_State* L);
static int luaGetFormattedTimeRemaining(lua_State* L);
static int luaReportError(lua_State* L);

static bool getArea(lua_State* L, std::list<uint32_t> &list, uint32_t &rows);
Expand Down
29 changes: 0 additions & 29 deletions src/utils/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,35 +1925,6 @@ std::vector<std::string> split(const std::string &str, char delimiter /* = ','*/
return tokens;
}

std::string getFormattedTimeRemaining(uint32_t time) {
const time_t timeRemaining = time - getTimeNow();

const int days = static_cast<int>(std::floor(timeRemaining / 86400));

std::stringstream output;
if (days > 1) {
output << days << " days";
return output.str();
}

const auto hours = static_cast<int>(std::floor((timeRemaining % 86400) / 3600));
const auto minutes = static_cast<int>(std::floor((timeRemaining % 3600) / 60));
const auto seconds = static_cast<int>(timeRemaining % 60);

if (hours == 0 && minutes == 0 && seconds > 0) {
output << " less than 1 minute";
} else {
if (hours > 0) {
output << hours << " hour" << (hours != 1 ? "s" : "");
}
if (minutes > 0) {
output << (hours > 0 ? " and " : "") << minutes << " minute" << (minutes != 1 ? "s" : "");
}
}

return output.str();
}

unsigned int getNumberOfCores() {
static auto cores = std::thread::hardware_concurrency();
return cores;
Expand Down
1 change: 0 additions & 1 deletion src/utils/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ uint8_t forgeBonus(int32_t number);

std::string formatPrice(std::string price, bool space /* = false*/);
std::vector<std::string> split(const std::string &str, char delimiter = ',');
std::string getFormattedTimeRemaining(uint32_t time);

unsigned int getNumberOfCores();

Expand Down
Loading