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