Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Rewrite Entity Component System #1110

Draft
wants to merge 122 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
c168f6c
Break out the model component
aronwk-aaron Feb 11, 2023
5097862
Merge branch 'main' into item-component
aronwk-aaron Feb 11, 2023
2ae9a92
fix cmake
aronwk-aaron Feb 11, 2023
c2d5be0
include
aronwk-aaron Mar 21, 2023
5e9a956
Merge branch 'main' into item-component
aronwk-aaron Mar 21, 2023
15988af
hey it compiles
aronwk-aaron Mar 21, 2023
716a5fc
Rename some variables in Component
EmosewaMC Jun 7, 2023
ea9d0d8
I hope this works
EmosewaMC Jun 7, 2023
9e9e4dc
Move to shared pointer
EmosewaMC Jun 7, 2023
d11e2db
update component names, document heirarchy
aronwk-aaron Jun 8, 2023
ec00f5f
holy mother of const
EmosewaMC Jun 9, 2023
62aa863
Remove shared pointer, ODR of componentType variable
EmosewaMC Jun 9, 2023
e2dfa18
Replace all auto with auto*
EmosewaMC Jun 9, 2023
f555ba8
Rename from GetOwningEntity to GetParentEntity
EmosewaMC Jun 9, 2023
6f05720
Rename some variables
EmosewaMC Jun 9, 2023
5da776a
Add blank classes for some Components
EmosewaMC Jun 9, 2023
f2d28cc
Update CMakeLists.txt
EmosewaMC Jun 9, 2023
0b37dc1
Update includes for propertyEnteranceComponent
EmosewaMC Jun 9, 2023
e3a716a
Further re-implement Entity::Initialize
EmosewaMC Jun 9, 2023
ddc5f0e
Merge branch 'main' into components-wheeeee
EmosewaMC Jun 9, 2023
a68fa69
Rename RebuildComponent to QuickbuildComponent
aronwk-aaron Jun 9, 2023
1c23f3c
Add test for component Whitelists
EmosewaMC Jun 10, 2023
2a27997
More robust tests
EmosewaMC Jun 10, 2023
5714ac5
Use std algorithms
EmosewaMC Jun 10, 2023
cebe3c7
Update to actually work with component list
EmosewaMC Jun 10, 2023
b91f84d
Collectible, Item, further re-implement initialize
EmosewaMC Jun 10, 2023
0b5df9f
Destroyable
EmosewaMC Jun 10, 2023
77dc6ff
Continued re-integration of Entity::Initialize
EmosewaMC Jun 11, 2023
5f139c7
Quickbuild and Destroyable reintegration
EmosewaMC Jun 11, 2023
b43e5c2
doesnt have a component
EmosewaMC Jun 11, 2023
f78ea1b
whitespace and comments in quickbuild
EmosewaMC Jun 11, 2023
fc719cb
Comment out done code
EmosewaMC Jun 11, 2023
36c44ec
Fully re-implemented initialize
EmosewaMC Jun 12, 2023
6f38a15
Minor formatting change
EmosewaMC Jun 12, 2023
262b6eb
Remove old Entity Initialize
EmosewaMC Jun 12, 2023
5be9146
Specify auto ptr
EmosewaMC Jun 12, 2023
3f38105
Extra * on one auto
EmosewaMC Jun 12, 2023
f9ac0a9
few more pointer specifiers
EmosewaMC Jun 12, 2023
d224a86
Use only 1 script component per Entity
EmosewaMC Jun 12, 2023
326c495
Use more clear control paths
EmosewaMC Jun 12, 2023
b2fee29
Better log and comment
EmosewaMC Jun 12, 2023
45bcc80
doesnt compile
EmosewaMC Jun 12, 2023
e389a61
update heirarchy
aronwk-aaron Jun 13, 2023
d8e2e92
use get
EmosewaMC Jun 14, 2023
31be1fb
remove script stuff
EmosewaMC Jun 14, 2023
fdd98ab
fix other script calls
aronwk-aaron Jun 14, 2023
83065df
I havent checked if this compiled
EmosewaMC Jun 15, 2023
451f7e7
switch to unique_ptrs for callback timers
EmosewaMC Jun 15, 2023
355f4f4
Update Entity.cpp
EmosewaMC Jun 15, 2023
2a8f40f
Finish file
EmosewaMC Jun 15, 2023
4d57eff
Update includes
EmosewaMC Jun 15, 2023
35e5d84
Remove empty destructors
EmosewaMC Jun 15, 2023
ea97596
Fix typo
EmosewaMC Jun 16, 2023
9a9b9aa
Merge branch 'components-wheeeee' of https://github.com/DarkflameUniv…
EmosewaMC Jun 16, 2023
9200612
Another consistency pass
EmosewaMC Jun 16, 2023
8916482
Organize Entity header
EmosewaMC Jun 16, 2023
a992a28
Merge from upstream
EmosewaMC Jun 16, 2023
be17d1a
Update DestroyableComponent.cpp
EmosewaMC Jun 16, 2023
68a5cc1
Use better API terminology for radii
EmosewaMC Jun 17, 2023
1bdec00
More organization of header
EmosewaMC Jun 17, 2023
e180430
Finish header re-ordering
EmosewaMC Jun 18, 2023
dc96fcb
Vendor cleanup and start Donation Vendor impl
aronwk-aaron Jun 23, 2023
907e045
some tweaks
aronwk-aaron Jun 23, 2023
c78760d
make inheritence clearer
aronwk-aaron Jun 23, 2023
f27e040
scaffold activity based components
aronwk-aaron Jun 23, 2023
bcbc588
Merge branch 'main' into components-wheeeee
aronwk-aaron Jun 23, 2023
34d22d2
AchievementVendor scaffold
aronwk-aaron Jun 23, 2023
d153d66
Merge branch 'item-component' into components-wheeeee
aronwk-aaron Jun 23, 2023
d44b18e
rough logic around loading physics
aronwk-aaron Jun 23, 2023
c237c16
group physicstogether in heirarchy
aronwk-aaron Jun 23, 2023
485a88d
move vars to be local
aronwk-aaron Jun 24, 2023
3f328a1
Merge upstream ghosting candidate changes
EmosewaMC Jun 26, 2023
fee1025
Remove commented out logic, add ghosting exclusion
EmosewaMC Jun 26, 2023
9121bf4
Entity work
EmosewaMC Jun 26, 2023
ec92782
Use better naming
EmosewaMC Jun 26, 2023
34cfd45
CombatAI and Vendor
EmosewaMC Jun 26, 2023
a5611e9
Bouncer cleanup
EmosewaMC Jun 26, 2023
06acd23
Use of final
EmosewaMC Jun 26, 2023
d29287f
Buff Component fixes
EmosewaMC Jun 26, 2023
68f90b7
rename possessor to possession
aronwk-aaron Jun 26, 2023
fd182d2
Update activing and racing components
aronwk-aaron Jun 26, 2023
fdcfbde
BuildBorderCleanup
EmosewaMC Jun 27, 2023
d9a3bea
Merge branch 'components-wheeeee' of https://github.com/DarkflameUniv…
EmosewaMC Jun 27, 2023
2abcb14
Character fixes - get it compiling again
EmosewaMC Jun 27, 2023
c6063aa
Component serialization updates
EmosewaMC Jun 27, 2023
7c12659
move ctor to header for collectible
EmosewaMC Jun 27, 2023
478b6ff
Move empty definitions to header
EmosewaMC Jun 27, 2023
f55bec0
Donation Component serialization
EmosewaMC Jun 27, 2023
c2fe7f6
HavokVehicleComponent improvements
EmosewaMC Jun 27, 2023
0544eeb
Add default constructor for EquipmentItem
EmosewaMC Jun 27, 2023
81404d9
InventoryComponent pass
EmosewaMC Jun 28, 2023
6fb1786
Add component order array
aronwk-aaron Jun 29, 2023
c22040c
ItemComponent Pass
EmosewaMC Jul 5, 2023
8ede5b8
Fix compilation error; add final specifiers
EmosewaMC Jul 5, 2023
cfec980
LevelProgressionComponent cleanup
EmosewaMC Jul 5, 2023
68a2a04
LUPExhibitComponent cleanup
EmosewaMC Jul 5, 2023
197d1bc
Merge branch 'main' into components-wheeeee
aronwk-aaron Jul 5, 2023
950a1fe
MissionComponent pass
EmosewaMC Jul 6, 2023
001f6a7
MissionOfferComponent pass
EmosewaMC Jul 6, 2023
5301346
ModelBehaviorComponent pass
EmosewaMC Jul 6, 2023
cf53e35
SwitchComponent pass
EmosewaMC Jul 7, 2023
28fbe20
ModuleAssemblyComponent pass
EmosewaMC Jul 8, 2023
790bd6c
Merge branch 'components-wheeeee' of https://github.com/DarkflameUniv…
EmosewaMC Jul 8, 2023
1b7be5d
Merge branch 'components-wheeeee' of https://github.com/DarkflameUniv…
EmosewaMC Jul 10, 2023
2528e02
add final
EmosewaMC Jul 10, 2023
8a512e5
MovementAiComponent pass
EmosewaMC Jul 10, 2023
d2a7e14
I am throwing this one out later.
EmosewaMC Jul 10, 2023
7ca9e59
MultiZoneEntranceComponent pass
EmosewaMC Jul 10, 2023
83780af
MutableModelBehaviorComponent pass
EmosewaMC Jul 10, 2023
87675aa
PetComponent pass
EmosewaMC Jul 10, 2023
28637a2
PhantomPhysicsComponent pass
EmosewaMC Jul 10, 2023
598d88b
PlayerForcedMovementComponent pass
EmosewaMC Jul 10, 2023
fe6b279
PossessableComponent pass
EmosewaMC Jul 10, 2023
59831fc
PhantomPhysicsComponent pass
EmosewaMC Jul 10, 2023
4d88f63
PossessionComponent pass
EmosewaMC Jul 10, 2023
37bcc81
PropertyComponent pass
EmosewaMC Jul 10, 2023
8678ed0
push no pass
EmosewaMC Jul 11, 2023
a37ec32
idek if ill keep this but yeah
EmosewaMC Jul 11, 2023
c204ea4
PropertyVendorComponent pass
EmosewaMC Jul 11, 2023
49f3d75
ProximityMonitorComponent re-pass
EmosewaMC Jul 11, 2023
949a6db
RailActivatorComponent pass
EmosewaMC Jul 11, 2023
6240eef
local work
EmosewaMC Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 83 additions & 61 deletions dGame/dComponents/PropertyEntranceComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "PropertyEntranceComponent.h"

#include <CDPropertyEntranceComponentTable.h>
#include "CDPropertyEntranceComponentTable.h"

#include "Character.h"
#include "Database.h"
Expand All @@ -16,7 +16,7 @@
#include "eGameMasterLevel.h"
#include "DluAssert.h"

PropertyEntranceComponent::PropertyEntranceComponent(Entity* parent, uint32_t componentID) : Component(parent) {
PropertyEntranceComponent::PropertyEntranceComponent(Entity* parent, int32_t componentID) : Component(parent) {
this->propertyQueries.clear();
m_ComponentId = componentID;
}
Expand Down Expand Up @@ -57,14 +57,14 @@ void PropertyEntranceComponent::OnEnterProperty(Entity* entity, uint32_t index,
// Increment index once here because the first index of other player properties is 2 in the propertyQueries cache.
index++;

const auto& pair = propertyQueries.find(entity->GetObjectID());
const auto& cachedQuery = propertyQueries.find(entity->GetObjectID());

if (pair == propertyQueries.end()) {
if (cachedQuery == propertyQueries.end()) {
Game::logger->Log("PropertyEntranceComponent", "Player %llu:%s did not have a property query open", entity->GetObjectID(), entity->GetCharacter()->GetName().c_str());
return;
}

const auto& query = pair->second;
const auto& query = cachedQuery->second;

if (index >= query.size()) return;

Expand All @@ -80,11 +80,25 @@ void PropertyEntranceComponent::OnEnterProperty(Entity* entity, uint32_t index,
launcher->Launch(entity, launcher->GetTargetZone(), cloneId);
}

std::string PropertyEntranceComponent::BuildQuery(Entity* entity, int32_t sortMethod, Character* character, std::string customQuery, bool wantLimits) {
std::string PropertyEntranceComponent::BuildQuery(const ePropertySortType sortMethod, Character* character, const std::string& customQuery, const bool wantLimits) {
const std::string baseQueryForProperties =
R"QUERY(
SELECT p.*
FROM properties as p
JOIN charinfo as ci
ON ci.prop_clone_id = p.clone_id
WHERE p.zone_id = ?
AND (
p.description LIKE ?
OR p.name LIKE ?
OR ci.name LIKE ?
)
AND p.privacy_option >= ?
)QUERY";
DluAssert(character != nullptr);
std::string base = customQuery.empty() ? baseQueryForProperties : customQuery;
std::string orderBy;
if (sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS) {
const std::string base = customQuery.empty() ? baseQueryForProperties : customQuery;
std::string orderBy = "ORDER BY p.last_updated DESC";
if (sortMethod == ePropertySortType::SORT_TYPE_FEATURED || sortMethod == ePropertySortType::SORT_TYPE_FRIENDS) {
std::stringstream friendsStream;
friendsStream << " AND p.owner_id IN (";

Expand All @@ -98,32 +112,28 @@ std::string PropertyEntranceComponent::BuildQuery(Entity* entity, int32_t sortMe
std::unique_ptr<sql::ResultSet> friendsListQueryResult(friendsListQuery->executeQuery());

if (friendsListQueryResult->next()) {
friendsStream << friendsListQueryResult->getInt(1);
friendsStream << friendsListQueryResult->getInt("requested_player");
while (friendsListQueryResult->next()) {
friendsStream << ',' << friendsListQueryResult->getInt(1);
friendsStream << ',' << friendsListQueryResult->getInt("requested_player");
}
}
// Replace trailing comma with the closing parenthesis.

// If we have no friends then use a -1 for the query.
if (friendsListQueryResult->rowsCount() == 0) friendsStream << -1;
friendsStream << ')';

orderBy += friendsStream.str() + " ORDER BY ci.name ASC";

} else if (sortMethod == SORT_TYPE_RECENT) {
} else if (sortMethod == ePropertySortType::SORT_TYPE_RECENT) {
orderBy = "ORDER BY p.last_updated DESC";
} else if (sortMethod == SORT_TYPE_REPUTATION) {
} else if (sortMethod == ePropertySortType::SORT_TYPE_REPUTATION) {
orderBy = "ORDER BY p.reputation DESC, p.last_updated DESC";
} else {
orderBy = "ORDER BY p.last_updated DESC";
}
return base + orderBy + (wantLimits ? " LIMIT ? OFFSET ?;" : " ;");
}

void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool includeNullAddress, bool includeNullDescription, bool playerOwn, bool updateUi, int32_t numResults, int32_t lReputationTime, int32_t sortMethod, int32_t startIndex, std::string filterText, const SystemAddress& sysAddr) {
std::vector<PropertySelectQueryProperty> entries;
PropertySelectQueryProperty playerEntry;
void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool includeNullAddress, bool includeNullDescription, bool playerOwn, bool updateUi, int32_t numResults, int32_t lReputationTime, ePropertySortType sortMethod, int32_t startIndex, std::string filterText, const SystemAddress& sysAddr) {
std::vector<PropertySelectQueryProperty> propertyPageEntries;
PropertySelectQueryProperty requestorEntry;

auto character = entity->GetCharacter();
if (!character) return;
Expand All @@ -139,58 +149,55 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
std::unique_ptr<sql::ResultSet> playerPropertyLookupResults(playerPropertyLookup->executeQuery());

// If the player has a property this query will have a single result.
requestorEntry.CloneId = character->GetPropertyCloneID();
requestorEntry.OwnerName = character->GetName();
if (playerPropertyLookupResults->next()) {
playerEntry.CloneId = playerPropertyLookupResults->getUInt64(4);;
playerEntry.OwnerName = character->GetName();
playerEntry.Name = playerPropertyLookupResults->getString(5).c_str();
playerEntry.Description = playerPropertyLookupResults->getString(6).c_str();
playerEntry.Reputation = playerPropertyLookupResults->getUInt(14);
playerEntry.IsBestFriend = true;
playerEntry.IsFriend = true;
playerEntry.IsModeratorApproved = playerPropertyLookupResults->getBoolean(10);
playerEntry.IsAlt = true;
playerEntry.IsOwned = true;
playerEntry.AccessType = playerPropertyLookupResults->getInt(9);
playerEntry.DateLastPublished = playerPropertyLookupResults->getInt64(11);
playerEntry.PerformanceCost = playerPropertyLookupResults->getDouble(16);
} else {
playerEntry.CloneId = character->GetPropertyCloneID();
playerEntry.OwnerName = character->GetName();
playerEntry.Description.clear();
playerEntry.Name.clear();
playerEntry.Reputation = 0.0f;
playerEntry.IsBestFriend = true;
playerEntry.IsFriend = true;
requestorEntry.Name = std::string(playerPropertyLookupResults->getString("name").c_str());
requestorEntry.Description = std::string(playerPropertyLookupResults->getString("description").c_str());
requestorEntry.Reputation = playerPropertyLookupResults->getUInt("reputation");
requestorEntry.IsBestFriend = true;
requestorEntry.IsFriend = true;
requestorEntry.IsModeratorApproved = playerPropertyLookupResults->getBoolean("mod_approved");
requestorEntry.IsAlt = true;
requestorEntry.IsOwned = true;
requestorEntry.AccessType = playerPropertyLookupResults->getInt("privacy_option");
requestorEntry.DateLastPublished = playerPropertyLookupResults->getInt64("last_updated");
requestorEntry.PerformanceCost = playerPropertyLookupResults->getDouble("performance_cost");
}

entries.push_back(playerEntry);
propertyPageEntries.push_back(requestorEntry);

const auto query = BuildQuery(entity, sortMethod, character);
const auto query = BuildQuery(sortMethod, character);

std::unique_ptr<sql::PreparedStatement> propertyLookup(Database::CreatePreppedStmt(query));

const auto searchString = "%" + filterText + "%";
PropertyPrivacyOption friendsLookup =
sortMethod == ePropertySortType::SORT_TYPE_FEATURED || sortMethod == ePropertySortType::SORT_TYPE_FRIENDS ?
PropertyPrivacyOption::Friends :
PropertyPrivacyOption::Public;

propertyLookup->setUInt(1, this->m_MapID);
propertyLookup->setString(2, searchString.c_str());
propertyLookup->setString(3, searchString.c_str());
propertyLookup->setString(4, searchString.c_str());
propertyLookup->setInt(5, sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS ? (uint32_t)PropertyPrivacyOption::Friends : (uint32_t)PropertyPrivacyOption::Public);
propertyLookup->setInt(5, static_cast<uint32_t>(friendsLookup));
propertyLookup->setInt(6, numResults);
propertyLookup->setInt(7, startIndex);

std::unique_ptr<sql::ResultSet> propertyEntry(propertyLookup->executeQuery());

while (propertyEntry->next()) {
PropertySelectQueryProperty playerPropertyEntry;
const auto owner = propertyEntry->getInt(2);
playerPropertyEntry.CloneId = propertyEntry->getUInt64(4);
playerPropertyEntry.Name = std::string(propertyEntry->getString(5).c_str());
playerPropertyEntry.Description = std::string(propertyEntry->getString(6).c_str());
playerPropertyEntry.AccessType = propertyEntry->getInt(9);
playerPropertyEntry.IsModeratorApproved = propertyEntry->getBoolean(10);
playerPropertyEntry.DateLastPublished = propertyEntry->getInt(11);
playerPropertyEntry.Reputation = static_cast<float>(propertyEntry->getInt(14));
playerPropertyEntry.PerformanceCost = static_cast<float>(propertyEntry->getDouble(16));
const auto owner = propertyEntry->getInt("owner_id");
playerPropertyEntry.CloneId = propertyEntry->getUInt64("clone_id");
playerPropertyEntry.Name = std::string(propertyEntry->getString("name").c_str());
playerPropertyEntry.Description = std::string(propertyEntry->getString("description").c_str());
playerPropertyEntry.AccessType = propertyEntry->getInt("privacy_option");
playerPropertyEntry.IsModeratorApproved = propertyEntry->getBoolean("mod_approved");
playerPropertyEntry.DateLastPublished = propertyEntry->getInt("last_updated");
playerPropertyEntry.Reputation = static_cast<float>(propertyEntry->getInt("reputation"));
playerPropertyEntry.PerformanceCost = static_cast<float>(propertyEntry->getDouble("performance_cost"));
playerPropertyEntry.OwnerName = "";
playerPropertyEntry.IsBestFriend = false;
playerPropertyEntry.IsFriend = false;
Expand All @@ -209,7 +216,7 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl
continue;
}
playerPropertyEntry.IsOwned = playerPropertyEntry.CloneId == character->GetPropertyCloneID();
playerPropertyEntry.OwnerName = std::string(nameResult->getString(1).c_str());
playerPropertyEntry.OwnerName = std::string(nameResult->getString("name").c_str());

// Query to get friend and best friend fields
std::unique_ptr<sql::PreparedStatement> friendCheck(
Expand All @@ -225,9 +232,9 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl

// If we got a result than the two players are friends.
playerPropertyEntry.IsFriend = friendResult->next();
playerPropertyEntry.IsBestFriend = playerPropertyEntry.IsFriend && friendResult->getInt(1) == 3;
playerPropertyEntry.IsBestFriend = playerPropertyEntry.IsFriend && friendResult->getInt("best_friend") == 3;

playerPropertyEntry.IsModeratorApproved = propertyEntry->getBoolean(10);
playerPropertyEntry.IsModeratorApproved = propertyEntry->getBoolean("mod_approved");

// So lead moderators can visit the property but also see that it is still awaiting approval.
if (!playerPropertyEntry.IsModeratorApproved && entity->GetGMLevel() >= eGameMasterLevel::LEAD_MODERATOR) {
Expand All @@ -248,23 +255,38 @@ void PropertyEntranceComponent::OnPropertyEntranceSync(Entity* entity, bool incl

if (isAltQueryResults->next()) playerPropertyEntry.IsAlt = true;

entries.push_back(playerPropertyEntry);
propertyPageEntries.push_back(playerPropertyEntry);
}
propertyQueries[entity->GetObjectID()] = entries;
propertyQueries[entity->GetObjectID()] = propertyPageEntries;

// Query here is to figure out whether or not to display the button to go to the next page or not.
auto buttonQuery = BuildQuery(entity, sortMethod, character, "SELECT COUNT(*) as numProperties FROM properties as p JOIN charinfo as ci ON ci.prop_clone_id = p.clone_id where p.zone_id = ? AND (p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ?) AND p.privacy_option >= ? ", false);
const std::string baseButtonQuery =
R"QUERY(
SELECT COUNT(*) as numProperties
FROM properties as p
JOIN charinfo as ci
ON ci.prop_clone_id = p.clone_id
WHERE p.zone_id = ?
AND (
p.description LIKE ?
OR p.name LIKE ?
OR ci.name LIKE ?
)
AND p.privacy_option >= ?
)QUERY";

auto buttonQuery = BuildQuery(sortMethod, character, baseButtonQuery, false);
std::unique_ptr<sql::PreparedStatement> propertiesLeft(Database::CreatePreppedStmt(buttonQuery));

propertiesLeft->setUInt(1, this->m_MapID);
propertiesLeft->setString(2, searchString.c_str());
propertiesLeft->setString(3, searchString.c_str());
propertiesLeft->setString(4, searchString.c_str());
propertiesLeft->setInt(5, sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS ? 1 : 2);
propertiesLeft->setInt(5, static_cast<uint32_t>(friendsLookup));

std::unique_ptr<sql::ResultSet> result(propertiesLeft->executeQuery());
result->next();
int32_t numberOfProperties = result->getInt("numProperties");

GameMessages::SendPropertySelectQuery(m_ParentEntity->GetObjectID(), startIndex, numberOfProperties - (startIndex + numResults) > 0, character->GetPropertyCloneID(), false, true, entries, sysAddr);
GameMessages::SendPropertySelectQuery(m_ParentEntity->GetObjectID(), startIndex, numberOfProperties - (startIndex + numResults) > 0, character->GetPropertyCloneID(), false, true, propertyPageEntries, sysAddr);
}
24 changes: 11 additions & 13 deletions dGame/dComponents/PropertyEntranceComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
#include "eReplicaComponentType.h"
#include "PropertySelectQueryProperty.h"

enum class ePropertySortType : int32_t {
SORT_TYPE_FRIENDS = 0,
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
SORT_TYPE_REPUTATION = 1,
SORT_TYPE_RECENT = 3,
SORT_TYPE_FEATURED = 5
};

/**
* Represents the launch pad that's used to select and browse properties
*/
class PropertyEntranceComponent : public Component {
class PropertyEntranceComponent final : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_ENTRANCE;
explicit PropertyEntranceComponent(Entity* parent, uint32_t componentID);
explicit PropertyEntranceComponent(Entity* parent, int32_t componentID);

void LoadTemplateData() override;

Expand Down Expand Up @@ -45,7 +52,7 @@ class PropertyEntranceComponent : public Component {
* @param filterText property names to search for
* @param sysAddr the address to send gamemessage responses to
*/
void OnPropertyEntranceSync(Entity* entity, bool includeNullAddress, bool includeNullDescription, bool playerOwn, bool updateUi, int32_t numResults, int32_t lReputationTime, int32_t sortMethod, int32_t startIndex, std::string filterText, const SystemAddress& sysAddr);
void OnPropertyEntranceSync(Entity* entity, bool includeNullAddress, bool includeNullDescription, bool playerOwn, bool updateUi, int32_t numResults, int32_t lReputationTime, ePropertySortType sortMethod, int32_t startIndex, std::string filterText, const SystemAddress& sysAddr);

/**
* Returns the name of this property
Expand All @@ -59,7 +66,7 @@ class PropertyEntranceComponent : public Component {
*/
[[nodiscard]] LWOMAPID GetMapID() const { return m_MapID; };

std::string BuildQuery(Entity* entity, int32_t sortMethod, Character* character, std::string customQuery = "", bool wantLimits = true);
[[nodiscard]] static std::string BuildQuery(const ePropertySortType sortMethod, Character* character, const std::string& customQuery = "", const bool wantLimits = true);

private:
/**
Expand All @@ -77,14 +84,5 @@ class PropertyEntranceComponent : public Component {
*/
LWOMAPID m_MapID;

enum ePropertySortType : int32_t {
SORT_TYPE_FRIENDS = 0,
SORT_TYPE_REPUTATION = 1,
SORT_TYPE_RECENT = 3,
SORT_TYPE_FEATURED = 5
};

std::string baseQueryForProperties = "SELECT p.* FROM properties as p JOIN charinfo as ci ON ci.prop_clone_id = p.clone_id where p.zone_id = ? AND (p.description LIKE ? OR p.name LIKE ? OR ci.name LIKE ?) AND p.privacy_option >= ? ";

int32_t m_ComponentId = -1;
};
12 changes: 6 additions & 6 deletions dGame/dComponents/PropertyManagementComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Information regarding which players may visit this property
*/
enum class PropertyPrivacyOption
enum class PropertyPrivacyOption : uint32_t
{
/**
* Default, only you can visit your property
Expand All @@ -18,12 +18,12 @@ enum class PropertyPrivacyOption
/**
* Your friends can visit your property
*/
Friends = 1,
Friends = 1,

/**
* Requires Mythran approval, everyone can visit your property
*/
Public = 2
/**
* Requires Mythran approval, everyone can visit your property
*/
Public = 2
};

/**
Expand Down
7 changes: 3 additions & 4 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2752,7 +2752,7 @@ void GameMessages::HandlePropertyEntranceSync(RakNet::BitStream* inStream, Entit
bool updateUi{};
int32_t numResults{};
int32_t reputation{};
int32_t sortMethod{};
ePropertySortType sortMethod{};
int32_t startIndex{};
uint32_t filterTextLength{};
std::string filterText{};
Expand All @@ -2769,15 +2769,14 @@ void GameMessages::HandlePropertyEntranceSync(RakNet::BitStream* inStream, Entit

for (auto i = 0u; i < filterTextLength; i++) {
char c;
inStream->Read(c);
filterText.push_back(c);
if (inStream->Read(c)) filterText.push_back(c);
}

auto* player = Player::GetPlayer(sysAddr);

auto* entranceComponent = entity->GetComponent<PropertyEntranceComponent>();

if (entranceComponent == nullptr) return;
if (!entranceComponent) return;

entranceComponent->OnPropertyEntranceSync(player,
includeNullAddress,
Expand Down
Loading