[Respawns] Convert Respawn Times to Repositories (#3949)

* [Respawns] Convert Respawn Times to Repositories

- Convert `respawn_times` based methods to repositories.

* Missed some.

* Comments
This commit is contained in:
Alex King
2024-01-12 23:38:31 -05:00
committed by GitHub
parent 818f833d04
commit 71f78b757e
7 changed files with 108 additions and 94 deletions
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseRespawnTimesRepository {
public:
struct RespawnTimes {
@@ -44,7 +44,39 @@ public:
*/
// Custom extended repository methods here
static void ClearExpiredRespawnTimers(Database& db)
{
db.QueryDatabase(
fmt::format(
"DELETE FROM `{}` WHERE (`start` + `duration`) < UNIX_TIMESTAMP(NOW())",
TableName()
)
);
}
static uint32 GetTimeRemaining(Database& db, uint32 spawn2_id, uint16 instance_id, time_t time_seconds)
{
const auto& l = RespawnTimesRepository::GetWhere(
db,
fmt::format(
"`id` = {} AND `instance_id` = {}",
spawn2_id,
instance_id
)
);
if (l.empty()) {
return 0;
}
auto r = l.front();
if ((r.start + r.duration) <= time_seconds) {
return 0;
}
return ((r.start + r.duration) - time_seconds);
}
};
#endif //EQEMU_RESPAWN_TIMES_REPOSITORY_H