From 8a9883c224da968d94c8dcea793a9d5f7743a805 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Tue, 14 Nov 2023 07:02:17 -0600 Subject: [PATCH] feat: use more zoneTable options (#1273) * feat: use more zoneTable options Allow setting framrate for the zone Allow setting if pets are allowed in the zone Allow setting if mounts are allowed in a zone Allow disabling saving location to a zone * address feedback --- dDatabase/Tables/CDZoneTableTable.cpp | 6 ++--- dDatabase/Tables/CDZoneTableTable.h | 6 ++--- dGame/Character.cpp | 2 +- .../ControllablePhysicsComponent.cpp | 2 +- dGame/dInventory/Item.cpp | 21 ++++++++++----- dWorldServer/PerformanceManager.cpp | 26 ++++++++++++++++--- dZoneManager/dZoneManager.cpp | 3 +++ dZoneManager/dZoneManager.h | 8 +++++- 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/dDatabase/Tables/CDZoneTableTable.cpp b/dDatabase/Tables/CDZoneTableTable.cpp index 1030593e..2793ccb9 100644 --- a/dDatabase/Tables/CDZoneTableTable.cpp +++ b/dDatabase/Tables/CDZoneTableTable.cpp @@ -31,7 +31,7 @@ void CDZoneTableTable::LoadValuesFromDatabase() { entry.smashableMaxDistance = tableData.getFloatField("smashableMaxDistance", -1.0f); UNUSED(entry.mixerProgram = tableData.getStringField("mixerProgram", "")); UNUSED(entry.clientPhysicsFramerate = tableData.getStringField("clientPhysicsFramerate", "")); - UNUSED(entry.serverPhysicsFramerate = tableData.getStringField("serverPhysicsFramerate", "")); + entry.serverPhysicsFramerate = tableData.getStringField("serverPhysicsFramerate", ""); entry.zoneControlTemplate = tableData.getIntField("zoneControlTemplate", -1); entry.widthInChunks = tableData.getIntField("widthInChunks", -1); entry.heightInChunks = tableData.getIntField("heightInChunks", -1); @@ -40,10 +40,10 @@ void CDZoneTableTable::LoadValuesFromDatabase() { entry.fZoneWeight = tableData.getFloatField("fZoneWeight", -1.0f); UNUSED(entry.thumbnail = tableData.getStringField("thumbnail", "")); entry.PlayerLoseCoinsOnDeath = tableData.getIntField("PlayerLoseCoinsOnDeath", -1) == 1 ? true : false; - UNUSED(entry.disableSaveLoc = tableData.getIntField("disableSaveLoc", -1) == 1 ? true : false); + entry.disableSaveLoc = tableData.getIntField("disableSaveLoc", -1) == 1 ? true : false; entry.teamRadius = tableData.getFloatField("teamRadius", -1.0f); UNUSED(entry.gate_version = tableData.getStringField("gate_version", "")); - UNUSED(entry.mountsAllowed = tableData.getIntField("mountsAllowed", -1) == 1 ? true : false); + entry.mountsAllowed = tableData.getIntField("mountsAllowed", -1) == 1 ? true : false; this->m_Entries.insert(std::make_pair(entry.zoneID, entry)); tableData.nextRow(); diff --git a/dDatabase/Tables/CDZoneTableTable.h b/dDatabase/Tables/CDZoneTableTable.h index fef8096f..c3f51aa6 100644 --- a/dDatabase/Tables/CDZoneTableTable.h +++ b/dDatabase/Tables/CDZoneTableTable.h @@ -18,7 +18,7 @@ struct CDZoneTable { float smashableMaxDistance; //!< The maximum smashable distance? UNUSED(std::string mixerProgram); //!< ??? UNUSED(std::string clientPhysicsFramerate); //!< The client physics framerate - UNUSED(std::string serverPhysicsFramerate); //!< The server physics framerate + std::string serverPhysicsFramerate; //!< The server physics framerate unsigned int zoneControlTemplate; //!< The Zone Control template unsigned int widthInChunks; //!< The width of the world in chunks unsigned int heightInChunks; //!< The height of the world in chunks @@ -27,10 +27,10 @@ struct CDZoneTable { float fZoneWeight; //!< ??? UNUSED(std::string thumbnail); //!< The thumbnail of the world bool PlayerLoseCoinsOnDeath; //!< Whether or not the user loses coins on death - UNUSED(bool disableSaveLoc); //!< Disables the saving location? + bool disableSaveLoc; //!< Disables the saving location? float teamRadius; //!< ??? UNUSED(std::string gate_version); //!< The gate version - UNUSED(bool mountsAllowed); //!< Whether or not mounts are allowed + bool mountsAllowed; //!< Whether or not mounts are allowed }; class CDZoneTableTable : public CDTable { diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 401af2d4..7259602f 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -314,7 +314,7 @@ void Character::SaveXMLToDatabase() { auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID(); // lzid garbage, binary concat of zoneID, zoneInstance and zoneClone - if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0) { + if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) { uint64_t lzidConcat = zoneInfo.GetCloneID(); lzidConcat = (lzidConcat << 16) | uint16_t(zoneInfo.GetInstanceID()); lzidConcat = (lzidConcat << 16) | uint16_t(zoneInfo.GetMapID()); diff --git a/dGame/dComponents/ControllablePhysicsComponent.cpp b/dGame/dComponents/ControllablePhysicsComponent.cpp index 08281ed5..dd981f66 100644 --- a/dGame/dComponents/ControllablePhysicsComponent.cpp +++ b/dGame/dComponents/ControllablePhysicsComponent.cpp @@ -187,7 +187,7 @@ void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) { auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID(); - if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0) { + if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0 && !Game::zoneManager->GetDisableSaveLocation()) { character->SetAttribute("lzx", m_Position.x); character->SetAttribute("lzy", m_Position.y); character->SetAttribute("lzz", m_Position.z); diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index a585e60e..6a0fd82b 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -19,6 +19,8 @@ #include "eObjectBits.h" #include "eReplicaComponentType.h" #include "eUseItemResponse.h" +#include "dZoneManager.h" +#include "ChatPackets.h" #include "CDBrickIDTableTable.h" #include "CDObjectSkillsTable.h" @@ -292,12 +294,19 @@ void Item::UseNonEquip(Item* item) { const auto type = static_cast(info->itemType); if (type == eItemType::MOUNT) { - playerInventoryComponent->HandlePossession(this); - // TODO Check if mounts are allowed to be spawned - } else if (type == eItemType::PET_INVENTORY_ITEM && subKey != LWOOBJID_EMPTY) { - const auto& databasePet = playerInventoryComponent->GetDatabasePet(subKey); - if (databasePet.lot != LOT_NULL) { - playerInventoryComponent->SpawnPet(this); + if (Game::zoneManager->GetMountsAllowed()){ + playerInventoryComponent->HandlePossession(this); + } else { + ChatPackets::SendSystemMessage(playerEntity->GetSystemAddress(), u"Mounts are not allowed in this zone"); + } + } else if (type == eItemType::PET_INVENTORY_ITEM && subKey != LWOOBJID_EMPTY ) { + if (Game::zoneManager->GetPetsAllowed()){ + const auto& databasePet = playerInventoryComponent->GetDatabasePet(subKey); + if (databasePet.lot != LOT_NULL) { + playerInventoryComponent->SpawnPet(this); + } + } else { + ChatPackets::SendSystemMessage(playerEntity->GetSystemAddress(), u"Pets are not allowed in this zone"); } // This precondition response is taken care of in SpawnPet(). } else { diff --git a/dWorldServer/PerformanceManager.cpp b/dWorldServer/PerformanceManager.cpp index 19f38d00..248be54a 100644 --- a/dWorldServer/PerformanceManager.cpp +++ b/dWorldServer/PerformanceManager.cpp @@ -1,5 +1,6 @@ #include "PerformanceManager.h" - +#include "CDZoneTableTable.h" +#include "CDClientManager.h" #include "UserManager.h" #define SOCIAL { lowFrameDelta } @@ -68,11 +69,30 @@ std::map PerformanceManager::m_Profiles = { }; void PerformanceManager::SelectProfile(LWOMAPID mapID) { - const auto pair = m_Profiles.find(mapID); + // Try to get it from zoneTable + CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable(); + if (zoneTable) { + const CDZoneTable* zone = zoneTable->Query(mapID); + if (zone) { + if (zone->serverPhysicsFramerate == "high"){ + m_CurrentProfile = { highFrameDelta }; + return; + } + if (zone->serverPhysicsFramerate == "medium"){ + m_CurrentProfile = { mediumFrameDelta }; + return; + } + if (zone->serverPhysicsFramerate == "low"){ + m_CurrentProfile = { lowFrameDelta }; + return; + } + } + } + // Fall back to hardcoded list and defaults + const auto pair = m_Profiles.find(mapID); if (pair == m_Profiles.end()) { m_CurrentProfile = m_DefaultProfile; - return; } diff --git a/dZoneManager/dZoneManager.cpp b/dZoneManager/dZoneManager.cpp index c87619cd..137a9cab 100644 --- a/dZoneManager/dZoneManager.cpp +++ b/dZoneManager/dZoneManager.cpp @@ -40,6 +40,9 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) { Game::entityManager->SetGhostDistanceMax(max + min); Game::entityManager->SetGhostDistanceMin(max); m_PlayerLoseCoinsOnDeath = zone->PlayerLoseCoinsOnDeath; + m_DisableSaveLocation = zone->disableSaveLoc; + m_MountsAllowed = zone->mountsAllowed; + m_PetsAllowed = zone->petsAllowed; } } diff --git a/dZoneManager/dZoneManager.h b/dZoneManager/dZoneManager.h index 1e08b008..b5db3f6e 100644 --- a/dZoneManager/dZoneManager.h +++ b/dZoneManager/dZoneManager.h @@ -41,6 +41,9 @@ public: void Update(float deltaTime); Entity* GetZoneControlObject() { return m_ZoneControlObject; } bool GetPlayerLoseCoinOnDeath() { return m_PlayerLoseCoinsOnDeath; } + bool GetDisableSaveLocation() { return m_DisableSaveLocation; } + bool GetMountsAllowed() { return m_MountsAllowed; } + bool GetPetsAllowed() { return m_PetsAllowed; } uint32_t GetUniqueMissionIdStartingValue(); bool CheckIfAccessibleZone(LWOMAPID zoneID); @@ -58,7 +61,10 @@ private: Zone* m_pZone = nullptr; LWOZONEID m_ZoneID; - bool m_PlayerLoseCoinsOnDeath; //Do players drop coins in this zone when smashed + bool m_PlayerLoseCoinsOnDeath = false; + bool m_DisableSaveLocation = false; + bool m_MountsAllowed = true; + bool m_PetsAllowed = true; std::map m_Spawners; WorldConfig* m_WorldConfig = nullptr;