From 666f0213ab91a7de3ce2bc5a55d0e7dde77238e6 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 27 Jul 2023 16:19:19 -0500 Subject: [PATCH] address feedback --- dGame/dComponents/VendorComponent.cpp | 45 ++++++++++++++++++--------- dGame/dComponents/VendorComponent.h | 12 +++---- dZoneManager/dZoneManager.cpp | 2 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/dGame/dComponents/VendorComponent.cpp b/dGame/dComponents/VendorComponent.cpp index f7d77f48..2b54ffe6 100644 --- a/dGame/dComponents/VendorComponent.cpp +++ b/dGame/dComponents/VendorComponent.cpp @@ -1,7 +1,8 @@ #include "VendorComponent.h" #include "BitStream.h" -#include "Game.h" #include "dServer.h" +#include "dZoneManager.h" +#include "WorldConfig.h" #include "CDComponentsRegistryTable.h" #include "CDVendorComponentTable.h" #include "CDLootMatrixTable.h" @@ -32,12 +33,14 @@ void VendorComponent::OnUse(Entity* originator) { void VendorComponent::RefreshInventory(bool isCreation) { SetHasStandardCostItems(false); SetHasMultiCostItems(false); + m_Inventory.clear(); // Custom code for Max vanity NPC and Mr.Ree cameras - MaxCustomVendorRefreshInventory(isCreation); - if(m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) return; + if(isCreation && m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) { + SetupMaxCustomVendor(); + return; + } - m_Inventory.clear(); auto* lootMatrixTable = CDClientManager::Instance().GetTable(); const auto lootMatrices = lootMatrixTable->Query([=](CDLootMatrix entry) { return (entry.LootMatrixIndex == m_LootMatrixID); }); @@ -54,6 +57,10 @@ void VendorComponent::RefreshInventory(bool isCreation) { for (const auto& item : vendorItems) { if (!m_HasStandardCostItems || !m_HasMultiCostItems) { auto itemComponentID = compRegistryTable->GetByIDAndType(item.itemid, eReplicaComponentType::ITEM); + if (itemComponentID != -1) { + Game::logger->Log("VendorComponent", "Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT()); + continue; + } auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID); if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true); if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true); @@ -70,7 +77,7 @@ void VendorComponent::RefreshInventory(bool isCreation) { vendorItems.erase(vendorItems.begin() + randomItemIndex); if (!m_HasStandardCostItems || !m_HasMultiCostItems) { auto itemComponentID = compRegistryTable->GetByIDAndType(randomItem.itemid, eReplicaComponentType::ITEM, -1); - if (itemComponentID == -1) { + if (itemComponentID != -1) { Game::logger->Log("VendorComponent", "Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT()); continue; } @@ -82,6 +89,7 @@ void VendorComponent::RefreshInventory(bool isCreation) { } } } + HandleMrReeCameras(); // Callback timer to refresh this inventory. if (m_RefreshTimeSeconds > 0.0) { @@ -102,24 +110,31 @@ void VendorComponent::SetupConstants() { std::vector vendorComps = vendorComponentTable->Query([=](CDVendorComponent entry) { return (entry.id == componentID); }); if (vendorComps.empty()) return; auto vendorData = vendorComps.at(0); - m_BuyScalar = vendorData.buyScalar; + if (vendorData.buyScalar == 0.0) m_BuyScalar = Game::zoneManager->GetWorldConfig()->vendorBuyMultiplier; + else m_BuyScalar = vendorData.buyScalar; m_SellScalar = vendorData.sellScalar; m_RefreshTimeSeconds = vendorData.refreshTimeSeconds; m_LootMatrixID = vendorData.LootMatrixIndex; } +bool VendorComponent::SellsItem(const LOT item) const { + return std::count_if(m_Inventory.begin(), m_Inventory.end(), [item](const SoldItem& lhs) { + return lhs.lot == item; + }) > 0; +} -void VendorComponent::MaxCustomVendorRefreshInventory(bool isCreation){ - if(isCreation && m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) { - SetHasStandardCostItems(true); - m_Inventory.push_back(SoldItem(11909, 0)); // Top hat w frog - m_Inventory.push_back(SoldItem(7785, 0)); // Flash bulb - m_Inventory.push_back(SoldItem(12764, 0)); // Big fountain soda - m_Inventory.push_back(SoldItem(12241, 0)); // Hot cocoa (from fb) - return; - } +void VendorComponent::SetupMaxCustomVendor(){ + SetHasStandardCostItems(true); + m_Inventory.push_back(SoldItem(11909, 0)); // Top hat w frog + m_Inventory.push_back(SoldItem(7785, 0)); // Flash bulb + m_Inventory.push_back(SoldItem(12764, 0)); // Big fountain soda + m_Inventory.push_back(SoldItem(12241, 0)); // Hot cocoa (from fb) +} + +void VendorComponent::HandleMrReeCameras(){ if (m_Parent->GetLOT() == 13569) { + SetHasStandardCostItems(true); auto randomCamera = GeneralUtils::GenerateRandomNumber(0, 2); LOT camera = 0; diff --git a/dGame/dComponents/VendorComponent.h b/dGame/dComponents/VendorComponent.h index f5a66af7..b2b7d8a6 100644 --- a/dGame/dComponents/VendorComponent.h +++ b/dGame/dComponents/VendorComponent.h @@ -27,12 +27,12 @@ public: void OnUse(Entity* originator) override; void RefreshInventory(bool isCreation = false); void SetupConstants(); + bool SellsItem(const LOT item) const; float GetBuyScalar() const { return m_BuyScalar; } float GetSellScalar() const { return m_SellScalar; } void SetBuyScalar(const float value) { m_BuyScalar = value; } void SetSellScalar(const float value) { m_SellScalar = value; } - - std::vector& GetInventory() { return m_Inventory; } + const std::vector& GetInventory() { return m_Inventory; } void SetHasMultiCostItems(const bool hasMultiCostItems) { if (m_HasMultiCostItems == hasMultiCostItems) return; @@ -46,14 +46,10 @@ public: m_DirtyVendor = true; } - bool SellsItem(const LOT item) const { - return std::count_if(m_Inventory.begin(), m_Inventory.end(), [item](const SoldItem& lhs) { - return lhs.lot == item; - }) > 0; - } - void MaxCustomVendorRefreshInventory(bool isCreation = false); private: + void SetupMaxCustomVendor(); + void HandleMrReeCameras(); float m_BuyScalar = 0.0f; float m_SellScalar = 0.0f; float m_RefreshTimeSeconds = 0.0f; diff --git a/dZoneManager/dZoneManager.cpp b/dZoneManager/dZoneManager.cpp index 51f6e640..7b352a57 100644 --- a/dZoneManager/dZoneManager.cpp +++ b/dZoneManager/dZoneManager.cpp @@ -277,7 +277,7 @@ void dZoneManager::LoadWorldConfig() { m_WorldConfig->characterMaxSlope = worldConfig.getFloatField("character_max_slope"); m_WorldConfig->defaultRespawnTime = worldConfig.getFloatField("defaultrespawntime"); m_WorldConfig->missionTooltipTimeout = worldConfig.getFloatField("mission_tooltip_timeout"); - m_WorldConfig->vendorBuyMultiplier = worldConfig.getFloatField("vendor_buy_multiplier"); + m_WorldConfig->vendorBuyMultiplier = worldConfig.getFloatField("vendor_buy_multiplier", 0.1); m_WorldConfig->petFollowRadius = worldConfig.getFloatField("pet_follow_radius"); m_WorldConfig->characterEyeHeight = worldConfig.getFloatField("character_eye_height"); m_WorldConfig->flightVerticalVelocity = worldConfig.getFloatField("flight_vertical_velocity");