mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-19 02:05:28 +00:00
refactor(component): group the component files by the client's families
Physics/, Activity/ (activity, scripted activity, shooting gallery, quickbuild, minigame control, racing control base, racing control, gate rush), Vendor/, Character/ (what the client makes with a character, plus ghost, minifig and mission), Sound/ and Property/; the rest stays where it was. File moves only; DLU_COMPONENT_INCLUDE_DIRS gives every target the folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
80
dGame/dComponents/Property/BuildBorderComponent.cpp
Normal file
80
dGame/dComponents/Property/BuildBorderComponent.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "BuildBorderComponent.h"
|
||||
#include "ObjectMessages.h"
|
||||
|
||||
#include "EntityManager.h"
|
||||
#include "GameMessages.h"
|
||||
#include "BuildingMessages.h"
|
||||
#include "Entity.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "Item.h"
|
||||
#include "PropertyManagementComponent.h"
|
||||
|
||||
BuildBorderComponent::BuildBorderComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
RegisterMsg(&BuildBorderComponent::OnRequestUse);
|
||||
}
|
||||
|
||||
BuildBorderComponent::~BuildBorderComponent() {
|
||||
}
|
||||
|
||||
bool BuildBorderComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
|
||||
if (event.msg.IsMissionChoice()) return false;
|
||||
auto* const originator = event.user;
|
||||
if (originator->GetCharacter()) {
|
||||
const auto& entities = Game::entityManager->GetEntitiesInGroup("PropertyPlaque");
|
||||
|
||||
auto buildArea = m_Parent->GetObjectID();
|
||||
|
||||
if (!entities.empty()) {
|
||||
buildArea = entities[0]->GetObjectID();
|
||||
|
||||
LOG("Using PropertyPlaque");
|
||||
}
|
||||
|
||||
auto* inventoryComponent = originator->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* thinkingHat = inventoryComponent->FindItemByLot(6086);
|
||||
|
||||
if (thinkingHat == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
inventoryComponent->PushEquippedItems();
|
||||
|
||||
LOG("Starting with %llu", buildArea);
|
||||
|
||||
if (PropertyManagementComponent::Instance() != nullptr) {
|
||||
GameMessages::StartArrangingWithItem arranging;
|
||||
arranging.target = originator->GetObjectID();
|
||||
arranging.firstTime = true;
|
||||
arranging.buildAreaID = buildArea;
|
||||
arranging.buildStartPos = originator->GetPosition();
|
||||
arranging.sourceBag = 0;
|
||||
arranging.sourceID = thinkingHat->GetId();
|
||||
arranging.sourceLot = thinkingHat->GetLot();
|
||||
arranging.sourceType = 4;
|
||||
arranging.targetID = 0;
|
||||
arranging.targetLot = -1;
|
||||
arranging.targetPos = NiPoint3Constant::ZERO;
|
||||
arranging.targetType = 0;
|
||||
arranging.SendToClient(originator->GetSystemAddress());
|
||||
} else {
|
||||
GameMessages::StartArrangingWithItem arranging;
|
||||
arranging.target = originator->GetObjectID();
|
||||
arranging.firstTime = true;
|
||||
arranging.buildAreaID = buildArea;
|
||||
arranging.buildStartPos = originator->GetPosition();
|
||||
arranging.SendToClient(originator->GetSystemAddress());
|
||||
}
|
||||
|
||||
InventoryComponent* inv = m_Parent->GetComponent<InventoryComponent>();
|
||||
if (!inv) return true;
|
||||
inv->PushEquippedItems(); // technically this is supposed to happen automatically... but it doesnt? so just keep this here
|
||||
}
|
||||
return true;
|
||||
}
|
||||
32
dGame/dComponents/Property/BuildBorderComponent.h
Normal file
32
dGame/dComponents/Property/BuildBorderComponent.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2018
|
||||
*/
|
||||
|
||||
#ifndef BUILDBORDERCOMPONENT_H
|
||||
#define BUILDBORDERCOMPONENT_H
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* Component for the build border, allowing the user to start building when interacting with it
|
||||
*/
|
||||
class BuildBorderComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::BUILD_BORDER;
|
||||
|
||||
BuildBorderComponent(Entity* parent, const int32_t componentID);
|
||||
~BuildBorderComponent() override;
|
||||
|
||||
/**
|
||||
* Causes the originator to start build with this entity as a reference point
|
||||
* @param originator the entity (probably a player) that triggered the event
|
||||
*/
|
||||
bool OnRequestUse(GameMessages::RequestUseEvent& event);
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // BUILDBORDERCOMPONENT_H
|
||||
22
dGame/dComponents/Property/PropertyComponent.h
Normal file
22
dGame/dComponents/Property/PropertyComponent.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2024
|
||||
*/
|
||||
|
||||
#ifndef PROPERTYCOMPONENT_H
|
||||
#define PROPERTYCOMPONENT_H
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* This component is unused and has no functionality
|
||||
*/
|
||||
class PropertyComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY;
|
||||
explicit PropertyComponent(Entity* const parentEntity, const int32_t componentID) noexcept : Component{ parentEntity, componentID } {}
|
||||
};
|
||||
|
||||
#endif // !PROPERTYCOMPONENT_H
|
||||
201
dGame/dComponents/Property/PropertyEntranceComponent.cpp
Normal file
201
dGame/dComponents/Property/PropertyEntranceComponent.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
#include "PropertyEntranceComponent.h"
|
||||
#include "ObjectMessages.h"
|
||||
|
||||
#include "CDPropertyEntranceComponentTable.h"
|
||||
|
||||
#include "Character.h"
|
||||
#include "Database.h"
|
||||
#include "GameMessages.h"
|
||||
#include "EffectsMessages.h"
|
||||
#include "PropertyManagementComponent.h"
|
||||
#include "PropertyMessages.h"
|
||||
#include "RocketLaunchpadControlComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "UserManager.h"
|
||||
#include "Logger.h"
|
||||
#include "Amf3.h"
|
||||
#include "eObjectBits.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "ePropertySortType.h"
|
||||
#include "User.h"
|
||||
|
||||
PropertyEntranceComponent::PropertyEntranceComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
RegisterMsg(&PropertyEntranceComponent::OnRequestUse);
|
||||
this->propertyQueries = {};
|
||||
}
|
||||
|
||||
// The PropertyEntranceComponent row
|
||||
void PropertyEntranceComponent::LoadDataFromTemplate() {
|
||||
auto table = CDClientManager::GetTable<CDPropertyEntranceComponentTable>();
|
||||
const auto& entry = table->GetByID(m_ComponentID);
|
||||
|
||||
this->m_MapID = entry.mapID;
|
||||
this->m_PropertyName = entry.propertyName;
|
||||
}
|
||||
|
||||
bool PropertyEntranceComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
|
||||
if (event.msg.IsMissionChoice()) return false;
|
||||
auto* const entity = event.user;
|
||||
auto* characterComponent = entity->GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return true;
|
||||
|
||||
auto* rocket = entity->GetComponent<CharacterComponent>()->RocketEquip(entity);
|
||||
if (!rocket) return true;
|
||||
|
||||
GameMessages::PropertyEntranceBegin msg;
|
||||
msg.target = m_Parent->GetObjectID();
|
||||
msg.Send(entity->GetSystemAddress());
|
||||
|
||||
AMFArrayValue args;
|
||||
|
||||
args.Insert("state", "property_menu");
|
||||
|
||||
GameMessages::UIMessageServerToSingleClient uiMessage;
|
||||
uiMessage.target = entity->GetObjectID();
|
||||
uiMessage.strMessageName = "pushGameState";
|
||||
uiMessage.args = std::move(args);
|
||||
uiMessage.SendToClient(entity->GetSystemAddress());
|
||||
return true;
|
||||
}
|
||||
|
||||
void PropertyEntranceComponent::OnEnterProperty(Entity* entity, uint32_t index, bool returnToZone, const SystemAddress& sysAddr) {
|
||||
LWOCLONEID cloneId = 0;
|
||||
|
||||
if (index == -1 && !returnToZone) {
|
||||
cloneId = entity->GetCharacter()->GetPropertyCloneID();
|
||||
} else if (index == -1 && returnToZone) {
|
||||
cloneId = 0;
|
||||
} else if (index >= 0) {
|
||||
// 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());
|
||||
|
||||
if (pair == propertyQueries.end()) return;
|
||||
|
||||
const auto& query = pair->second;
|
||||
|
||||
if (index >= query.size()) return;
|
||||
|
||||
cloneId = query[index].cloneId;
|
||||
}
|
||||
|
||||
auto* launcher = m_Parent->GetComponent<RocketLaunchpadControlComponent>();
|
||||
|
||||
if (launcher == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
launcher->SetSelectedCloneId(entity->GetObjectID(), cloneId);
|
||||
|
||||
launcher->Launch(entity, launcher->GetTargetZone(), cloneId);
|
||||
}
|
||||
|
||||
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) {
|
||||
const auto* const character = entity->GetCharacter();
|
||||
if (!character) return;
|
||||
const auto* const user = character->GetParentUser();
|
||||
if (!user) return;
|
||||
|
||||
auto& entries = propertyQueries[entity->GetObjectID()];
|
||||
entries.clear();
|
||||
// Player property goes in index 1 of the vector. This is how the client expects it.
|
||||
const auto playerProperty = Database::Get()->GetPropertyInfo(m_MapID, character->GetPropertyCloneID());
|
||||
|
||||
// If the player has a property this query will have a single result.
|
||||
auto& playerEntry = entries.emplace_back();
|
||||
if (playerProperty.has_value()) {
|
||||
playerEntry.ownerName = GeneralUtils::UTF8ToUTF16(character->GetName());
|
||||
playerEntry.isBff = true;
|
||||
playerEntry.isFriend = true;
|
||||
playerEntry.isAlt = true;
|
||||
playerEntry.isOwned = true;
|
||||
playerEntry.cloneId = playerProperty->cloneId;
|
||||
playerEntry.name = GeneralUtils::UTF8ToUTF16(playerProperty->name);
|
||||
playerEntry.description = GeneralUtils::UTF8ToUTF16(playerProperty->description);
|
||||
playerEntry.accessType = playerProperty->privacyOption;
|
||||
playerEntry.isModApproved = playerProperty->modApproved;
|
||||
playerEntry.dateLastPublished = playerProperty->lastUpdatedTime;
|
||||
playerEntry.reputation = playerProperty->reputation;
|
||||
playerEntry.performanceCost = playerProperty->performanceCost;
|
||||
auto& entry = playerEntry;
|
||||
} else {
|
||||
playerEntry.ownerName = GeneralUtils::UTF8ToUTF16(character->GetName());
|
||||
playerEntry.isBff = true;
|
||||
playerEntry.isFriend = true;
|
||||
playerEntry.isAlt = false;
|
||||
playerEntry.isOwned = false;
|
||||
playerEntry.cloneId = character->GetPropertyCloneID();
|
||||
playerEntry.name = u"";
|
||||
playerEntry.description = u"";
|
||||
playerEntry.accessType = 0;
|
||||
playerEntry.isModApproved = false;
|
||||
playerEntry.dateLastPublished = 0;
|
||||
playerEntry.reputation = 0;
|
||||
playerEntry.performanceCost = 0.0f;
|
||||
}
|
||||
|
||||
IProperty::PropertyLookup propertyLookup;
|
||||
propertyLookup.mapId = m_MapID;
|
||||
propertyLookup.searchString = filterText;
|
||||
propertyLookup.sortChoice = static_cast<ePropertySortType>(sortMethod);
|
||||
propertyLookup.playerSort = static_cast<uint32_t>(sortMethod == SORT_TYPE_FEATURED || sortMethod == SORT_TYPE_FRIENDS ? PropertyPrivacyOption::Friends : PropertyPrivacyOption::Public);
|
||||
propertyLookup.playerId = character->GetID();
|
||||
propertyLookup.numResults = numResults;
|
||||
propertyLookup.startIndex = startIndex;
|
||||
|
||||
const auto lookupResult = Database::Get()->GetProperties(propertyLookup);
|
||||
|
||||
for (const auto& propertyEntry : lookupResult.entries) {
|
||||
const auto owner = propertyEntry.ownerId;
|
||||
const auto otherCharacter = Database::Get()->GetCharacterInfo(owner);
|
||||
if (!otherCharacter.has_value()) {
|
||||
LOG("Failed to find property owner name for %llu!", owner);
|
||||
continue;
|
||||
}
|
||||
auto& entry = entries.emplace_back();
|
||||
|
||||
entry.isOwned = entry.cloneId == otherCharacter->cloneId;
|
||||
entry.ownerName = GeneralUtils::UTF8ToUTF16(otherCharacter->name);
|
||||
entry.cloneId = propertyEntry.cloneId;
|
||||
entry.name = GeneralUtils::UTF8ToUTF16(propertyEntry.name);
|
||||
entry.description = GeneralUtils::UTF8ToUTF16(propertyEntry.description);
|
||||
entry.accessType = propertyEntry.privacyOption;
|
||||
entry.isModApproved = propertyEntry.modApproved;
|
||||
entry.dateLastPublished = propertyEntry.lastUpdatedTime;
|
||||
entry.reputation = propertyEntry.reputation;
|
||||
entry.performanceCost = propertyEntry.performanceCost;
|
||||
entry.isBff = false;
|
||||
entry.isFriend = false;
|
||||
// Query to get friend and best friend fields
|
||||
const auto friendCheck = Database::Get()->GetBestFriendStatus(character->GetID(), owner);
|
||||
// If we got a result than the two players are friends.
|
||||
if (friendCheck.has_value()) {
|
||||
entry.isFriend = true;
|
||||
entry.isBff = friendCheck->bestFriendStatus == 3;
|
||||
}
|
||||
|
||||
if (!entry.isModApproved && entity->GetGMLevel() >= eGameMasterLevel::LEAD_MODERATOR) {
|
||||
entry.name = u"[AWAITING APPROVAL]";
|
||||
entry.description = u"[AWAITING APPROVAL]";
|
||||
entry.isModApproved = true;
|
||||
}
|
||||
|
||||
// Query to determine whether this property is an alt character of the entity.
|
||||
for (const auto charid : Database::Get()->GetAccountCharacterIds(user->GetAccountID())) {
|
||||
entry.isAlt = charid == owner;
|
||||
if (entry.isAlt) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Query here is to figure out whether or not to display the button to go to the next page or not.
|
||||
GameMessages::PropertySelectQuery query;
|
||||
query.target = m_Parent->GetObjectID();
|
||||
query.navOffset = startIndex;
|
||||
query.thereAreMore = lookupResult.totalEntriesMatchingQuery - (startIndex + numResults) > 0;
|
||||
query.cloneId = character->GetPropertyCloneID();
|
||||
query.hasFeaturedProperty = false;
|
||||
query.wasFriends = true;
|
||||
query.properties = entries;
|
||||
query.Send(sysAddr);
|
||||
}
|
||||
80
dGame/dComponents/Property/PropertyEntranceComponent.h
Normal file
80
dGame/dComponents/Property/PropertyEntranceComponent.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "Component.h"
|
||||
#include "Entity.h"
|
||||
#include "EntityManager.h"
|
||||
#include "GameMessages.h"
|
||||
#include "PropertyMessages.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* Represents the launch pad that's used to select and browse properties
|
||||
*/
|
||||
class PropertyEntranceComponent final : public Component {
|
||||
public:
|
||||
explicit PropertyEntranceComponent(Entity* parent, const int32_t componentID);
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_ENTRANCE;
|
||||
|
||||
void LoadDataFromTemplate() override;
|
||||
|
||||
/**
|
||||
* Handles a RequestUse for some other entity, rendering the property browse menu
|
||||
* @param entity the entity that triggered the event
|
||||
*/
|
||||
bool OnRequestUse(GameMessages::RequestUseEvent& event);
|
||||
|
||||
/**
|
||||
* Handles the event triggered when the entity selects a property to visit and makes the entity to there
|
||||
* @param entity the entity that triggered the event
|
||||
* @param index the index of the property property
|
||||
* @param returnToZone whether or not the entity wishes to go back to the launch zone
|
||||
* @param sysAddr the address to send gamemessage responses to
|
||||
*/
|
||||
void OnEnterProperty(Entity* entity, uint32_t index, bool returnToZone, const SystemAddress& sysAddr);
|
||||
|
||||
/**
|
||||
* Handles a request for information on available properties when an entity lands on the property
|
||||
* @param entity the entity that triggered the event
|
||||
* @param includeNullAddress unused
|
||||
* @param includeNullDescription unused
|
||||
* @param playerOwn only query properties owned by the entity
|
||||
* @param updateUi unused
|
||||
* @param numResults unused
|
||||
* @param lReputationTime unused
|
||||
* @param sortMethod unused
|
||||
* @param startIndex the minimum index to start the query off
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Returns the name of this property
|
||||
* @return the name of this property
|
||||
*/
|
||||
[[nodiscard]] std::string GetPropertyName() const { return m_PropertyName; };
|
||||
|
||||
/**
|
||||
* Returns the map ID for this property
|
||||
* @return the map ID for this property
|
||||
*/
|
||||
[[nodiscard]] LWOMAPID GetMapID() const noexcept { return m_MapID; };
|
||||
|
||||
private:
|
||||
/**
|
||||
* Cache of property information that was queried for property launched, indexed by property ID
|
||||
*/
|
||||
std::map<LWOOBJID, std::vector<GameMessages::PropertySelectQuery::PropertyInfo>> propertyQueries;
|
||||
|
||||
/**
|
||||
* The custom name for this property
|
||||
*/
|
||||
std::string m_PropertyName;
|
||||
|
||||
/**
|
||||
* The base map ID for this property (Avant Grove, etc).
|
||||
*/
|
||||
LWOMAPID m_MapID;
|
||||
};
|
||||
1018
dGame/dComponents/Property/PropertyManagementComponent.cpp
Normal file
1018
dGame/dComponents/Property/PropertyManagementComponent.cpp
Normal file
File diff suppressed because it is too large
Load Diff
322
dGame/dComponents/Property/PropertyManagementComponent.h
Normal file
322
dGame/dComponents/Property/PropertyManagementComponent.h
Normal file
@@ -0,0 +1,322 @@
|
||||
#pragma once
|
||||
|
||||
#include "ePropertyPrivacyOption.h"
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "LDFFormat.h"
|
||||
|
||||
class Item;
|
||||
|
||||
namespace GameMessages {
|
||||
struct DownloadPropertyData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main component that handles interactions with a property, generally the plaques you see on properties.
|
||||
*/
|
||||
class PropertyManagementComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT;
|
||||
PropertyManagementComponent(Entity* parent, const int32_t componentID);
|
||||
~PropertyManagementComponent() override;
|
||||
static PropertyManagementComponent* Instance();
|
||||
|
||||
/**
|
||||
* Whether the player can build on this property: its owner, or with property_bff_build a best friend of the owner
|
||||
* while the owner is building (and, once in build mode, until they leave it)
|
||||
*/
|
||||
bool CanBuild(const Entity& player) const;
|
||||
|
||||
// A player finished loading into this world: looks up whether they are a best friend of the owner
|
||||
void OnPlayerLoaded(Entity& player);
|
||||
|
||||
// A player left this world: ends their building and updates who else can build
|
||||
void OnPlayerRemoved(Entity& player);
|
||||
|
||||
// Tells every player whose right to build changed (CanBuild) and ends building for those who lost it
|
||||
void UpdateBuildRights();
|
||||
|
||||
/**
|
||||
* Event handler for when an entity requests information about this property, will send back whether it's owned, etc.
|
||||
* @param originator the entity that triggered the event
|
||||
* @param sysAddr the address to send game message responses to
|
||||
* @param author optional explicit ID for the property, if not set defaults to the originator
|
||||
*/
|
||||
void OnQueryPropertyData(Entity* originator, const SystemAddress& sysAddr, LWOOBJID author = LWOOBJID_EMPTY);
|
||||
|
||||
/**
|
||||
* Handles a RequestUse, telling the client who owns this property, etc.
|
||||
* @param originator the entity that triggered the event
|
||||
*/
|
||||
bool OnRequestUse(GameMessages::RequestUseEvent& event);
|
||||
|
||||
/**
|
||||
* Sets the owner of this property
|
||||
* @param value the owner to set
|
||||
*/
|
||||
void SetOwnerId(LWOOBJID value);
|
||||
|
||||
/**
|
||||
* Returns the ID of the owner of this property
|
||||
* @return the ID of the owner of this property
|
||||
*/
|
||||
LWOOBJID GetOwnerId() const;
|
||||
|
||||
/**
|
||||
* Returns the owner of this property
|
||||
* @return the owner of this property
|
||||
*/
|
||||
Entity* GetOwner() const;
|
||||
|
||||
/**
|
||||
* sets the owner of this property
|
||||
* @param value the owner to set
|
||||
*/
|
||||
void SetOwner(Entity* value);
|
||||
|
||||
/**
|
||||
* Returns the paths that this property has
|
||||
* @return the paths that this property has
|
||||
*/
|
||||
std::vector<NiPoint3> GetPaths() const;
|
||||
|
||||
/**
|
||||
* Returns the privacy options for this property
|
||||
* @return the privacy options for this property
|
||||
*/
|
||||
PropertyPrivacyOption GetPrivacyOption() const;
|
||||
|
||||
/**
|
||||
* Updates the privacy option for this property
|
||||
* @param value the privacy option to set
|
||||
*/
|
||||
void SetPrivacyOption(PropertyPrivacyOption value);
|
||||
|
||||
/**
|
||||
* Updates information of this property, saving it to the database
|
||||
* @param name the name to set for the property
|
||||
* @param description the description to set for the property
|
||||
*/
|
||||
void UpdatePropertyDetails(std::string name, std::string description);
|
||||
|
||||
/**
|
||||
* Makes this property owned by the passed player ID, storing it in the database
|
||||
* @param playerId the ID of the entity that claimed the property
|
||||
*
|
||||
* @return If the claim is successful return true.
|
||||
*/
|
||||
bool Claim(LWOOBJID playerId);
|
||||
|
||||
/**
|
||||
* Event triggered when a player who can build starts building. The first one to start (the owner) makes the property
|
||||
* private, pauses the models and sends away the players who can't build.
|
||||
*/
|
||||
void OnStartBuilding(Entity& builder);
|
||||
|
||||
/**
|
||||
* Event triggered when a builder finished building. When the last one finishes the property is re-applied for
|
||||
* moderation, gets its privacy back and the models run again.
|
||||
*/
|
||||
void OnFinishBuilding(const Entity& builder);
|
||||
|
||||
/**
|
||||
* Places a model from the builder's inventory on the property
|
||||
* @param builder the player placing the model
|
||||
* @param id the ID of the model item to place
|
||||
* @param position the position to place the model on
|
||||
* @param rotation the rotation to place the model on
|
||||
*/
|
||||
void UpdateModelPosition(Entity& builder, LWOOBJID id, NiPoint3 position, NiQuaternion rotation);
|
||||
|
||||
/**
|
||||
* Takes a model off the property, into the inventory of the player who placed it
|
||||
* @param builder the player taking the model off
|
||||
* @param id the ID of the model to delete
|
||||
* @param deleteReason the reason of the deletion, e.g. picked up or destroyed (in case of UGC)
|
||||
*/
|
||||
void DeleteModel(Entity& builder, LWOOBJID id, int deleteReason);
|
||||
|
||||
/**
|
||||
* Spawns a model on the property and records it in the property's models (not yet saved)
|
||||
* @param lot the model object's LOT (14 for a brick built model)
|
||||
* @param modelId the model's id in properties_contents (its UGID)
|
||||
* @param config extra config for the model object
|
||||
* @param placedBy the player who placed it
|
||||
*/
|
||||
Entity* SpawnModel(LOT lot, LWOOBJID modelId, const NiPoint3& position, const NiQuaternion& rotation, const LwoNameValue& config, LWOOBJID placedBy);
|
||||
|
||||
/**
|
||||
* Places a model item of the builder's on the property, uses the item up and saves the property
|
||||
* @return the placed model's id, or LWOOBJID_EMPTY if it could not be placed
|
||||
*/
|
||||
LWOOBJID PlaceModelFromItem(const Entity& builder, Item& item, const NiPoint3& position, const NiQuaternion& rotation);
|
||||
|
||||
// The player who placed a model (by its id in properties_contents); the owner for models placed before this was kept
|
||||
LWOOBJID GetPlacedBy(LWOOBJID modelId) const;
|
||||
|
||||
// GetModelsOnProperty with every model on the property
|
||||
void SendModelsOnProperty() const;
|
||||
|
||||
/**
|
||||
* Updates whether or not this property is approved by a moderator
|
||||
* @param value true if the property should be approved, false otherwise
|
||||
*/
|
||||
void UpdateApprovedStatus(bool value, const std::string& rejectionReason = "");
|
||||
|
||||
// A moderator decided on this property from the dashboard (already saved): keep this world's copy in step
|
||||
void ApplyModeration(bool approved, const std::string& reason);
|
||||
|
||||
/**
|
||||
* Loads all the models on this property from the database
|
||||
*/
|
||||
void Load();
|
||||
|
||||
/**
|
||||
* Saves all the models from this property to the database
|
||||
*/
|
||||
void Save();
|
||||
|
||||
/**
|
||||
* Adds a model to the cache of models
|
||||
* @param modelId the ID of the model
|
||||
* @param spawnerId the ID of the object that spawned the model
|
||||
*/
|
||||
void AddModel(LWOOBJID modelId, LWOOBJID spawnerId);
|
||||
|
||||
/**
|
||||
* Returns all the models on this property, indexed by property ID, containing their spawn objects
|
||||
* @return all the models on this proeprty
|
||||
*/
|
||||
const std::map<LWOOBJID, LWOOBJID>& GetModels() const;
|
||||
|
||||
LWOCLONEID GetCloneId() { return clone_Id; };
|
||||
|
||||
LWOOBJID GetId() const noexcept { return propertyId; }
|
||||
|
||||
// Reputation visitors just gave (PropertyReputation.h; the database is updated there), so property data shows it
|
||||
void AddReputation(uint32_t points) { reputation += points; }
|
||||
uint32_t GetReputation() const noexcept { return reputation; }
|
||||
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage) const;
|
||||
|
||||
/**
|
||||
* Live updates (docs/LiveUpdate.md): a new instance of this property is about to load it from the database. Takes
|
||||
* everyone out of build mode, saves, and from then on nobody can build or claim it here and it is never saved again,
|
||||
* so the new instance's saves can't be overwritten by this one.
|
||||
*/
|
||||
void FreezeForHandOff();
|
||||
|
||||
// The hand-off was called off before anyone went to the new instance: building and saving work again
|
||||
void Unfreeze();
|
||||
|
||||
bool IsFrozen() const noexcept { return frozen; }
|
||||
|
||||
// Players in build mode here now
|
||||
size_t GetBuilderCount() const noexcept { return builders.size(); }
|
||||
private:
|
||||
// Sends the property's data to one player; a player who can build is told they own it, which is the client's only
|
||||
// check before editing (the owner's name stays the owner's)
|
||||
void SendPropertyData(const Entity& player, const GameMessages::DownloadPropertyData& message);
|
||||
|
||||
// Whether the player is a best friend of the owner (looked up the first time)
|
||||
bool IsBestFriend(LWOOBJID player) const;
|
||||
|
||||
// OnFinishBuilding without updating who can build; false if they weren't building
|
||||
bool EndBuilding(const Entity& builder);
|
||||
|
||||
/**
|
||||
* This
|
||||
*/
|
||||
static PropertyManagementComponent* instance;
|
||||
|
||||
// Handed off to a new instance for a live update (FreezeForHandOff)
|
||||
bool frozen = false;
|
||||
|
||||
/**
|
||||
* The ID of the owner of this property
|
||||
*/
|
||||
LWOOBJID owner = LWOOBJID_EMPTY;
|
||||
|
||||
/**
|
||||
* The LOT of this console
|
||||
*/
|
||||
uint32_t templateId = 0;
|
||||
|
||||
/**
|
||||
* The unique ID for this property, if it's owned
|
||||
*/
|
||||
LWOOBJID propertyId = LWOOBJID_EMPTY;
|
||||
|
||||
/**
|
||||
* The time since this property was claimed
|
||||
*/
|
||||
uint64_t claimedTime = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
/**
|
||||
* The models that are placed on this property
|
||||
*/
|
||||
std::map<LWOOBJID /* ObjectID */, LWOOBJID /* SpawnerID */> models = {};
|
||||
|
||||
/**
|
||||
* The name of this property
|
||||
*/
|
||||
std::string propertyName = "";
|
||||
|
||||
/**
|
||||
* The clone ID of this property
|
||||
*/
|
||||
LWOCLONEID clone_Id = 0;
|
||||
|
||||
/**
|
||||
* Whether a moderator was requested
|
||||
*/
|
||||
bool moderatorRequested = false;
|
||||
|
||||
/**
|
||||
* The rejection reason for the property
|
||||
*/
|
||||
std::string rejectionReason = "";
|
||||
|
||||
/**
|
||||
* The description of this property
|
||||
*/
|
||||
std::string propertyDescription = "";
|
||||
|
||||
/**
|
||||
* The reputation of this property
|
||||
*/
|
||||
uint32_t reputation = 0;
|
||||
|
||||
/**
|
||||
* The last time this property was updated
|
||||
*/
|
||||
uint32_t LastUpdatedTime = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
/**
|
||||
* Determines which players may visit this property
|
||||
*/
|
||||
PropertyPrivacyOption privacyOption = PropertyPrivacyOption::Private;
|
||||
|
||||
/**
|
||||
* The privacy setting before it was changed, saved to set back after a player finishes building
|
||||
*/
|
||||
PropertyPrivacyOption originalPrivacyOption = PropertyPrivacyOption::Private;
|
||||
|
||||
// Whether each player on the property is a best friend of the owner, looked up once per player (again when the
|
||||
// owner changes)
|
||||
mutable std::map<LWOOBJID, bool> bestFriends;
|
||||
|
||||
// Whether each player on the property was last told they can build (see SendPropertyData)
|
||||
std::map<LWOOBJID, bool> sentBuildRights;
|
||||
|
||||
// Players building right now
|
||||
std::set<LWOOBJID> builders;
|
||||
|
||||
// Who placed each model, by its id in properties_contents (LWOOBJID_EMPTY: the owner)
|
||||
std::map<LWOOBJID, LWOOBJID> placedBy;
|
||||
};
|
||||
17
dGame/dComponents/Property/PropertyPlaqueComponent.h
Normal file
17
dGame/dComponents/Property/PropertyPlaqueComponent.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef PROPERTYPLAQUECOMPONENT_H
|
||||
#define PROPERTYPLAQUECOMPONENT_H
|
||||
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* Property plaque, as the client's LoadPropertyPlaqueComponent makes it from the registry. Nothing of it is sent or done on the server yet.
|
||||
*/
|
||||
class PropertyPlaqueComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_PLAQUE;
|
||||
|
||||
PropertyPlaqueComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
};
|
||||
|
||||
#endif // PROPERTYPLAQUECOMPONENT_H
|
||||
69
dGame/dComponents/Property/PropertyVendorComponent.cpp
Normal file
69
dGame/dComponents/Property/PropertyVendorComponent.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "PropertyVendorComponent.h"
|
||||
#include "ObjectMessages.h"
|
||||
|
||||
#include "PropertyMessages.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Character.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "PropertyManagementComponent.h"
|
||||
#include "UserManager.h"
|
||||
|
||||
PropertyVendorComponent::PropertyVendorComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
RegisterMsg(&PropertyVendorComponent::OnRequestUse);
|
||||
}
|
||||
|
||||
bool PropertyVendorComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
|
||||
if (event.msg.IsMissionChoice()) return false;
|
||||
auto* const originator = event.user;
|
||||
if (PropertyManagementComponent::Instance() == nullptr) return true;
|
||||
|
||||
OnQueryPropertyData(originator, originator->GetSystemAddress());
|
||||
|
||||
if (PropertyManagementComponent::Instance()->GetOwnerId() == LWOOBJID_EMPTY) {
|
||||
LOG("Property vendor opening!");
|
||||
|
||||
GameMessages::OpenPropertyVendor msg;
|
||||
msg.target = m_Parent->GetObjectID();
|
||||
msg.Send(originator->GetSystemAddress());
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PropertyVendorComponent::OnQueryPropertyData(Entity* originator, const SystemAddress& sysAddr) {
|
||||
if (PropertyManagementComponent::Instance() == nullptr) return;
|
||||
|
||||
PropertyManagementComponent::Instance()->OnQueryPropertyData(originator, sysAddr, m_Parent->GetObjectID());
|
||||
}
|
||||
|
||||
void PropertyVendorComponent::OnBuyFromVendor(Entity* originator, const bool confirmed, const LOT lot, const uint32_t count) {
|
||||
if (PropertyManagementComponent::Instance() == nullptr) return;
|
||||
|
||||
if (PropertyManagementComponent::Instance()->Claim(originator->GetObjectID()) == false) {
|
||||
LOG("FAILED TO CLAIM PROPERTY. PLAYER ID IS %llu", originator->GetObjectID());
|
||||
return;
|
||||
}
|
||||
|
||||
GameMessages::PropertyRentalResponse msg;
|
||||
msg.target = m_Parent->GetObjectID();
|
||||
msg.cloneid = 0;
|
||||
msg.code = 0;
|
||||
msg.propertyID = 0;
|
||||
msg.rentdue = 0;
|
||||
msg.Send(originator->GetSystemAddress());
|
||||
|
||||
auto* controller = Game::zoneManager->GetZoneControlObject();
|
||||
|
||||
controller->OnFireEventServerSide(m_Parent, "propertyRented");
|
||||
|
||||
PropertyManagementComponent::Instance()->SetOwner(originator);
|
||||
|
||||
PropertyManagementComponent::Instance()->OnQueryPropertyData(originator, originator->GetSystemAddress());
|
||||
|
||||
LOG("Fired event; (%d) (%i) (%i)", confirmed, lot, count);
|
||||
}
|
||||
|
||||
37
dGame/dComponents/Property/PropertyVendorComponent.h
Normal file
37
dGame/dComponents/Property/PropertyVendorComponent.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "Entity.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* The property guard that stands on a property before it's claimed, allows entities to attempt claiming this property.
|
||||
*/
|
||||
class PropertyVendorComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_VENDOR;
|
||||
explicit PropertyVendorComponent(Entity* parent, const int32_t componentID);
|
||||
|
||||
/**
|
||||
* Handles a use event from some entity, if the property is cleared this allows the entity to claim it
|
||||
* @param originator the entity that triggered this event
|
||||
*/
|
||||
bool OnRequestUse(GameMessages::RequestUseEvent& event);
|
||||
|
||||
/**
|
||||
* Handles a property data query after the property has been claimed, sending information about the property to the
|
||||
* triggering entity.
|
||||
* @param originator the entity that triggered the event
|
||||
* @param sysAddr the system address to send game message response to
|
||||
*/
|
||||
void OnQueryPropertyData(Entity* originator, const SystemAddress& sysAddr);
|
||||
|
||||
/**
|
||||
* Claims the property
|
||||
* @param originator the entity that attempted to claim the property
|
||||
* @param confirmed unused
|
||||
* @param lot unused
|
||||
* @param count unused
|
||||
*/
|
||||
void OnBuyFromVendor(Entity* originator, bool confirmed, LOT lot, uint32_t count);
|
||||
};
|
||||
Reference in New Issue
Block a user