mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-25 15:07:28 +00:00
rebuild
This commit is contained in:
parent
84708b860a
commit
4a189edf43
@ -1,7 +1,6 @@
|
|||||||
#include "CDRebuildComponentTable.h"
|
#include "CDRebuildComponentTable.h"
|
||||||
|
|
||||||
void CDRebuildComponentTable::LoadValuesFromDatabase() {
|
void CDRebuildComponentTable::LoadValuesFromDatabase() {
|
||||||
|
|
||||||
// First, get the size of the table
|
// First, get the size of the table
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RebuildComponent");
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RebuildComponent");
|
||||||
@ -11,16 +10,13 @@ void CDRebuildComponentTable::LoadValuesFromDatabase() {
|
|||||||
tableSize.nextRow();
|
tableSize.nextRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
tableSize.finalize();
|
|
||||||
|
|
||||||
// Reserve the size
|
|
||||||
this->entries.reserve(size);
|
this->entries.reserve(size);
|
||||||
|
|
||||||
// Now get the data
|
// Now get the data
|
||||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RebuildComponent");
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RebuildComponent order by id");
|
||||||
while (!tableData.eof()) {
|
while (!tableData.eof()) {
|
||||||
CDRebuildComponent entry;
|
CDRebuildComponent entry;
|
||||||
entry.id = tableData.getIntField("id", -1);
|
uint32_t id = tableData.getIntField("id", -1);
|
||||||
entry.reset_time = tableData.getFloatField("reset_time", -1.0f);
|
entry.reset_time = tableData.getFloatField("reset_time", -1.0f);
|
||||||
entry.complete_time = tableData.getFloatField("complete_time", -1.0f);
|
entry.complete_time = tableData.getFloatField("complete_time", -1.0f);
|
||||||
entry.take_imagination = tableData.getIntField("take_imagination", -1);
|
entry.take_imagination = tableData.getIntField("take_imagination", -1);
|
||||||
@ -31,23 +27,14 @@ void CDRebuildComponentTable::LoadValuesFromDatabase() {
|
|||||||
entry.post_imagination_cost = tableData.getIntField("post_imagination_cost", -1);
|
entry.post_imagination_cost = tableData.getIntField("post_imagination_cost", -1);
|
||||||
entry.time_before_smash = tableData.getFloatField("time_before_smash", -1.0f);
|
entry.time_before_smash = tableData.getFloatField("time_before_smash", -1.0f);
|
||||||
|
|
||||||
this->entries.push_back(entry);
|
this->entries.push_back(std::make_pair(id, entry));
|
||||||
tableData.nextRow();
|
tableData.nextRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
tableData.finalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CDRebuildComponent> CDRebuildComponentTable::Query(std::function<bool(CDRebuildComponent)> predicate) {
|
const std::optional<CDRebuildComponent> CDRebuildComponentTable::Get(uint32_t componentId) {
|
||||||
|
auto result = std::lower_bound(this->entries.begin(), this->entries.end(), componentId, [](const auto& entry, const auto& componentId) {
|
||||||
std::vector<CDRebuildComponent> data = cpplinq::from(this->entries)
|
return entry.first < componentId;
|
||||||
>> cpplinq::where(predicate)
|
});
|
||||||
>> cpplinq::to_vector();
|
return result == this->entries.end() ? std::nullopt : std::make_optional(result->second);
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<CDRebuildComponent>& CDRebuildComponentTable::GetEntries() const {
|
|
||||||
return this->entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "CDTable.h"
|
#include "CDTable.h"
|
||||||
|
|
||||||
struct CDRebuildComponent {
|
struct CDRebuildComponent {
|
||||||
unsigned int id; //!< The component Id
|
|
||||||
float reset_time; //!< The reset time
|
float reset_time; //!< The reset time
|
||||||
float complete_time; //!< The complete time
|
float complete_time; //!< The complete time
|
||||||
unsigned int take_imagination; //!< The amount of imagination it costs
|
unsigned int take_imagination; //!< The amount of imagination it costs
|
||||||
@ -18,13 +17,11 @@ struct CDRebuildComponent {
|
|||||||
|
|
||||||
class CDRebuildComponentTable : public CDTable<CDRebuildComponentTable> {
|
class CDRebuildComponentTable : public CDTable<CDRebuildComponentTable> {
|
||||||
private:
|
private:
|
||||||
std::vector<CDRebuildComponent> entries;
|
std::vector<std::pair<uint32_t, CDRebuildComponent>> entries;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void LoadValuesFromDatabase();
|
void LoadValuesFromDatabase();
|
||||||
// Queries the table with a custom "where" clause
|
// Queries the table with a custom "where" clause
|
||||||
std::vector<CDRebuildComponent> Query(std::function<bool(CDRebuildComponent)> predicate);
|
const std::optional<CDRebuildComponent> Get(uint32_t componentId);
|
||||||
|
|
||||||
const std::vector<CDRebuildComponent>& GetEntries() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -536,17 +536,17 @@ void Entity::Initialize() {
|
|||||||
m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp));
|
m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp));
|
||||||
|
|
||||||
CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
|
CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
|
||||||
std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == rebuildComponentID); });
|
auto rebCompData = rebCompTable->Get(rebuildComponentID);
|
||||||
|
|
||||||
if (rebCompData.size() > 0) {
|
if (rebCompData) {
|
||||||
comp->SetResetTime(rebCompData[0].reset_time);
|
comp->SetResetTime(rebCompData->reset_time);
|
||||||
comp->SetCompleteTime(rebCompData[0].complete_time);
|
comp->SetCompleteTime(rebCompData->complete_time);
|
||||||
comp->SetTakeImagination(rebCompData[0].take_imagination);
|
comp->SetTakeImagination(rebCompData->take_imagination);
|
||||||
comp->SetInterruptible(rebCompData[0].interruptible);
|
comp->SetInterruptible(rebCompData->interruptible);
|
||||||
comp->SetSelfActivator(rebCompData[0].self_activator);
|
comp->SetSelfActivator(rebCompData->self_activator);
|
||||||
comp->SetActivityId(rebCompData[0].activityID);
|
comp->SetActivityId(rebCompData->activityID);
|
||||||
comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
|
comp->SetPostImaginationCost(rebCompData->post_imagination_cost);
|
||||||
comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash);
|
comp->SetTimeBeforeSmash(rebCompData->time_before_smash);
|
||||||
|
|
||||||
const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time");
|
const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user