exp modifiers, pets, timers

This commit is contained in:
Chris Miles
2025-05-17 15:43:31 -05:00
parent 36fc7b6e7f
commit 2c1cb55f14
6 changed files with 102 additions and 109 deletions
+24 -37
View File
@@ -22,6 +22,7 @@
#include "ptimer.h"
#include "database.h"
#include "strings.h"
#include "repositories/timers_repository.h"
#ifdef _WINDOWS
#include <winsock2.h>
@@ -149,27 +150,6 @@ bool PersistentTimer::Load(Database *db) {
return true;
}
bool PersistentTimer::Store(Database *db) {
if(Expired(db, false)) //dont need to store expired timers.
return true;
std::string query = StringFormat("REPLACE INTO timers "
" (char_id, type, start, duration, enable) "
" VALUES (%lu, %u, %lu, %lu, %d)",
(unsigned long)_char_id, _type, (unsigned long)start_time,
(unsigned long)timer_time, enabled ? 1: 0);
#ifdef DEBUG_PTIMERS
printf("Storing timer: char %lu of type %u: '%s'\n", (unsigned long)_char_id, _type, query.c_str());
#endif
auto results = db->QueryDatabase(query);
if (!results.Success()) {
return false;
}
return true;
}
bool PersistentTimer::Clear(Database *db) {
std::string query = StringFormat("DELETE FROM timers "
@@ -304,27 +284,34 @@ bool PTimerList::Load(Database *db) {
return true;
}
bool PTimerList::Store(Database *db) {
#ifdef DEBUG_PTIMERS
printf("Storing all timers for char %lu\n", (unsigned long)_char_id);
#endif
bool PTimerList::Store(Database *db)
{
auto e = TimersRepository::NewEntity();
std::vector<TimersRepository::Timers> entries;
std::map<pTimerType, PersistentTimer *>::iterator s;
s = _list.begin();
bool res = true;
while(s != _list.end()) {
if(s->second != nullptr) {
#ifdef DEBUG_PTIMERS
printf("Storing timer %u for char %lu\n", s->first, (unsigned long)_char_id);
#endif
if(!s->second->Store(db))
res = false;
for (auto &[type, timer] : _list) {
if (!timer) {
continue;
}
++s;
e.char_id = _char_id;
e.type = type;
e.start = timer->GetStartTime();
e.duration = timer->GetTimerTime();
e.enable = timer->Enabled() ? 1 : 0;
entries.emplace_back(e);
}
return(res);
if (!entries.empty()) {
Expired(db, false);
TimersRepository::ReplaceMany(*db, entries);
}
return true;
}
bool PTimerList::Clear(Database *db) {
_list.clear();
-1
View File
@@ -91,7 +91,6 @@ public:
inline bool Enabled() { return enabled; }
bool Load(Database *db);
bool Store(Database *db);
bool Clear(Database *db);
protected:
@@ -115,8 +115,8 @@ public:
uint8_t lfg;
std::string mailkey;
uint8_t xtargets;
uint8_t ingame;
uint32_t first_login;
uint8_t ingame;
uint32_t e_aa_effects;
uint32_t e_percent_to_aa;
uint32_t e_expended_aa_spent;
@@ -231,8 +231,8 @@ public:
"lfg",
"mailkey",
"xtargets",
"ingame",
"first_login",
"ingame",
"e_aa_effects",
"e_percent_to_aa",
"e_expended_aa_spent",
@@ -343,8 +343,8 @@ public:
"lfg",
"mailkey",
"xtargets",
"ingame",
"first_login",
"ingame",
"e_aa_effects",
"e_percent_to_aa",
"e_expended_aa_spent",
@@ -489,8 +489,8 @@ public:
e.lfg = 0;
e.mailkey = "";
e.xtargets = 5;
e.ingame = 0;
e.first_login = 0;
e.ingame = 0;
e.e_aa_effects = 0;
e.e_percent_to_aa = 0;
e.e_expended_aa_spent = 0;
@@ -631,8 +631,8 @@ public:
e.lfg = row[93] ? static_cast<uint8_t>(strtoul(row[93], nullptr, 10)) : 0;
e.mailkey = row[94] ? row[94] : "";
e.xtargets = row[95] ? static_cast<uint8_t>(strtoul(row[95], nullptr, 10)) : 5;
e.ingame = row[96] ? static_cast<uint8_t>(strtoul(row[96], nullptr, 10)) : 0;
e.first_login = row[97] ? static_cast<uint32_t>(strtoul(row[97], nullptr, 10)) : 0;
e.first_login = row[96] ? static_cast<uint32_t>(strtoul(row[96], nullptr, 10)) : 0;
e.ingame = row[97] ? static_cast<uint8_t>(strtoul(row[97], nullptr, 10)) : 0;
e.e_aa_effects = row[98] ? static_cast<uint32_t>(strtoul(row[98], nullptr, 10)) : 0;
e.e_percent_to_aa = row[99] ? static_cast<uint32_t>(strtoul(row[99], nullptr, 10)) : 0;
e.e_expended_aa_spent = row[100] ? static_cast<uint32_t>(strtoul(row[100], nullptr, 10)) : 0;
@@ -769,8 +769,8 @@ public:
v.push_back(columns[93] + " = " + std::to_string(e.lfg));
v.push_back(columns[94] + " = '" + Strings::Escape(e.mailkey) + "'");
v.push_back(columns[95] + " = " + std::to_string(e.xtargets));
v.push_back(columns[96] + " = " + std::to_string(e.ingame));
v.push_back(columns[97] + " = " + std::to_string(e.first_login));
v.push_back(columns[96] + " = " + std::to_string(e.first_login));
v.push_back(columns[97] + " = " + std::to_string(e.ingame));
v.push_back(columns[98] + " = " + std::to_string(e.e_aa_effects));
v.push_back(columns[99] + " = " + std::to_string(e.e_percent_to_aa));
v.push_back(columns[100] + " = " + std::to_string(e.e_expended_aa_spent));
@@ -896,8 +896,8 @@ public:
v.push_back(std::to_string(e.lfg));
v.push_back("'" + Strings::Escape(e.mailkey) + "'");
v.push_back(std::to_string(e.xtargets));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.first_login));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.e_aa_effects));
v.push_back(std::to_string(e.e_percent_to_aa));
v.push_back(std::to_string(e.e_expended_aa_spent));
@@ -1031,8 +1031,8 @@ public:
v.push_back(std::to_string(e.lfg));
v.push_back("'" + Strings::Escape(e.mailkey) + "'");
v.push_back(std::to_string(e.xtargets));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.first_login));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.e_aa_effects));
v.push_back(std::to_string(e.e_percent_to_aa));
v.push_back(std::to_string(e.e_expended_aa_spent));
@@ -1170,8 +1170,8 @@ public:
e.lfg = row[93] ? static_cast<uint8_t>(strtoul(row[93], nullptr, 10)) : 0;
e.mailkey = row[94] ? row[94] : "";
e.xtargets = row[95] ? static_cast<uint8_t>(strtoul(row[95], nullptr, 10)) : 5;
e.ingame = row[96] ? static_cast<uint8_t>(strtoul(row[96], nullptr, 10)) : 0;
e.first_login = row[97] ? static_cast<uint32_t>(strtoul(row[97], nullptr, 10)) : 0;
e.first_login = row[96] ? static_cast<uint32_t>(strtoul(row[96], nullptr, 10)) : 0;
e.ingame = row[97] ? static_cast<uint8_t>(strtoul(row[97], nullptr, 10)) : 0;
e.e_aa_effects = row[98] ? static_cast<uint32_t>(strtoul(row[98], nullptr, 10)) : 0;
e.e_percent_to_aa = row[99] ? static_cast<uint32_t>(strtoul(row[99], nullptr, 10)) : 0;
e.e_expended_aa_spent = row[100] ? static_cast<uint32_t>(strtoul(row[100], nullptr, 10)) : 0;
@@ -1300,8 +1300,8 @@ public:
e.lfg = row[93] ? static_cast<uint8_t>(strtoul(row[93], nullptr, 10)) : 0;
e.mailkey = row[94] ? row[94] : "";
e.xtargets = row[95] ? static_cast<uint8_t>(strtoul(row[95], nullptr, 10)) : 5;
e.ingame = row[96] ? static_cast<uint8_t>(strtoul(row[96], nullptr, 10)) : 0;
e.first_login = row[97] ? static_cast<uint32_t>(strtoul(row[97], nullptr, 10)) : 0;
e.first_login = row[96] ? static_cast<uint32_t>(strtoul(row[96], nullptr, 10)) : 0;
e.ingame = row[97] ? static_cast<uint8_t>(strtoul(row[97], nullptr, 10)) : 0;
e.e_aa_effects = row[98] ? static_cast<uint32_t>(strtoul(row[98], nullptr, 10)) : 0;
e.e_percent_to_aa = row[99] ? static_cast<uint32_t>(strtoul(row[99], nullptr, 10)) : 0;
e.e_expended_aa_spent = row[100] ? static_cast<uint32_t>(strtoul(row[100], nullptr, 10)) : 0;
@@ -1480,8 +1480,8 @@ public:
v.push_back(std::to_string(e.lfg));
v.push_back("'" + Strings::Escape(e.mailkey) + "'");
v.push_back(std::to_string(e.xtargets));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.first_login));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.e_aa_effects));
v.push_back(std::to_string(e.e_percent_to_aa));
v.push_back(std::to_string(e.e_expended_aa_spent));
@@ -1608,8 +1608,8 @@ public:
v.push_back(std::to_string(e.lfg));
v.push_back("'" + Strings::Escape(e.mailkey) + "'");
v.push_back(std::to_string(e.xtargets));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.first_login));
v.push_back(std::to_string(e.ingame));
v.push_back(std::to_string(e.e_aa_effects));
v.push_back(std::to_string(e.e_percent_to_aa));
v.push_back(std::to_string(e.e_expended_aa_spent));