mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user