mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-10 02:08:20 +00:00
names and descriptions work
This commit is contained in:
parent
10f8d40b69
commit
abd978c348
@ -660,7 +660,7 @@ void Entity::Initialize() {
|
||||
}
|
||||
|
||||
PetComponent* petComponent;
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0 && !TryGetComponent(eReplicaComponentType::PET, petComponent) && !HasComponent(eReplicaComponentType::MODEL)) {
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::ITEM) > 0) {
|
||||
AddComponent<ItemComponent>();
|
||||
}
|
||||
|
||||
@ -901,6 +901,14 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacke
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
outBitStream.Write<uint16_t>(name[i]);
|
||||
}
|
||||
} else if (HasVar(u"userModelName")) {
|
||||
const auto& name = GetVar<std::string>(u"userModelName");
|
||||
outBitStream.Write<uint8_t>(uint8_t(name.size()));
|
||||
|
||||
for (size_t i = 0; i < name.size(); ++i) {
|
||||
outBitStream.Write<uint16_t>(name[i]);
|
||||
}
|
||||
|
||||
} else {
|
||||
const auto& name = GetVar<std::string>(u"npcName");
|
||||
outBitStream.Write<uint8_t>(uint8_t(name.size()));
|
||||
|
@ -1,5 +1,29 @@
|
||||
#include "ItemComponent.h"
|
||||
|
||||
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
|
||||
outBitStream.Write0();
|
||||
ItemComponent::ItemComponent(Entity* entity) : Component(entity) {
|
||||
m_UgcId = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||
m_Description = GeneralUtils::ASCIIToUTF16(m_Parent->GetVar<std::string>(u"userModelDesc"));
|
||||
m_Dirty = false;
|
||||
m_ModerationStatus = 2;
|
||||
LOG("%s", m_Parent->GetVarAsString(u"userModelDesc").c_str());
|
||||
}
|
||||
|
||||
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
|
||||
outBitStream.Write(m_Dirty || isConstruction);
|
||||
if (m_Dirty || isConstruction) {
|
||||
outBitStream.Write(m_UgcId);
|
||||
outBitStream.Write(m_ModerationStatus);
|
||||
outBitStream.Write(!m_Description.empty());
|
||||
if (!m_Description.empty()) {
|
||||
outBitStream.Write<uint32_t>(m_Description.size());
|
||||
outBitStream.Write(m_Description);
|
||||
}
|
||||
if (!isConstruction) m_Dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemComponent::UpdateDescription(const std::u16string& description) {
|
||||
if (m_Description == description) return;
|
||||
m_Dirty = true;
|
||||
m_Description = description;
|
||||
}
|
||||
|
@ -8,9 +8,16 @@ class ItemComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::ITEM;
|
||||
|
||||
ItemComponent(Entity* entity) : Component(entity) {}
|
||||
ItemComponent(Entity* entity);
|
||||
|
||||
void Serialize(RakNet::BitStream& bitStream, bool isConstruction) override;
|
||||
|
||||
void UpdateDescription(const std::u16string& description);
|
||||
private:
|
||||
std::u16string m_Description;
|
||||
bool m_Dirty = false;
|
||||
LWOOBJID m_UgcId = LWOOBJID_EMPTY;
|
||||
uint32_t m_ModerationStatus = 0;
|
||||
};
|
||||
|
||||
#endif //!__ITEMCOMPONENT__H__
|
||||
|
@ -10,19 +10,9 @@
|
||||
ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
|
||||
m_OriginalPosition = m_Parent->GetDefaultPosition();
|
||||
m_OriginalRotation = m_Parent->GetDefaultRotation();
|
||||
|
||||
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||
}
|
||||
|
||||
void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
// ItemComponent Serialization. Pets do not get this serialization.
|
||||
if (!m_Parent->HasComponent(eReplicaComponentType::PET)) {
|
||||
outBitStream.Write1();
|
||||
outBitStream.Write<LWOOBJID>(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID());
|
||||
outBitStream.Write<int>(0);
|
||||
outBitStream.Write0();
|
||||
}
|
||||
|
||||
//actual model component:
|
||||
outBitStream.Write1(); // Yes we are writing model info
|
||||
outBitStream.Write0(); // Is pickable
|
||||
|
@ -126,9 +126,4 @@ private:
|
||||
* The rotation original of the model
|
||||
*/
|
||||
NiQuaternion m_OriginalRotation;
|
||||
|
||||
/**
|
||||
* The ID of the user that made the model
|
||||
*/
|
||||
LWOOBJID m_userModelID;
|
||||
};
|
||||
|
@ -21,7 +21,9 @@
|
||||
#include "eObjectBits.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "ItemComponent.h"
|
||||
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include "CppScripts.h"
|
||||
|
||||
@ -152,21 +154,39 @@ void PropertyManagementComponent::SetPrivacyOption(PropertyPrivacyOption value)
|
||||
Database::Get()->UpdatePropertyModerationInfo(info);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::string description) {
|
||||
void PropertyManagementComponent::UpdatePropertyDetails(const UpdatePropertyWithFilterCheck& update) {
|
||||
if (owner == LWOOBJID_EMPTY) return;
|
||||
|
||||
propertyName = name;
|
||||
if (update.isProperty) {
|
||||
propertyName = update.name;
|
||||
|
||||
propertyDescription = description;
|
||||
propertyDescription = update.description;
|
||||
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.name = propertyName;
|
||||
info.description = propertyDescription;
|
||||
IProperty::Info info;
|
||||
info.id = propertyId;
|
||||
info.name = propertyName;
|
||||
info.description = propertyDescription;
|
||||
|
||||
Database::Get()->UpdatePropertyDetails(info);
|
||||
Database::Get()->UpdatePropertyDetails(info);
|
||||
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
} else {
|
||||
auto* entity = Game::entityManager->GetEntity(update.worldId);
|
||||
if (!entity) return;
|
||||
|
||||
entity->SetVar<std::string>(u"userModelName", update.name);
|
||||
entity->SetVar<std::string>(u"userModelDesc", update.description);
|
||||
auto* owner = GetOwner();
|
||||
if (!owner) return;
|
||||
|
||||
GameMessages::SendSetName(update.worldId, GeneralUtils::ASCIIToUTF16(update.name), owner->GetSystemAddress());
|
||||
auto* itemComponent = entity->GetComponent<ItemComponent>();
|
||||
if (itemComponent) {
|
||||
itemComponent->UpdateDescription(GeneralUtils::ASCIIToUTF16(update.description));
|
||||
}
|
||||
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
@ -195,7 +215,7 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
|
||||
auto prop_path = zone->GetPath(m_Parent->GetVarAsString(u"propertyName"));
|
||||
|
||||
if (prop_path){
|
||||
if (prop_path) {
|
||||
if (!prop_path->property.displayName.empty()) name = prop_path->property.displayName;
|
||||
description = prop_path->property.displayDesc;
|
||||
}
|
||||
@ -325,12 +345,13 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
return;
|
||||
}
|
||||
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
auto* node = new SpawnerNode();
|
||||
|
||||
node->position = position;
|
||||
node->rotation = rotation;
|
||||
node->config = item->GetConfig();
|
||||
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
ObjectIDManager::RequestPersistentID([this, node, modelLOT, entity, position, rotation, originalRotation](uint32_t persistentId) {
|
||||
SpawnerInfo info{};
|
||||
@ -484,7 +505,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
return;
|
||||
}
|
||||
|
||||
inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::DELETION, INVALID, {}, LWOOBJID_EMPTY, false);
|
||||
inventoryComponent->AddItem(model->GetLOT(), 1, eLootSourceType::DELETION, INVALID, model->GetSettings(), LWOOBJID_EMPTY, false);
|
||||
|
||||
auto* item = inventoryComponent->FindItemByLot(model->GetLOT());
|
||||
|
||||
|
@ -17,12 +17,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
|
||||
};
|
||||
|
||||
/**
|
||||
@ -30,6 +30,13 @@ enum class PropertyPrivacyOption {
|
||||
*/
|
||||
class PropertyManagementComponent final : public Component {
|
||||
public:
|
||||
struct UpdatePropertyWithFilterCheck {
|
||||
LWOOBJID objectId;
|
||||
LWOOBJID worldId;
|
||||
bool isProperty;
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY_MANAGEMENT;
|
||||
PropertyManagementComponent(Entity* parent);
|
||||
static PropertyManagementComponent* Instance();
|
||||
@ -95,7 +102,7 @@ public:
|
||||
* @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);
|
||||
void UpdatePropertyDetails(const UpdatePropertyWithFilterCheck& update);
|
||||
|
||||
/**
|
||||
* Makes this property owned by the passed player ID, storing it in the database
|
||||
|
@ -2207,19 +2207,17 @@ void GameMessages::HandleUnUseModel(RakNet::BitStream& inStream, Entity* entity,
|
||||
}
|
||||
|
||||
void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
bool isProperty{};
|
||||
LWOOBJID objectId{};
|
||||
PropertyManagementComponent::UpdatePropertyWithFilterCheck filterCheck{};
|
||||
LWOOBJID playerId{};
|
||||
LWOOBJID worldId{};
|
||||
uint32_t nameLength{};
|
||||
std::u16string name{};
|
||||
uint32_t descriptionLength{};
|
||||
std::u16string description{};
|
||||
|
||||
inStream.Read(isProperty);
|
||||
inStream.Read(objectId);
|
||||
inStream.Read(filterCheck.isProperty);
|
||||
inStream.Read(filterCheck.objectId);
|
||||
inStream.Read(playerId);
|
||||
inStream.Read(worldId);
|
||||
inStream.Read(filterCheck.worldId);
|
||||
|
||||
inStream.Read(descriptionLength);
|
||||
for (uint32_t i = 0; i < descriptionLength; ++i) {
|
||||
@ -2227,6 +2225,7 @@ void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream&
|
||||
inStream.Read(character);
|
||||
description.push_back(character);
|
||||
}
|
||||
filterCheck.description = GeneralUtils::UTF16ToWTF8(description);
|
||||
|
||||
inStream.Read(nameLength);
|
||||
for (uint32_t i = 0; i < nameLength; ++i) {
|
||||
@ -2234,8 +2233,11 @@ void GameMessages::HandleUpdatePropertyOrModelForFilterCheck(RakNet::BitStream&
|
||||
inStream.Read(character);
|
||||
name.push_back(character);
|
||||
}
|
||||
filterCheck.name = GeneralUtils::UTF16ToWTF8(name);
|
||||
LOG("names %s desc %s", filterCheck.name.c_str(), filterCheck.description.c_str());
|
||||
if (filterCheck.name.empty() || filterCheck.description.empty()) return;
|
||||
|
||||
PropertyManagementComponent::Instance()->UpdatePropertyDetails(GeneralUtils::UTF16ToWTF8(name), GeneralUtils::UTF16ToWTF8(description));
|
||||
PropertyManagementComponent::Instance()->UpdatePropertyDetails(filterCheck);
|
||||
}
|
||||
|
||||
void GameMessages::HandleQueryPropertyData(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
|
@ -529,12 +529,6 @@ void Item::RemoveFromInventory() {
|
||||
|
||||
Item::~Item() {
|
||||
delete preconditions;
|
||||
|
||||
for (auto* value : config) {
|
||||
delete value;
|
||||
}
|
||||
|
||||
config.clear();
|
||||
}
|
||||
|
||||
void Item::SaveConfigXml(tinyxml2::XMLElement& i) const {
|
||||
|
Loading…
Reference in New Issue
Block a user