mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-21 21:17:25 +00:00
Document what needs to be done
May not do the recursive restriction cause they aren't used in the live game
This commit is contained in:
parent
5ba37ff7d6
commit
3cfbc9d3df
@ -1,10 +1,16 @@
|
|||||||
#include "CDDeletionRestrictionsTable.h"
|
#include "CDDeletionRestrictionsTable.h"
|
||||||
#include "GeneralUtils.h"
|
#include "GeneralUtils.h"
|
||||||
|
#include "eDeletionRestrictionsCheckType.h"
|
||||||
|
|
||||||
|
CDDeletionRestriction CDDeletionRestrictionsTable::Default = {
|
||||||
|
.id = 0,
|
||||||
|
.restricted = false,
|
||||||
|
.ids = {},
|
||||||
|
.checkType = eDeletionRestrictionsCheckType::MAX
|
||||||
|
};
|
||||||
|
|
||||||
//! Constructor
|
|
||||||
void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
|
void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
|
||||||
|
|
||||||
// First, get the size of the table
|
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM CurrencyTable");
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM CurrencyTable");
|
||||||
while (!tableSize.eof()) {
|
while (!tableSize.eof()) {
|
||||||
@ -15,14 +21,11 @@ void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
|
|||||||
|
|
||||||
tableSize.finalize();
|
tableSize.finalize();
|
||||||
|
|
||||||
// Reserve the size
|
|
||||||
auto& entries = GetEntriesMutable();
|
auto& entries = GetEntriesMutable();
|
||||||
entries.reserve(size);
|
|
||||||
|
|
||||||
// Now get the data
|
|
||||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions");
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM DeletionRestrictions");
|
||||||
while (!tableData.eof()) {
|
while (!tableData.eof()) {
|
||||||
CDDeletionRestrictions entry;
|
CDDeletionRestriction entry;
|
||||||
entry.id = tableData.getIntField("id", -1);
|
entry.id = tableData.getIntField("id", -1);
|
||||||
if (entry.id == -1) continue;
|
if (entry.id == -1) continue;
|
||||||
entry.restricted = tableData.getIntField("restricted", -1);
|
entry.restricted = tableData.getIntField("restricted", -1);
|
||||||
@ -37,17 +40,18 @@ void CDDeletionRestrictionsTable::LoadValuesFromDatabase() {
|
|||||||
}
|
}
|
||||||
entry.checkType = static_cast<eDeletionRestrictionsCheckType>(tableData.getIntField("checkType", 6)); // MAX
|
entry.checkType = static_cast<eDeletionRestrictionsCheckType>(tableData.getIntField("checkType", 6)); // MAX
|
||||||
|
|
||||||
entries.push_back(entry);
|
entries.insert(std::make_pair(entry.id, entry));
|
||||||
tableData.nextRow();
|
tableData.nextRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
tableData.finalize();
|
tableData.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CDDeletionRestrictions> CDDeletionRestrictionsTable::Query(std::function<bool(CDDeletionRestrictions)> predicate) {
|
const CDDeletionRestriction& CDDeletionRestrictionsTable::GetByID(uint32_t id) {
|
||||||
std::vector<CDDeletionRestrictions> data = cpplinq::from(GetEntries())
|
auto& entries = GetEntries();
|
||||||
>> cpplinq::where(predicate)
|
const auto& it = entries.find(id);
|
||||||
>> cpplinq::to_vector();
|
if (it != entries.end()) {
|
||||||
|
return it->second;
|
||||||
return data;
|
}
|
||||||
|
return Default;
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,17 @@
|
|||||||
|
|
||||||
enum class eDeletionRestrictionsCheckType : uint32_t;
|
enum class eDeletionRestrictionsCheckType : uint32_t;
|
||||||
|
|
||||||
struct CDDeletionRestrictions {
|
struct CDDeletionRestriction {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
bool restricted;
|
bool restricted;
|
||||||
std::vector<uint32_t> ids;
|
std::vector<uint32_t> ids;
|
||||||
eDeletionRestrictionsCheckType checkType;
|
eDeletionRestrictionsCheckType checkType;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDDeletionRestrictionsTable : public CDTable<CDDeletionRestrictionsTable, std::vector<CDDeletionRestrictions>> {
|
class CDDeletionRestrictionsTable : public CDTable<CDDeletionRestrictionsTable, std::map<uint32_t, CDDeletionRestriction>> {
|
||||||
public:
|
public:
|
||||||
void LoadValuesFromDatabase();
|
void LoadValuesFromDatabase();
|
||||||
std::vector<CDDeletionRestrictions> Query(std::function<bool(CDDeletionRestrictions)> predicate);
|
const CDDeletionRestriction& GetByID(uint32_t id);
|
||||||
|
|
||||||
|
static CDDeletionRestriction Default;
|
||||||
};
|
};
|
||||||
|
@ -21,11 +21,13 @@
|
|||||||
#include "eUseItemResponse.h"
|
#include "eUseItemResponse.h"
|
||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
#include "ChatPackets.h"
|
#include "ChatPackets.h"
|
||||||
|
#include "eDeletionRestrictionsCheckType.h"
|
||||||
|
|
||||||
#include "CDBrickIDTableTable.h"
|
#include "CDBrickIDTableTable.h"
|
||||||
#include "CDObjectSkillsTable.h"
|
#include "CDObjectSkillsTable.h"
|
||||||
#include "CDComponentsRegistryTable.h"
|
#include "CDComponentsRegistryTable.h"
|
||||||
#include "CDPackageComponentTable.h"
|
#include "CDPackageComponentTable.h"
|
||||||
|
#include "CDDeletionRestrictionsTable.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::map<std::string, std::string> ExtraSettingAbbreviations = {
|
const std::map<std::string, std::string> ExtraSettingAbbreviations = {
|
||||||
@ -568,3 +570,43 @@ void Item::LoadConfigXml(const tinyxml2::XMLElement& i) {
|
|||||||
config.push_back(LDFBaseData::DataFromString(value));
|
config.push_back(LDFBaseData::DataFromString(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Item::CanDeleteItem(Item* item) {
|
||||||
|
if (!item) return false;
|
||||||
|
// TODO:
|
||||||
|
// Check if item is being possessed
|
||||||
|
// Check if the owner is mounting item? (how is this different than the above)
|
||||||
|
// Allow GM 9 to freely delete
|
||||||
|
// Finally, check Deletion Restriction
|
||||||
|
const auto& itemComponent = item->inventory->FindItemComponent(item->lot);
|
||||||
|
if (itemComponent.delResIndex == -1) return true;
|
||||||
|
return CheckDeletionRestriction(itemComponent.delResIndex, item->lot);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Item::CheckDeletionRestriction(uint32_t delResIndex, LOT item) {
|
||||||
|
auto* delresTable = CDClientManager::GetTable<CDDeletionRestrictionsTable>();
|
||||||
|
const auto restriction = delresTable->GetByID(delResIndex);
|
||||||
|
|
||||||
|
switch(restriction.checkType) {
|
||||||
|
case eDeletionRestrictionsCheckType::INCLUDE_LOTS:
|
||||||
|
if (std::ranges::find(restriction.ids, item) != restriction.ids.end()) return false;
|
||||||
|
else return true;
|
||||||
|
case eDeletionRestrictionsCheckType::EXCLUDE_LOTS:
|
||||||
|
if (std::ranges::find(restriction.ids, item) != restriction.ids.end()) return true;
|
||||||
|
else return false;
|
||||||
|
case eDeletionRestrictionsCheckType::ANY_OF_THESE:
|
||||||
|
// TODO: Implement
|
||||||
|
return true;
|
||||||
|
case eDeletionRestrictionsCheckType::ALL_OF_THESE:
|
||||||
|
// TODO: Implement
|
||||||
|
return true;
|
||||||
|
case eDeletionRestrictionsCheckType::WHILE_IN_ZONE:
|
||||||
|
if (std::ranges::find(restriction.ids, Game::zoneManager->GetZoneID().GetMapID()) != restriction.ids.end()) return false;
|
||||||
|
else return true;
|
||||||
|
case eDeletionRestrictionsCheckType::ALWAYS_RESTRICTED:
|
||||||
|
return false;
|
||||||
|
case eDeletionRestrictionsCheckType::MAX:
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -228,6 +228,13 @@ public:
|
|||||||
|
|
||||||
void LoadConfigXml(const tinyxml2::XMLElement& i);
|
void LoadConfigXml(const tinyxml2::XMLElement& i);
|
||||||
|
|
||||||
|
bool CanDeleteItem(Item* item);
|
||||||
|
|
||||||
|
bool CheckDeletionRestriction(uint32_t delResIndex, LOT item);
|
||||||
|
|
||||||
|
bool CheckDeletionRestrictionRecursion(std::set<uint32_t>& delResIndexs, uint32_t delResIndex);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* The object ID of this item
|
* The object ID of this item
|
||||||
|
Loading…
Reference in New Issue
Block a user