From 5e3c869141a01b02a1925181fc007f7153470c00 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Wed, 5 Jun 2024 02:39:36 -0500 Subject: [PATCH] WIP --- .../dEnums/eDeletionRestrictionsCheckType.h | 16 ++++++ .../CDClientDatabase/CDClientManager.cpp | 3 ++ .../CDDeletionRestrictionsTable.cpp | 53 +++++++++++++++++++ .../CDDeletionRestrictionsTable.h | 18 +++++++ .../CDClientTables/CDItemComponentTable.h | 2 +- 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 dCommon/dEnums/eDeletionRestrictionsCheckType.h create mode 100644 dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.cpp create mode 100644 dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.h diff --git a/dCommon/dEnums/eDeletionRestrictionsCheckType.h b/dCommon/dEnums/eDeletionRestrictionsCheckType.h new file mode 100644 index 00000000..adda09aa --- /dev/null +++ b/dCommon/dEnums/eDeletionRestrictionsCheckType.h @@ -0,0 +1,16 @@ +#ifndef __EDELETIONRESTRICTIONSCHECKTYPE__H__ +#define __EDELETIONRESTRICTIONSCHECKTYPE__H__ + +#include + +enum class eDeletionRestrictionsCheckType : uint32_t { + INCLUDE_LOTS, + EXCLUDE_LOTS, + ANY_OF_THESE, + ALL_OF_THESE, + ZONE, + RESTRICTED, + MAX +}; + +#endif //!__EDELETIONRESTRICTIONSCHECKTYPE__H__ diff --git a/dDatabase/CDClientDatabase/CDClientManager.cpp b/dDatabase/CDClientDatabase/CDClientManager.cpp index 6ecfb0ad..e1802d26 100644 --- a/dDatabase/CDClientDatabase/CDClientManager.cpp +++ b/dDatabase/CDClientDatabase/CDClientManager.cpp @@ -41,6 +41,7 @@ #include "CDRailActivatorComponent.h" #include "CDRewardCodesTable.h" #include "CDPetComponentTable.h" +#include "CDDeletionRestrictionsTable.h" #ifndef CDCLIENT_CACHE_ALL // Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory. @@ -103,6 +104,7 @@ DEFINE_TABLE_STORAGE(CDSkillBehaviorTable); DEFINE_TABLE_STORAGE(CDTamingBuildPuzzleTable); DEFINE_TABLE_STORAGE(CDVendorComponentTable); DEFINE_TABLE_STORAGE(CDZoneTableTable); +DEFINE_TABLE_STORAGE(CDDeletionRestrictionsTable) void CDClientManager::LoadValuesFromDatabase() { if (!CDClientDatabase::isConnected) { @@ -150,6 +152,7 @@ void CDClientManager::LoadValuesFromDatabase() { CDTamingBuildPuzzleTable::Instance().LoadValuesFromDatabase(); CDVendorComponentTable::Instance().LoadValuesFromDatabase(); CDZoneTableTable::Instance().LoadValuesFromDatabase(); + CDDeletionRestrictionsTable::Instance().LoadValuesFromDatabase(); } void CDClientManager::LoadValuesFromDefaults() { diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.cpp b/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.cpp new file mode 100644 index 00000000..8cdc9ec8 --- /dev/null +++ b/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.cpp @@ -0,0 +1,53 @@ +#include "CDDeletionRestrictionsTable.h" +#include "GeneralUtils.h" + +//! Constructor +void CDDeletionRestrictionsTable::LoadValuesFromDatabase() { + + // First, get the size of the table + uint32_t size = 0; + auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM CurrencyTable"); + while (!tableSize.eof()) { + size = tableSize.getIntField(0, 0); + + tableSize.nextRow(); + } + + tableSize.finalize(); + + // Reserve the size + auto& entries = GetEntriesMutable(); + entries.reserve(size); + + // Now get the data + auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions"); + while (!tableData.eof()) { + CDDeletionRestrictions entry; + entry.id = tableData.getIntField("id", -1); + if (entry.id == -1) continue; + entry.restricted = tableData.getIntField("restricted", -1); + const std::string raw_ids = tableData.getStringField("ids", ""); + if (!raw_ids.empty()) { + for (const auto& idstr : GeneralUtils::SplitString(raw_ids, ',')) { + if (!idstr.empty()) { + const auto id = GeneralUtils::TryParse(idstr).value_or(-1); + if (id != -1) entry.ids.push_back(id); + } + } + } + entry.checkType = static_cast(tableData.getIntField("checkType", 6)); + + entries.push_back(entry); + tableData.nextRow(); + } + + tableData.finalize(); +} + +std::vector CDDeletionRestrictionsTable::Query(std::function predicate) { + std::vector data = cpplinq::from(GetEntries()) + >> cpplinq::where(predicate) + >> cpplinq::to_vector(); + + return data; +} diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.h new file mode 100644 index 00000000..718e7bab --- /dev/null +++ b/dDatabase/CDClientDatabase/CDClientTables/CDDeletionRestrictionsTable.h @@ -0,0 +1,18 @@ +#pragma once + +#include "CDTable.h" + +enum class eDeletionRestrictionsCheckType : uint32_t; + +struct CDDeletionRestrictions { + uint32_t id; + bool restricted; + std::vector ids; + eDeletionRestrictionsCheckType checkType; +}; + +class CDDeletionRestrictionsTable : public CDTable> { +public: + void LoadValuesFromDatabase(); + std::vector Query(std::function predicate); +}; diff --git a/dDatabase/CDClientDatabase/CDClientTables/CDItemComponentTable.h b/dDatabase/CDClientDatabase/CDClientTables/CDItemComponentTable.h index 60a3e412..58bee024 100644 --- a/dDatabase/CDClientDatabase/CDClientTables/CDItemComponentTable.h +++ b/dDatabase/CDClientDatabase/CDClientTables/CDItemComponentTable.h @@ -33,7 +33,7 @@ struct CDItemComponent { uint32_t itemRating; //!< ??? bool isTwoHanded; //!< Whether or not the item is double handed uint32_t minNumRequired; //!< Maybe the minimum number required for a mission, or to own this object? - uint32_t delResIndex; //!< ??? + uint32_t delResIndex; //!< Relates to DeletionRestrictions Table uint32_t currencyLOT; //!< ??? uint32_t altCurrencyCost; //!< ??? std::string subItems; //!< A comma seperate string of sub items (maybe for multi-itemed things like faction test gear set)